Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 62 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 94 | |
| 95 | if (result) |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | if (result) |
| 100 | return result; |
| 101 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 104 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 108 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 109 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 110 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 113 | !attrs[NL80211_ATTR_IFINDEX] && |
| 114 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 115 | return ERR_PTR(-EINVAL); |
| 116 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 121 | if (attrs[NL80211_ATTR_WDEV]) { |
| 122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 123 | struct wireless_dev *wdev; |
| 124 | bool found = false; |
| 125 | |
| 126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 127 | if (tmp) { |
| 128 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 129 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 130 | if (wdev->identifier != (u32)wdev_id) |
| 131 | continue; |
| 132 | found = true; |
| 133 | break; |
| 134 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | |
| 136 | if (!found) |
| 137 | tmp = NULL; |
| 138 | |
| 139 | if (rdev && tmp != rdev) |
| 140 | return ERR_PTR(-EINVAL); |
| 141 | rdev = tmp; |
| 142 | } |
| 143 | } |
| 144 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 145 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 146 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 147 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 148 | if (netdev) { |
| 149 | if (netdev->ieee80211_ptr) |
| 150 | tmp = wiphy_to_dev( |
| 151 | netdev->ieee80211_ptr->wiphy); |
| 152 | else |
| 153 | tmp = NULL; |
| 154 | |
| 155 | dev_put(netdev); |
| 156 | |
| 157 | /* not wireless device -- return error */ |
| 158 | if (!tmp) |
| 159 | return ERR_PTR(-EINVAL); |
| 160 | |
| 161 | /* mismatch -- return error */ |
| 162 | if (rdev && tmp != rdev) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 166 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 169 | if (!rdev) |
| 170 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (netns != wiphy_net(&rdev->wiphy)) |
| 173 | return ERR_PTR(-ENODEV); |
| 174 | |
| 175 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
| 179 | * This function returns a pointer to the driver |
| 180 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | * |
| 182 | * The result of this can be a PTR_ERR and hence must |
| 183 | * be checked with IS_ERR() for errors. |
| 184 | */ |
| 185 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 186 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 188 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 191 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 192 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 193 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 194 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 195 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 196 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 197 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 198 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 199 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 200 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 201 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 202 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 203 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 204 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 205 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 206 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 207 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 208 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 209 | |
| 210 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 211 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 212 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 213 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 214 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 215 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 216 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 218 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 219 | .len = WLAN_MAX_KEY_LEN }, |
| 220 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 221 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 225 | |
| 226 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 228 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 229 | .len = IEEE80211_MAX_DATA_LEN }, |
| 230 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 231 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 232 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 233 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 234 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 235 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 236 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 239 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 240 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 241 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 242 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 243 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 244 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 245 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 246 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 247 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 248 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 249 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 250 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 251 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 252 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 253 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 256 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 258 | |
| 259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 264 | |
| 265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 266 | .len = IEEE80211_MAX_SSID_LEN }, |
| 267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 272 | [NL80211_ATTR_STA_FLAGS2] = { |
| 273 | .len = sizeof(struct nl80211_sta_flag_update), |
| 274 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 284 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_DATA_LEN }, |
| 290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 327 | .len = NL80211_HT_CAPABILITY_LEN |
| 328 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 347 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 350 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 353 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 354 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 355 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 356 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 357 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 358 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 359 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 360 | }; |
| 361 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 362 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 363 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 364 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 365 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 366 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 367 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 368 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 369 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 370 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 371 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 372 | }; |
| 373 | |
| 374 | /* policy for the key default flags */ |
| 375 | static const struct nla_policy |
| 376 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 377 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 378 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 379 | }; |
| 380 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 381 | /* policy for WoWLAN attributes */ |
| 382 | static const struct nla_policy |
| 383 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 384 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 385 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 386 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 387 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 388 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 389 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 390 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 391 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 392 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 393 | }; |
| 394 | |
| 395 | static const struct nla_policy |
| 396 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 397 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 398 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 399 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 400 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 401 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 402 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 403 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 404 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 405 | }, |
| 406 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 407 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 408 | }, |
| 409 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 410 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 411 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 412 | }; |
| 413 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 414 | /* policy for coalesce rule attributes */ |
| 415 | static const struct nla_policy |
| 416 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 417 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 418 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 419 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 420 | }; |
| 421 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 422 | /* policy for GTK rekey offload attributes */ |
| 423 | static const struct nla_policy |
| 424 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 425 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 426 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 427 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 428 | }; |
| 429 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 430 | static const struct nla_policy |
| 431 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 432 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 433 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 434 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 435 | }; |
| 436 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 437 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 438 | struct netlink_callback *cb, |
| 439 | struct cfg80211_registered_device **rdev, |
| 440 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 441 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 442 | int err; |
| 443 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 444 | rtnl_lock(); |
| 445 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 446 | if (!cb->args[0]) { |
| 447 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 448 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 449 | nl80211_policy); |
| 450 | if (err) |
| 451 | goto out_unlock; |
| 452 | |
| 453 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 454 | nl80211_fam.attrbuf); |
| 455 | if (IS_ERR(*wdev)) { |
| 456 | err = PTR_ERR(*wdev); |
| 457 | goto out_unlock; |
| 458 | } |
| 459 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 460 | /* 0 is the first index - add 1 to parse only once */ |
| 461 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 462 | cb->args[1] = (*wdev)->identifier; |
| 463 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 464 | /* subtract the 1 again here */ |
| 465 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 466 | struct wireless_dev *tmp; |
| 467 | |
| 468 | if (!wiphy) { |
| 469 | err = -ENODEV; |
| 470 | goto out_unlock; |
| 471 | } |
| 472 | *rdev = wiphy_to_dev(wiphy); |
| 473 | *wdev = NULL; |
| 474 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 475 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 476 | if (tmp->identifier == cb->args[1]) { |
| 477 | *wdev = tmp; |
| 478 | break; |
| 479 | } |
| 480 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 481 | |
| 482 | if (!*wdev) { |
| 483 | err = -ENODEV; |
| 484 | goto out_unlock; |
| 485 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 486 | } |
| 487 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 488 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 489 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 490 | rtnl_unlock(); |
| 491 | return err; |
| 492 | } |
| 493 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 494 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 495 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 496 | rtnl_unlock(); |
| 497 | } |
| 498 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 499 | /* IE validation */ |
| 500 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 501 | { |
| 502 | const u8 *pos; |
| 503 | int len; |
| 504 | |
| 505 | if (!attr) |
| 506 | return true; |
| 507 | |
| 508 | pos = nla_data(attr); |
| 509 | len = nla_len(attr); |
| 510 | |
| 511 | while (len) { |
| 512 | u8 elemlen; |
| 513 | |
| 514 | if (len < 2) |
| 515 | return false; |
| 516 | len -= 2; |
| 517 | |
| 518 | elemlen = pos[1]; |
| 519 | if (elemlen > len) |
| 520 | return false; |
| 521 | |
| 522 | len -= elemlen; |
| 523 | pos += 2 + elemlen; |
| 524 | } |
| 525 | |
| 526 | return true; |
| 527 | } |
| 528 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 529 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 530 | 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] | 531 | int flags, u8 cmd) |
| 532 | { |
| 533 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 534 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 535 | } |
| 536 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 537 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 538 | struct ieee80211_channel *chan, |
| 539 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 540 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 541 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 542 | chan->center_freq)) |
| 543 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 544 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 545 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 546 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 547 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 548 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 549 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 550 | goto nla_put_failure; |
| 551 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 552 | goto nla_put_failure; |
| 553 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 554 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 555 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 556 | goto nla_put_failure; |
| 557 | if (large) { |
| 558 | u32 time; |
| 559 | |
| 560 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 561 | |
| 562 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 563 | chan->dfs_state)) |
| 564 | goto nla_put_failure; |
| 565 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 566 | time)) |
| 567 | goto nla_put_failure; |
| 568 | } |
| 569 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 570 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 571 | if (large) { |
| 572 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 573 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 574 | goto nla_put_failure; |
| 575 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 576 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 577 | goto nla_put_failure; |
| 578 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 579 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 580 | goto nla_put_failure; |
| 581 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 582 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 583 | goto nla_put_failure; |
| 584 | } |
| 585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 586 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 587 | DBM_TO_MBM(chan->max_power))) |
| 588 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 589 | |
| 590 | return 0; |
| 591 | |
| 592 | nla_put_failure: |
| 593 | return -ENOBUFS; |
| 594 | } |
| 595 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 596 | /* netlink command implementations */ |
| 597 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 598 | struct key_parse { |
| 599 | struct key_params p; |
| 600 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 601 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 602 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 603 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 604 | }; |
| 605 | |
| 606 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 607 | { |
| 608 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 609 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 610 | nl80211_key_policy); |
| 611 | if (err) |
| 612 | return err; |
| 613 | |
| 614 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 615 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 616 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 617 | if (k->def) { |
| 618 | k->def_uni = true; |
| 619 | k->def_multi = true; |
| 620 | } |
| 621 | if (k->defmgmt) |
| 622 | k->def_multi = true; |
| 623 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 624 | if (tb[NL80211_KEY_IDX]) |
| 625 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 626 | |
| 627 | if (tb[NL80211_KEY_DATA]) { |
| 628 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 629 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 630 | } |
| 631 | |
| 632 | if (tb[NL80211_KEY_SEQ]) { |
| 633 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 634 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 635 | } |
| 636 | |
| 637 | if (tb[NL80211_KEY_CIPHER]) |
| 638 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 639 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 640 | if (tb[NL80211_KEY_TYPE]) { |
| 641 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 642 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 643 | return -EINVAL; |
| 644 | } |
| 645 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 646 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 647 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 648 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 649 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 650 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 651 | if (err) |
| 652 | return err; |
| 653 | |
| 654 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 655 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 656 | } |
| 657 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 662 | { |
| 663 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 664 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 665 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 666 | } |
| 667 | |
| 668 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 669 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 670 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 671 | } |
| 672 | |
| 673 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 674 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 675 | |
| 676 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 677 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 678 | |
| 679 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 680 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 681 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 682 | if (k->def) { |
| 683 | k->def_uni = true; |
| 684 | k->def_multi = true; |
| 685 | } |
| 686 | if (k->defmgmt) |
| 687 | k->def_multi = true; |
| 688 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 689 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 690 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 691 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 692 | return -EINVAL; |
| 693 | } |
| 694 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 695 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 696 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 697 | int err = nla_parse_nested( |
| 698 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 699 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 700 | nl80211_key_default_policy); |
| 701 | if (err) |
| 702 | return err; |
| 703 | |
| 704 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 705 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 706 | } |
| 707 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 712 | { |
| 713 | int err; |
| 714 | |
| 715 | memset(k, 0, sizeof(*k)); |
| 716 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 717 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 718 | |
| 719 | if (info->attrs[NL80211_ATTR_KEY]) |
| 720 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 721 | else |
| 722 | err = nl80211_parse_key_old(info, k); |
| 723 | |
| 724 | if (err) |
| 725 | return err; |
| 726 | |
| 727 | if (k->def && k->defmgmt) |
| 728 | return -EINVAL; |
| 729 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 730 | if (k->defmgmt) { |
| 731 | if (k->def_uni || !k->def_multi) |
| 732 | return -EINVAL; |
| 733 | } |
| 734 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 735 | if (k->idx != -1) { |
| 736 | if (k->defmgmt) { |
| 737 | if (k->idx < 4 || k->idx > 5) |
| 738 | return -EINVAL; |
| 739 | } else if (k->def) { |
| 740 | if (k->idx < 0 || k->idx > 3) |
| 741 | return -EINVAL; |
| 742 | } else { |
| 743 | if (k->idx < 0 || k->idx > 5) |
| 744 | return -EINVAL; |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 751 | static struct cfg80211_cached_keys * |
| 752 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 753 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 754 | { |
| 755 | struct key_parse parse; |
| 756 | struct nlattr *key; |
| 757 | struct cfg80211_cached_keys *result; |
| 758 | int rem, err, def = 0; |
| 759 | |
| 760 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 761 | if (!result) |
| 762 | return ERR_PTR(-ENOMEM); |
| 763 | |
| 764 | result->def = -1; |
| 765 | result->defmgmt = -1; |
| 766 | |
| 767 | nla_for_each_nested(key, keys, rem) { |
| 768 | memset(&parse, 0, sizeof(parse)); |
| 769 | parse.idx = -1; |
| 770 | |
| 771 | err = nl80211_parse_key_new(key, &parse); |
| 772 | if (err) |
| 773 | goto error; |
| 774 | err = -EINVAL; |
| 775 | if (!parse.p.key) |
| 776 | goto error; |
| 777 | if (parse.idx < 0 || parse.idx > 4) |
| 778 | goto error; |
| 779 | if (parse.def) { |
| 780 | if (def) |
| 781 | goto error; |
| 782 | def = 1; |
| 783 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 784 | if (!parse.def_uni || !parse.def_multi) |
| 785 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 786 | } else if (parse.defmgmt) |
| 787 | goto error; |
| 788 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 789 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 790 | if (err) |
| 791 | goto error; |
| 792 | result->params[parse.idx].cipher = parse.p.cipher; |
| 793 | result->params[parse.idx].key_len = parse.p.key_len; |
| 794 | result->params[parse.idx].key = result->data[parse.idx]; |
| 795 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 796 | |
| 797 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 798 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 799 | if (no_ht) |
| 800 | *no_ht = true; |
| 801 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | return result; |
| 805 | error: |
| 806 | kfree(result); |
| 807 | return ERR_PTR(err); |
| 808 | } |
| 809 | |
| 810 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 811 | { |
| 812 | ASSERT_WDEV_LOCK(wdev); |
| 813 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 814 | switch (wdev->iftype) { |
| 815 | case NL80211_IFTYPE_AP: |
| 816 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 817 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 818 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 819 | break; |
| 820 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 821 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 822 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 823 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 824 | return -ENOLINK; |
| 825 | break; |
| 826 | default: |
| 827 | return -EINVAL; |
| 828 | } |
| 829 | |
| 830 | return 0; |
| 831 | } |
| 832 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 833 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 834 | { |
| 835 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 836 | int i; |
| 837 | |
| 838 | if (!nl_modes) |
| 839 | goto nla_put_failure; |
| 840 | |
| 841 | i = 0; |
| 842 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 843 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 844 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 845 | ifmodes >>= 1; |
| 846 | i++; |
| 847 | } |
| 848 | |
| 849 | nla_nest_end(msg, nl_modes); |
| 850 | return 0; |
| 851 | |
| 852 | nla_put_failure: |
| 853 | return -ENOBUFS; |
| 854 | } |
| 855 | |
| 856 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 857 | struct sk_buff *msg, |
| 858 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 859 | { |
| 860 | struct nlattr *nl_combis; |
| 861 | int i, j; |
| 862 | |
| 863 | nl_combis = nla_nest_start(msg, |
| 864 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 865 | if (!nl_combis) |
| 866 | goto nla_put_failure; |
| 867 | |
| 868 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 869 | const struct ieee80211_iface_combination *c; |
| 870 | struct nlattr *nl_combi, *nl_limits; |
| 871 | |
| 872 | c = &wiphy->iface_combinations[i]; |
| 873 | |
| 874 | nl_combi = nla_nest_start(msg, i + 1); |
| 875 | if (!nl_combi) |
| 876 | goto nla_put_failure; |
| 877 | |
| 878 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 879 | if (!nl_limits) |
| 880 | goto nla_put_failure; |
| 881 | |
| 882 | for (j = 0; j < c->n_limits; j++) { |
| 883 | struct nlattr *nl_limit; |
| 884 | |
| 885 | nl_limit = nla_nest_start(msg, j + 1); |
| 886 | if (!nl_limit) |
| 887 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 888 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 889 | c->limits[j].max)) |
| 890 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 891 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 892 | c->limits[j].types)) |
| 893 | goto nla_put_failure; |
| 894 | nla_nest_end(msg, nl_limit); |
| 895 | } |
| 896 | |
| 897 | nla_nest_end(msg, nl_limits); |
| 898 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 899 | if (c->beacon_int_infra_match && |
| 900 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 901 | goto nla_put_failure; |
| 902 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 903 | c->num_different_channels) || |
| 904 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 905 | c->max_interfaces)) |
| 906 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 907 | if (large && |
| 908 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 909 | c->radar_detect_widths)) |
| 910 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 911 | |
| 912 | nla_nest_end(msg, nl_combi); |
| 913 | } |
| 914 | |
| 915 | nla_nest_end(msg, nl_combis); |
| 916 | |
| 917 | return 0; |
| 918 | nla_put_failure: |
| 919 | return -ENOBUFS; |
| 920 | } |
| 921 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 922 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 923 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 924 | struct sk_buff *msg) |
| 925 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 926 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 927 | struct nlattr *nl_tcp; |
| 928 | |
| 929 | if (!tcp) |
| 930 | return 0; |
| 931 | |
| 932 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 933 | if (!nl_tcp) |
| 934 | return -ENOBUFS; |
| 935 | |
| 936 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 937 | tcp->data_payload_max)) |
| 938 | return -ENOBUFS; |
| 939 | |
| 940 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 941 | tcp->data_payload_max)) |
| 942 | return -ENOBUFS; |
| 943 | |
| 944 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 945 | return -ENOBUFS; |
| 946 | |
| 947 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 948 | sizeof(*tcp->tok), tcp->tok)) |
| 949 | return -ENOBUFS; |
| 950 | |
| 951 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 952 | tcp->data_interval_max)) |
| 953 | return -ENOBUFS; |
| 954 | |
| 955 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 956 | tcp->wake_payload_max)) |
| 957 | return -ENOBUFS; |
| 958 | |
| 959 | nla_nest_end(msg, nl_tcp); |
| 960 | return 0; |
| 961 | } |
| 962 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 963 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 964 | struct cfg80211_registered_device *dev, |
| 965 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 966 | { |
| 967 | struct nlattr *nl_wowlan; |
| 968 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 969 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 970 | return 0; |
| 971 | |
| 972 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 973 | if (!nl_wowlan) |
| 974 | return -ENOBUFS; |
| 975 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 976 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 977 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 978 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 979 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 980 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 981 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 982 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 983 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 984 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 985 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 986 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 987 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 988 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 989 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 990 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 991 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 992 | return -ENOBUFS; |
| 993 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 994 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 995 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 996 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 997 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 998 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 999 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1000 | }; |
| 1001 | |
| 1002 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1003 | sizeof(pat), &pat)) |
| 1004 | return -ENOBUFS; |
| 1005 | } |
| 1006 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1007 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1008 | return -ENOBUFS; |
| 1009 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1010 | nla_nest_end(msg, nl_wowlan); |
| 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | #endif |
| 1015 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1016 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1017 | struct cfg80211_registered_device *dev) |
| 1018 | { |
| 1019 | struct nl80211_coalesce_rule_support rule; |
| 1020 | |
| 1021 | if (!dev->wiphy.coalesce) |
| 1022 | return 0; |
| 1023 | |
| 1024 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1025 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1026 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1027 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1028 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1029 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1030 | |
| 1031 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1032 | return -ENOBUFS; |
| 1033 | |
| 1034 | return 0; |
| 1035 | } |
| 1036 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1037 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1038 | struct ieee80211_supported_band *sband) |
| 1039 | { |
| 1040 | struct nlattr *nl_rates, *nl_rate; |
| 1041 | struct ieee80211_rate *rate; |
| 1042 | int i; |
| 1043 | |
| 1044 | /* add HT info */ |
| 1045 | if (sband->ht_cap.ht_supported && |
| 1046 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1047 | sizeof(sband->ht_cap.mcs), |
| 1048 | &sband->ht_cap.mcs) || |
| 1049 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1050 | sband->ht_cap.cap) || |
| 1051 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1052 | sband->ht_cap.ampdu_factor) || |
| 1053 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1054 | sband->ht_cap.ampdu_density))) |
| 1055 | return -ENOBUFS; |
| 1056 | |
| 1057 | /* add VHT info */ |
| 1058 | if (sband->vht_cap.vht_supported && |
| 1059 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1060 | sizeof(sband->vht_cap.vht_mcs), |
| 1061 | &sband->vht_cap.vht_mcs) || |
| 1062 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1063 | sband->vht_cap.cap))) |
| 1064 | return -ENOBUFS; |
| 1065 | |
| 1066 | /* add bitrates */ |
| 1067 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1068 | if (!nl_rates) |
| 1069 | return -ENOBUFS; |
| 1070 | |
| 1071 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1072 | nl_rate = nla_nest_start(msg, i); |
| 1073 | if (!nl_rate) |
| 1074 | return -ENOBUFS; |
| 1075 | |
| 1076 | rate = &sband->bitrates[i]; |
| 1077 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1078 | rate->bitrate)) |
| 1079 | return -ENOBUFS; |
| 1080 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1081 | nla_put_flag(msg, |
| 1082 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1083 | return -ENOBUFS; |
| 1084 | |
| 1085 | nla_nest_end(msg, nl_rate); |
| 1086 | } |
| 1087 | |
| 1088 | nla_nest_end(msg, nl_rates); |
| 1089 | |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
| 1093 | static int |
| 1094 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1095 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1096 | { |
| 1097 | u16 stypes; |
| 1098 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1099 | enum nl80211_iftype ift; |
| 1100 | int i; |
| 1101 | |
| 1102 | if (!mgmt_stypes) |
| 1103 | return 0; |
| 1104 | |
| 1105 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1106 | if (!nl_ifs) |
| 1107 | return -ENOBUFS; |
| 1108 | |
| 1109 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1110 | nl_ftypes = nla_nest_start(msg, ift); |
| 1111 | if (!nl_ftypes) |
| 1112 | return -ENOBUFS; |
| 1113 | i = 0; |
| 1114 | stypes = mgmt_stypes[ift].tx; |
| 1115 | while (stypes) { |
| 1116 | if ((stypes & 1) && |
| 1117 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1118 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1119 | return -ENOBUFS; |
| 1120 | stypes >>= 1; |
| 1121 | i++; |
| 1122 | } |
| 1123 | nla_nest_end(msg, nl_ftypes); |
| 1124 | } |
| 1125 | |
| 1126 | nla_nest_end(msg, nl_ifs); |
| 1127 | |
| 1128 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1129 | if (!nl_ifs) |
| 1130 | return -ENOBUFS; |
| 1131 | |
| 1132 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1133 | nl_ftypes = nla_nest_start(msg, ift); |
| 1134 | if (!nl_ftypes) |
| 1135 | return -ENOBUFS; |
| 1136 | i = 0; |
| 1137 | stypes = mgmt_stypes[ift].rx; |
| 1138 | while (stypes) { |
| 1139 | if ((stypes & 1) && |
| 1140 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1141 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1142 | return -ENOBUFS; |
| 1143 | stypes >>= 1; |
| 1144 | i++; |
| 1145 | } |
| 1146 | nla_nest_end(msg, nl_ftypes); |
| 1147 | } |
| 1148 | nla_nest_end(msg, nl_ifs); |
| 1149 | |
| 1150 | return 0; |
| 1151 | } |
| 1152 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1153 | struct nl80211_dump_wiphy_state { |
| 1154 | s64 filter_wiphy; |
| 1155 | long start; |
| 1156 | long split_start, band_start, chan_start; |
| 1157 | bool split; |
| 1158 | }; |
| 1159 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1160 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1161 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1162 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1163 | { |
| 1164 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1165 | struct nlattr *nl_bands, *nl_band; |
| 1166 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1167 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1168 | enum ieee80211_band band; |
| 1169 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1170 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1171 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1172 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1173 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1174 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1175 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1176 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1177 | return -ENOBUFS; |
| 1178 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1179 | if (WARN_ON(!state)) |
| 1180 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1181 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1182 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1183 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1184 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1185 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1186 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1187 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1188 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1189 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1190 | case 0: |
| 1191 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1192 | dev->wiphy.retry_short) || |
| 1193 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1194 | dev->wiphy.retry_long) || |
| 1195 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1196 | dev->wiphy.frag_threshold) || |
| 1197 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1198 | dev->wiphy.rts_threshold) || |
| 1199 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1200 | dev->wiphy.coverage_class) || |
| 1201 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1202 | dev->wiphy.max_scan_ssids) || |
| 1203 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1204 | dev->wiphy.max_sched_scan_ssids) || |
| 1205 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1206 | dev->wiphy.max_scan_ie_len) || |
| 1207 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1208 | dev->wiphy.max_sched_scan_ie_len) || |
| 1209 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1210 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1211 | goto nla_put_failure; |
| 1212 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1213 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1214 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1215 | goto nla_put_failure; |
| 1216 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1217 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1218 | goto nla_put_failure; |
| 1219 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1220 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1221 | goto nla_put_failure; |
| 1222 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1223 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1224 | goto nla_put_failure; |
| 1225 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1226 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1227 | goto nla_put_failure; |
| 1228 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1229 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1230 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1231 | state->split_start++; |
| 1232 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1233 | break; |
| 1234 | case 1: |
| 1235 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1236 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1237 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1238 | goto nla_put_failure; |
| 1239 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1240 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1241 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1242 | goto nla_put_failure; |
| 1243 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1244 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1245 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1246 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1247 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1248 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1249 | dev->wiphy.available_antennas_tx) || |
| 1250 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1251 | dev->wiphy.available_antennas_rx)) |
| 1252 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1253 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1254 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1255 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1256 | dev->wiphy.probe_resp_offload)) |
| 1257 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1258 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1259 | if ((dev->wiphy.available_antennas_tx || |
| 1260 | dev->wiphy.available_antennas_rx) && |
| 1261 | dev->ops->get_antenna) { |
| 1262 | u32 tx_ant = 0, rx_ant = 0; |
| 1263 | int res; |
| 1264 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1265 | if (!res) { |
| 1266 | if (nla_put_u32(msg, |
| 1267 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1268 | tx_ant) || |
| 1269 | nla_put_u32(msg, |
| 1270 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1271 | rx_ant)) |
| 1272 | goto nla_put_failure; |
| 1273 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1274 | } |
| 1275 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1276 | state->split_start++; |
| 1277 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | break; |
| 1279 | case 2: |
| 1280 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1281 | dev->wiphy.interface_modes)) |
| 1282 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1283 | state->split_start++; |
| 1284 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1285 | break; |
| 1286 | case 3: |
| 1287 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1288 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1289 | goto nla_put_failure; |
| 1290 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1291 | for (band = state->band_start; |
| 1292 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1293 | struct ieee80211_supported_band *sband; |
| 1294 | |
| 1295 | sband = dev->wiphy.bands[band]; |
| 1296 | |
| 1297 | if (!sband) |
| 1298 | continue; |
| 1299 | |
| 1300 | nl_band = nla_nest_start(msg, band); |
| 1301 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1302 | goto nla_put_failure; |
| 1303 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1304 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | case 0: |
| 1306 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1307 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1308 | state->chan_start++; |
| 1309 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1310 | break; |
| 1311 | default: |
| 1312 | /* add frequencies */ |
| 1313 | nl_freqs = nla_nest_start( |
| 1314 | msg, NL80211_BAND_ATTR_FREQS); |
| 1315 | if (!nl_freqs) |
| 1316 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1317 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1318 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1319 | i < sband->n_channels; |
| 1320 | i++) { |
| 1321 | nl_freq = nla_nest_start(msg, i); |
| 1322 | if (!nl_freq) |
| 1323 | goto nla_put_failure; |
| 1324 | |
| 1325 | chan = &sband->channels[i]; |
| 1326 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1327 | if (nl80211_msg_put_channel( |
| 1328 | msg, chan, |
| 1329 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | goto nla_put_failure; |
| 1331 | |
| 1332 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1333 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1334 | break; |
| 1335 | } |
| 1336 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1337 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1338 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1339 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1340 | nla_nest_end(msg, nl_freqs); |
| 1341 | } |
| 1342 | |
| 1343 | nla_nest_end(msg, nl_band); |
| 1344 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1345 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1346 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1347 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1348 | band--; |
| 1349 | break; |
| 1350 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1351 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1352 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1353 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1354 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1355 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1356 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1357 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1358 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1359 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1360 | if (state->band_start == 0 && state->chan_start == 0) |
| 1361 | state->split_start++; |
| 1362 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1363 | break; |
| 1364 | case 4: |
| 1365 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1366 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1367 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1368 | |
| 1369 | i = 0; |
| 1370 | #define CMD(op, n) \ |
| 1371 | do { \ |
| 1372 | if (dev->ops->op) { \ |
| 1373 | i++; \ |
| 1374 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1375 | goto nla_put_failure; \ |
| 1376 | } \ |
| 1377 | } while (0) |
| 1378 | |
| 1379 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1380 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1381 | CMD(add_key, NEW_KEY); |
| 1382 | CMD(start_ap, START_AP); |
| 1383 | CMD(add_station, NEW_STATION); |
| 1384 | CMD(add_mpath, NEW_MPATH); |
| 1385 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1386 | CMD(change_bss, SET_BSS); |
| 1387 | CMD(auth, AUTHENTICATE); |
| 1388 | CMD(assoc, ASSOCIATE); |
| 1389 | CMD(deauth, DEAUTHENTICATE); |
| 1390 | CMD(disassoc, DISASSOCIATE); |
| 1391 | CMD(join_ibss, JOIN_IBSS); |
| 1392 | CMD(join_mesh, JOIN_MESH); |
| 1393 | CMD(set_pmksa, SET_PMKSA); |
| 1394 | CMD(del_pmksa, DEL_PMKSA); |
| 1395 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1396 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1397 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1398 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1399 | CMD(mgmt_tx, FRAME); |
| 1400 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1401 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1402 | i++; |
| 1403 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1404 | goto nla_put_failure; |
| 1405 | } |
| 1406 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1407 | dev->ops->join_mesh) { |
| 1408 | i++; |
| 1409 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1410 | goto nla_put_failure; |
| 1411 | } |
| 1412 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1413 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1414 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1415 | CMD(tdls_oper, TDLS_OPER); |
| 1416 | } |
| 1417 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1418 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1419 | CMD(probe_client, PROBE_CLIENT); |
| 1420 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1421 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1422 | i++; |
| 1423 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1424 | goto nla_put_failure; |
| 1425 | } |
| 1426 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1427 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1428 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1429 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1430 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1431 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1432 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1433 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1434 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1435 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1436 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1437 | #endif |
| 1438 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1439 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1440 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1441 | if (dev->ops->connect || dev->ops->auth) { |
| 1442 | i++; |
| 1443 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1444 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1445 | } |
| 1446 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1447 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1448 | i++; |
| 1449 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1450 | goto nla_put_failure; |
| 1451 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1452 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1453 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1454 | state->split_start++; |
| 1455 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1456 | break; |
| 1457 | case 5: |
| 1458 | if (dev->ops->remain_on_channel && |
| 1459 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1460 | nla_put_u32(msg, |
| 1461 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1462 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1463 | goto nla_put_failure; |
| 1464 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1465 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1466 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1467 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1468 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1469 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1470 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1471 | state->split_start++; |
| 1472 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1473 | break; |
| 1474 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1475 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1476 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1477 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1478 | state->split_start++; |
| 1479 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1480 | break; |
| 1481 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1482 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1483 | #endif |
| 1484 | case 7: |
| 1485 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1486 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1487 | goto nla_put_failure; |
| 1488 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1489 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1490 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1492 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1493 | state->split_start++; |
| 1494 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1495 | break; |
| 1496 | case 8: |
| 1497 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1498 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1499 | dev->wiphy.ap_sme_capa)) |
| 1500 | goto nla_put_failure; |
| 1501 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1502 | features = dev->wiphy.features; |
| 1503 | /* |
| 1504 | * We can only add the per-channel limit information if the |
| 1505 | * dump is split, otherwise it makes it too big. Therefore |
| 1506 | * only advertise it in that case. |
| 1507 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1508 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1509 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1510 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1511 | goto nla_put_failure; |
| 1512 | |
| 1513 | if (dev->wiphy.ht_capa_mod_mask && |
| 1514 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1515 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1516 | dev->wiphy.ht_capa_mod_mask)) |
| 1517 | goto nla_put_failure; |
| 1518 | |
| 1519 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1520 | dev->wiphy.max_acl_mac_addrs && |
| 1521 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1522 | dev->wiphy.max_acl_mac_addrs)) |
| 1523 | goto nla_put_failure; |
| 1524 | |
| 1525 | /* |
| 1526 | * Any information below this point is only available to |
| 1527 | * applications that can deal with it being split. This |
| 1528 | * helps ensure that newly added capabilities don't break |
| 1529 | * older tools by overrunning their buffers. |
| 1530 | * |
| 1531 | * We still increment split_start so that in the split |
| 1532 | * case we'll continue with more data in the next round, |
| 1533 | * but break unconditionally so unsplit data stops here. |
| 1534 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1535 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1536 | break; |
| 1537 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1538 | if (dev->wiphy.extended_capabilities && |
| 1539 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1540 | dev->wiphy.extended_capabilities_len, |
| 1541 | dev->wiphy.extended_capabilities) || |
| 1542 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1543 | dev->wiphy.extended_capabilities_len, |
| 1544 | dev->wiphy.extended_capabilities_mask))) |
| 1545 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1547 | if (dev->wiphy.vht_capa_mod_mask && |
| 1548 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1549 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1550 | dev->wiphy.vht_capa_mod_mask)) |
| 1551 | goto nla_put_failure; |
| 1552 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1553 | state->split_start++; |
| 1554 | break; |
| 1555 | case 10: |
| 1556 | if (nl80211_send_coalesce(msg, dev)) |
| 1557 | goto nla_put_failure; |
| 1558 | |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame^] | 1559 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1560 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1561 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1562 | goto nla_put_failure; |
| 1563 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1564 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1565 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1567 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1568 | return genlmsg_end(msg, hdr); |
| 1569 | |
| 1570 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1571 | genlmsg_cancel(msg, hdr); |
| 1572 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1573 | } |
| 1574 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1575 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1576 | struct netlink_callback *cb, |
| 1577 | struct nl80211_dump_wiphy_state *state) |
| 1578 | { |
| 1579 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1580 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1581 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1582 | /* ignore parse errors for backward compatibility */ |
| 1583 | if (ret) |
| 1584 | return 0; |
| 1585 | |
| 1586 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1587 | if (tb[NL80211_ATTR_WIPHY]) |
| 1588 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1589 | if (tb[NL80211_ATTR_WDEV]) |
| 1590 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1591 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1592 | struct net_device *netdev; |
| 1593 | struct cfg80211_registered_device *rdev; |
| 1594 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1595 | |
| 1596 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1597 | if (!netdev) |
| 1598 | return -ENODEV; |
| 1599 | if (netdev->ieee80211_ptr) { |
| 1600 | rdev = wiphy_to_dev( |
| 1601 | netdev->ieee80211_ptr->wiphy); |
| 1602 | state->filter_wiphy = rdev->wiphy_idx; |
| 1603 | } |
| 1604 | dev_put(netdev); |
| 1605 | } |
| 1606 | |
| 1607 | return 0; |
| 1608 | } |
| 1609 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1610 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1611 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1612 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1613 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1614 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1615 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1616 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1617 | if (!state) { |
| 1618 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1619 | if (!state) { |
| 1620 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1621 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1622 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1623 | state->filter_wiphy = -1; |
| 1624 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1625 | if (ret) { |
| 1626 | kfree(state); |
| 1627 | rtnl_unlock(); |
| 1628 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1630 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1631 | } |
| 1632 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1633 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1634 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1635 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1636 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1637 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1638 | if (state->filter_wiphy != -1 && |
| 1639 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1640 | continue; |
| 1641 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1642 | do { |
| 1643 | ret = nl80211_send_wiphy(dev, skb, |
| 1644 | NETLINK_CB(cb->skb).portid, |
| 1645 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1646 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1647 | if (ret < 0) { |
| 1648 | /* |
| 1649 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1650 | * or EMSGSIZE returned), this SKB is still |
| 1651 | * empty (so it's not too big because another |
| 1652 | * wiphy dataset is already in the skb) and |
| 1653 | * we've not tried to adjust the dump allocation |
| 1654 | * yet ... then adjust the alloc size to be |
| 1655 | * bigger, and return 1 but with the empty skb. |
| 1656 | * This results in an empty message being RX'ed |
| 1657 | * in userspace, but that is ignored. |
| 1658 | * |
| 1659 | * We can then retry with the larger buffer. |
| 1660 | */ |
| 1661 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1662 | !skb->len && |
| 1663 | cb->min_dump_alloc < 4096) { |
| 1664 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1665 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1666 | return 1; |
| 1667 | } |
| 1668 | idx--; |
| 1669 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1670 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1671 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1672 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1673 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1674 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1675 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1676 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1677 | |
| 1678 | return skb->len; |
| 1679 | } |
| 1680 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1681 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1682 | { |
| 1683 | kfree((void *)cb->args[0]); |
| 1684 | return 0; |
| 1685 | } |
| 1686 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1687 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1688 | { |
| 1689 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1690 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1691 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1692 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1693 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1694 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1695 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1696 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1697 | 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] | 1698 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1699 | nlmsg_free(msg); |
| 1700 | return -ENOBUFS; |
| 1701 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1702 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1703 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1706 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1707 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1708 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1709 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1710 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1711 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1712 | }; |
| 1713 | |
| 1714 | static int parse_txq_params(struct nlattr *tb[], |
| 1715 | struct ieee80211_txq_params *txq_params) |
| 1716 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1717 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1718 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1719 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1720 | return -EINVAL; |
| 1721 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1722 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1723 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1724 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1725 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1726 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1727 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1728 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1729 | return -EINVAL; |
| 1730 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1731 | return 0; |
| 1732 | } |
| 1733 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1734 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1735 | { |
| 1736 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1737 | * You can only set the channel explicitly for WDS interfaces, |
| 1738 | * all others have their channel managed via their respective |
| 1739 | * "establish a connection" command (connect, join, ...) |
| 1740 | * |
| 1741 | * For AP/GO and mesh mode, the channel can be set with the |
| 1742 | * channel userspace API, but is only stored and passed to the |
| 1743 | * low-level driver when the AP starts or the mesh is joined. |
| 1744 | * This is for backward compatibility, userspace can also give |
| 1745 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1746 | * |
| 1747 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1748 | * whatever else is going on, so they have their own special |
| 1749 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1750 | */ |
| 1751 | return !wdev || |
| 1752 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1753 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1754 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1755 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1756 | } |
| 1757 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1758 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1759 | struct genl_info *info, |
| 1760 | struct cfg80211_chan_def *chandef) |
| 1761 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1762 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1763 | |
| 1764 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1765 | return -EINVAL; |
| 1766 | |
| 1767 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1768 | |
| 1769 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1770 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1771 | chandef->center_freq1 = control_freq; |
| 1772 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1773 | |
| 1774 | /* Primary channel not allowed */ |
| 1775 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1776 | return -EINVAL; |
| 1777 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1778 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1779 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1780 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1781 | chantype = nla_get_u32( |
| 1782 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1783 | |
| 1784 | switch (chantype) { |
| 1785 | case NL80211_CHAN_NO_HT: |
| 1786 | case NL80211_CHAN_HT20: |
| 1787 | case NL80211_CHAN_HT40PLUS: |
| 1788 | case NL80211_CHAN_HT40MINUS: |
| 1789 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1790 | chantype); |
| 1791 | break; |
| 1792 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1793 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1794 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1795 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1796 | chandef->width = |
| 1797 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1798 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1799 | chandef->center_freq1 = |
| 1800 | nla_get_u32( |
| 1801 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1802 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1803 | chandef->center_freq2 = |
| 1804 | nla_get_u32( |
| 1805 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1806 | } |
| 1807 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1808 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1809 | return -EINVAL; |
| 1810 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1811 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1812 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1813 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1814 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1815 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1816 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1817 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1818 | return -EINVAL; |
| 1819 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1820 | return 0; |
| 1821 | } |
| 1822 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1823 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1824 | struct wireless_dev *wdev, |
| 1825 | struct genl_info *info) |
| 1826 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1827 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1828 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1829 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1830 | |
| 1831 | if (wdev) |
| 1832 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1833 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1834 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1835 | return -EOPNOTSUPP; |
| 1836 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1837 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1838 | if (result) |
| 1839 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1840 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1841 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1842 | case NL80211_IFTYPE_AP: |
| 1843 | case NL80211_IFTYPE_P2P_GO: |
| 1844 | if (wdev->beacon_interval) { |
| 1845 | result = -EBUSY; |
| 1846 | break; |
| 1847 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1848 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1849 | result = -EINVAL; |
| 1850 | break; |
| 1851 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1852 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1853 | result = 0; |
| 1854 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1855 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1856 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1857 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1858 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1859 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1860 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1861 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1862 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1863 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1864 | |
| 1865 | return result; |
| 1866 | } |
| 1867 | |
| 1868 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1869 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1870 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1871 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1872 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1873 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1874 | } |
| 1875 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1876 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1877 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1878 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1879 | struct net_device *dev = info->user_ptr[1]; |
| 1880 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1881 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1882 | |
| 1883 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1884 | return -EINVAL; |
| 1885 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1886 | if (netif_running(dev)) |
| 1887 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1888 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1889 | if (!rdev->ops->set_wds_peer) |
| 1890 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1891 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1892 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1893 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1894 | |
| 1895 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1896 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1900 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1901 | { |
| 1902 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1903 | struct net_device *netdev = NULL; |
| 1904 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1905 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1906 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1907 | u32 changed; |
| 1908 | u8 retry_short = 0, retry_long = 0; |
| 1909 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1910 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1911 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1912 | ASSERT_RTNL(); |
| 1913 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1914 | /* |
| 1915 | * Try to find the wiphy and netdev. Normally this |
| 1916 | * function shouldn't need the netdev, but this is |
| 1917 | * done for backward compatibility -- previously |
| 1918 | * setting the channel was done per wiphy, but now |
| 1919 | * it is per netdev. Previous userland like hostapd |
| 1920 | * also passed a netdev to set_wiphy, so that it is |
| 1921 | * possible to let that go to the right netdev! |
| 1922 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1923 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1924 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1925 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1926 | |
| 1927 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1928 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1929 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1930 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1931 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1932 | } |
| 1933 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1934 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1935 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1936 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1937 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1938 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1939 | wdev = NULL; |
| 1940 | netdev = NULL; |
| 1941 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1942 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1943 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1944 | |
| 1945 | /* |
| 1946 | * end workaround code, by now the rdev is available |
| 1947 | * and locked, and wdev may or may not be NULL. |
| 1948 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1949 | |
| 1950 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1951 | result = cfg80211_dev_rename( |
| 1952 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1953 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1954 | if (result) |
| 1955 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1956 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1957 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1958 | struct ieee80211_txq_params txq_params; |
| 1959 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1960 | |
| 1961 | if (!rdev->ops->set_txq_params) { |
| 1962 | result = -EOPNOTSUPP; |
| 1963 | goto bad_res; |
| 1964 | } |
| 1965 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1966 | if (!netdev) { |
| 1967 | result = -EINVAL; |
| 1968 | goto bad_res; |
| 1969 | } |
| 1970 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1971 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1972 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1973 | result = -EINVAL; |
| 1974 | goto bad_res; |
| 1975 | } |
| 1976 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1977 | if (!netif_running(netdev)) { |
| 1978 | result = -ENETDOWN; |
| 1979 | goto bad_res; |
| 1980 | } |
| 1981 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1982 | nla_for_each_nested(nl_txq_params, |
| 1983 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1984 | rem_txq_params) { |
| 1985 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1986 | nla_data(nl_txq_params), |
| 1987 | nla_len(nl_txq_params), |
| 1988 | txq_params_policy); |
| 1989 | result = parse_txq_params(tb, &txq_params); |
| 1990 | if (result) |
| 1991 | goto bad_res; |
| 1992 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1993 | result = rdev_set_txq_params(rdev, netdev, |
| 1994 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1995 | if (result) |
| 1996 | goto bad_res; |
| 1997 | } |
| 1998 | } |
| 1999 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2000 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2001 | result = __nl80211_set_channel(rdev, |
| 2002 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2003 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2004 | if (result) |
| 2005 | goto bad_res; |
| 2006 | } |
| 2007 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2008 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2009 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2010 | enum nl80211_tx_power_setting type; |
| 2011 | int idx, mbm = 0; |
| 2012 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2013 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2014 | txp_wdev = NULL; |
| 2015 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2016 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2017 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2018 | goto bad_res; |
| 2019 | } |
| 2020 | |
| 2021 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2022 | type = nla_get_u32(info->attrs[idx]); |
| 2023 | |
| 2024 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2025 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2026 | result = -EINVAL; |
| 2027 | goto bad_res; |
| 2028 | } |
| 2029 | |
| 2030 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2031 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2032 | mbm = nla_get_u32(info->attrs[idx]); |
| 2033 | } |
| 2034 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2035 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2036 | if (result) |
| 2037 | goto bad_res; |
| 2038 | } |
| 2039 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2040 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2041 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2042 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2043 | if ((!rdev->wiphy.available_antennas_tx && |
| 2044 | !rdev->wiphy.available_antennas_rx) || |
| 2045 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2046 | result = -EOPNOTSUPP; |
| 2047 | goto bad_res; |
| 2048 | } |
| 2049 | |
| 2050 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2051 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2052 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2053 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2054 | * available antenna masks, except for the "all" mask */ |
| 2055 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2056 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2057 | result = -EINVAL; |
| 2058 | goto bad_res; |
| 2059 | } |
| 2060 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2061 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2062 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2063 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2064 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2065 | if (result) |
| 2066 | goto bad_res; |
| 2067 | } |
| 2068 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2069 | changed = 0; |
| 2070 | |
| 2071 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2072 | retry_short = nla_get_u8( |
| 2073 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2074 | if (retry_short == 0) { |
| 2075 | result = -EINVAL; |
| 2076 | goto bad_res; |
| 2077 | } |
| 2078 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2079 | } |
| 2080 | |
| 2081 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2082 | retry_long = nla_get_u8( |
| 2083 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2084 | if (retry_long == 0) { |
| 2085 | result = -EINVAL; |
| 2086 | goto bad_res; |
| 2087 | } |
| 2088 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2089 | } |
| 2090 | |
| 2091 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2092 | frag_threshold = nla_get_u32( |
| 2093 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2094 | if (frag_threshold < 256) { |
| 2095 | result = -EINVAL; |
| 2096 | goto bad_res; |
| 2097 | } |
| 2098 | if (frag_threshold != (u32) -1) { |
| 2099 | /* |
| 2100 | * Fragments (apart from the last one) are required to |
| 2101 | * have even length. Make the fragmentation code |
| 2102 | * simpler by stripping LSB should someone try to use |
| 2103 | * odd threshold value. |
| 2104 | */ |
| 2105 | frag_threshold &= ~0x1; |
| 2106 | } |
| 2107 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2108 | } |
| 2109 | |
| 2110 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2111 | rts_threshold = nla_get_u32( |
| 2112 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2113 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2114 | } |
| 2115 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2116 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2117 | coverage_class = nla_get_u8( |
| 2118 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2119 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2120 | } |
| 2121 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2122 | if (changed) { |
| 2123 | u8 old_retry_short, old_retry_long; |
| 2124 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2125 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2126 | |
| 2127 | if (!rdev->ops->set_wiphy_params) { |
| 2128 | result = -EOPNOTSUPP; |
| 2129 | goto bad_res; |
| 2130 | } |
| 2131 | |
| 2132 | old_retry_short = rdev->wiphy.retry_short; |
| 2133 | old_retry_long = rdev->wiphy.retry_long; |
| 2134 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2135 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2136 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2137 | |
| 2138 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2139 | rdev->wiphy.retry_short = retry_short; |
| 2140 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2141 | rdev->wiphy.retry_long = retry_long; |
| 2142 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2143 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2144 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2145 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2146 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2147 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2148 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2149 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2150 | if (result) { |
| 2151 | rdev->wiphy.retry_short = old_retry_short; |
| 2152 | rdev->wiphy.retry_long = old_retry_long; |
| 2153 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2154 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2155 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2156 | } |
| 2157 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2158 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2159 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2160 | if (netdev) |
| 2161 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2162 | return result; |
| 2163 | } |
| 2164 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2165 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2166 | { |
| 2167 | return (u64)wdev->identifier | |
| 2168 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2169 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2170 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2171 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2172 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2173 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2174 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2175 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2176 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2177 | chandef->chan->center_freq)) |
| 2178 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2179 | switch (chandef->width) { |
| 2180 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2181 | case NL80211_CHAN_WIDTH_20: |
| 2182 | case NL80211_CHAN_WIDTH_40: |
| 2183 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2184 | cfg80211_get_chandef_type(chandef))) |
| 2185 | return -ENOBUFS; |
| 2186 | break; |
| 2187 | default: |
| 2188 | break; |
| 2189 | } |
| 2190 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2191 | return -ENOBUFS; |
| 2192 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2193 | return -ENOBUFS; |
| 2194 | if (chandef->center_freq2 && |
| 2195 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2196 | return -ENOBUFS; |
| 2197 | return 0; |
| 2198 | } |
| 2199 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2200 | 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] | 2201 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2202 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2203 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2204 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2205 | void *hdr; |
| 2206 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2207 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2208 | if (!hdr) |
| 2209 | return -1; |
| 2210 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2211 | if (dev && |
| 2212 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2213 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2214 | goto nla_put_failure; |
| 2215 | |
| 2216 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2217 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2218 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2219 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2220 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2221 | rdev->devlist_generation ^ |
| 2222 | (cfg80211_rdev_list_generation << 2))) |
| 2223 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2224 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2225 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2226 | int ret; |
| 2227 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2228 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2229 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2230 | if (ret == 0) { |
| 2231 | if (nl80211_send_chandef(msg, &chandef)) |
| 2232 | goto nla_put_failure; |
| 2233 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2234 | } |
| 2235 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2236 | if (wdev->ssid_len) { |
| 2237 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2238 | goto nla_put_failure; |
| 2239 | } |
| 2240 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2241 | return genlmsg_end(msg, hdr); |
| 2242 | |
| 2243 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2244 | genlmsg_cancel(msg, hdr); |
| 2245 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2249 | { |
| 2250 | int wp_idx = 0; |
| 2251 | int if_idx = 0; |
| 2252 | int wp_start = cb->args[0]; |
| 2253 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2254 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2255 | struct wireless_dev *wdev; |
| 2256 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2257 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2258 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2259 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2260 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2261 | if (wp_idx < wp_start) { |
| 2262 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2263 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2264 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2265 | if_idx = 0; |
| 2266 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2267 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2268 | if (if_idx < if_start) { |
| 2269 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2270 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2271 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2272 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2273 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2274 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2275 | goto out; |
| 2276 | } |
| 2277 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2278 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2279 | |
| 2280 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2281 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2282 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2283 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2284 | |
| 2285 | cb->args[0] = wp_idx; |
| 2286 | cb->args[1] = if_idx; |
| 2287 | |
| 2288 | return skb->len; |
| 2289 | } |
| 2290 | |
| 2291 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2292 | { |
| 2293 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2294 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2295 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2296 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2297 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2298 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2299 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2300 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2301 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2302 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2303 | nlmsg_free(msg); |
| 2304 | return -ENOBUFS; |
| 2305 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2306 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2307 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2308 | } |
| 2309 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2310 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2311 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2312 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2313 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2314 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2315 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2316 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2317 | }; |
| 2318 | |
| 2319 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2320 | { |
| 2321 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2322 | int flag; |
| 2323 | |
| 2324 | *mntrflags = 0; |
| 2325 | |
| 2326 | if (!nla) |
| 2327 | return -EINVAL; |
| 2328 | |
| 2329 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2330 | nla, mntr_flags_policy)) |
| 2331 | return -EINVAL; |
| 2332 | |
| 2333 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2334 | if (flags[flag]) |
| 2335 | *mntrflags |= (1<<flag); |
| 2336 | |
| 2337 | return 0; |
| 2338 | } |
| 2339 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2340 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2341 | struct net_device *netdev, u8 use_4addr, |
| 2342 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2343 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2344 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2345 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2346 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2347 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2348 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2349 | |
| 2350 | switch (iftype) { |
| 2351 | case NL80211_IFTYPE_AP_VLAN: |
| 2352 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2353 | return 0; |
| 2354 | break; |
| 2355 | case NL80211_IFTYPE_STATION: |
| 2356 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2357 | return 0; |
| 2358 | break; |
| 2359 | default: |
| 2360 | break; |
| 2361 | } |
| 2362 | |
| 2363 | return -EOPNOTSUPP; |
| 2364 | } |
| 2365 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2366 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2367 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2368 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2369 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2370 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2371 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2372 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2373 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2374 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2375 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2376 | memset(¶ms, 0, sizeof(params)); |
| 2377 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2378 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2379 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2380 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2381 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2382 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2383 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2384 | if (ntype > NL80211_IFTYPE_MAX) |
| 2385 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2386 | } |
| 2387 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2388 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2389 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2390 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2391 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2392 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2393 | if (netif_running(dev)) |
| 2394 | return -EBUSY; |
| 2395 | |
| 2396 | wdev_lock(wdev); |
| 2397 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2398 | IEEE80211_MAX_MESH_ID_LEN); |
| 2399 | wdev->mesh_id_up_len = |
| 2400 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2401 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2402 | wdev->mesh_id_up_len); |
| 2403 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2404 | } |
| 2405 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2406 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2407 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2408 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2409 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2410 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2411 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2412 | } else { |
| 2413 | params.use_4addr = -1; |
| 2414 | } |
| 2415 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2416 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2417 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2418 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2419 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2420 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2421 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2422 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2423 | |
| 2424 | flags = &_flags; |
| 2425 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2426 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2427 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2428 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2429 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2430 | return -EOPNOTSUPP; |
| 2431 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2432 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2433 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2434 | else |
| 2435 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2436 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2437 | if (!err && params.use_4addr != -1) |
| 2438 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2439 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2440 | return err; |
| 2441 | } |
| 2442 | |
| 2443 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2446 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2447 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2448 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2449 | int err; |
| 2450 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2451 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2452 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2453 | memset(¶ms, 0, sizeof(params)); |
| 2454 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2455 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2456 | return -EINVAL; |
| 2457 | |
| 2458 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2459 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2460 | if (type > NL80211_IFTYPE_MAX) |
| 2461 | return -EINVAL; |
| 2462 | } |
| 2463 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2464 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2465 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2466 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2467 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2468 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2469 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2470 | ETH_ALEN); |
| 2471 | if (!is_valid_ether_addr(params.macaddr)) |
| 2472 | return -EADDRNOTAVAIL; |
| 2473 | } |
| 2474 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2475 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2476 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2477 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2478 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2479 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2480 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2481 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2482 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2483 | if (!msg) |
| 2484 | return -ENOMEM; |
| 2485 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2486 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2487 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2488 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2489 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2490 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2491 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2492 | return -EOPNOTSUPP; |
| 2493 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2494 | wdev = rdev_add_virtual_intf(rdev, |
| 2495 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2496 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2497 | if (IS_ERR(wdev)) { |
| 2498 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2499 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2500 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2501 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2502 | switch (type) { |
| 2503 | case NL80211_IFTYPE_MESH_POINT: |
| 2504 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2505 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2506 | wdev_lock(wdev); |
| 2507 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2508 | IEEE80211_MAX_MESH_ID_LEN); |
| 2509 | wdev->mesh_id_up_len = |
| 2510 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2511 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2512 | wdev->mesh_id_up_len); |
| 2513 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2514 | break; |
| 2515 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2516 | /* |
| 2517 | * P2P Device doesn't have a netdev, so doesn't go |
| 2518 | * through the netdev notifier and must be added here |
| 2519 | */ |
| 2520 | mutex_init(&wdev->mtx); |
| 2521 | INIT_LIST_HEAD(&wdev->event_list); |
| 2522 | spin_lock_init(&wdev->event_lock); |
| 2523 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2524 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2525 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2526 | wdev->identifier = ++rdev->wdev_id; |
| 2527 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2528 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2529 | break; |
| 2530 | default: |
| 2531 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2532 | } |
| 2533 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2534 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2535 | rdev, wdev) < 0) { |
| 2536 | nlmsg_free(msg); |
| 2537 | return -ENOBUFS; |
| 2538 | } |
| 2539 | |
| 2540 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2544 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2545 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2546 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2547 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2548 | if (!rdev->ops->del_virtual_intf) |
| 2549 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2550 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2551 | /* |
| 2552 | * If we remove a wireless device without a netdev then clear |
| 2553 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2554 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2555 | * since the wdev has been freed, unlike with a netdev where |
| 2556 | * we need the dev_put() for the netdev to really be freed. |
| 2557 | */ |
| 2558 | if (!wdev->netdev) |
| 2559 | info->user_ptr[1] = NULL; |
| 2560 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2561 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2562 | } |
| 2563 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2564 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2565 | { |
| 2566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2567 | struct net_device *dev = info->user_ptr[1]; |
| 2568 | u16 noack_map; |
| 2569 | |
| 2570 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2571 | return -EINVAL; |
| 2572 | |
| 2573 | if (!rdev->ops->set_noack_map) |
| 2574 | return -EOPNOTSUPP; |
| 2575 | |
| 2576 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2577 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2578 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2579 | } |
| 2580 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2581 | struct get_key_cookie { |
| 2582 | struct sk_buff *msg; |
| 2583 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2584 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2585 | }; |
| 2586 | |
| 2587 | static void get_key_callback(void *c, struct key_params *params) |
| 2588 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2589 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2590 | struct get_key_cookie *cookie = c; |
| 2591 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2592 | if ((params->key && |
| 2593 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2594 | params->key_len, params->key)) || |
| 2595 | (params->seq && |
| 2596 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2597 | params->seq_len, params->seq)) || |
| 2598 | (params->cipher && |
| 2599 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2600 | params->cipher))) |
| 2601 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2602 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2603 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2604 | if (!key) |
| 2605 | goto nla_put_failure; |
| 2606 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2607 | if ((params->key && |
| 2608 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2609 | params->key_len, params->key)) || |
| 2610 | (params->seq && |
| 2611 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2612 | params->seq_len, params->seq)) || |
| 2613 | (params->cipher && |
| 2614 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2615 | params->cipher))) |
| 2616 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2617 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2618 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2619 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2620 | |
| 2621 | nla_nest_end(cookie->msg, key); |
| 2622 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2623 | return; |
| 2624 | nla_put_failure: |
| 2625 | cookie->error = 1; |
| 2626 | } |
| 2627 | |
| 2628 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2629 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2631 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2632 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2633 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2634 | const u8 *mac_addr = NULL; |
| 2635 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2636 | struct get_key_cookie cookie = { |
| 2637 | .error = 0, |
| 2638 | }; |
| 2639 | void *hdr; |
| 2640 | struct sk_buff *msg; |
| 2641 | |
| 2642 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2643 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2644 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2645 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2646 | return -EINVAL; |
| 2647 | |
| 2648 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2649 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2650 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2651 | pairwise = !!mac_addr; |
| 2652 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2653 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2654 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2655 | return -EINVAL; |
| 2656 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2657 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2658 | return -EINVAL; |
| 2659 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2660 | } |
| 2661 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2662 | if (!rdev->ops->get_key) |
| 2663 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2664 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2665 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2666 | if (!msg) |
| 2667 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2668 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2669 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2670 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2671 | if (!hdr) |
| 2672 | return -ENOBUFS; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2673 | |
| 2674 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2675 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2676 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2677 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2678 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2679 | goto nla_put_failure; |
| 2680 | if (mac_addr && |
| 2681 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2682 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2683 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2684 | if (pairwise && mac_addr && |
| 2685 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2686 | return -ENOENT; |
| 2687 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2688 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2689 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2690 | |
| 2691 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2692 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2693 | |
| 2694 | if (cookie.error) |
| 2695 | goto nla_put_failure; |
| 2696 | |
| 2697 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2698 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2699 | |
| 2700 | nla_put_failure: |
| 2701 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2702 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2703 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2704 | return err; |
| 2705 | } |
| 2706 | |
| 2707 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2708 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2710 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2711 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2712 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2713 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2714 | err = nl80211_parse_key(info, &key); |
| 2715 | if (err) |
| 2716 | return err; |
| 2717 | |
| 2718 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2719 | return -EINVAL; |
| 2720 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2721 | /* only support setting default key */ |
| 2722 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2723 | return -EINVAL; |
| 2724 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2725 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2726 | |
| 2727 | if (key.def) { |
| 2728 | if (!rdev->ops->set_default_key) { |
| 2729 | err = -EOPNOTSUPP; |
| 2730 | goto out; |
| 2731 | } |
| 2732 | |
| 2733 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2734 | if (err) |
| 2735 | goto out; |
| 2736 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2737 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2738 | key.def_uni, key.def_multi); |
| 2739 | |
| 2740 | if (err) |
| 2741 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2742 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2743 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2744 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2745 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2746 | } else { |
| 2747 | if (key.def_uni || !key.def_multi) { |
| 2748 | err = -EINVAL; |
| 2749 | goto out; |
| 2750 | } |
| 2751 | |
| 2752 | if (!rdev->ops->set_default_mgmt_key) { |
| 2753 | err = -EOPNOTSUPP; |
| 2754 | goto out; |
| 2755 | } |
| 2756 | |
| 2757 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2758 | if (err) |
| 2759 | goto out; |
| 2760 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2761 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2762 | if (err) |
| 2763 | goto out; |
| 2764 | |
| 2765 | #ifdef CONFIG_CFG80211_WEXT |
| 2766 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2767 | #endif |
| 2768 | } |
| 2769 | |
| 2770 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2771 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2772 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2773 | return err; |
| 2774 | } |
| 2775 | |
| 2776 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2777 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2779 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2780 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2781 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2782 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2783 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2784 | err = nl80211_parse_key(info, &key); |
| 2785 | if (err) |
| 2786 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2787 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2788 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2789 | return -EINVAL; |
| 2790 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2791 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2792 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2793 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2794 | if (key.type == -1) { |
| 2795 | if (mac_addr) |
| 2796 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2797 | else |
| 2798 | key.type = NL80211_KEYTYPE_GROUP; |
| 2799 | } |
| 2800 | |
| 2801 | /* for now */ |
| 2802 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2803 | key.type != NL80211_KEYTYPE_GROUP) |
| 2804 | return -EINVAL; |
| 2805 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2806 | if (!rdev->ops->add_key) |
| 2807 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2808 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2809 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2810 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2811 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2812 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2813 | |
| 2814 | wdev_lock(dev->ieee80211_ptr); |
| 2815 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2816 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2817 | err = rdev_add_key(rdev, dev, key.idx, |
| 2818 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2819 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2820 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2821 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2822 | return err; |
| 2823 | } |
| 2824 | |
| 2825 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2826 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2827 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2828 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2829 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2830 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2831 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2832 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2833 | err = nl80211_parse_key(info, &key); |
| 2834 | if (err) |
| 2835 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2836 | |
| 2837 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2838 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2839 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2840 | if (key.type == -1) { |
| 2841 | if (mac_addr) |
| 2842 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2843 | else |
| 2844 | key.type = NL80211_KEYTYPE_GROUP; |
| 2845 | } |
| 2846 | |
| 2847 | /* for now */ |
| 2848 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2849 | key.type != NL80211_KEYTYPE_GROUP) |
| 2850 | return -EINVAL; |
| 2851 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2852 | if (!rdev->ops->del_key) |
| 2853 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2854 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2855 | wdev_lock(dev->ieee80211_ptr); |
| 2856 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2857 | |
| 2858 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2859 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2860 | err = -ENOENT; |
| 2861 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2862 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2863 | err = rdev_del_key(rdev, dev, key.idx, |
| 2864 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2865 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2866 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2867 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2868 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2869 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2870 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2871 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2872 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2873 | } |
| 2874 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2875 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2876 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2877 | return err; |
| 2878 | } |
| 2879 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2880 | /* This function returns an error or the number of nested attributes */ |
| 2881 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2882 | { |
| 2883 | struct nlattr *attr; |
| 2884 | int n_entries = 0, tmp; |
| 2885 | |
| 2886 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2887 | if (nla_len(attr) != ETH_ALEN) |
| 2888 | return -EINVAL; |
| 2889 | |
| 2890 | n_entries++; |
| 2891 | } |
| 2892 | |
| 2893 | return n_entries; |
| 2894 | } |
| 2895 | |
| 2896 | /* |
| 2897 | * This function parses ACL information and allocates memory for ACL data. |
| 2898 | * On successful return, the calling function is responsible to free the |
| 2899 | * ACL buffer returned by this function. |
| 2900 | */ |
| 2901 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2902 | struct genl_info *info) |
| 2903 | { |
| 2904 | enum nl80211_acl_policy acl_policy; |
| 2905 | struct nlattr *attr; |
| 2906 | struct cfg80211_acl_data *acl; |
| 2907 | int i = 0, n_entries, tmp; |
| 2908 | |
| 2909 | if (!wiphy->max_acl_mac_addrs) |
| 2910 | return ERR_PTR(-EOPNOTSUPP); |
| 2911 | |
| 2912 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2913 | return ERR_PTR(-EINVAL); |
| 2914 | |
| 2915 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2916 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2917 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2918 | return ERR_PTR(-EINVAL); |
| 2919 | |
| 2920 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2921 | return ERR_PTR(-EINVAL); |
| 2922 | |
| 2923 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2924 | if (n_entries < 0) |
| 2925 | return ERR_PTR(n_entries); |
| 2926 | |
| 2927 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2928 | return ERR_PTR(-ENOTSUPP); |
| 2929 | |
| 2930 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2931 | GFP_KERNEL); |
| 2932 | if (!acl) |
| 2933 | return ERR_PTR(-ENOMEM); |
| 2934 | |
| 2935 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2936 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2937 | i++; |
| 2938 | } |
| 2939 | |
| 2940 | acl->n_acl_entries = n_entries; |
| 2941 | acl->acl_policy = acl_policy; |
| 2942 | |
| 2943 | return acl; |
| 2944 | } |
| 2945 | |
| 2946 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2947 | { |
| 2948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2949 | struct net_device *dev = info->user_ptr[1]; |
| 2950 | struct cfg80211_acl_data *acl; |
| 2951 | int err; |
| 2952 | |
| 2953 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2954 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2955 | return -EOPNOTSUPP; |
| 2956 | |
| 2957 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2958 | return -EINVAL; |
| 2959 | |
| 2960 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2961 | if (IS_ERR(acl)) |
| 2962 | return PTR_ERR(acl); |
| 2963 | |
| 2964 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2965 | |
| 2966 | kfree(acl); |
| 2967 | |
| 2968 | return err; |
| 2969 | } |
| 2970 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2971 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2972 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2973 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2974 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2975 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2976 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2977 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2978 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2979 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2980 | return -EINVAL; |
| 2981 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2982 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2983 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2984 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2985 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2986 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2987 | if (!bcn->head_len) |
| 2988 | return -EINVAL; |
| 2989 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2990 | } |
| 2991 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2992 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2993 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2994 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2995 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2996 | } |
| 2997 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2998 | if (!haveinfo) |
| 2999 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3000 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3001 | if (attrs[NL80211_ATTR_IE]) { |
| 3002 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3003 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3004 | } |
| 3005 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3006 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3007 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3008 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3009 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3010 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3011 | } |
| 3012 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3013 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3014 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3015 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3016 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3017 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3018 | } |
| 3019 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3020 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3021 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3022 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3023 | } |
| 3024 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3025 | return 0; |
| 3026 | } |
| 3027 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3028 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3029 | struct cfg80211_ap_settings *params) |
| 3030 | { |
| 3031 | struct wireless_dev *wdev; |
| 3032 | bool ret = false; |
| 3033 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3034 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3035 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3036 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3037 | continue; |
| 3038 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3039 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3040 | continue; |
| 3041 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3042 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3043 | ret = true; |
| 3044 | break; |
| 3045 | } |
| 3046 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3047 | return ret; |
| 3048 | } |
| 3049 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3050 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3051 | enum nl80211_auth_type auth_type, |
| 3052 | enum nl80211_commands cmd) |
| 3053 | { |
| 3054 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3055 | return false; |
| 3056 | |
| 3057 | switch (cmd) { |
| 3058 | case NL80211_CMD_AUTHENTICATE: |
| 3059 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3060 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3061 | return false; |
| 3062 | return true; |
| 3063 | case NL80211_CMD_CONNECT: |
| 3064 | case NL80211_CMD_START_AP: |
| 3065 | /* SAE not supported yet */ |
| 3066 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3067 | return false; |
| 3068 | return true; |
| 3069 | default: |
| 3070 | return false; |
| 3071 | } |
| 3072 | } |
| 3073 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3074 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3075 | { |
| 3076 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3077 | struct net_device *dev = info->user_ptr[1]; |
| 3078 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3079 | struct cfg80211_ap_settings params; |
| 3080 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3081 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3082 | |
| 3083 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3084 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3085 | return -EOPNOTSUPP; |
| 3086 | |
| 3087 | if (!rdev->ops->start_ap) |
| 3088 | return -EOPNOTSUPP; |
| 3089 | |
| 3090 | if (wdev->beacon_interval) |
| 3091 | return -EALREADY; |
| 3092 | |
| 3093 | memset(¶ms, 0, sizeof(params)); |
| 3094 | |
| 3095 | /* these are required for START_AP */ |
| 3096 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3097 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3098 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3099 | return -EINVAL; |
| 3100 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3101 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3102 | if (err) |
| 3103 | return err; |
| 3104 | |
| 3105 | params.beacon_interval = |
| 3106 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3107 | params.dtim_period = |
| 3108 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3109 | |
| 3110 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3111 | if (err) |
| 3112 | return err; |
| 3113 | |
| 3114 | /* |
| 3115 | * In theory, some of these attributes should be required here |
| 3116 | * but since they were not used when the command was originally |
| 3117 | * added, keep them optional for old user space programs to let |
| 3118 | * them continue to work with drivers that do not need the |
| 3119 | * additional information -- drivers must check! |
| 3120 | */ |
| 3121 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3122 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3123 | params.ssid_len = |
| 3124 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3125 | if (params.ssid_len == 0 || |
| 3126 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3127 | return -EINVAL; |
| 3128 | } |
| 3129 | |
| 3130 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3131 | params.hidden_ssid = nla_get_u32( |
| 3132 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3133 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3134 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3135 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3136 | return -EINVAL; |
| 3137 | } |
| 3138 | |
| 3139 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3140 | |
| 3141 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3142 | params.auth_type = nla_get_u32( |
| 3143 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3144 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3145 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3146 | return -EINVAL; |
| 3147 | } else |
| 3148 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3149 | |
| 3150 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3151 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3152 | if (err) |
| 3153 | return err; |
| 3154 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3155 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3156 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3157 | return -EOPNOTSUPP; |
| 3158 | params.inactivity_timeout = nla_get_u16( |
| 3159 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3160 | } |
| 3161 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3162 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3163 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3164 | return -EINVAL; |
| 3165 | params.p2p_ctwindow = |
| 3166 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3167 | if (params.p2p_ctwindow > 127) |
| 3168 | return -EINVAL; |
| 3169 | if (params.p2p_ctwindow != 0 && |
| 3170 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3171 | return -EINVAL; |
| 3172 | } |
| 3173 | |
| 3174 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3175 | u8 tmp; |
| 3176 | |
| 3177 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3178 | return -EINVAL; |
| 3179 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3180 | if (tmp > 1) |
| 3181 | return -EINVAL; |
| 3182 | params.p2p_opp_ps = tmp; |
| 3183 | if (params.p2p_opp_ps != 0 && |
| 3184 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3185 | return -EINVAL; |
| 3186 | } |
| 3187 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3188 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3189 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3190 | if (err) |
| 3191 | return err; |
| 3192 | } else if (wdev->preset_chandef.chan) { |
| 3193 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3194 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3195 | return -EINVAL; |
| 3196 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3197 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3198 | return -EINVAL; |
| 3199 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3200 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3201 | if (err < 0) |
| 3202 | return err; |
| 3203 | if (err) { |
| 3204 | radar_detect_width = BIT(params.chandef.width); |
| 3205 | params.radar_required = true; |
| 3206 | } |
| 3207 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3208 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3209 | params.chandef.chan, |
| 3210 | CHAN_MODE_SHARED, |
| 3211 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3212 | if (err) |
| 3213 | return err; |
| 3214 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3215 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3216 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3217 | if (IS_ERR(params.acl)) |
| 3218 | return PTR_ERR(params.acl); |
| 3219 | } |
| 3220 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3221 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3222 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3223 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3224 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3225 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3226 | wdev->ssid_len = params.ssid_len; |
| 3227 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3228 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3229 | |
| 3230 | kfree(params.acl); |
| 3231 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3232 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3233 | } |
| 3234 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3235 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3236 | { |
| 3237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3238 | struct net_device *dev = info->user_ptr[1]; |
| 3239 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3240 | struct cfg80211_beacon_data params; |
| 3241 | int err; |
| 3242 | |
| 3243 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3244 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3245 | return -EOPNOTSUPP; |
| 3246 | |
| 3247 | if (!rdev->ops->change_beacon) |
| 3248 | return -EOPNOTSUPP; |
| 3249 | |
| 3250 | if (!wdev->beacon_interval) |
| 3251 | return -EINVAL; |
| 3252 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3253 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3254 | if (err) |
| 3255 | return err; |
| 3256 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3257 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | 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] | 3261 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3262 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3263 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3264 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3265 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3266 | } |
| 3267 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3268 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3269 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3270 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3271 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3272 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3273 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3274 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3275 | }; |
| 3276 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3277 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3278 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3279 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3280 | { |
| 3281 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3282 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3283 | int flag; |
| 3284 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3285 | /* |
| 3286 | * Try parsing the new attribute first so userspace |
| 3287 | * can specify both for older kernels. |
| 3288 | */ |
| 3289 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3290 | if (nla) { |
| 3291 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3292 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3293 | sta_flags = nla_data(nla); |
| 3294 | params->sta_flags_mask = sta_flags->mask; |
| 3295 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3296 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3297 | if ((params->sta_flags_mask | |
| 3298 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3299 | return -EINVAL; |
| 3300 | return 0; |
| 3301 | } |
| 3302 | |
| 3303 | /* if present, parse the old attribute */ |
| 3304 | |
| 3305 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3306 | if (!nla) |
| 3307 | return 0; |
| 3308 | |
| 3309 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3310 | nla, sta_flags_policy)) |
| 3311 | return -EINVAL; |
| 3312 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3313 | /* |
| 3314 | * Only allow certain flags for interface types so that |
| 3315 | * other attributes are silently ignored. Remember that |
| 3316 | * this is backward compatibility code with old userspace |
| 3317 | * and shouldn't be hit in other cases anyway. |
| 3318 | */ |
| 3319 | switch (iftype) { |
| 3320 | case NL80211_IFTYPE_AP: |
| 3321 | case NL80211_IFTYPE_AP_VLAN: |
| 3322 | case NL80211_IFTYPE_P2P_GO: |
| 3323 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3324 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3325 | BIT(NL80211_STA_FLAG_WME) | |
| 3326 | BIT(NL80211_STA_FLAG_MFP); |
| 3327 | break; |
| 3328 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3329 | case NL80211_IFTYPE_STATION: |
| 3330 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3331 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3332 | break; |
| 3333 | case NL80211_IFTYPE_MESH_POINT: |
| 3334 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3335 | BIT(NL80211_STA_FLAG_MFP) | |
| 3336 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3337 | default: |
| 3338 | return -EINVAL; |
| 3339 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3340 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3341 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3342 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3343 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3344 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3345 | /* no longer support new API additions in old API */ |
| 3346 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3347 | return -EINVAL; |
| 3348 | } |
| 3349 | } |
| 3350 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3351 | return 0; |
| 3352 | } |
| 3353 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3354 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3355 | int attr) |
| 3356 | { |
| 3357 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3358 | u32 bitrate; |
| 3359 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3360 | |
| 3361 | rate = nla_nest_start(msg, attr); |
| 3362 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3363 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3364 | |
| 3365 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3366 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3367 | /* report 16-bit bitrate only if we can */ |
| 3368 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3369 | if (bitrate > 0 && |
| 3370 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3371 | return false; |
| 3372 | if (bitrate_compat > 0 && |
| 3373 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3374 | return false; |
| 3375 | |
| 3376 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3377 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3378 | return false; |
| 3379 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3380 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3381 | return false; |
| 3382 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3383 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3384 | return false; |
| 3385 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3386 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3387 | return false; |
| 3388 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3389 | return false; |
| 3390 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3391 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3392 | return false; |
| 3393 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3394 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3395 | return false; |
| 3396 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3397 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3398 | return false; |
| 3399 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3400 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3401 | return false; |
| 3402 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3403 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3404 | return false; |
| 3405 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3406 | |
| 3407 | nla_nest_end(msg, rate); |
| 3408 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3409 | } |
| 3410 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3411 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3412 | int id) |
| 3413 | { |
| 3414 | void *attr; |
| 3415 | int i = 0; |
| 3416 | |
| 3417 | if (!mask) |
| 3418 | return true; |
| 3419 | |
| 3420 | attr = nla_nest_start(msg, id); |
| 3421 | if (!attr) |
| 3422 | return false; |
| 3423 | |
| 3424 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3425 | if (!(mask & BIT(i))) |
| 3426 | continue; |
| 3427 | |
| 3428 | if (nla_put_u8(msg, i, signal[i])) |
| 3429 | return false; |
| 3430 | } |
| 3431 | |
| 3432 | nla_nest_end(msg, attr); |
| 3433 | |
| 3434 | return true; |
| 3435 | } |
| 3436 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3437 | 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] | 3438 | int flags, |
| 3439 | struct cfg80211_registered_device *rdev, |
| 3440 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3441 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3442 | { |
| 3443 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3444 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3445 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3446 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3447 | if (!hdr) |
| 3448 | return -1; |
| 3449 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3450 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3451 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3452 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3453 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3454 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3455 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3456 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3457 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3458 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3459 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3460 | sinfo->connected_time)) |
| 3461 | goto nla_put_failure; |
| 3462 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3463 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3464 | sinfo->inactive_time)) |
| 3465 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3466 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3467 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3468 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3469 | (u32)sinfo->rx_bytes)) |
| 3470 | goto nla_put_failure; |
| 3471 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3472 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3473 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3474 | (u32)sinfo->tx_bytes)) |
| 3475 | goto nla_put_failure; |
| 3476 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3477 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3478 | sinfo->rx_bytes)) |
| 3479 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3480 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3481 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3482 | sinfo->tx_bytes)) |
| 3483 | goto nla_put_failure; |
| 3484 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3485 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3486 | goto nla_put_failure; |
| 3487 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3488 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3489 | goto nla_put_failure; |
| 3490 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3491 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3492 | sinfo->plink_state)) |
| 3493 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3494 | switch (rdev->wiphy.signal_type) { |
| 3495 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3496 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3497 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3498 | sinfo->signal)) |
| 3499 | goto nla_put_failure; |
| 3500 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3501 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3502 | sinfo->signal_avg)) |
| 3503 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3504 | break; |
| 3505 | default: |
| 3506 | break; |
| 3507 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3508 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3509 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3510 | sinfo->chain_signal, |
| 3511 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3512 | goto nla_put_failure; |
| 3513 | } |
| 3514 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3515 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3516 | sinfo->chain_signal_avg, |
| 3517 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3518 | goto nla_put_failure; |
| 3519 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3520 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3521 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3522 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3523 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3524 | } |
| 3525 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3526 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3527 | NL80211_STA_INFO_RX_BITRATE)) |
| 3528 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3529 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3530 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3531 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3532 | sinfo->rx_packets)) |
| 3533 | goto nla_put_failure; |
| 3534 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3535 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3536 | sinfo->tx_packets)) |
| 3537 | goto nla_put_failure; |
| 3538 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3539 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3540 | sinfo->tx_retries)) |
| 3541 | goto nla_put_failure; |
| 3542 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3543 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3544 | sinfo->tx_failed)) |
| 3545 | goto nla_put_failure; |
| 3546 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3547 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3548 | sinfo->beacon_loss_count)) |
| 3549 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3550 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3551 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3552 | sinfo->local_pm)) |
| 3553 | goto nla_put_failure; |
| 3554 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3555 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3556 | sinfo->peer_pm)) |
| 3557 | goto nla_put_failure; |
| 3558 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3559 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3560 | sinfo->nonpeer_pm)) |
| 3561 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3562 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3563 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3564 | if (!bss_param) |
| 3565 | goto nla_put_failure; |
| 3566 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3567 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3568 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3569 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3570 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3571 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3572 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3573 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3574 | sinfo->bss_param.dtim_period) || |
| 3575 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3576 | sinfo->bss_param.beacon_interval)) |
| 3577 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3578 | |
| 3579 | nla_nest_end(msg, bss_param); |
| 3580 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3581 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3582 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3583 | sizeof(struct nl80211_sta_flag_update), |
| 3584 | &sinfo->sta_flags)) |
| 3585 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3586 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3587 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3588 | sinfo->t_offset)) |
| 3589 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3590 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3591 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3592 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3593 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3594 | sinfo->assoc_req_ies)) |
| 3595 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3596 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3597 | return genlmsg_end(msg, hdr); |
| 3598 | |
| 3599 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3600 | genlmsg_cancel(msg, hdr); |
| 3601 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3602 | } |
| 3603 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3604 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3605 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3606 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3607 | struct station_info sinfo; |
| 3608 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3609 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3610 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3611 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3612 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3613 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3614 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3615 | if (err) |
| 3616 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3617 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3618 | if (!wdev->netdev) { |
| 3619 | err = -EINVAL; |
| 3620 | goto out_err; |
| 3621 | } |
| 3622 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3623 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3624 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3625 | goto out_err; |
| 3626 | } |
| 3627 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3628 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3629 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3630 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3631 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3632 | if (err == -ENOENT) |
| 3633 | break; |
| 3634 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3635 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3636 | |
| 3637 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3638 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3639 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3640 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3641 | &sinfo) < 0) |
| 3642 | goto out; |
| 3643 | |
| 3644 | sta_idx++; |
| 3645 | } |
| 3646 | |
| 3647 | |
| 3648 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3649 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3650 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3651 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3652 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3653 | |
| 3654 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3655 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3656 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3657 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3658 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3659 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3660 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3661 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3662 | struct sk_buff *msg; |
| 3663 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3664 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3665 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3666 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3667 | |
| 3668 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3669 | return -EINVAL; |
| 3670 | |
| 3671 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3672 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3673 | if (!rdev->ops->get_station) |
| 3674 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3675 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3676 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3677 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3678 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3679 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3680 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3681 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3682 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3683 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3684 | 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] | 3685 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3686 | nlmsg_free(msg); |
| 3687 | return -ENOBUFS; |
| 3688 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3689 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3690 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3691 | } |
| 3692 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3693 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3694 | struct station_parameters *params, |
| 3695 | enum cfg80211_station_type statype) |
| 3696 | { |
| 3697 | if (params->listen_interval != -1) |
| 3698 | return -EINVAL; |
| 3699 | if (params->aid) |
| 3700 | return -EINVAL; |
| 3701 | |
| 3702 | /* When you run into this, adjust the code below for the new flag */ |
| 3703 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3704 | |
| 3705 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3706 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3707 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3708 | /* |
| 3709 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3710 | * code doesn't have the bug of including TDLS in the |
| 3711 | * mask everywhere. |
| 3712 | */ |
| 3713 | if (params->sta_flags_mask & |
| 3714 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3715 | BIT(NL80211_STA_FLAG_MFP) | |
| 3716 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3717 | return -EINVAL; |
| 3718 | break; |
| 3719 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3720 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3721 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3722 | return -EINVAL; |
| 3723 | /* ignore since it can't change */ |
| 3724 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3725 | break; |
| 3726 | default: |
| 3727 | /* disallow mesh-specific things */ |
| 3728 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3729 | return -EINVAL; |
| 3730 | if (params->local_pm) |
| 3731 | return -EINVAL; |
| 3732 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3733 | return -EINVAL; |
| 3734 | } |
| 3735 | |
| 3736 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3737 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3738 | /* TDLS can't be set, ... */ |
| 3739 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3740 | return -EINVAL; |
| 3741 | /* |
| 3742 | * ... but don't bother the driver with it. This works around |
| 3743 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3744 | * TLDS_PEER flag in the mask even for AP mode. |
| 3745 | */ |
| 3746 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3747 | } |
| 3748 | |
| 3749 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3750 | /* reject other things that can't change */ |
| 3751 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3752 | return -EINVAL; |
| 3753 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3754 | return -EINVAL; |
| 3755 | if (params->supported_rates) |
| 3756 | return -EINVAL; |
| 3757 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3758 | return -EINVAL; |
| 3759 | } |
| 3760 | |
| 3761 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3762 | if (params->vlan) |
| 3763 | return -EINVAL; |
| 3764 | } |
| 3765 | |
| 3766 | switch (statype) { |
| 3767 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3768 | /* Use this only for authorizing/unauthorizing a station */ |
| 3769 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3770 | return -EOPNOTSUPP; |
| 3771 | break; |
| 3772 | case CFG80211_STA_AP_CLIENT: |
| 3773 | /* accept only the listed bits */ |
| 3774 | if (params->sta_flags_mask & |
| 3775 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3776 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3777 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3778 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3779 | BIT(NL80211_STA_FLAG_WME) | |
| 3780 | BIT(NL80211_STA_FLAG_MFP))) |
| 3781 | return -EINVAL; |
| 3782 | |
| 3783 | /* but authenticated/associated only if driver handles it */ |
| 3784 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3785 | params->sta_flags_mask & |
| 3786 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3787 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3788 | return -EINVAL; |
| 3789 | break; |
| 3790 | case CFG80211_STA_IBSS: |
| 3791 | case CFG80211_STA_AP_STA: |
| 3792 | /* reject any changes other than AUTHORIZED */ |
| 3793 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3794 | return -EINVAL; |
| 3795 | break; |
| 3796 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3797 | /* reject any changes other than AUTHORIZED or WME */ |
| 3798 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3799 | BIT(NL80211_STA_FLAG_WME))) |
| 3800 | return -EINVAL; |
| 3801 | /* force (at least) rates when authorizing */ |
| 3802 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3803 | !params->supported_rates) |
| 3804 | return -EINVAL; |
| 3805 | break; |
| 3806 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3807 | /* reject any changes */ |
| 3808 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3809 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3810 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3811 | return -EINVAL; |
| 3812 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3813 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3814 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3815 | return -EINVAL; |
| 3816 | break; |
| 3817 | } |
| 3818 | |
| 3819 | return 0; |
| 3820 | } |
| 3821 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3822 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3823 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3824 | * 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] | 3825 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3826 | static struct net_device *get_vlan(struct genl_info *info, |
| 3827 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3828 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3829 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3830 | struct net_device *v; |
| 3831 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3832 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3833 | if (!vlanattr) |
| 3834 | return NULL; |
| 3835 | |
| 3836 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3837 | if (!v) |
| 3838 | return ERR_PTR(-ENODEV); |
| 3839 | |
| 3840 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3841 | ret = -EINVAL; |
| 3842 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3843 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3844 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3845 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3846 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3847 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3848 | ret = -EINVAL; |
| 3849 | goto error; |
| 3850 | } |
| 3851 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3852 | if (!netif_running(v)) { |
| 3853 | ret = -ENETDOWN; |
| 3854 | goto error; |
| 3855 | } |
| 3856 | |
| 3857 | return v; |
| 3858 | error: |
| 3859 | dev_put(v); |
| 3860 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3861 | } |
| 3862 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3863 | static struct nla_policy |
| 3864 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3865 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3866 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3867 | }; |
| 3868 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3869 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3870 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3871 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3872 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3873 | struct nlattr *nla; |
| 3874 | int err; |
| 3875 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3876 | /* parse WME attributes if present */ |
| 3877 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3878 | return 0; |
| 3879 | |
| 3880 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3881 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3882 | nl80211_sta_wme_policy); |
| 3883 | if (err) |
| 3884 | return err; |
| 3885 | |
| 3886 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3887 | params->uapsd_queues = nla_get_u8( |
| 3888 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3889 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3890 | return -EINVAL; |
| 3891 | |
| 3892 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3893 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3894 | |
| 3895 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3896 | return -EINVAL; |
| 3897 | |
| 3898 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3899 | |
| 3900 | return 0; |
| 3901 | } |
| 3902 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3903 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3904 | struct station_parameters *params) |
| 3905 | { |
| 3906 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3907 | params->supported_channels = |
| 3908 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3909 | params->supported_channels_len = |
| 3910 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3911 | /* |
| 3912 | * Need to include at least one (first channel, number of |
| 3913 | * channels) tuple for each subband, and must have proper |
| 3914 | * tuples for the rest of the data as well. |
| 3915 | */ |
| 3916 | if (params->supported_channels_len < 2) |
| 3917 | return -EINVAL; |
| 3918 | if (params->supported_channels_len % 2) |
| 3919 | return -EINVAL; |
| 3920 | } |
| 3921 | |
| 3922 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3923 | params->supported_oper_classes = |
| 3924 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3925 | params->supported_oper_classes_len = |
| 3926 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3927 | /* |
| 3928 | * The value of the Length field of the Supported Operating |
| 3929 | * Classes element is between 2 and 253. |
| 3930 | */ |
| 3931 | if (params->supported_oper_classes_len < 2 || |
| 3932 | params->supported_oper_classes_len > 253) |
| 3933 | return -EINVAL; |
| 3934 | } |
| 3935 | return 0; |
| 3936 | } |
| 3937 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3938 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3939 | struct station_parameters *params) |
| 3940 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3941 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3942 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3943 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3944 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3945 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3946 | params->ht_capa = |
| 3947 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3948 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3949 | params->vht_capa = |
| 3950 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3951 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3952 | err = nl80211_parse_sta_channel_info(info, params); |
| 3953 | if (err) |
| 3954 | return err; |
| 3955 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3956 | return nl80211_parse_sta_wme(info, params); |
| 3957 | } |
| 3958 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3959 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3960 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3961 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3962 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3963 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3964 | u8 *mac_addr; |
| 3965 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3966 | |
| 3967 | memset(¶ms, 0, sizeof(params)); |
| 3968 | |
| 3969 | params.listen_interval = -1; |
| 3970 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3971 | if (!rdev->ops->change_station) |
| 3972 | return -EOPNOTSUPP; |
| 3973 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3974 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3975 | return -EINVAL; |
| 3976 | |
| 3977 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3978 | return -EINVAL; |
| 3979 | |
| 3980 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3981 | |
| 3982 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3983 | params.supported_rates = |
| 3984 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3985 | params.supported_rates_len = |
| 3986 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3987 | } |
| 3988 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3989 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3990 | params.capability = |
| 3991 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3992 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3993 | } |
| 3994 | |
| 3995 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3996 | params.ext_capab = |
| 3997 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3998 | params.ext_capab_len = |
| 3999 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4000 | } |
| 4001 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4002 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4003 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4004 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4005 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4006 | return -EINVAL; |
| 4007 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4008 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4009 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4010 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4011 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4012 | return -EINVAL; |
| 4013 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4014 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4015 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4016 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4017 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4018 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4019 | return -EINVAL; |
| 4020 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4021 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4022 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4023 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4024 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4025 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4026 | |
| 4027 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4028 | pm > NL80211_MESH_POWER_MAX) |
| 4029 | return -EINVAL; |
| 4030 | |
| 4031 | params.local_pm = pm; |
| 4032 | } |
| 4033 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4034 | /* Include parameters for TDLS peer (will check later) */ |
| 4035 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4036 | if (err) |
| 4037 | return err; |
| 4038 | |
| 4039 | params.vlan = get_vlan(info, rdev); |
| 4040 | if (IS_ERR(params.vlan)) |
| 4041 | return PTR_ERR(params.vlan); |
| 4042 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4043 | switch (dev->ieee80211_ptr->iftype) { |
| 4044 | case NL80211_IFTYPE_AP: |
| 4045 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4046 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4047 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4048 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4049 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4050 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4051 | break; |
| 4052 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4053 | err = -EOPNOTSUPP; |
| 4054 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4055 | } |
| 4056 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4057 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4058 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4059 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4060 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4061 | if (params.vlan) |
| 4062 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4063 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4064 | return err; |
| 4065 | } |
| 4066 | |
| 4067 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4068 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4069 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4070 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4071 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4072 | struct station_parameters params; |
| 4073 | u8 *mac_addr = NULL; |
| 4074 | |
| 4075 | memset(¶ms, 0, sizeof(params)); |
| 4076 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4077 | if (!rdev->ops->add_station) |
| 4078 | return -EOPNOTSUPP; |
| 4079 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4080 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4081 | return -EINVAL; |
| 4082 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4083 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4084 | return -EINVAL; |
| 4085 | |
| 4086 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4087 | return -EINVAL; |
| 4088 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4089 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4090 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4091 | return -EINVAL; |
| 4092 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4093 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4094 | params.supported_rates = |
| 4095 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4096 | params.supported_rates_len = |
| 4097 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4098 | params.listen_interval = |
| 4099 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4100 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4101 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4102 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4103 | else |
| 4104 | 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] | 4105 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4106 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4107 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4108 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4109 | params.capability = |
| 4110 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4111 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4112 | } |
| 4113 | |
| 4114 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4115 | params.ext_capab = |
| 4116 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4117 | params.ext_capab_len = |
| 4118 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4119 | } |
| 4120 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4121 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4122 | params.ht_capa = |
| 4123 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4124 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4125 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4126 | params.vht_capa = |
| 4127 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4128 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4129 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4130 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4131 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4132 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4133 | return -EINVAL; |
| 4134 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4135 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4136 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4137 | if (err) |
| 4138 | return err; |
| 4139 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4140 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4141 | if (err) |
| 4142 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4143 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4144 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4145 | return -EINVAL; |
| 4146 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4147 | /* When you run into this, adjust the code below for the new flag */ |
| 4148 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4149 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4150 | switch (dev->ieee80211_ptr->iftype) { |
| 4151 | case NL80211_IFTYPE_AP: |
| 4152 | case NL80211_IFTYPE_AP_VLAN: |
| 4153 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4154 | /* ignore WME attributes if iface/sta is not capable */ |
| 4155 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4156 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4157 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4158 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4159 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4160 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4161 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4162 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4163 | /* but don't bother the driver with it */ |
| 4164 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4165 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4166 | /* allow authenticated/associated only if driver handles it */ |
| 4167 | if (!(rdev->wiphy.features & |
| 4168 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4169 | params.sta_flags_mask & |
| 4170 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4171 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4172 | return -EINVAL; |
| 4173 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4174 | /* must be last in here for error handling */ |
| 4175 | params.vlan = get_vlan(info, rdev); |
| 4176 | if (IS_ERR(params.vlan)) |
| 4177 | return PTR_ERR(params.vlan); |
| 4178 | break; |
| 4179 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4180 | /* ignore uAPSD data */ |
| 4181 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4182 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4183 | /* associated is disallowed */ |
| 4184 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4185 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4186 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4187 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4188 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4189 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4190 | break; |
| 4191 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4192 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4193 | /* ignore uAPSD data */ |
| 4194 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4195 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4196 | /* these are disallowed */ |
| 4197 | if (params.sta_flags_mask & |
| 4198 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4199 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4200 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4201 | /* Only TDLS peers can be added */ |
| 4202 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4203 | return -EINVAL; |
| 4204 | /* Can only add if TDLS ... */ |
| 4205 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4206 | return -EOPNOTSUPP; |
| 4207 | /* ... with external setup is supported */ |
| 4208 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4209 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4210 | /* |
| 4211 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4212 | * as authorized, but it shouldn't yet be. |
| 4213 | */ |
| 4214 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4215 | break; |
| 4216 | default: |
| 4217 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4218 | } |
| 4219 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4220 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4221 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4222 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4223 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4224 | if (params.vlan) |
| 4225 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4226 | return err; |
| 4227 | } |
| 4228 | |
| 4229 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4230 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4231 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4232 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4233 | u8 *mac_addr = NULL; |
| 4234 | |
| 4235 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4236 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4237 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4238 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4239 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4240 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4241 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4242 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4243 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4244 | if (!rdev->ops->del_station) |
| 4245 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4246 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4247 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4248 | } |
| 4249 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4250 | 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] | 4251 | int flags, struct net_device *dev, |
| 4252 | u8 *dst, u8 *next_hop, |
| 4253 | struct mpath_info *pinfo) |
| 4254 | { |
| 4255 | void *hdr; |
| 4256 | struct nlattr *pinfoattr; |
| 4257 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4258 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4259 | if (!hdr) |
| 4260 | return -1; |
| 4261 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4262 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4263 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4264 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4265 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4266 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4267 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4268 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4269 | if (!pinfoattr) |
| 4270 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4271 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4272 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4273 | pinfo->frame_qlen)) |
| 4274 | goto nla_put_failure; |
| 4275 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4276 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4277 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4278 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4279 | pinfo->metric)) || |
| 4280 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4281 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4282 | pinfo->exptime)) || |
| 4283 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4284 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4285 | pinfo->flags)) || |
| 4286 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4287 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4288 | pinfo->discovery_timeout)) || |
| 4289 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4290 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4291 | pinfo->discovery_retries))) |
| 4292 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4293 | |
| 4294 | nla_nest_end(msg, pinfoattr); |
| 4295 | |
| 4296 | return genlmsg_end(msg, hdr); |
| 4297 | |
| 4298 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4299 | genlmsg_cancel(msg, hdr); |
| 4300 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4304 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4305 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4306 | struct mpath_info pinfo; |
| 4307 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4308 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4309 | u8 dst[ETH_ALEN]; |
| 4310 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4311 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4312 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4313 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4314 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4315 | if (err) |
| 4316 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4317 | |
| 4318 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4319 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4320 | goto out_err; |
| 4321 | } |
| 4322 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4323 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4324 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4325 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4326 | } |
| 4327 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4328 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4329 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4330 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4331 | if (err == -ENOENT) |
| 4332 | break; |
| 4333 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4334 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4335 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4336 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4337 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4338 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4339 | &pinfo) < 0) |
| 4340 | goto out; |
| 4341 | |
| 4342 | path_idx++; |
| 4343 | } |
| 4344 | |
| 4345 | |
| 4346 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4347 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4348 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4349 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4350 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4351 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4355 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4357 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4358 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4359 | struct mpath_info pinfo; |
| 4360 | struct sk_buff *msg; |
| 4361 | u8 *dst = NULL; |
| 4362 | u8 next_hop[ETH_ALEN]; |
| 4363 | |
| 4364 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4365 | |
| 4366 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4367 | return -EINVAL; |
| 4368 | |
| 4369 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4370 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4371 | if (!rdev->ops->get_mpath) |
| 4372 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4373 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4374 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4375 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4376 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4377 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4378 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4379 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4380 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4381 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4382 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4383 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4384 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4385 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4386 | dev, dst, next_hop, &pinfo) < 0) { |
| 4387 | nlmsg_free(msg); |
| 4388 | return -ENOBUFS; |
| 4389 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4390 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4391 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4392 | } |
| 4393 | |
| 4394 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4395 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4397 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4398 | u8 *dst = NULL; |
| 4399 | u8 *next_hop = NULL; |
| 4400 | |
| 4401 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4402 | return -EINVAL; |
| 4403 | |
| 4404 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4405 | return -EINVAL; |
| 4406 | |
| 4407 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4408 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4409 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4410 | if (!rdev->ops->change_mpath) |
| 4411 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4412 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4413 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4414 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4415 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4416 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4417 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4418 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4419 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4420 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4421 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4422 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4423 | u8 *dst = NULL; |
| 4424 | u8 *next_hop = NULL; |
| 4425 | |
| 4426 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4427 | return -EINVAL; |
| 4428 | |
| 4429 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4430 | return -EINVAL; |
| 4431 | |
| 4432 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4433 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4434 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4435 | if (!rdev->ops->add_mpath) |
| 4436 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4437 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4438 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4439 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4440 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4441 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4442 | } |
| 4443 | |
| 4444 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4445 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4447 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4448 | u8 *dst = NULL; |
| 4449 | |
| 4450 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4451 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4452 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4453 | if (!rdev->ops->del_mpath) |
| 4454 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4455 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4456 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4457 | } |
| 4458 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4459 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4460 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4461 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4462 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4463 | struct bss_parameters params; |
| 4464 | |
| 4465 | memset(¶ms, 0, sizeof(params)); |
| 4466 | /* default to not changing parameters */ |
| 4467 | params.use_cts_prot = -1; |
| 4468 | params.use_short_preamble = -1; |
| 4469 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4470 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4471 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4472 | params.p2p_ctwindow = -1; |
| 4473 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4474 | |
| 4475 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4476 | params.use_cts_prot = |
| 4477 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4478 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4479 | params.use_short_preamble = |
| 4480 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4481 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4482 | params.use_short_slot_time = |
| 4483 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4484 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4485 | params.basic_rates = |
| 4486 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4487 | params.basic_rates_len = |
| 4488 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4489 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4490 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4491 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4492 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4493 | params.ht_opmode = |
| 4494 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4495 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4496 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4497 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4498 | return -EINVAL; |
| 4499 | params.p2p_ctwindow = |
| 4500 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4501 | if (params.p2p_ctwindow < 0) |
| 4502 | return -EINVAL; |
| 4503 | if (params.p2p_ctwindow != 0 && |
| 4504 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4505 | return -EINVAL; |
| 4506 | } |
| 4507 | |
| 4508 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4509 | u8 tmp; |
| 4510 | |
| 4511 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4512 | return -EINVAL; |
| 4513 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4514 | if (tmp > 1) |
| 4515 | return -EINVAL; |
| 4516 | params.p2p_opp_ps = tmp; |
| 4517 | if (params.p2p_opp_ps && |
| 4518 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4519 | return -EINVAL; |
| 4520 | } |
| 4521 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4522 | if (!rdev->ops->change_bss) |
| 4523 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4524 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4526 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4527 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4528 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4529 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4530 | } |
| 4531 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4532 | 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] | 4533 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4534 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4535 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4536 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4537 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4538 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4539 | }; |
| 4540 | |
| 4541 | static int parse_reg_rule(struct nlattr *tb[], |
| 4542 | struct ieee80211_reg_rule *reg_rule) |
| 4543 | { |
| 4544 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4545 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4546 | |
| 4547 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4548 | return -EINVAL; |
| 4549 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4550 | return -EINVAL; |
| 4551 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4552 | return -EINVAL; |
| 4553 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4554 | return -EINVAL; |
| 4555 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4556 | return -EINVAL; |
| 4557 | |
| 4558 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4559 | |
| 4560 | freq_range->start_freq_khz = |
| 4561 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4562 | freq_range->end_freq_khz = |
| 4563 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4564 | freq_range->max_bandwidth_khz = |
| 4565 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4566 | |
| 4567 | power_rule->max_eirp = |
| 4568 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4569 | |
| 4570 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4571 | power_rule->max_antenna_gain = |
| 4572 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4573 | |
| 4574 | return 0; |
| 4575 | } |
| 4576 | |
| 4577 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4578 | { |
| 4579 | int r; |
| 4580 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4581 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4582 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4583 | /* |
| 4584 | * You should only get this when cfg80211 hasn't yet initialized |
| 4585 | * completely when built-in to the kernel right between the time |
| 4586 | * window between nl80211_init() and regulatory_init(), if that is |
| 4587 | * even possible. |
| 4588 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4589 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4590 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4591 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4592 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4593 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4594 | |
| 4595 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4596 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4597 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4598 | user_reg_hint_type = |
| 4599 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4600 | else |
| 4601 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4602 | |
| 4603 | switch (user_reg_hint_type) { |
| 4604 | case NL80211_USER_REG_HINT_USER: |
| 4605 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4606 | break; |
| 4607 | default: |
| 4608 | return -EINVAL; |
| 4609 | } |
| 4610 | |
| 4611 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4612 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4613 | return r; |
| 4614 | } |
| 4615 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4616 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4617 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4618 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4620 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4621 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4622 | struct mesh_config cur_params; |
| 4623 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4624 | void *hdr; |
| 4625 | struct nlattr *pinfoattr; |
| 4626 | struct sk_buff *msg; |
| 4627 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4628 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4629 | return -EOPNOTSUPP; |
| 4630 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4631 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4632 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4633 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4634 | wdev_lock(wdev); |
| 4635 | /* If not connected, get default parameters */ |
| 4636 | if (!wdev->mesh_id_len) |
| 4637 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4638 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4639 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4640 | wdev_unlock(wdev); |
| 4641 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4642 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4643 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4644 | |
| 4645 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4646 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4647 | if (!msg) |
| 4648 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4649 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4650 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4651 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4652 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4653 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4654 | if (!pinfoattr) |
| 4655 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4656 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4657 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4658 | cur_params.dot11MeshRetryTimeout) || |
| 4659 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4660 | cur_params.dot11MeshConfirmTimeout) || |
| 4661 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4662 | cur_params.dot11MeshHoldingTimeout) || |
| 4663 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4664 | cur_params.dot11MeshMaxPeerLinks) || |
| 4665 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4666 | cur_params.dot11MeshMaxRetries) || |
| 4667 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4668 | cur_params.dot11MeshTTL) || |
| 4669 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4670 | cur_params.element_ttl) || |
| 4671 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4672 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4673 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4674 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4675 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4676 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4677 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4678 | cur_params.path_refresh_time) || |
| 4679 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4680 | cur_params.min_discovery_timeout) || |
| 4681 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4682 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4683 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4684 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4685 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4686 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4687 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4688 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4689 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4690 | cur_params.dot11MeshHWMPRootMode) || |
| 4691 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4692 | cur_params.dot11MeshHWMPRannInterval) || |
| 4693 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4694 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4695 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4696 | cur_params.dot11MeshForwarding) || |
| 4697 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4698 | cur_params.rssi_threshold) || |
| 4699 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4700 | cur_params.ht_opmode) || |
| 4701 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4702 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4703 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4704 | cur_params.dot11MeshHWMProotInterval) || |
| 4705 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4706 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4707 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4708 | cur_params.power_mode) || |
| 4709 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4710 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4711 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4712 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4713 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4714 | nla_nest_end(msg, pinfoattr); |
| 4715 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4716 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4717 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4718 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4719 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4720 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4721 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4722 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4723 | } |
| 4724 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4725 | 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] | 4726 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4727 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4728 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4729 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4730 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4731 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4732 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4733 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4734 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4735 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4736 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4737 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4738 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4739 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4740 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4741 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4742 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4743 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4744 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4745 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4746 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4747 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4748 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4749 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4750 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4751 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4752 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4753 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4754 | }; |
| 4755 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4756 | static const struct nla_policy |
| 4757 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4758 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4759 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4760 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4761 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4762 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4763 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4764 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4765 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4766 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4767 | }; |
| 4768 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4769 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4770 | struct mesh_config *cfg, |
| 4771 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4772 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4773 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4774 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4775 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4776 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4777 | do { \ |
| 4778 | if (tb[attr]) { \ |
| 4779 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4780 | return -EINVAL; \ |
| 4781 | cfg->param = fn(tb[attr]); \ |
| 4782 | mask |= (1 << (attr - 1)); \ |
| 4783 | } \ |
| 4784 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4785 | |
| 4786 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4787 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4788 | return -EINVAL; |
| 4789 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4790 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4791 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4792 | return -EINVAL; |
| 4793 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4794 | /* This makes sure that there aren't more than 32 mesh config |
| 4795 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4796 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4797 | |
| 4798 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4799 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4800 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4801 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4802 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4803 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4804 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4805 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4806 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4807 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4808 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4809 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4810 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4811 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4812 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4813 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4814 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4815 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4816 | 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] | 4817 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4818 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4819 | 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] | 4820 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4821 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4822 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4823 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4824 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4825 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4826 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4827 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4828 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4829 | 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] | 4830 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4831 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4832 | 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] | 4833 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4834 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4835 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4836 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4837 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4838 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4839 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4840 | 1, 65535, mask, |
| 4841 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4842 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4843 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4844 | 1, 65535, mask, |
| 4845 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4846 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4847 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4848 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4849 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4850 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4851 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4852 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4853 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4854 | nla_get_u8); |
| 4855 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4856 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4857 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4858 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4859 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4860 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4861 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4863 | mask, NL80211_MESHCONF_FORWARDING, |
| 4864 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4865 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4866 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4867 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4868 | 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] | 4869 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4870 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4871 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4872 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4873 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4874 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4875 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4876 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4877 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4878 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4879 | dot11MeshHWMPconfirmationInterval, |
| 4880 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4881 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4882 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4883 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4884 | NL80211_MESH_POWER_ACTIVE, |
| 4885 | NL80211_MESH_POWER_MAX, |
| 4886 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4887 | nla_get_u32); |
| 4888 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4889 | 0, 65535, mask, |
| 4890 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4891 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4892 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4893 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4894 | if (mask_out) |
| 4895 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4896 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4897 | return 0; |
| 4898 | |
| 4899 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4900 | } |
| 4901 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4902 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4903 | struct mesh_setup *setup) |
| 4904 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4905 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4906 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4907 | |
| 4908 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4909 | return -EINVAL; |
| 4910 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4911 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4912 | nl80211_mesh_setup_params_policy)) |
| 4913 | return -EINVAL; |
| 4914 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4915 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4916 | setup->sync_method = |
| 4917 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4918 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4919 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4920 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4921 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4922 | setup->path_sel_proto = |
| 4923 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4924 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4925 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4926 | |
| 4927 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4928 | setup->path_metric = |
| 4929 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4930 | IEEE80211_PATH_METRIC_VENDOR : |
| 4931 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4932 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4933 | |
| 4934 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4935 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4936 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4937 | if (!is_valid_ie_attr(ieattr)) |
| 4938 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4939 | setup->ie = nla_data(ieattr); |
| 4940 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4941 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4942 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4943 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4944 | return -EINVAL; |
| 4945 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4946 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4947 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4948 | if (setup->is_secure) |
| 4949 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4950 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4951 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4952 | if (!setup->user_mpm) |
| 4953 | return -EINVAL; |
| 4954 | setup->auth_id = |
| 4955 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4956 | } |
| 4957 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4958 | return 0; |
| 4959 | } |
| 4960 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4961 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4962 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4963 | { |
| 4964 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4965 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4966 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4967 | struct mesh_config cfg; |
| 4968 | u32 mask; |
| 4969 | int err; |
| 4970 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4971 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4972 | return -EOPNOTSUPP; |
| 4973 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4974 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4975 | return -EOPNOTSUPP; |
| 4976 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4977 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4978 | if (err) |
| 4979 | return err; |
| 4980 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4981 | wdev_lock(wdev); |
| 4982 | if (!wdev->mesh_id_len) |
| 4983 | err = -ENOLINK; |
| 4984 | |
| 4985 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4986 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4987 | |
| 4988 | wdev_unlock(wdev); |
| 4989 | |
| 4990 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4991 | } |
| 4992 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4993 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4994 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4995 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4996 | struct sk_buff *msg; |
| 4997 | void *hdr = NULL; |
| 4998 | struct nlattr *nl_reg_rules; |
| 4999 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5000 | |
| 5001 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5002 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5003 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5004 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5005 | if (!msg) |
| 5006 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5007 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5008 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5009 | NL80211_CMD_GET_REG); |
| 5010 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5011 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5012 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5013 | if (reg_last_request_cell_base() && |
| 5014 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5015 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5016 | goto nla_put_failure; |
| 5017 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5018 | rcu_read_lock(); |
| 5019 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5020 | |
| 5021 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5022 | (regdom->dfs_region && |
| 5023 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5024 | goto nla_put_failure_rcu; |
| 5025 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5026 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5027 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5028 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5029 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5030 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5031 | struct nlattr *nl_reg_rule; |
| 5032 | const struct ieee80211_reg_rule *reg_rule; |
| 5033 | const struct ieee80211_freq_range *freq_range; |
| 5034 | const struct ieee80211_power_rule *power_rule; |
| 5035 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5036 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5037 | freq_range = ®_rule->freq_range; |
| 5038 | power_rule = ®_rule->power_rule; |
| 5039 | |
| 5040 | nl_reg_rule = nla_nest_start(msg, i); |
| 5041 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5042 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5043 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5044 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5045 | reg_rule->flags) || |
| 5046 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5047 | freq_range->start_freq_khz) || |
| 5048 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5049 | freq_range->end_freq_khz) || |
| 5050 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5051 | freq_range->max_bandwidth_khz) || |
| 5052 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5053 | power_rule->max_antenna_gain) || |
| 5054 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5055 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5056 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5057 | |
| 5058 | nla_nest_end(msg, nl_reg_rule); |
| 5059 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5060 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5061 | |
| 5062 | nla_nest_end(msg, nl_reg_rules); |
| 5063 | |
| 5064 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5065 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5066 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5067 | nla_put_failure_rcu: |
| 5068 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5069 | nla_put_failure: |
| 5070 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5071 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5072 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5073 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5074 | } |
| 5075 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5076 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5077 | { |
| 5078 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5079 | struct nlattr *nl_reg_rule; |
| 5080 | char *alpha2 = NULL; |
| 5081 | int rem_reg_rules = 0, r = 0; |
| 5082 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5083 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5084 | struct ieee80211_regdomain *rd = NULL; |
| 5085 | |
| 5086 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5087 | return -EINVAL; |
| 5088 | |
| 5089 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5090 | return -EINVAL; |
| 5091 | |
| 5092 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5093 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5094 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5095 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5096 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5097 | 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] | 5098 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5099 | num_rules++; |
| 5100 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5101 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5104 | if (!reg_is_valid_request(alpha2)) |
| 5105 | return -EINVAL; |
| 5106 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5107 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5108 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5109 | |
| 5110 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5111 | if (!rd) |
| 5112 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5113 | |
| 5114 | rd->n_reg_rules = num_rules; |
| 5115 | rd->alpha2[0] = alpha2[0]; |
| 5116 | rd->alpha2[1] = alpha2[1]; |
| 5117 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5118 | /* |
| 5119 | * Disable DFS master mode if the DFS region was |
| 5120 | * not supported or known on this kernel. |
| 5121 | */ |
| 5122 | if (reg_supported_dfs_region(dfs_region)) |
| 5123 | rd->dfs_region = dfs_region; |
| 5124 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5125 | 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] | 5126 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5127 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5128 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5129 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5130 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5131 | if (r) |
| 5132 | goto bad_reg; |
| 5133 | |
| 5134 | rule_idx++; |
| 5135 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5136 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5137 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5138 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5139 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5140 | } |
| 5141 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5142 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5143 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5144 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5145 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5146 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5147 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5148 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5149 | } |
| 5150 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5151 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5152 | { |
| 5153 | struct nlattr *attr1, *attr2; |
| 5154 | int n_channels = 0, tmp1, tmp2; |
| 5155 | |
| 5156 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5157 | n_channels++; |
| 5158 | /* |
| 5159 | * Some hardware has a limited channel list for |
| 5160 | * scanning, and it is pretty much nonsensical |
| 5161 | * to scan for a channel twice, so disallow that |
| 5162 | * and don't require drivers to check that the |
| 5163 | * channel list they get isn't longer than what |
| 5164 | * they can scan, as long as they can scan all |
| 5165 | * the channels they registered at once. |
| 5166 | */ |
| 5167 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5168 | if (attr1 != attr2 && |
| 5169 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5170 | return 0; |
| 5171 | } |
| 5172 | |
| 5173 | return n_channels; |
| 5174 | } |
| 5175 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5176 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5177 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5178 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5179 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5180 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5181 | struct nlattr *attr; |
| 5182 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5183 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5184 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5185 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5186 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5187 | return -EINVAL; |
| 5188 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5189 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5190 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5191 | if (!rdev->ops->scan) |
| 5192 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5193 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5194 | if (rdev->scan_req) { |
| 5195 | err = -EBUSY; |
| 5196 | goto unlock; |
| 5197 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5198 | |
| 5199 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5200 | n_channels = validate_scan_freqs( |
| 5201 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5202 | if (!n_channels) { |
| 5203 | err = -EINVAL; |
| 5204 | goto unlock; |
| 5205 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5206 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5207 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5208 | n_channels = 0; |
| 5209 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5210 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5211 | if (wiphy->bands[band]) |
| 5212 | n_channels += wiphy->bands[band]->n_channels; |
| 5213 | } |
| 5214 | |
| 5215 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5216 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5217 | n_ssids++; |
| 5218 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5219 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5220 | err = -EINVAL; |
| 5221 | goto unlock; |
| 5222 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5223 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5224 | if (info->attrs[NL80211_ATTR_IE]) |
| 5225 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5226 | else |
| 5227 | ie_len = 0; |
| 5228 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5229 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5230 | err = -EINVAL; |
| 5231 | goto unlock; |
| 5232 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5233 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5234 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5235 | + sizeof(*request->ssids) * n_ssids |
| 5236 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5237 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5238 | if (!request) { |
| 5239 | err = -ENOMEM; |
| 5240 | goto unlock; |
| 5241 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5242 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5243 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5244 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5245 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5246 | if (ie_len) { |
| 5247 | if (request->ssids) |
| 5248 | request->ie = (void *)(request->ssids + n_ssids); |
| 5249 | else |
| 5250 | request->ie = (void *)(request->channels + n_channels); |
| 5251 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5252 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5253 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5254 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5255 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5256 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5257 | struct ieee80211_channel *chan; |
| 5258 | |
| 5259 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5260 | |
| 5261 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5262 | err = -EINVAL; |
| 5263 | goto out_free; |
| 5264 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5265 | |
| 5266 | /* ignore disabled channels */ |
| 5267 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5268 | continue; |
| 5269 | |
| 5270 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5271 | i++; |
| 5272 | } |
| 5273 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5274 | enum ieee80211_band band; |
| 5275 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5276 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5277 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5278 | int j; |
| 5279 | if (!wiphy->bands[band]) |
| 5280 | continue; |
| 5281 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5282 | struct ieee80211_channel *chan; |
| 5283 | |
| 5284 | chan = &wiphy->bands[band]->channels[j]; |
| 5285 | |
| 5286 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5287 | continue; |
| 5288 | |
| 5289 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5290 | i++; |
| 5291 | } |
| 5292 | } |
| 5293 | } |
| 5294 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5295 | if (!i) { |
| 5296 | err = -EINVAL; |
| 5297 | goto out_free; |
| 5298 | } |
| 5299 | |
| 5300 | request->n_channels = i; |
| 5301 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5302 | i = 0; |
| 5303 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5304 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5305 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5306 | err = -EINVAL; |
| 5307 | goto out_free; |
| 5308 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5309 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5310 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5311 | i++; |
| 5312 | } |
| 5313 | } |
| 5314 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5315 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5316 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5317 | memcpy((void *)request->ie, |
| 5318 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5319 | request->ie_len); |
| 5320 | } |
| 5321 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5322 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5323 | if (wiphy->bands[i]) |
| 5324 | request->rates[i] = |
| 5325 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5326 | |
| 5327 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5328 | nla_for_each_nested(attr, |
| 5329 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5330 | tmp) { |
| 5331 | enum ieee80211_band band = nla_type(attr); |
| 5332 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5333 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5334 | err = -EINVAL; |
| 5335 | goto out_free; |
| 5336 | } |
| 5337 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5338 | nla_data(attr), |
| 5339 | nla_len(attr), |
| 5340 | &request->rates[band]); |
| 5341 | if (err) |
| 5342 | goto out_free; |
| 5343 | } |
| 5344 | } |
| 5345 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5346 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5347 | request->flags = nla_get_u32( |
| 5348 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5349 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5350 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5351 | err = -EOPNOTSUPP; |
| 5352 | goto out_free; |
| 5353 | } |
| 5354 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5355 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5356 | request->no_cck = |
| 5357 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5358 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5359 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5360 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5361 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5362 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5363 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5364 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5365 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5366 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5367 | nl80211_send_scan_start(rdev, wdev); |
| 5368 | if (wdev->netdev) |
| 5369 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5370 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5371 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5372 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5373 | kfree(request); |
| 5374 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5375 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5376 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5377 | return err; |
| 5378 | } |
| 5379 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5380 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5381 | struct genl_info *info) |
| 5382 | { |
| 5383 | struct cfg80211_sched_scan_request *request; |
| 5384 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5385 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5386 | struct nlattr *attr; |
| 5387 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5388 | 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] | 5389 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5390 | enum ieee80211_band band; |
| 5391 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5392 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5393 | |
| 5394 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5395 | !rdev->ops->sched_scan_start) |
| 5396 | return -EOPNOTSUPP; |
| 5397 | |
| 5398 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5399 | return -EINVAL; |
| 5400 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5401 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5402 | return -EINVAL; |
| 5403 | |
| 5404 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5405 | if (interval == 0) |
| 5406 | return -EINVAL; |
| 5407 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5408 | wiphy = &rdev->wiphy; |
| 5409 | |
| 5410 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5411 | n_channels = validate_scan_freqs( |
| 5412 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5413 | if (!n_channels) |
| 5414 | return -EINVAL; |
| 5415 | } else { |
| 5416 | n_channels = 0; |
| 5417 | |
| 5418 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5419 | if (wiphy->bands[band]) |
| 5420 | n_channels += wiphy->bands[band]->n_channels; |
| 5421 | } |
| 5422 | |
| 5423 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5424 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5425 | tmp) |
| 5426 | n_ssids++; |
| 5427 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5428 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5429 | return -EINVAL; |
| 5430 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5431 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5432 | nla_for_each_nested(attr, |
| 5433 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5434 | tmp) |
| 5435 | n_match_sets++; |
| 5436 | |
| 5437 | if (n_match_sets > wiphy->max_match_sets) |
| 5438 | return -EINVAL; |
| 5439 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5440 | if (info->attrs[NL80211_ATTR_IE]) |
| 5441 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5442 | else |
| 5443 | ie_len = 0; |
| 5444 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5445 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5446 | return -EINVAL; |
| 5447 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5448 | if (rdev->sched_scan_req) { |
| 5449 | err = -EINPROGRESS; |
| 5450 | goto out; |
| 5451 | } |
| 5452 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5453 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5454 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5455 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5456 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5457 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5458 | if (!request) { |
| 5459 | err = -ENOMEM; |
| 5460 | goto out; |
| 5461 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5462 | |
| 5463 | if (n_ssids) |
| 5464 | request->ssids = (void *)&request->channels[n_channels]; |
| 5465 | request->n_ssids = n_ssids; |
| 5466 | if (ie_len) { |
| 5467 | if (request->ssids) |
| 5468 | request->ie = (void *)(request->ssids + n_ssids); |
| 5469 | else |
| 5470 | request->ie = (void *)(request->channels + n_channels); |
| 5471 | } |
| 5472 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5473 | if (n_match_sets) { |
| 5474 | if (request->ie) |
| 5475 | request->match_sets = (void *)(request->ie + ie_len); |
| 5476 | else if (request->ssids) |
| 5477 | request->match_sets = |
| 5478 | (void *)(request->ssids + n_ssids); |
| 5479 | else |
| 5480 | request->match_sets = |
| 5481 | (void *)(request->channels + n_channels); |
| 5482 | } |
| 5483 | request->n_match_sets = n_match_sets; |
| 5484 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5485 | i = 0; |
| 5486 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5487 | /* user specified, bail out if channel not found */ |
| 5488 | nla_for_each_nested(attr, |
| 5489 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5490 | tmp) { |
| 5491 | struct ieee80211_channel *chan; |
| 5492 | |
| 5493 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5494 | |
| 5495 | if (!chan) { |
| 5496 | err = -EINVAL; |
| 5497 | goto out_free; |
| 5498 | } |
| 5499 | |
| 5500 | /* ignore disabled channels */ |
| 5501 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5502 | continue; |
| 5503 | |
| 5504 | request->channels[i] = chan; |
| 5505 | i++; |
| 5506 | } |
| 5507 | } else { |
| 5508 | /* all channels */ |
| 5509 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5510 | int j; |
| 5511 | if (!wiphy->bands[band]) |
| 5512 | continue; |
| 5513 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5514 | struct ieee80211_channel *chan; |
| 5515 | |
| 5516 | chan = &wiphy->bands[band]->channels[j]; |
| 5517 | |
| 5518 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5519 | continue; |
| 5520 | |
| 5521 | request->channels[i] = chan; |
| 5522 | i++; |
| 5523 | } |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | if (!i) { |
| 5528 | err = -EINVAL; |
| 5529 | goto out_free; |
| 5530 | } |
| 5531 | |
| 5532 | request->n_channels = i; |
| 5533 | |
| 5534 | i = 0; |
| 5535 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5536 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5537 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5538 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5539 | err = -EINVAL; |
| 5540 | goto out_free; |
| 5541 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5542 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5543 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5544 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5545 | i++; |
| 5546 | } |
| 5547 | } |
| 5548 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5549 | i = 0; |
| 5550 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5551 | nla_for_each_nested(attr, |
| 5552 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5553 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5554 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5555 | |
| 5556 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5557 | nla_data(attr), nla_len(attr), |
| 5558 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5559 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5560 | if (ssid) { |
| 5561 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5562 | err = -EINVAL; |
| 5563 | goto out_free; |
| 5564 | } |
| 5565 | memcpy(request->match_sets[i].ssid.ssid, |
| 5566 | nla_data(ssid), nla_len(ssid)); |
| 5567 | request->match_sets[i].ssid.ssid_len = |
| 5568 | nla_len(ssid); |
| 5569 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5570 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5571 | if (rssi) |
| 5572 | request->rssi_thold = nla_get_u32(rssi); |
| 5573 | else |
| 5574 | request->rssi_thold = |
| 5575 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5576 | i++; |
| 5577 | } |
| 5578 | } |
| 5579 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5580 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5581 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5582 | memcpy((void *)request->ie, |
| 5583 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5584 | request->ie_len); |
| 5585 | } |
| 5586 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5587 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5588 | request->flags = nla_get_u32( |
| 5589 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5590 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5591 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5592 | err = -EOPNOTSUPP; |
| 5593 | goto out_free; |
| 5594 | } |
| 5595 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5596 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5597 | request->dev = dev; |
| 5598 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5599 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5600 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5601 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5602 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5603 | if (!err) { |
| 5604 | rdev->sched_scan_req = request; |
| 5605 | nl80211_send_sched_scan(rdev, dev, |
| 5606 | NL80211_CMD_START_SCHED_SCAN); |
| 5607 | goto out; |
| 5608 | } |
| 5609 | |
| 5610 | out_free: |
| 5611 | kfree(request); |
| 5612 | out: |
| 5613 | return err; |
| 5614 | } |
| 5615 | |
| 5616 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5617 | struct genl_info *info) |
| 5618 | { |
| 5619 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5620 | |
| 5621 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5622 | !rdev->ops->sched_scan_stop) |
| 5623 | return -EOPNOTSUPP; |
| 5624 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5625 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5626 | } |
| 5627 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5628 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5629 | struct genl_info *info) |
| 5630 | { |
| 5631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5632 | struct net_device *dev = info->user_ptr[1]; |
| 5633 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5634 | struct cfg80211_chan_def chandef; |
| 5635 | int err; |
| 5636 | |
| 5637 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5638 | if (err) |
| 5639 | return err; |
| 5640 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5641 | if (netif_carrier_ok(dev)) |
| 5642 | return -EBUSY; |
| 5643 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5644 | if (wdev->cac_started) |
| 5645 | return -EBUSY; |
| 5646 | |
| 5647 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5648 | if (err < 0) |
| 5649 | return err; |
| 5650 | |
| 5651 | if (err == 0) |
| 5652 | return -EINVAL; |
| 5653 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5654 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5655 | return -EINVAL; |
| 5656 | |
| 5657 | if (!rdev->ops->start_radar_detection) |
| 5658 | return -EOPNOTSUPP; |
| 5659 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5660 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5661 | chandef.chan, CHAN_MODE_SHARED, |
| 5662 | BIT(chandef.width)); |
| 5663 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5664 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5665 | |
| 5666 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5667 | if (!err) { |
| 5668 | wdev->channel = chandef.chan; |
| 5669 | wdev->cac_started = true; |
| 5670 | wdev->cac_start_time = jiffies; |
| 5671 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5672 | return err; |
| 5673 | } |
| 5674 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5675 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5676 | { |
| 5677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5678 | struct net_device *dev = info->user_ptr[1]; |
| 5679 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5680 | struct cfg80211_csa_settings params; |
| 5681 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5682 | * function is called under RTNL lock, so this should not be a problem. |
| 5683 | */ |
| 5684 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5685 | u8 radar_detect_width = 0; |
| 5686 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5687 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5688 | |
| 5689 | if (!rdev->ops->channel_switch || |
| 5690 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5691 | return -EOPNOTSUPP; |
| 5692 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5693 | switch (dev->ieee80211_ptr->iftype) { |
| 5694 | case NL80211_IFTYPE_AP: |
| 5695 | case NL80211_IFTYPE_P2P_GO: |
| 5696 | need_new_beacon = true; |
| 5697 | |
| 5698 | /* useless if AP is not running */ |
| 5699 | if (!wdev->beacon_interval) |
| 5700 | return -EINVAL; |
| 5701 | break; |
| 5702 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5703 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5704 | break; |
| 5705 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5706 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5707 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5708 | |
| 5709 | memset(¶ms, 0, sizeof(params)); |
| 5710 | |
| 5711 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5712 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5713 | return -EINVAL; |
| 5714 | |
| 5715 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5716 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5717 | return -EINVAL; |
| 5718 | |
| 5719 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5720 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5721 | if (!need_new_beacon) |
| 5722 | goto skip_beacons; |
| 5723 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5724 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5725 | if (err) |
| 5726 | return err; |
| 5727 | |
| 5728 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5729 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5730 | nl80211_policy); |
| 5731 | if (err) |
| 5732 | return err; |
| 5733 | |
| 5734 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5735 | if (err) |
| 5736 | return err; |
| 5737 | |
| 5738 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5739 | return -EINVAL; |
| 5740 | |
| 5741 | params.counter_offset_beacon = |
| 5742 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5743 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5744 | return -EINVAL; |
| 5745 | |
| 5746 | /* sanity check - counters should be the same */ |
| 5747 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5748 | params.count) |
| 5749 | return -EINVAL; |
| 5750 | |
| 5751 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5752 | params.counter_offset_presp = |
| 5753 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5754 | if (params.counter_offset_presp >= |
| 5755 | params.beacon_csa.probe_resp_len) |
| 5756 | return -EINVAL; |
| 5757 | |
| 5758 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5759 | params.count) |
| 5760 | return -EINVAL; |
| 5761 | } |
| 5762 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5763 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5764 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5765 | if (err) |
| 5766 | return err; |
| 5767 | |
| 5768 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5769 | return -EINVAL; |
| 5770 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5771 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5772 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5773 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5774 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5775 | ¶ms.chandef); |
| 5776 | if (err < 0) { |
| 5777 | return err; |
| 5778 | } else if (err) { |
| 5779 | radar_detect_width = BIT(params.chandef.width); |
| 5780 | params.radar_required = true; |
| 5781 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5785 | params.chandef.chan, |
| 5786 | CHAN_MODE_SHARED, |
| 5787 | radar_detect_width); |
| 5788 | if (err) |
| 5789 | return err; |
| 5790 | |
| 5791 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5792 | params.block_tx = true; |
| 5793 | |
| 5794 | return rdev_channel_switch(rdev, dev, ¶ms); |
| 5795 | } |
| 5796 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5797 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5798 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5799 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5800 | struct wireless_dev *wdev, |
| 5801 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5802 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5803 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5804 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5805 | void *hdr; |
| 5806 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5807 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5808 | |
| 5809 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5810 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5811 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5812 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5813 | if (!hdr) |
| 5814 | return -1; |
| 5815 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5816 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5817 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5818 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5819 | goto nla_put_failure; |
| 5820 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5821 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5822 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5823 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5824 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5825 | |
| 5826 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5827 | if (!bss) |
| 5828 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5829 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5830 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5831 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5832 | |
| 5833 | rcu_read_lock(); |
| 5834 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5835 | if (ies) { |
| 5836 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5837 | goto fail_unlock_rcu; |
| 5838 | tsf = true; |
| 5839 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5840 | ies->len, ies->data)) |
| 5841 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5842 | } |
| 5843 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5844 | if (ies) { |
| 5845 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5846 | goto fail_unlock_rcu; |
| 5847 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5848 | ies->len, ies->data)) |
| 5849 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5850 | } |
| 5851 | rcu_read_unlock(); |
| 5852 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5853 | if (res->beacon_interval && |
| 5854 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5855 | goto nla_put_failure; |
| 5856 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5857 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5858 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5859 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5860 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5861 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5862 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5863 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5864 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5865 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5866 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5867 | break; |
| 5868 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5869 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5870 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5871 | break; |
| 5872 | default: |
| 5873 | break; |
| 5874 | } |
| 5875 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5876 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5877 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5878 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5879 | if (intbss == wdev->current_bss && |
| 5880 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5881 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5882 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5883 | break; |
| 5884 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5885 | if (intbss == wdev->current_bss && |
| 5886 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5887 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5888 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5889 | break; |
| 5890 | default: |
| 5891 | break; |
| 5892 | } |
| 5893 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5894 | nla_nest_end(msg, bss); |
| 5895 | |
| 5896 | return genlmsg_end(msg, hdr); |
| 5897 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5898 | fail_unlock_rcu: |
| 5899 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5900 | nla_put_failure: |
| 5901 | genlmsg_cancel(msg, hdr); |
| 5902 | return -EMSGSIZE; |
| 5903 | } |
| 5904 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5905 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5906 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5907 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5908 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5909 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5910 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5911 | int err; |
| 5912 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5913 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5914 | if (err) |
| 5915 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5916 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5917 | wdev_lock(wdev); |
| 5918 | spin_lock_bh(&rdev->bss_lock); |
| 5919 | cfg80211_bss_expire(rdev); |
| 5920 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5921 | cb->seq = rdev->bss_generation; |
| 5922 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5923 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5924 | if (++idx <= start) |
| 5925 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5926 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5927 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5928 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5929 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5930 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5931 | } |
| 5932 | } |
| 5933 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5934 | spin_unlock_bh(&rdev->bss_lock); |
| 5935 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5936 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5937 | cb->args[2] = idx; |
| 5938 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5939 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5940 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5941 | } |
| 5942 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5943 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5944 | int flags, struct net_device *dev, |
| 5945 | struct survey_info *survey) |
| 5946 | { |
| 5947 | void *hdr; |
| 5948 | struct nlattr *infoattr; |
| 5949 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5950 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5951 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5952 | if (!hdr) |
| 5953 | return -ENOMEM; |
| 5954 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5955 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5956 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5957 | |
| 5958 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5959 | if (!infoattr) |
| 5960 | goto nla_put_failure; |
| 5961 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5962 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5963 | survey->channel->center_freq)) |
| 5964 | goto nla_put_failure; |
| 5965 | |
| 5966 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5967 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5968 | goto nla_put_failure; |
| 5969 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5970 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5971 | goto nla_put_failure; |
| 5972 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5973 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5974 | survey->channel_time)) |
| 5975 | goto nla_put_failure; |
| 5976 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5977 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5978 | survey->channel_time_busy)) |
| 5979 | goto nla_put_failure; |
| 5980 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5981 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5982 | survey->channel_time_ext_busy)) |
| 5983 | goto nla_put_failure; |
| 5984 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5985 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5986 | survey->channel_time_rx)) |
| 5987 | goto nla_put_failure; |
| 5988 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5989 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5990 | survey->channel_time_tx)) |
| 5991 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5992 | |
| 5993 | nla_nest_end(msg, infoattr); |
| 5994 | |
| 5995 | return genlmsg_end(msg, hdr); |
| 5996 | |
| 5997 | nla_put_failure: |
| 5998 | genlmsg_cancel(msg, hdr); |
| 5999 | return -EMSGSIZE; |
| 6000 | } |
| 6001 | |
| 6002 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6003 | struct netlink_callback *cb) |
| 6004 | { |
| 6005 | struct survey_info survey; |
| 6006 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6007 | struct wireless_dev *wdev; |
| 6008 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6009 | int res; |
| 6010 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6011 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6012 | if (res) |
| 6013 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6014 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6015 | if (!wdev->netdev) { |
| 6016 | res = -EINVAL; |
| 6017 | goto out_err; |
| 6018 | } |
| 6019 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6020 | if (!dev->ops->dump_survey) { |
| 6021 | res = -EOPNOTSUPP; |
| 6022 | goto out_err; |
| 6023 | } |
| 6024 | |
| 6025 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6026 | struct ieee80211_channel *chan; |
| 6027 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6028 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6029 | if (res == -ENOENT) |
| 6030 | break; |
| 6031 | if (res) |
| 6032 | goto out_err; |
| 6033 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6034 | /* Survey without a channel doesn't make sense */ |
| 6035 | if (!survey.channel) { |
| 6036 | res = -EINVAL; |
| 6037 | goto out; |
| 6038 | } |
| 6039 | |
| 6040 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6041 | survey.channel->center_freq); |
| 6042 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6043 | survey_idx++; |
| 6044 | continue; |
| 6045 | } |
| 6046 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6047 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6048 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6049 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6050 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6051 | goto out; |
| 6052 | survey_idx++; |
| 6053 | } |
| 6054 | |
| 6055 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6056 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6057 | res = skb->len; |
| 6058 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6059 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6060 | return res; |
| 6061 | } |
| 6062 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6063 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6064 | { |
| 6065 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6066 | NL80211_WPA_VERSION_2)); |
| 6067 | } |
| 6068 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6069 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6070 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6072 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6073 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6074 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6075 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6076 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6077 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6078 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6079 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6080 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6081 | return -EINVAL; |
| 6082 | |
| 6083 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6084 | return -EINVAL; |
| 6085 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6086 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6087 | return -EINVAL; |
| 6088 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6089 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6090 | return -EINVAL; |
| 6091 | |
| 6092 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6093 | return -EINVAL; |
| 6094 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6095 | err = nl80211_parse_key(info, &key); |
| 6096 | if (err) |
| 6097 | return err; |
| 6098 | |
| 6099 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6100 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6101 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6102 | if (!key.p.key || !key.p.key_len) |
| 6103 | return -EINVAL; |
| 6104 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6105 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6106 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6107 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6108 | return -EINVAL; |
| 6109 | if (key.idx > 4) |
| 6110 | return -EINVAL; |
| 6111 | } else { |
| 6112 | key.p.key_len = 0; |
| 6113 | key.p.key = NULL; |
| 6114 | } |
| 6115 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6116 | if (key.idx >= 0) { |
| 6117 | int i; |
| 6118 | bool ok = false; |
| 6119 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6120 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6121 | ok = true; |
| 6122 | break; |
| 6123 | } |
| 6124 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6125 | if (!ok) |
| 6126 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6127 | } |
| 6128 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6129 | if (!rdev->ops->auth) |
| 6130 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6131 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6132 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6133 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6134 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6135 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6136 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6137 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6138 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6139 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6140 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6141 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6142 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6143 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6144 | |
| 6145 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6146 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6147 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6148 | } |
| 6149 | |
| 6150 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6151 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6153 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6154 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6155 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6156 | return -EINVAL; |
| 6157 | |
| 6158 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6159 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6160 | return -EINVAL; |
| 6161 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6162 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6163 | /* need to include at least Auth Transaction and Status Code */ |
| 6164 | if (sae_data_len < 4) |
| 6165 | return -EINVAL; |
| 6166 | } |
| 6167 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6168 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6169 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6170 | /* |
| 6171 | * Since we no longer track auth state, ignore |
| 6172 | * requests to only change local state. |
| 6173 | */ |
| 6174 | if (local_state_change) |
| 6175 | return 0; |
| 6176 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6177 | wdev_lock(dev->ieee80211_ptr); |
| 6178 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6179 | ssid, ssid_len, ie, ie_len, |
| 6180 | key.p.key, key.p.key_len, key.idx, |
| 6181 | sae_data, sae_data_len); |
| 6182 | wdev_unlock(dev->ieee80211_ptr); |
| 6183 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6184 | } |
| 6185 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6186 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6187 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6188 | struct cfg80211_crypto_settings *settings, |
| 6189 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6190 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6191 | memset(settings, 0, sizeof(*settings)); |
| 6192 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6193 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6194 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6195 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6196 | u16 proto; |
| 6197 | proto = nla_get_u16( |
| 6198 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6199 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6200 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6201 | proto != ETH_P_PAE) |
| 6202 | return -EINVAL; |
| 6203 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6204 | settings->control_port_no_encrypt = true; |
| 6205 | } else |
| 6206 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6207 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6208 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6209 | void *data; |
| 6210 | int len, i; |
| 6211 | |
| 6212 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6213 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6214 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6215 | |
| 6216 | if (len % sizeof(u32)) |
| 6217 | return -EINVAL; |
| 6218 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6219 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6220 | return -EINVAL; |
| 6221 | |
| 6222 | memcpy(settings->ciphers_pairwise, data, len); |
| 6223 | |
| 6224 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6225 | if (!cfg80211_supported_cipher_suite( |
| 6226 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6227 | settings->ciphers_pairwise[i])) |
| 6228 | return -EINVAL; |
| 6229 | } |
| 6230 | |
| 6231 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6232 | settings->cipher_group = |
| 6233 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6234 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6235 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6236 | return -EINVAL; |
| 6237 | } |
| 6238 | |
| 6239 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6240 | settings->wpa_versions = |
| 6241 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6242 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6243 | return -EINVAL; |
| 6244 | } |
| 6245 | |
| 6246 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6247 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6248 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6249 | |
| 6250 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6251 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6252 | settings->n_akm_suites = len / sizeof(u32); |
| 6253 | |
| 6254 | if (len % sizeof(u32)) |
| 6255 | return -EINVAL; |
| 6256 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6257 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6258 | return -EINVAL; |
| 6259 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6260 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6261 | } |
| 6262 | |
| 6263 | return 0; |
| 6264 | } |
| 6265 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6266 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6267 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6268 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6269 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6270 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6271 | struct cfg80211_assoc_request req = {}; |
| 6272 | const u8 *bssid, *ssid; |
| 6273 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6274 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6275 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6276 | return -EINVAL; |
| 6277 | |
| 6278 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6279 | !info->attrs[NL80211_ATTR_SSID] || |
| 6280 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6281 | return -EINVAL; |
| 6282 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6283 | if (!rdev->ops->assoc) |
| 6284 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6285 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6286 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6287 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6288 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6289 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6290 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6291 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6292 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6293 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6294 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6295 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6296 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6297 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6298 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6299 | |
| 6300 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6301 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6302 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6303 | } |
| 6304 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6305 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6306 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6307 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6308 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6309 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6310 | else if (mfp != NL80211_MFP_NO) |
| 6311 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6312 | } |
| 6313 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6314 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6315 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6316 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6317 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6318 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6319 | |
| 6320 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6321 | memcpy(&req.ht_capa_mask, |
| 6322 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6323 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6324 | |
| 6325 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6326 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6327 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6328 | memcpy(&req.ht_capa, |
| 6329 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6330 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6331 | } |
| 6332 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6333 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6334 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6335 | |
| 6336 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6337 | memcpy(&req.vht_capa_mask, |
| 6338 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6339 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6340 | |
| 6341 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6342 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6343 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6344 | memcpy(&req.vht_capa, |
| 6345 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6346 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6347 | } |
| 6348 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6349 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6350 | if (!err) { |
| 6351 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6352 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6353 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6354 | wdev_unlock(dev->ieee80211_ptr); |
| 6355 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6356 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6357 | return err; |
| 6358 | } |
| 6359 | |
| 6360 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6361 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6363 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6364 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6365 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6366 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6367 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6368 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6369 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6370 | return -EINVAL; |
| 6371 | |
| 6372 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6373 | return -EINVAL; |
| 6374 | |
| 6375 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6376 | return -EINVAL; |
| 6377 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6378 | if (!rdev->ops->deauth) |
| 6379 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6380 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6382 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6383 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6384 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6385 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6386 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6387 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6388 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6389 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6390 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6391 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6392 | |
| 6393 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6394 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6395 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6396 | } |
| 6397 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6398 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6399 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6400 | wdev_lock(dev->ieee80211_ptr); |
| 6401 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6402 | local_state_change); |
| 6403 | wdev_unlock(dev->ieee80211_ptr); |
| 6404 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6408 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6410 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6411 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6412 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6413 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6414 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6415 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6416 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6417 | return -EINVAL; |
| 6418 | |
| 6419 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6420 | return -EINVAL; |
| 6421 | |
| 6422 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6423 | return -EINVAL; |
| 6424 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6425 | if (!rdev->ops->disassoc) |
| 6426 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6427 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6428 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6429 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6430 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6431 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6432 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6433 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6434 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6435 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6436 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6437 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6438 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6439 | |
| 6440 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6441 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6442 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6443 | } |
| 6444 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6445 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6446 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6447 | wdev_lock(dev->ieee80211_ptr); |
| 6448 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6449 | local_state_change); |
| 6450 | wdev_unlock(dev->ieee80211_ptr); |
| 6451 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6452 | } |
| 6453 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6454 | static bool |
| 6455 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6456 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6457 | int rateval) |
| 6458 | { |
| 6459 | struct wiphy *wiphy = &rdev->wiphy; |
| 6460 | bool found = false; |
| 6461 | int band, i; |
| 6462 | |
| 6463 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6464 | struct ieee80211_supported_band *sband; |
| 6465 | |
| 6466 | sband = wiphy->bands[band]; |
| 6467 | if (!sband) |
| 6468 | continue; |
| 6469 | |
| 6470 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6471 | if (sband->bitrates[i].bitrate == rateval) { |
| 6472 | mcast_rate[band] = i + 1; |
| 6473 | found = true; |
| 6474 | break; |
| 6475 | } |
| 6476 | } |
| 6477 | } |
| 6478 | |
| 6479 | return found; |
| 6480 | } |
| 6481 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6482 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6483 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6484 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6485 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6486 | struct cfg80211_ibss_params ibss; |
| 6487 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6488 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6489 | int err; |
| 6490 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6491 | memset(&ibss, 0, sizeof(ibss)); |
| 6492 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6493 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6494 | return -EINVAL; |
| 6495 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6496 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6497 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6498 | return -EINVAL; |
| 6499 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6500 | ibss.beacon_interval = 100; |
| 6501 | |
| 6502 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6503 | ibss.beacon_interval = |
| 6504 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6505 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6506 | return -EINVAL; |
| 6507 | } |
| 6508 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6509 | if (!rdev->ops->join_ibss) |
| 6510 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6511 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6512 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6513 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6514 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6515 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6516 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6517 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6518 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6519 | |
| 6520 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6521 | return -EINVAL; |
| 6522 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6523 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6524 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6525 | |
| 6526 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6527 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6528 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6529 | } |
| 6530 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6531 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6532 | if (err) |
| 6533 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6534 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6535 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6536 | return -EINVAL; |
| 6537 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6538 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6539 | case NL80211_CHAN_WIDTH_5: |
| 6540 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6541 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6542 | break; |
| 6543 | case NL80211_CHAN_WIDTH_20: |
| 6544 | case NL80211_CHAN_WIDTH_40: |
| 6545 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6546 | break; |
| 6547 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6548 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6549 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6550 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6551 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6552 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6553 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6554 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6555 | u8 *rates = |
| 6556 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6557 | int n_rates = |
| 6558 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6559 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6560 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6561 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6562 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6563 | &ibss.basic_rates); |
| 6564 | if (err) |
| 6565 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6566 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6567 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6568 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6569 | memcpy(&ibss.ht_capa_mask, |
| 6570 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6571 | sizeof(ibss.ht_capa_mask)); |
| 6572 | |
| 6573 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6574 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6575 | return -EINVAL; |
| 6576 | memcpy(&ibss.ht_capa, |
| 6577 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6578 | sizeof(ibss.ht_capa)); |
| 6579 | } |
| 6580 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6581 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6582 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6583 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6584 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6585 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6586 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6587 | bool no_ht = false; |
| 6588 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6589 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6590 | info->attrs[NL80211_ATTR_KEYS], |
| 6591 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6592 | if (IS_ERR(connkeys)) |
| 6593 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6594 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6595 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6596 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6597 | kfree(connkeys); |
| 6598 | return -EINVAL; |
| 6599 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6600 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6601 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6602 | ibss.control_port = |
| 6603 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6604 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6605 | ibss.userspace_handles_dfs = |
| 6606 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6607 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6608 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6609 | if (err) |
| 6610 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6611 | return err; |
| 6612 | } |
| 6613 | |
| 6614 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6615 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6617 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6618 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6619 | if (!rdev->ops->leave_ibss) |
| 6620 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6621 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6622 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6623 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6624 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6625 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6626 | } |
| 6627 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6628 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6629 | { |
| 6630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6631 | struct net_device *dev = info->user_ptr[1]; |
| 6632 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6633 | u32 nla_rate; |
| 6634 | int err; |
| 6635 | |
| 6636 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6637 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6638 | return -EOPNOTSUPP; |
| 6639 | |
| 6640 | if (!rdev->ops->set_mcast_rate) |
| 6641 | return -EOPNOTSUPP; |
| 6642 | |
| 6643 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6644 | |
| 6645 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6646 | return -EINVAL; |
| 6647 | |
| 6648 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6649 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6650 | return -EINVAL; |
| 6651 | |
| 6652 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6653 | |
| 6654 | return err; |
| 6655 | } |
| 6656 | |
| 6657 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6658 | #ifdef CONFIG_NL80211_TESTMODE |
| 6659 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6660 | .name = "testmode", |
| 6661 | }; |
| 6662 | |
| 6663 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6664 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6665 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6666 | struct wireless_dev *wdev = |
| 6667 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6668 | int err; |
| 6669 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6670 | if (!rdev->ops->testmode_cmd) |
| 6671 | return -EOPNOTSUPP; |
| 6672 | |
| 6673 | if (IS_ERR(wdev)) { |
| 6674 | err = PTR_ERR(wdev); |
| 6675 | if (err != -EINVAL) |
| 6676 | return err; |
| 6677 | wdev = NULL; |
| 6678 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6679 | return -EINVAL; |
| 6680 | } |
| 6681 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6682 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6683 | return -EINVAL; |
| 6684 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6685 | rdev->testmode_info = info; |
| 6686 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6687 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6688 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6689 | rdev->testmode_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6690 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6691 | return err; |
| 6692 | } |
| 6693 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6694 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6695 | struct netlink_callback *cb) |
| 6696 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6697 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6698 | int err; |
| 6699 | long phy_idx; |
| 6700 | void *data = NULL; |
| 6701 | int data_len = 0; |
| 6702 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6703 | rtnl_lock(); |
| 6704 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6705 | if (cb->args[0]) { |
| 6706 | /* |
| 6707 | * 0 is a valid index, but not valid for args[0], |
| 6708 | * so we need to offset by 1. |
| 6709 | */ |
| 6710 | phy_idx = cb->args[0] - 1; |
| 6711 | } else { |
| 6712 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6713 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6714 | nl80211_policy); |
| 6715 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6716 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6717 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6718 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6719 | nl80211_fam.attrbuf); |
| 6720 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6721 | err = PTR_ERR(rdev); |
| 6722 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6723 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6724 | phy_idx = rdev->wiphy_idx; |
| 6725 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6726 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6727 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6728 | cb->args[1] = |
| 6729 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6730 | } |
| 6731 | |
| 6732 | if (cb->args[1]) { |
| 6733 | data = nla_data((void *)cb->args[1]); |
| 6734 | data_len = nla_len((void *)cb->args[1]); |
| 6735 | } |
| 6736 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6737 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6738 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6739 | err = -ENOENT; |
| 6740 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6741 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6742 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6743 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6744 | err = -EOPNOTSUPP; |
| 6745 | goto out_err; |
| 6746 | } |
| 6747 | |
| 6748 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6749 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6750 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6751 | NL80211_CMD_TESTMODE); |
| 6752 | struct nlattr *tmdata; |
| 6753 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6754 | if (!hdr) |
| 6755 | break; |
| 6756 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6757 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6758 | genlmsg_cancel(skb, hdr); |
| 6759 | break; |
| 6760 | } |
| 6761 | |
| 6762 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6763 | if (!tmdata) { |
| 6764 | genlmsg_cancel(skb, hdr); |
| 6765 | break; |
| 6766 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6767 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6768 | nla_nest_end(skb, tmdata); |
| 6769 | |
| 6770 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6771 | genlmsg_cancel(skb, hdr); |
| 6772 | break; |
| 6773 | } else if (err) { |
| 6774 | genlmsg_cancel(skb, hdr); |
| 6775 | goto out_err; |
| 6776 | } |
| 6777 | |
| 6778 | genlmsg_end(skb, hdr); |
| 6779 | } |
| 6780 | |
| 6781 | err = skb->len; |
| 6782 | /* see above */ |
| 6783 | cb->args[0] = phy_idx + 1; |
| 6784 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6785 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6786 | return err; |
| 6787 | } |
| 6788 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6789 | static struct sk_buff * |
| 6790 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6791 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6792 | { |
| 6793 | struct sk_buff *skb; |
| 6794 | void *hdr; |
| 6795 | struct nlattr *data; |
| 6796 | |
| 6797 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6798 | if (!skb) |
| 6799 | return NULL; |
| 6800 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6801 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6802 | if (!hdr) { |
| 6803 | kfree_skb(skb); |
| 6804 | return NULL; |
| 6805 | } |
| 6806 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6807 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6808 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6809 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6810 | |
| 6811 | ((void **)skb->cb)[0] = rdev; |
| 6812 | ((void **)skb->cb)[1] = hdr; |
| 6813 | ((void **)skb->cb)[2] = data; |
| 6814 | |
| 6815 | return skb; |
| 6816 | |
| 6817 | nla_put_failure: |
| 6818 | kfree_skb(skb); |
| 6819 | return NULL; |
| 6820 | } |
| 6821 | |
| 6822 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6823 | int approxlen) |
| 6824 | { |
| 6825 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6826 | |
| 6827 | if (WARN_ON(!rdev->testmode_info)) |
| 6828 | return NULL; |
| 6829 | |
| 6830 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6831 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6832 | rdev->testmode_info->snd_seq, |
| 6833 | GFP_KERNEL); |
| 6834 | } |
| 6835 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6836 | |
| 6837 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6838 | { |
| 6839 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6840 | void *hdr = ((void **)skb->cb)[1]; |
| 6841 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6842 | |
| 6843 | if (WARN_ON(!rdev->testmode_info)) { |
| 6844 | kfree_skb(skb); |
| 6845 | return -EINVAL; |
| 6846 | } |
| 6847 | |
| 6848 | nla_nest_end(skb, data); |
| 6849 | genlmsg_end(skb, hdr); |
| 6850 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6851 | } |
| 6852 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6853 | |
| 6854 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6855 | int approxlen, gfp_t gfp) |
| 6856 | { |
| 6857 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6858 | |
| 6859 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6860 | } |
| 6861 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6862 | |
| 6863 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6864 | { |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6865 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6866 | void *hdr = ((void **)skb->cb)[1]; |
| 6867 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6868 | |
| 6869 | nla_nest_end(skb, data); |
| 6870 | genlmsg_end(skb, hdr); |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6871 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, |
| 6872 | nl80211_testmode_mcgrp.id, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6873 | } |
| 6874 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6875 | #endif |
| 6876 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6877 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6878 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6880 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6881 | struct cfg80211_connect_params connect; |
| 6882 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6883 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6884 | int err; |
| 6885 | |
| 6886 | memset(&connect, 0, sizeof(connect)); |
| 6887 | |
| 6888 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6889 | return -EINVAL; |
| 6890 | |
| 6891 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6892 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6893 | return -EINVAL; |
| 6894 | |
| 6895 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6896 | connect.auth_type = |
| 6897 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6898 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6899 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6900 | return -EINVAL; |
| 6901 | } else |
| 6902 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6903 | |
| 6904 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6905 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6906 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6907 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6908 | if (err) |
| 6909 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6910 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6911 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6912 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6913 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6914 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6915 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6916 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6917 | connect.bg_scan_period = -1; |
| 6918 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6919 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6920 | connect.bg_scan_period = |
| 6921 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6922 | } |
| 6923 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6924 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6925 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6926 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6927 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6928 | |
| 6929 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6930 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6931 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6932 | } |
| 6933 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6934 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6935 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6936 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6937 | connect.mfp != NL80211_MFP_NO) |
| 6938 | return -EINVAL; |
| 6939 | } else { |
| 6940 | connect.mfp = NL80211_MFP_NO; |
| 6941 | } |
| 6942 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6943 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6944 | connect.channel = |
| 6945 | ieee80211_get_channel(wiphy, |
| 6946 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6947 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6948 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6949 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6950 | } |
| 6951 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6952 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6953 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6954 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6955 | if (IS_ERR(connkeys)) |
| 6956 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6957 | } |
| 6958 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6959 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6960 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6961 | |
| 6962 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6963 | memcpy(&connect.ht_capa_mask, |
| 6964 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6965 | sizeof(connect.ht_capa_mask)); |
| 6966 | |
| 6967 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6968 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6969 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6970 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6971 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6972 | memcpy(&connect.ht_capa, |
| 6973 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6974 | sizeof(connect.ht_capa)); |
| 6975 | } |
| 6976 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6977 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6978 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6979 | |
| 6980 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6981 | memcpy(&connect.vht_capa_mask, |
| 6982 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6983 | sizeof(connect.vht_capa_mask)); |
| 6984 | |
| 6985 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6986 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6987 | kfree(connkeys); |
| 6988 | return -EINVAL; |
| 6989 | } |
| 6990 | memcpy(&connect.vht_capa, |
| 6991 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6992 | sizeof(connect.vht_capa)); |
| 6993 | } |
| 6994 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6995 | wdev_lock(dev->ieee80211_ptr); |
| 6996 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6997 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6998 | if (err) |
| 6999 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7000 | return err; |
| 7001 | } |
| 7002 | |
| 7003 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7004 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7006 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7007 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7008 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7009 | |
| 7010 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7011 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7012 | else |
| 7013 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7014 | |
| 7015 | if (reason == 0) |
| 7016 | return -EINVAL; |
| 7017 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7018 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7019 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7020 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7021 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7022 | wdev_lock(dev->ieee80211_ptr); |
| 7023 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7024 | wdev_unlock(dev->ieee80211_ptr); |
| 7025 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7026 | } |
| 7027 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7028 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7029 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7031 | struct net *net; |
| 7032 | int err; |
| 7033 | u32 pid; |
| 7034 | |
| 7035 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7036 | return -EINVAL; |
| 7037 | |
| 7038 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7039 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7040 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7041 | if (IS_ERR(net)) |
| 7042 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7043 | |
| 7044 | err = 0; |
| 7045 | |
| 7046 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7047 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7048 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7049 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7050 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7051 | return err; |
| 7052 | } |
| 7053 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7054 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7055 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7057 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7058 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7059 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7060 | struct cfg80211_pmksa pmksa; |
| 7061 | |
| 7062 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7063 | |
| 7064 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7065 | return -EINVAL; |
| 7066 | |
| 7067 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7068 | return -EINVAL; |
| 7069 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7070 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7071 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7072 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7073 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7074 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7075 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7076 | |
| 7077 | switch (info->genlhdr->cmd) { |
| 7078 | case NL80211_CMD_SET_PMKSA: |
| 7079 | rdev_ops = rdev->ops->set_pmksa; |
| 7080 | break; |
| 7081 | case NL80211_CMD_DEL_PMKSA: |
| 7082 | rdev_ops = rdev->ops->del_pmksa; |
| 7083 | break; |
| 7084 | default: |
| 7085 | WARN_ON(1); |
| 7086 | break; |
| 7087 | } |
| 7088 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7089 | if (!rdev_ops) |
| 7090 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7091 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7092 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7093 | } |
| 7094 | |
| 7095 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7096 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7098 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7099 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7100 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7101 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7102 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7103 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7104 | if (!rdev->ops->flush_pmksa) |
| 7105 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7106 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7107 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7108 | } |
| 7109 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7110 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7111 | { |
| 7112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7113 | struct net_device *dev = info->user_ptr[1]; |
| 7114 | u8 action_code, dialog_token; |
| 7115 | u16 status_code; |
| 7116 | u8 *peer; |
| 7117 | |
| 7118 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7119 | !rdev->ops->tdls_mgmt) |
| 7120 | return -EOPNOTSUPP; |
| 7121 | |
| 7122 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7123 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7124 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7125 | !info->attrs[NL80211_ATTR_IE] || |
| 7126 | !info->attrs[NL80211_ATTR_MAC]) |
| 7127 | return -EINVAL; |
| 7128 | |
| 7129 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7130 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7131 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7132 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7133 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7134 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7135 | dialog_token, status_code, |
| 7136 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7137 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7138 | } |
| 7139 | |
| 7140 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7141 | { |
| 7142 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7143 | struct net_device *dev = info->user_ptr[1]; |
| 7144 | enum nl80211_tdls_operation operation; |
| 7145 | u8 *peer; |
| 7146 | |
| 7147 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7148 | !rdev->ops->tdls_oper) |
| 7149 | return -EOPNOTSUPP; |
| 7150 | |
| 7151 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7152 | !info->attrs[NL80211_ATTR_MAC]) |
| 7153 | return -EINVAL; |
| 7154 | |
| 7155 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7156 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7157 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7158 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7159 | } |
| 7160 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7161 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7162 | struct genl_info *info) |
| 7163 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7164 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7165 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7166 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7167 | struct sk_buff *msg; |
| 7168 | void *hdr; |
| 7169 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7170 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7171 | int err; |
| 7172 | |
| 7173 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7174 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7175 | return -EINVAL; |
| 7176 | |
| 7177 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7178 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7179 | if (!rdev->ops->remain_on_channel || |
| 7180 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7181 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7182 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7183 | /* |
| 7184 | * We should be on that channel for at least a minimum amount of |
| 7185 | * time (10ms) but no longer than the driver supports. |
| 7186 | */ |
| 7187 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7188 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7189 | return -EINVAL; |
| 7190 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7191 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7192 | if (err) |
| 7193 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7194 | |
| 7195 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7196 | if (!msg) |
| 7197 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7198 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7199 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7200 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7201 | if (!hdr) { |
| 7202 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7203 | goto free_msg; |
| 7204 | } |
| 7205 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7206 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7207 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7208 | |
| 7209 | if (err) |
| 7210 | goto free_msg; |
| 7211 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7212 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7213 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7214 | |
| 7215 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7216 | |
| 7217 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7218 | |
| 7219 | nla_put_failure: |
| 7220 | err = -ENOBUFS; |
| 7221 | free_msg: |
| 7222 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7223 | return err; |
| 7224 | } |
| 7225 | |
| 7226 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7227 | struct genl_info *info) |
| 7228 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7230 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7231 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7232 | |
| 7233 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7234 | return -EINVAL; |
| 7235 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7236 | if (!rdev->ops->cancel_remain_on_channel) |
| 7237 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7238 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7239 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7240 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7241 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7242 | } |
| 7243 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7244 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7245 | u8 *rates, u8 rates_len) |
| 7246 | { |
| 7247 | u8 i; |
| 7248 | u32 mask = 0; |
| 7249 | |
| 7250 | for (i = 0; i < rates_len; i++) { |
| 7251 | int rate = (rates[i] & 0x7f) * 5; |
| 7252 | int ridx; |
| 7253 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7254 | struct ieee80211_rate *srate = |
| 7255 | &sband->bitrates[ridx]; |
| 7256 | if (rate == srate->bitrate) { |
| 7257 | mask |= 1 << ridx; |
| 7258 | break; |
| 7259 | } |
| 7260 | } |
| 7261 | if (ridx == sband->n_bitrates) |
| 7262 | return 0; /* rate not found */ |
| 7263 | } |
| 7264 | |
| 7265 | return mask; |
| 7266 | } |
| 7267 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7268 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7269 | u8 *rates, u8 rates_len, |
| 7270 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7271 | { |
| 7272 | u8 i; |
| 7273 | |
| 7274 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7275 | |
| 7276 | for (i = 0; i < rates_len; i++) { |
| 7277 | int ridx, rbit; |
| 7278 | |
| 7279 | ridx = rates[i] / 8; |
| 7280 | rbit = BIT(rates[i] % 8); |
| 7281 | |
| 7282 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7283 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7284 | return false; |
| 7285 | |
| 7286 | /* check availability */ |
| 7287 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7288 | mcs[ridx] |= rbit; |
| 7289 | else |
| 7290 | return false; |
| 7291 | } |
| 7292 | |
| 7293 | return true; |
| 7294 | } |
| 7295 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7296 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7297 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7298 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7299 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7300 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7301 | }; |
| 7302 | |
| 7303 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7304 | struct genl_info *info) |
| 7305 | { |
| 7306 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7308 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7309 | int rem, i; |
| 7310 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7311 | struct nlattr *tx_rates; |
| 7312 | struct ieee80211_supported_band *sband; |
| 7313 | |
| 7314 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7315 | return -EINVAL; |
| 7316 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7317 | if (!rdev->ops->set_bitrate_mask) |
| 7318 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7319 | |
| 7320 | memset(&mask, 0, sizeof(mask)); |
| 7321 | /* Default to all rates enabled */ |
| 7322 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7323 | sband = rdev->wiphy.bands[i]; |
| 7324 | mask.control[i].legacy = |
| 7325 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7326 | if (sband) |
| 7327 | memcpy(mask.control[i].mcs, |
| 7328 | sband->ht_cap.mcs.rx_mask, |
| 7329 | sizeof(mask.control[i].mcs)); |
| 7330 | else |
| 7331 | memset(mask.control[i].mcs, 0, |
| 7332 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | /* |
| 7336 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7337 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7338 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7339 | 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] | 7340 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7341 | { |
| 7342 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7343 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7344 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7345 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7346 | if (sband == NULL) |
| 7347 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7348 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7349 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7350 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7351 | mask.control[band].legacy = rateset_to_mask( |
| 7352 | sband, |
| 7353 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7354 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7355 | if ((mask.control[band].legacy == 0) && |
| 7356 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7357 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7358 | } |
| 7359 | if (tb[NL80211_TXRATE_MCS]) { |
| 7360 | if (!ht_rateset_to_mask( |
| 7361 | sband, |
| 7362 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7363 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7364 | mask.control[band].mcs)) |
| 7365 | return -EINVAL; |
| 7366 | } |
| 7367 | |
| 7368 | if (mask.control[band].legacy == 0) { |
| 7369 | /* don't allow empty legacy rates if HT |
| 7370 | * is not even supported. */ |
| 7371 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7372 | return -EINVAL; |
| 7373 | |
| 7374 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7375 | if (mask.control[band].mcs[i]) |
| 7376 | break; |
| 7377 | |
| 7378 | /* legacy and mcs rates may not be both empty */ |
| 7379 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7380 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7381 | } |
| 7382 | } |
| 7383 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7384 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7385 | } |
| 7386 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7387 | 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] | 7388 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7389 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7390 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7391 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7392 | |
| 7393 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7394 | return -EINVAL; |
| 7395 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7396 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7397 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7398 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7399 | switch (wdev->iftype) { |
| 7400 | case NL80211_IFTYPE_STATION: |
| 7401 | case NL80211_IFTYPE_ADHOC: |
| 7402 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7403 | case NL80211_IFTYPE_AP: |
| 7404 | case NL80211_IFTYPE_AP_VLAN: |
| 7405 | case NL80211_IFTYPE_MESH_POINT: |
| 7406 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7407 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7408 | break; |
| 7409 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7410 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7411 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7412 | |
| 7413 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7414 | if (!rdev->ops->mgmt_tx) |
| 7415 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7416 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7417 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7418 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7419 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7420 | } |
| 7421 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7422 | 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] | 7423 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7424 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7425 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7426 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7427 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7428 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7429 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7430 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7431 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7432 | bool offchan, no_cck, dont_wait_for_ack; |
| 7433 | |
| 7434 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7435 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7436 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7437 | return -EINVAL; |
| 7438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7439 | if (!rdev->ops->mgmt_tx) |
| 7440 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7441 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7442 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7443 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7444 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7445 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7446 | case NL80211_IFTYPE_STATION: |
| 7447 | case NL80211_IFTYPE_ADHOC: |
| 7448 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7449 | case NL80211_IFTYPE_AP: |
| 7450 | case NL80211_IFTYPE_AP_VLAN: |
| 7451 | case NL80211_IFTYPE_MESH_POINT: |
| 7452 | case NL80211_IFTYPE_P2P_GO: |
| 7453 | break; |
| 7454 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7455 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7456 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7457 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7458 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7459 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7460 | return -EINVAL; |
| 7461 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7462 | |
| 7463 | /* |
| 7464 | * We should wait on the channel for at least a minimum amount |
| 7465 | * of time (10ms) but no longer than the driver supports. |
| 7466 | */ |
| 7467 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7468 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7469 | return -EINVAL; |
| 7470 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7471 | } |
| 7472 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7473 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7474 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7475 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7476 | return -EINVAL; |
| 7477 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7478 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7479 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7480 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7481 | * the driver. The latter will use the current one |
| 7482 | */ |
| 7483 | chandef.chan = NULL; |
| 7484 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7485 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7486 | if (err) |
| 7487 | return err; |
| 7488 | } |
| 7489 | |
| 7490 | if (!chandef.chan && offchan) |
| 7491 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7492 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7493 | if (!dont_wait_for_ack) { |
| 7494 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7495 | if (!msg) |
| 7496 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7497 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7498 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7499 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7500 | if (!hdr) { |
| 7501 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7502 | goto free_msg; |
| 7503 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7504 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7505 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7506 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7507 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7508 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7509 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7510 | if (err) |
| 7511 | goto free_msg; |
| 7512 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7513 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7514 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7515 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7516 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7517 | genlmsg_end(msg, hdr); |
| 7518 | return genlmsg_reply(msg, info); |
| 7519 | } |
| 7520 | |
| 7521 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7522 | |
| 7523 | nla_put_failure: |
| 7524 | err = -ENOBUFS; |
| 7525 | free_msg: |
| 7526 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7527 | return err; |
| 7528 | } |
| 7529 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7530 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7531 | { |
| 7532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7533 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7534 | u64 cookie; |
| 7535 | |
| 7536 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7537 | return -EINVAL; |
| 7538 | |
| 7539 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7540 | return -EOPNOTSUPP; |
| 7541 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7542 | switch (wdev->iftype) { |
| 7543 | case NL80211_IFTYPE_STATION: |
| 7544 | case NL80211_IFTYPE_ADHOC: |
| 7545 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7546 | case NL80211_IFTYPE_AP: |
| 7547 | case NL80211_IFTYPE_AP_VLAN: |
| 7548 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7549 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7550 | break; |
| 7551 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7552 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7553 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7554 | |
| 7555 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7556 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7557 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7558 | } |
| 7559 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7560 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7561 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7563 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7564 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7565 | u8 ps_state; |
| 7566 | bool state; |
| 7567 | int err; |
| 7568 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7569 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7570 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7571 | |
| 7572 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7573 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7574 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7575 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7576 | |
| 7577 | wdev = dev->ieee80211_ptr; |
| 7578 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7579 | if (!rdev->ops->set_power_mgmt) |
| 7580 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7581 | |
| 7582 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7583 | |
| 7584 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7585 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7586 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7587 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7588 | if (!err) |
| 7589 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7590 | return err; |
| 7591 | } |
| 7592 | |
| 7593 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7594 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7596 | enum nl80211_ps_state ps_state; |
| 7597 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7598 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7599 | struct sk_buff *msg; |
| 7600 | void *hdr; |
| 7601 | int err; |
| 7602 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7603 | wdev = dev->ieee80211_ptr; |
| 7604 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7605 | if (!rdev->ops->set_power_mgmt) |
| 7606 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7607 | |
| 7608 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7609 | if (!msg) |
| 7610 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7611 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7612 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7613 | NL80211_CMD_GET_POWER_SAVE); |
| 7614 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7616 | goto free_msg; |
| 7617 | } |
| 7618 | |
| 7619 | if (wdev->ps) |
| 7620 | ps_state = NL80211_PS_ENABLED; |
| 7621 | else |
| 7622 | ps_state = NL80211_PS_DISABLED; |
| 7623 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7624 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7625 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7626 | |
| 7627 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7628 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7629 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7630 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7631 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7632 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7633 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7634 | return err; |
| 7635 | } |
| 7636 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7637 | static struct nla_policy |
| 7638 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7639 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7640 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7641 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7642 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7643 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7644 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7645 | }; |
| 7646 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7647 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7648 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7649 | { |
| 7650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7651 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7653 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7654 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7655 | return -EINVAL; |
| 7656 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7657 | if (!rdev->ops->set_cqm_txe_config) |
| 7658 | return -EOPNOTSUPP; |
| 7659 | |
| 7660 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7661 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7662 | return -EOPNOTSUPP; |
| 7663 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7664 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7665 | } |
| 7666 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7667 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7668 | s32 threshold, u32 hysteresis) |
| 7669 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7670 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7671 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7672 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7673 | |
| 7674 | if (threshold > 0) |
| 7675 | return -EINVAL; |
| 7676 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7677 | /* disabling - hysteresis should also be zero then */ |
| 7678 | if (threshold == 0) |
| 7679 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7680 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7681 | if (!rdev->ops->set_cqm_rssi_config) |
| 7682 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7683 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7684 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7685 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7686 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7687 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7688 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7689 | } |
| 7690 | |
| 7691 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7692 | { |
| 7693 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7694 | struct nlattr *cqm; |
| 7695 | int err; |
| 7696 | |
| 7697 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7698 | if (!cqm) |
| 7699 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7700 | |
| 7701 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7702 | nl80211_attr_cqm_policy); |
| 7703 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7704 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7705 | |
| 7706 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7707 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7708 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7709 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7710 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7711 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7712 | } |
| 7713 | |
| 7714 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7715 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7716 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7717 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7718 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7719 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7720 | |
| 7721 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7722 | } |
| 7723 | |
| 7724 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7725 | } |
| 7726 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7727 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7728 | { |
| 7729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7730 | struct net_device *dev = info->user_ptr[1]; |
| 7731 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7732 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7733 | int err; |
| 7734 | |
| 7735 | /* start with default */ |
| 7736 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7737 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7738 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7739 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7740 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7741 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7742 | if (err) |
| 7743 | return err; |
| 7744 | } |
| 7745 | |
| 7746 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7747 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7748 | return -EINVAL; |
| 7749 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7750 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7751 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7752 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7753 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7754 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7755 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7756 | return -EINVAL; |
| 7757 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7758 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7759 | setup.beacon_interval = |
| 7760 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7761 | if (setup.beacon_interval < 10 || |
| 7762 | setup.beacon_interval > 10000) |
| 7763 | return -EINVAL; |
| 7764 | } |
| 7765 | |
| 7766 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7767 | setup.dtim_period = |
| 7768 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7769 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7770 | return -EINVAL; |
| 7771 | } |
| 7772 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7773 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7774 | /* parse additional setup parameters if given */ |
| 7775 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7776 | if (err) |
| 7777 | return err; |
| 7778 | } |
| 7779 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7780 | if (setup.user_mpm) |
| 7781 | cfg.auto_open_plinks = false; |
| 7782 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7783 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7784 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7785 | if (err) |
| 7786 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7787 | } else { |
| 7788 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7789 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7790 | } |
| 7791 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7792 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7793 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7794 | int n_rates = |
| 7795 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7796 | struct ieee80211_supported_band *sband; |
| 7797 | |
| 7798 | if (!setup.chandef.chan) |
| 7799 | return -EINVAL; |
| 7800 | |
| 7801 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7802 | |
| 7803 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7804 | &setup.basic_rates); |
| 7805 | if (err) |
| 7806 | return err; |
| 7807 | } |
| 7808 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7809 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7810 | } |
| 7811 | |
| 7812 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7813 | { |
| 7814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7815 | struct net_device *dev = info->user_ptr[1]; |
| 7816 | |
| 7817 | return cfg80211_leave_mesh(rdev, dev); |
| 7818 | } |
| 7819 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7820 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7821 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7822 | struct cfg80211_registered_device *rdev) |
| 7823 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7824 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7825 | struct nlattr *nl_pats, *nl_pat; |
| 7826 | int i, pat_len; |
| 7827 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7828 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7829 | return 0; |
| 7830 | |
| 7831 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7832 | if (!nl_pats) |
| 7833 | return -ENOBUFS; |
| 7834 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7835 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7836 | nl_pat = nla_nest_start(msg, i + 1); |
| 7837 | if (!nl_pat) |
| 7838 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7839 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7840 | 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] | 7841 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7842 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7843 | wowlan->patterns[i].pattern) || |
| 7844 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7845 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7846 | return -ENOBUFS; |
| 7847 | nla_nest_end(msg, nl_pat); |
| 7848 | } |
| 7849 | nla_nest_end(msg, nl_pats); |
| 7850 | |
| 7851 | return 0; |
| 7852 | } |
| 7853 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7854 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7855 | struct cfg80211_wowlan_tcp *tcp) |
| 7856 | { |
| 7857 | struct nlattr *nl_tcp; |
| 7858 | |
| 7859 | if (!tcp) |
| 7860 | return 0; |
| 7861 | |
| 7862 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7863 | if (!nl_tcp) |
| 7864 | return -ENOBUFS; |
| 7865 | |
| 7866 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7867 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7868 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7869 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7870 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7871 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7872 | tcp->payload_len, tcp->payload) || |
| 7873 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7874 | tcp->data_interval) || |
| 7875 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7876 | tcp->wake_len, tcp->wake_data) || |
| 7877 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7878 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7879 | return -ENOBUFS; |
| 7880 | |
| 7881 | if (tcp->payload_seq.len && |
| 7882 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7883 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7884 | return -ENOBUFS; |
| 7885 | |
| 7886 | if (tcp->payload_tok.len && |
| 7887 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7888 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7889 | &tcp->payload_tok)) |
| 7890 | return -ENOBUFS; |
| 7891 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7892 | nla_nest_end(msg, nl_tcp); |
| 7893 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7894 | return 0; |
| 7895 | } |
| 7896 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7897 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7898 | { |
| 7899 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7900 | struct sk_buff *msg; |
| 7901 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7902 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7903 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7904 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7905 | return -EOPNOTSUPP; |
| 7906 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7907 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7908 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7909 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7910 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7911 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7912 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7913 | } |
| 7914 | |
| 7915 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7916 | if (!msg) |
| 7917 | return -ENOMEM; |
| 7918 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7919 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7920 | NL80211_CMD_GET_WOWLAN); |
| 7921 | if (!hdr) |
| 7922 | goto nla_put_failure; |
| 7923 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7924 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7925 | struct nlattr *nl_wowlan; |
| 7926 | |
| 7927 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7928 | if (!nl_wowlan) |
| 7929 | goto nla_put_failure; |
| 7930 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7931 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7932 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7933 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7934 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7935 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7936 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7937 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7938 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7939 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7940 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7941 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7942 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7943 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7944 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7945 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7946 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7947 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7948 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7949 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7950 | if (nl80211_send_wowlan_tcp(msg, |
| 7951 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7952 | goto nla_put_failure; |
| 7953 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7954 | nla_nest_end(msg, nl_wowlan); |
| 7955 | } |
| 7956 | |
| 7957 | genlmsg_end(msg, hdr); |
| 7958 | return genlmsg_reply(msg, info); |
| 7959 | |
| 7960 | nla_put_failure: |
| 7961 | nlmsg_free(msg); |
| 7962 | return -ENOBUFS; |
| 7963 | } |
| 7964 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7965 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7966 | struct nlattr *attr, |
| 7967 | struct cfg80211_wowlan *trig) |
| 7968 | { |
| 7969 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7970 | struct cfg80211_wowlan_tcp *cfg; |
| 7971 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7972 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7973 | u32 size; |
| 7974 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7975 | int err, port; |
| 7976 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7977 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7978 | return -EINVAL; |
| 7979 | |
| 7980 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7981 | nla_data(attr), nla_len(attr), |
| 7982 | nl80211_wowlan_tcp_policy); |
| 7983 | if (err) |
| 7984 | return err; |
| 7985 | |
| 7986 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7987 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7988 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7989 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7990 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7991 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7992 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7993 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7994 | return -EINVAL; |
| 7995 | |
| 7996 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7997 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7998 | return -EINVAL; |
| 7999 | |
| 8000 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8001 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8002 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8003 | return -EINVAL; |
| 8004 | |
| 8005 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8006 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8007 | return -EINVAL; |
| 8008 | |
| 8009 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8010 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8011 | return -EINVAL; |
| 8012 | |
| 8013 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8014 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8015 | |
| 8016 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8017 | tokens_size = tokln - sizeof(*tok); |
| 8018 | |
| 8019 | if (!tok->len || tokens_size % tok->len) |
| 8020 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8021 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8022 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8023 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8024 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8025 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8026 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8027 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8028 | return -EINVAL; |
| 8029 | if (tok->offset + tok->len > data_size) |
| 8030 | return -EINVAL; |
| 8031 | } |
| 8032 | |
| 8033 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8034 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8035 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8036 | return -EINVAL; |
| 8037 | if (seq->len == 0 || seq->len > 4) |
| 8038 | return -EINVAL; |
| 8039 | if (seq->len + seq->offset > data_size) |
| 8040 | return -EINVAL; |
| 8041 | } |
| 8042 | |
| 8043 | size = sizeof(*cfg); |
| 8044 | size += data_size; |
| 8045 | size += wake_size + wake_mask_size; |
| 8046 | size += tokens_size; |
| 8047 | |
| 8048 | cfg = kzalloc(size, GFP_KERNEL); |
| 8049 | if (!cfg) |
| 8050 | return -ENOMEM; |
| 8051 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8052 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8053 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8054 | ETH_ALEN); |
| 8055 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8056 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8057 | else |
| 8058 | port = 0; |
| 8059 | #ifdef CONFIG_INET |
| 8060 | /* allocate a socket and port for it and use it */ |
| 8061 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8062 | IPPROTO_TCP, &cfg->sock, 1); |
| 8063 | if (err) { |
| 8064 | kfree(cfg); |
| 8065 | return err; |
| 8066 | } |
| 8067 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8068 | sock_release(cfg->sock); |
| 8069 | kfree(cfg); |
| 8070 | return -EADDRINUSE; |
| 8071 | } |
| 8072 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8073 | #else |
| 8074 | if (!port) { |
| 8075 | kfree(cfg); |
| 8076 | return -EINVAL; |
| 8077 | } |
| 8078 | cfg->src_port = port; |
| 8079 | #endif |
| 8080 | |
| 8081 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8082 | cfg->payload_len = data_size; |
| 8083 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8084 | memcpy((void *)cfg->payload, |
| 8085 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8086 | data_size); |
| 8087 | if (seq) |
| 8088 | cfg->payload_seq = *seq; |
| 8089 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8090 | cfg->wake_len = wake_size; |
| 8091 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8092 | memcpy((void *)cfg->wake_data, |
| 8093 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8094 | wake_size); |
| 8095 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8096 | data_size + wake_size; |
| 8097 | memcpy((void *)cfg->wake_mask, |
| 8098 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8099 | wake_mask_size); |
| 8100 | if (tok) { |
| 8101 | cfg->tokens_size = tokens_size; |
| 8102 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8103 | } |
| 8104 | |
| 8105 | trig->tcp = cfg; |
| 8106 | |
| 8107 | return 0; |
| 8108 | } |
| 8109 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8110 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8111 | { |
| 8112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8113 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8114 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8115 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8116 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8117 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8118 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8119 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8120 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8121 | return -EOPNOTSUPP; |
| 8122 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8123 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8124 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8125 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8126 | goto set_wakeup; |
| 8127 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8128 | |
| 8129 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8130 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8131 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8132 | nl80211_wowlan_policy); |
| 8133 | if (err) |
| 8134 | return err; |
| 8135 | |
| 8136 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8137 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8138 | return -EINVAL; |
| 8139 | new_triggers.any = true; |
| 8140 | } |
| 8141 | |
| 8142 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8143 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8144 | return -EINVAL; |
| 8145 | new_triggers.disconnect = true; |
| 8146 | } |
| 8147 | |
| 8148 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8149 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8150 | return -EINVAL; |
| 8151 | new_triggers.magic_pkt = true; |
| 8152 | } |
| 8153 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8154 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8155 | return -EINVAL; |
| 8156 | |
| 8157 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8158 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8159 | return -EINVAL; |
| 8160 | new_triggers.gtk_rekey_failure = true; |
| 8161 | } |
| 8162 | |
| 8163 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8164 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8165 | return -EINVAL; |
| 8166 | new_triggers.eap_identity_req = true; |
| 8167 | } |
| 8168 | |
| 8169 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8170 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8171 | return -EINVAL; |
| 8172 | new_triggers.four_way_handshake = true; |
| 8173 | } |
| 8174 | |
| 8175 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8176 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8177 | return -EINVAL; |
| 8178 | new_triggers.rfkill_release = true; |
| 8179 | } |
| 8180 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8181 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8182 | struct nlattr *pat; |
| 8183 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8184 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8185 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8186 | |
| 8187 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8188 | rem) |
| 8189 | n_patterns++; |
| 8190 | if (n_patterns > wowlan->n_patterns) |
| 8191 | return -EINVAL; |
| 8192 | |
| 8193 | new_triggers.patterns = kcalloc(n_patterns, |
| 8194 | sizeof(new_triggers.patterns[0]), |
| 8195 | GFP_KERNEL); |
| 8196 | if (!new_triggers.patterns) |
| 8197 | return -ENOMEM; |
| 8198 | |
| 8199 | new_triggers.n_patterns = n_patterns; |
| 8200 | i = 0; |
| 8201 | |
| 8202 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8203 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8204 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8205 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8206 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8207 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8208 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8209 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8210 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8211 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8212 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8213 | goto error; |
| 8214 | if (pat_len > wowlan->pattern_max_len || |
| 8215 | pat_len < wowlan->pattern_min_len) |
| 8216 | goto error; |
| 8217 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8218 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8219 | pkt_offset = 0; |
| 8220 | else |
| 8221 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8222 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8223 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8224 | goto error; |
| 8225 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8226 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8227 | new_triggers.patterns[i].mask = |
| 8228 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8229 | if (!new_triggers.patterns[i].mask) { |
| 8230 | err = -ENOMEM; |
| 8231 | goto error; |
| 8232 | } |
| 8233 | new_triggers.patterns[i].pattern = |
| 8234 | new_triggers.patterns[i].mask + mask_len; |
| 8235 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8236 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8237 | mask_len); |
| 8238 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8239 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8240 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8241 | pat_len); |
| 8242 | i++; |
| 8243 | } |
| 8244 | } |
| 8245 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8246 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8247 | err = nl80211_parse_wowlan_tcp( |
| 8248 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8249 | &new_triggers); |
| 8250 | if (err) |
| 8251 | goto error; |
| 8252 | } |
| 8253 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8254 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8255 | if (!ntrig) { |
| 8256 | err = -ENOMEM; |
| 8257 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8258 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8259 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8260 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8261 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8262 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8263 | if (rdev->ops->set_wakeup && |
| 8264 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8265 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8266 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8267 | return 0; |
| 8268 | error: |
| 8269 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8270 | kfree(new_triggers.patterns[i].mask); |
| 8271 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8272 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8273 | sock_release(new_triggers.tcp->sock); |
| 8274 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8275 | return err; |
| 8276 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8277 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8278 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8279 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8280 | struct cfg80211_registered_device *rdev) |
| 8281 | { |
| 8282 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8283 | int i, j, pat_len; |
| 8284 | struct cfg80211_coalesce_rules *rule; |
| 8285 | |
| 8286 | if (!rdev->coalesce->n_rules) |
| 8287 | return 0; |
| 8288 | |
| 8289 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8290 | if (!nl_rules) |
| 8291 | return -ENOBUFS; |
| 8292 | |
| 8293 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8294 | nl_rule = nla_nest_start(msg, i + 1); |
| 8295 | if (!nl_rule) |
| 8296 | return -ENOBUFS; |
| 8297 | |
| 8298 | rule = &rdev->coalesce->rules[i]; |
| 8299 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8300 | rule->delay)) |
| 8301 | return -ENOBUFS; |
| 8302 | |
| 8303 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8304 | rule->condition)) |
| 8305 | return -ENOBUFS; |
| 8306 | |
| 8307 | nl_pats = nla_nest_start(msg, |
| 8308 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8309 | if (!nl_pats) |
| 8310 | return -ENOBUFS; |
| 8311 | |
| 8312 | for (j = 0; j < rule->n_patterns; j++) { |
| 8313 | nl_pat = nla_nest_start(msg, j + 1); |
| 8314 | if (!nl_pat) |
| 8315 | return -ENOBUFS; |
| 8316 | pat_len = rule->patterns[j].pattern_len; |
| 8317 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8318 | DIV_ROUND_UP(pat_len, 8), |
| 8319 | rule->patterns[j].mask) || |
| 8320 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8321 | rule->patterns[j].pattern) || |
| 8322 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8323 | rule->patterns[j].pkt_offset)) |
| 8324 | return -ENOBUFS; |
| 8325 | nla_nest_end(msg, nl_pat); |
| 8326 | } |
| 8327 | nla_nest_end(msg, nl_pats); |
| 8328 | nla_nest_end(msg, nl_rule); |
| 8329 | } |
| 8330 | nla_nest_end(msg, nl_rules); |
| 8331 | |
| 8332 | return 0; |
| 8333 | } |
| 8334 | |
| 8335 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8336 | { |
| 8337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8338 | struct sk_buff *msg; |
| 8339 | void *hdr; |
| 8340 | |
| 8341 | if (!rdev->wiphy.coalesce) |
| 8342 | return -EOPNOTSUPP; |
| 8343 | |
| 8344 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8345 | if (!msg) |
| 8346 | return -ENOMEM; |
| 8347 | |
| 8348 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8349 | NL80211_CMD_GET_COALESCE); |
| 8350 | if (!hdr) |
| 8351 | goto nla_put_failure; |
| 8352 | |
| 8353 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8354 | goto nla_put_failure; |
| 8355 | |
| 8356 | genlmsg_end(msg, hdr); |
| 8357 | return genlmsg_reply(msg, info); |
| 8358 | |
| 8359 | nla_put_failure: |
| 8360 | nlmsg_free(msg); |
| 8361 | return -ENOBUFS; |
| 8362 | } |
| 8363 | |
| 8364 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8365 | { |
| 8366 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8367 | int i, j; |
| 8368 | struct cfg80211_coalesce_rules *rule; |
| 8369 | |
| 8370 | if (!coalesce) |
| 8371 | return; |
| 8372 | |
| 8373 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8374 | rule = &coalesce->rules[i]; |
| 8375 | for (j = 0; j < rule->n_patterns; j++) |
| 8376 | kfree(rule->patterns[j].mask); |
| 8377 | kfree(rule->patterns); |
| 8378 | } |
| 8379 | kfree(coalesce->rules); |
| 8380 | kfree(coalesce); |
| 8381 | rdev->coalesce = NULL; |
| 8382 | } |
| 8383 | |
| 8384 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8385 | struct nlattr *rule, |
| 8386 | struct cfg80211_coalesce_rules *new_rule) |
| 8387 | { |
| 8388 | int err, i; |
| 8389 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8390 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8391 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8392 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8393 | |
| 8394 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8395 | nla_len(rule), nl80211_coalesce_policy); |
| 8396 | if (err) |
| 8397 | return err; |
| 8398 | |
| 8399 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8400 | new_rule->delay = |
| 8401 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8402 | if (new_rule->delay > coalesce->max_delay) |
| 8403 | return -EINVAL; |
| 8404 | |
| 8405 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8406 | new_rule->condition = |
| 8407 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8408 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8409 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8410 | return -EINVAL; |
| 8411 | |
| 8412 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8413 | return -EINVAL; |
| 8414 | |
| 8415 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8416 | rem) |
| 8417 | n_patterns++; |
| 8418 | if (n_patterns > coalesce->n_patterns) |
| 8419 | return -EINVAL; |
| 8420 | |
| 8421 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8422 | GFP_KERNEL); |
| 8423 | if (!new_rule->patterns) |
| 8424 | return -ENOMEM; |
| 8425 | |
| 8426 | new_rule->n_patterns = n_patterns; |
| 8427 | i = 0; |
| 8428 | |
| 8429 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8430 | rem) { |
| 8431 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8432 | nla_len(pat), NULL); |
| 8433 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8434 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8435 | return -EINVAL; |
| 8436 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8437 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8438 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8439 | return -EINVAL; |
| 8440 | if (pat_len > coalesce->pattern_max_len || |
| 8441 | pat_len < coalesce->pattern_min_len) |
| 8442 | return -EINVAL; |
| 8443 | |
| 8444 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8445 | pkt_offset = 0; |
| 8446 | else |
| 8447 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8448 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8449 | return -EINVAL; |
| 8450 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8451 | |
| 8452 | new_rule->patterns[i].mask = |
| 8453 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8454 | if (!new_rule->patterns[i].mask) |
| 8455 | return -ENOMEM; |
| 8456 | new_rule->patterns[i].pattern = |
| 8457 | new_rule->patterns[i].mask + mask_len; |
| 8458 | memcpy(new_rule->patterns[i].mask, |
| 8459 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8460 | new_rule->patterns[i].pattern_len = pat_len; |
| 8461 | memcpy(new_rule->patterns[i].pattern, |
| 8462 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8463 | i++; |
| 8464 | } |
| 8465 | |
| 8466 | return 0; |
| 8467 | } |
| 8468 | |
| 8469 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8470 | { |
| 8471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8472 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8473 | struct cfg80211_coalesce new_coalesce = {}; |
| 8474 | struct cfg80211_coalesce *n_coalesce; |
| 8475 | int err, rem_rule, n_rules = 0, i, j; |
| 8476 | struct nlattr *rule; |
| 8477 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8478 | |
| 8479 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8480 | return -EOPNOTSUPP; |
| 8481 | |
| 8482 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8483 | cfg80211_rdev_free_coalesce(rdev); |
| 8484 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8485 | return 0; |
| 8486 | } |
| 8487 | |
| 8488 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8489 | rem_rule) |
| 8490 | n_rules++; |
| 8491 | if (n_rules > coalesce->n_rules) |
| 8492 | return -EINVAL; |
| 8493 | |
| 8494 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8495 | GFP_KERNEL); |
| 8496 | if (!new_coalesce.rules) |
| 8497 | return -ENOMEM; |
| 8498 | |
| 8499 | new_coalesce.n_rules = n_rules; |
| 8500 | i = 0; |
| 8501 | |
| 8502 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8503 | rem_rule) { |
| 8504 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8505 | &new_coalesce.rules[i]); |
| 8506 | if (err) |
| 8507 | goto error; |
| 8508 | |
| 8509 | i++; |
| 8510 | } |
| 8511 | |
| 8512 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8513 | if (err) |
| 8514 | goto error; |
| 8515 | |
| 8516 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8517 | if (!n_coalesce) { |
| 8518 | err = -ENOMEM; |
| 8519 | goto error; |
| 8520 | } |
| 8521 | cfg80211_rdev_free_coalesce(rdev); |
| 8522 | rdev->coalesce = n_coalesce; |
| 8523 | |
| 8524 | return 0; |
| 8525 | error: |
| 8526 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8527 | tmp_rule = &new_coalesce.rules[i]; |
| 8528 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8529 | kfree(tmp_rule->patterns[j].mask); |
| 8530 | kfree(tmp_rule->patterns); |
| 8531 | } |
| 8532 | kfree(new_coalesce.rules); |
| 8533 | |
| 8534 | return err; |
| 8535 | } |
| 8536 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8537 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8538 | { |
| 8539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8540 | struct net_device *dev = info->user_ptr[1]; |
| 8541 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8542 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8543 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8544 | int err; |
| 8545 | |
| 8546 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8547 | return -EINVAL; |
| 8548 | |
| 8549 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8550 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8551 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8552 | nl80211_rekey_policy); |
| 8553 | if (err) |
| 8554 | return err; |
| 8555 | |
| 8556 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8557 | return -ERANGE; |
| 8558 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8559 | return -ERANGE; |
| 8560 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8561 | return -ERANGE; |
| 8562 | |
| 8563 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8564 | NL80211_KEK_LEN); |
| 8565 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8566 | NL80211_KCK_LEN); |
| 8567 | memcpy(rekey_data.replay_ctr, |
| 8568 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8569 | NL80211_REPLAY_CTR_LEN); |
| 8570 | |
| 8571 | wdev_lock(wdev); |
| 8572 | if (!wdev->current_bss) { |
| 8573 | err = -ENOTCONN; |
| 8574 | goto out; |
| 8575 | } |
| 8576 | |
| 8577 | if (!rdev->ops->set_rekey_data) { |
| 8578 | err = -EOPNOTSUPP; |
| 8579 | goto out; |
| 8580 | } |
| 8581 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8582 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8583 | out: |
| 8584 | wdev_unlock(wdev); |
| 8585 | return err; |
| 8586 | } |
| 8587 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8588 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8589 | struct genl_info *info) |
| 8590 | { |
| 8591 | struct net_device *dev = info->user_ptr[1]; |
| 8592 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8593 | |
| 8594 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8595 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8596 | return -EINVAL; |
| 8597 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8598 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8599 | return -EBUSY; |
| 8600 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8601 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8602 | return 0; |
| 8603 | } |
| 8604 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8605 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8606 | struct genl_info *info) |
| 8607 | { |
| 8608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8609 | struct net_device *dev = info->user_ptr[1]; |
| 8610 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8611 | struct sk_buff *msg; |
| 8612 | void *hdr; |
| 8613 | const u8 *addr; |
| 8614 | u64 cookie; |
| 8615 | int err; |
| 8616 | |
| 8617 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8618 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8619 | return -EOPNOTSUPP; |
| 8620 | |
| 8621 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8622 | return -EINVAL; |
| 8623 | |
| 8624 | if (!rdev->ops->probe_client) |
| 8625 | return -EOPNOTSUPP; |
| 8626 | |
| 8627 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8628 | if (!msg) |
| 8629 | return -ENOMEM; |
| 8630 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8631 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8632 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8633 | if (!hdr) { |
| 8634 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8635 | goto free_msg; |
| 8636 | } |
| 8637 | |
| 8638 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8639 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8640 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8641 | if (err) |
| 8642 | goto free_msg; |
| 8643 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8644 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8645 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8646 | |
| 8647 | genlmsg_end(msg, hdr); |
| 8648 | |
| 8649 | return genlmsg_reply(msg, info); |
| 8650 | |
| 8651 | nla_put_failure: |
| 8652 | err = -ENOBUFS; |
| 8653 | free_msg: |
| 8654 | nlmsg_free(msg); |
| 8655 | return err; |
| 8656 | } |
| 8657 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8658 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8659 | { |
| 8660 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8661 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8662 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8663 | |
| 8664 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8665 | return -EOPNOTSUPP; |
| 8666 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8667 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8668 | if (!nreg) |
| 8669 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8670 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8671 | /* First, check if already registered. */ |
| 8672 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8673 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8674 | if (reg->nlportid == info->snd_portid) { |
| 8675 | rv = -EALREADY; |
| 8676 | goto out_err; |
| 8677 | } |
| 8678 | } |
| 8679 | /* Add it to the list */ |
| 8680 | nreg->nlportid = info->snd_portid; |
| 8681 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8682 | |
| 8683 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8684 | |
| 8685 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8686 | out_err: |
| 8687 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8688 | kfree(nreg); |
| 8689 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8690 | } |
| 8691 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8692 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8693 | { |
| 8694 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8695 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8696 | int err; |
| 8697 | |
| 8698 | if (!rdev->ops->start_p2p_device) |
| 8699 | return -EOPNOTSUPP; |
| 8700 | |
| 8701 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8702 | return -EOPNOTSUPP; |
| 8703 | |
| 8704 | if (wdev->p2p_started) |
| 8705 | return 0; |
| 8706 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8707 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8708 | if (err) |
| 8709 | return err; |
| 8710 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8711 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8712 | if (err) |
| 8713 | return err; |
| 8714 | |
| 8715 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8716 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8717 | |
| 8718 | return 0; |
| 8719 | } |
| 8720 | |
| 8721 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8722 | { |
| 8723 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8724 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8725 | |
| 8726 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8727 | return -EOPNOTSUPP; |
| 8728 | |
| 8729 | if (!rdev->ops->stop_p2p_device) |
| 8730 | return -EOPNOTSUPP; |
| 8731 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8732 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8733 | |
| 8734 | return 0; |
| 8735 | } |
| 8736 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8737 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8738 | struct genl_info *info) |
| 8739 | { |
| 8740 | void *hdr; |
| 8741 | struct sk_buff *msg; |
| 8742 | |
| 8743 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8744 | if (!msg) |
| 8745 | return -ENOMEM; |
| 8746 | |
| 8747 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8748 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8749 | if (!hdr) |
| 8750 | goto nla_put_failure; |
| 8751 | |
| 8752 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8753 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8754 | goto nla_put_failure; |
| 8755 | |
| 8756 | genlmsg_end(msg, hdr); |
| 8757 | return genlmsg_reply(msg, info); |
| 8758 | |
| 8759 | nla_put_failure: |
| 8760 | kfree_skb(msg); |
| 8761 | return -ENOBUFS; |
| 8762 | } |
| 8763 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8764 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8765 | { |
| 8766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8767 | struct cfg80211_update_ft_ies_params ft_params; |
| 8768 | struct net_device *dev = info->user_ptr[1]; |
| 8769 | |
| 8770 | if (!rdev->ops->update_ft_ies) |
| 8771 | return -EOPNOTSUPP; |
| 8772 | |
| 8773 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8774 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8775 | return -EINVAL; |
| 8776 | |
| 8777 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8778 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8779 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8780 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8781 | |
| 8782 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8783 | } |
| 8784 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8785 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8786 | struct genl_info *info) |
| 8787 | { |
| 8788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8789 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8790 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8791 | u16 duration; |
| 8792 | int ret; |
| 8793 | |
| 8794 | if (!rdev->ops->crit_proto_start) |
| 8795 | return -EOPNOTSUPP; |
| 8796 | |
| 8797 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8798 | return -EINVAL; |
| 8799 | |
| 8800 | if (rdev->crit_proto_nlportid) |
| 8801 | return -EBUSY; |
| 8802 | |
| 8803 | /* determine protocol if provided */ |
| 8804 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8805 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8806 | |
| 8807 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8808 | return -EINVAL; |
| 8809 | |
| 8810 | /* timeout must be provided */ |
| 8811 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8812 | return -EINVAL; |
| 8813 | |
| 8814 | duration = |
| 8815 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8816 | |
| 8817 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8818 | return -ERANGE; |
| 8819 | |
| 8820 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8821 | if (!ret) |
| 8822 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8823 | |
| 8824 | return ret; |
| 8825 | } |
| 8826 | |
| 8827 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8828 | struct genl_info *info) |
| 8829 | { |
| 8830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8831 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8832 | |
| 8833 | if (!rdev->ops->crit_proto_stop) |
| 8834 | return -EOPNOTSUPP; |
| 8835 | |
| 8836 | if (rdev->crit_proto_nlportid) { |
| 8837 | rdev->crit_proto_nlportid = 0; |
| 8838 | rdev_crit_proto_stop(rdev, wdev); |
| 8839 | } |
| 8840 | return 0; |
| 8841 | } |
| 8842 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8843 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8844 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8845 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8846 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8847 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8848 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8849 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8850 | /* 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] | 8851 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8852 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8853 | |
| 8854 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8855 | struct genl_info *info) |
| 8856 | { |
| 8857 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8858 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8859 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8860 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8861 | |
| 8862 | if (rtnl) |
| 8863 | rtnl_lock(); |
| 8864 | |
| 8865 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8866 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8867 | if (IS_ERR(rdev)) { |
| 8868 | if (rtnl) |
| 8869 | rtnl_unlock(); |
| 8870 | return PTR_ERR(rdev); |
| 8871 | } |
| 8872 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8873 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8874 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8875 | ASSERT_RTNL(); |
| 8876 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8877 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8878 | info->attrs); |
| 8879 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8880 | if (rtnl) |
| 8881 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8882 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8883 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8884 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8885 | dev = wdev->netdev; |
| 8886 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8887 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8888 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8889 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8890 | if (rtnl) |
| 8891 | rtnl_unlock(); |
| 8892 | return -EINVAL; |
| 8893 | } |
| 8894 | |
| 8895 | info->user_ptr[1] = dev; |
| 8896 | } else { |
| 8897 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8898 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8899 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8900 | if (dev) { |
| 8901 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8902 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8903 | if (rtnl) |
| 8904 | rtnl_unlock(); |
| 8905 | return -ENETDOWN; |
| 8906 | } |
| 8907 | |
| 8908 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8909 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8910 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8911 | if (rtnl) |
| 8912 | rtnl_unlock(); |
| 8913 | return -ENETDOWN; |
| 8914 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8915 | } |
| 8916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8917 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8918 | } |
| 8919 | |
| 8920 | return 0; |
| 8921 | } |
| 8922 | |
| 8923 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8924 | struct genl_info *info) |
| 8925 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8926 | if (info->user_ptr[1]) { |
| 8927 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8928 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8929 | |
| 8930 | if (wdev->netdev) |
| 8931 | dev_put(wdev->netdev); |
| 8932 | } else { |
| 8933 | dev_put(info->user_ptr[1]); |
| 8934 | } |
| 8935 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8936 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8937 | rtnl_unlock(); |
| 8938 | } |
| 8939 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8940 | static struct genl_ops nl80211_ops[] = { |
| 8941 | { |
| 8942 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8943 | .doit = nl80211_get_wiphy, |
| 8944 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 8945 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8946 | .policy = nl80211_policy, |
| 8947 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8948 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8949 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8950 | }, |
| 8951 | { |
| 8952 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8953 | .doit = nl80211_set_wiphy, |
| 8954 | .policy = nl80211_policy, |
| 8955 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8956 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8957 | }, |
| 8958 | { |
| 8959 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8960 | .doit = nl80211_get_interface, |
| 8961 | .dumpit = nl80211_dump_interface, |
| 8962 | .policy = nl80211_policy, |
| 8963 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8964 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8965 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8966 | }, |
| 8967 | { |
| 8968 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8969 | .doit = nl80211_set_interface, |
| 8970 | .policy = nl80211_policy, |
| 8971 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8972 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8973 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8974 | }, |
| 8975 | { |
| 8976 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8977 | .doit = nl80211_new_interface, |
| 8978 | .policy = nl80211_policy, |
| 8979 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8980 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8981 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8982 | }, |
| 8983 | { |
| 8984 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8985 | .doit = nl80211_del_interface, |
| 8986 | .policy = nl80211_policy, |
| 8987 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8988 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8989 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8990 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8991 | { |
| 8992 | .cmd = NL80211_CMD_GET_KEY, |
| 8993 | .doit = nl80211_get_key, |
| 8994 | .policy = nl80211_policy, |
| 8995 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8996 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8997 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8998 | }, |
| 8999 | { |
| 9000 | .cmd = NL80211_CMD_SET_KEY, |
| 9001 | .doit = nl80211_set_key, |
| 9002 | .policy = nl80211_policy, |
| 9003 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9004 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9005 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9006 | }, |
| 9007 | { |
| 9008 | .cmd = NL80211_CMD_NEW_KEY, |
| 9009 | .doit = nl80211_new_key, |
| 9010 | .policy = nl80211_policy, |
| 9011 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9012 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9013 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9014 | }, |
| 9015 | { |
| 9016 | .cmd = NL80211_CMD_DEL_KEY, |
| 9017 | .doit = nl80211_del_key, |
| 9018 | .policy = nl80211_policy, |
| 9019 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9020 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9021 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9022 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9023 | { |
| 9024 | .cmd = NL80211_CMD_SET_BEACON, |
| 9025 | .policy = nl80211_policy, |
| 9026 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9027 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9028 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9029 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9030 | }, |
| 9031 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9032 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9033 | .policy = nl80211_policy, |
| 9034 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9035 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9036 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9037 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9038 | }, |
| 9039 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9040 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9041 | .policy = nl80211_policy, |
| 9042 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9043 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9044 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9045 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9046 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9047 | { |
| 9048 | .cmd = NL80211_CMD_GET_STATION, |
| 9049 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9050 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9051 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9052 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9053 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9054 | }, |
| 9055 | { |
| 9056 | .cmd = NL80211_CMD_SET_STATION, |
| 9057 | .doit = nl80211_set_station, |
| 9058 | .policy = nl80211_policy, |
| 9059 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9060 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9061 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9062 | }, |
| 9063 | { |
| 9064 | .cmd = NL80211_CMD_NEW_STATION, |
| 9065 | .doit = nl80211_new_station, |
| 9066 | .policy = nl80211_policy, |
| 9067 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9068 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9069 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9070 | }, |
| 9071 | { |
| 9072 | .cmd = NL80211_CMD_DEL_STATION, |
| 9073 | .doit = nl80211_del_station, |
| 9074 | .policy = nl80211_policy, |
| 9075 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9076 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9077 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9078 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9079 | { |
| 9080 | .cmd = NL80211_CMD_GET_MPATH, |
| 9081 | .doit = nl80211_get_mpath, |
| 9082 | .dumpit = nl80211_dump_mpath, |
| 9083 | .policy = nl80211_policy, |
| 9084 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9085 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9086 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9087 | }, |
| 9088 | { |
| 9089 | .cmd = NL80211_CMD_SET_MPATH, |
| 9090 | .doit = nl80211_set_mpath, |
| 9091 | .policy = nl80211_policy, |
| 9092 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9093 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9094 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9095 | }, |
| 9096 | { |
| 9097 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9098 | .doit = nl80211_new_mpath, |
| 9099 | .policy = nl80211_policy, |
| 9100 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9101 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9102 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9103 | }, |
| 9104 | { |
| 9105 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9106 | .doit = nl80211_del_mpath, |
| 9107 | .policy = nl80211_policy, |
| 9108 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9109 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9110 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9111 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9112 | { |
| 9113 | .cmd = NL80211_CMD_SET_BSS, |
| 9114 | .doit = nl80211_set_bss, |
| 9115 | .policy = nl80211_policy, |
| 9116 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9117 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9118 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9119 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9120 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9121 | .cmd = NL80211_CMD_GET_REG, |
| 9122 | .doit = nl80211_get_reg, |
| 9123 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9124 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9125 | /* can be retrieved by unprivileged users */ |
| 9126 | }, |
| 9127 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9128 | .cmd = NL80211_CMD_SET_REG, |
| 9129 | .doit = nl80211_set_reg, |
| 9130 | .policy = nl80211_policy, |
| 9131 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9132 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9133 | }, |
| 9134 | { |
| 9135 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9136 | .doit = nl80211_req_set_reg, |
| 9137 | .policy = nl80211_policy, |
| 9138 | .flags = GENL_ADMIN_PERM, |
| 9139 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9140 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9141 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9142 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9143 | .policy = nl80211_policy, |
| 9144 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9145 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9146 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9147 | }, |
| 9148 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9149 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9150 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9151 | .policy = nl80211_policy, |
| 9152 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9153 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9154 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9155 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9156 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9157 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9158 | .doit = nl80211_trigger_scan, |
| 9159 | .policy = nl80211_policy, |
| 9160 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9161 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9162 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9163 | }, |
| 9164 | { |
| 9165 | .cmd = NL80211_CMD_GET_SCAN, |
| 9166 | .policy = nl80211_policy, |
| 9167 | .dumpit = nl80211_dump_scan, |
| 9168 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9169 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9170 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9171 | .doit = nl80211_start_sched_scan, |
| 9172 | .policy = nl80211_policy, |
| 9173 | .flags = GENL_ADMIN_PERM, |
| 9174 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9175 | NL80211_FLAG_NEED_RTNL, |
| 9176 | }, |
| 9177 | { |
| 9178 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9179 | .doit = nl80211_stop_sched_scan, |
| 9180 | .policy = nl80211_policy, |
| 9181 | .flags = GENL_ADMIN_PERM, |
| 9182 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9183 | NL80211_FLAG_NEED_RTNL, |
| 9184 | }, |
| 9185 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9186 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9187 | .doit = nl80211_authenticate, |
| 9188 | .policy = nl80211_policy, |
| 9189 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9190 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9191 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9192 | }, |
| 9193 | { |
| 9194 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9195 | .doit = nl80211_associate, |
| 9196 | .policy = nl80211_policy, |
| 9197 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9198 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9199 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9200 | }, |
| 9201 | { |
| 9202 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9203 | .doit = nl80211_deauthenticate, |
| 9204 | .policy = nl80211_policy, |
| 9205 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9206 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9207 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9208 | }, |
| 9209 | { |
| 9210 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9211 | .doit = nl80211_disassociate, |
| 9212 | .policy = nl80211_policy, |
| 9213 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9214 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9215 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9216 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9217 | { |
| 9218 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9219 | .doit = nl80211_join_ibss, |
| 9220 | .policy = nl80211_policy, |
| 9221 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9222 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9223 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9224 | }, |
| 9225 | { |
| 9226 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9227 | .doit = nl80211_leave_ibss, |
| 9228 | .policy = nl80211_policy, |
| 9229 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9230 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9231 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9232 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9233 | #ifdef CONFIG_NL80211_TESTMODE |
| 9234 | { |
| 9235 | .cmd = NL80211_CMD_TESTMODE, |
| 9236 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9237 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9238 | .policy = nl80211_policy, |
| 9239 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9240 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9241 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9242 | }, |
| 9243 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9244 | { |
| 9245 | .cmd = NL80211_CMD_CONNECT, |
| 9246 | .doit = nl80211_connect, |
| 9247 | .policy = nl80211_policy, |
| 9248 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9250 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9251 | }, |
| 9252 | { |
| 9253 | .cmd = NL80211_CMD_DISCONNECT, |
| 9254 | .doit = nl80211_disconnect, |
| 9255 | .policy = nl80211_policy, |
| 9256 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9258 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9259 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9260 | { |
| 9261 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9262 | .doit = nl80211_wiphy_netns, |
| 9263 | .policy = nl80211_policy, |
| 9264 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9265 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9266 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9267 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9268 | { |
| 9269 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9270 | .policy = nl80211_policy, |
| 9271 | .dumpit = nl80211_dump_survey, |
| 9272 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9273 | { |
| 9274 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9275 | .doit = nl80211_setdel_pmksa, |
| 9276 | .policy = nl80211_policy, |
| 9277 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9278 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9279 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9280 | }, |
| 9281 | { |
| 9282 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9283 | .doit = nl80211_setdel_pmksa, |
| 9284 | .policy = nl80211_policy, |
| 9285 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9286 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9287 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9288 | }, |
| 9289 | { |
| 9290 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9291 | .doit = nl80211_flush_pmksa, |
| 9292 | .policy = nl80211_policy, |
| 9293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9294 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9295 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9296 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9297 | { |
| 9298 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9299 | .doit = nl80211_remain_on_channel, |
| 9300 | .policy = nl80211_policy, |
| 9301 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9302 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9303 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9304 | }, |
| 9305 | { |
| 9306 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9307 | .doit = nl80211_cancel_remain_on_channel, |
| 9308 | .policy = nl80211_policy, |
| 9309 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9310 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9311 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9312 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9313 | { |
| 9314 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9315 | .doit = nl80211_set_tx_bitrate_mask, |
| 9316 | .policy = nl80211_policy, |
| 9317 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9318 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9319 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9320 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9321 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9322 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9323 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9324 | .policy = nl80211_policy, |
| 9325 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9326 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9327 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9328 | }, |
| 9329 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9330 | .cmd = NL80211_CMD_FRAME, |
| 9331 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9332 | .policy = nl80211_policy, |
| 9333 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9334 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9335 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9336 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9337 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9338 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9339 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9340 | .policy = nl80211_policy, |
| 9341 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9342 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9343 | NL80211_FLAG_NEED_RTNL, |
| 9344 | }, |
| 9345 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9346 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9347 | .doit = nl80211_set_power_save, |
| 9348 | .policy = nl80211_policy, |
| 9349 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9350 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9351 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9352 | }, |
| 9353 | { |
| 9354 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9355 | .doit = nl80211_get_power_save, |
| 9356 | .policy = nl80211_policy, |
| 9357 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9358 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9359 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9360 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9361 | { |
| 9362 | .cmd = NL80211_CMD_SET_CQM, |
| 9363 | .doit = nl80211_set_cqm, |
| 9364 | .policy = nl80211_policy, |
| 9365 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9366 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9367 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9368 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9369 | { |
| 9370 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9371 | .doit = nl80211_set_channel, |
| 9372 | .policy = nl80211_policy, |
| 9373 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9374 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9375 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9376 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9377 | { |
| 9378 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9379 | .doit = nl80211_set_wds_peer, |
| 9380 | .policy = nl80211_policy, |
| 9381 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9382 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9383 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9384 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9385 | { |
| 9386 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9387 | .doit = nl80211_join_mesh, |
| 9388 | .policy = nl80211_policy, |
| 9389 | .flags = GENL_ADMIN_PERM, |
| 9390 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9391 | NL80211_FLAG_NEED_RTNL, |
| 9392 | }, |
| 9393 | { |
| 9394 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9395 | .doit = nl80211_leave_mesh, |
| 9396 | .policy = nl80211_policy, |
| 9397 | .flags = GENL_ADMIN_PERM, |
| 9398 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9399 | NL80211_FLAG_NEED_RTNL, |
| 9400 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9401 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9402 | { |
| 9403 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9404 | .doit = nl80211_get_wowlan, |
| 9405 | .policy = nl80211_policy, |
| 9406 | /* can be retrieved by unprivileged users */ |
| 9407 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9408 | NL80211_FLAG_NEED_RTNL, |
| 9409 | }, |
| 9410 | { |
| 9411 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9412 | .doit = nl80211_set_wowlan, |
| 9413 | .policy = nl80211_policy, |
| 9414 | .flags = GENL_ADMIN_PERM, |
| 9415 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9416 | NL80211_FLAG_NEED_RTNL, |
| 9417 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9418 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9419 | { |
| 9420 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9421 | .doit = nl80211_set_rekey_data, |
| 9422 | .policy = nl80211_policy, |
| 9423 | .flags = GENL_ADMIN_PERM, |
| 9424 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9425 | NL80211_FLAG_NEED_RTNL, |
| 9426 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9427 | { |
| 9428 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9429 | .doit = nl80211_tdls_mgmt, |
| 9430 | .policy = nl80211_policy, |
| 9431 | .flags = GENL_ADMIN_PERM, |
| 9432 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9433 | NL80211_FLAG_NEED_RTNL, |
| 9434 | }, |
| 9435 | { |
| 9436 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9437 | .doit = nl80211_tdls_oper, |
| 9438 | .policy = nl80211_policy, |
| 9439 | .flags = GENL_ADMIN_PERM, |
| 9440 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9441 | NL80211_FLAG_NEED_RTNL, |
| 9442 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9443 | { |
| 9444 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9445 | .doit = nl80211_register_unexpected_frame, |
| 9446 | .policy = nl80211_policy, |
| 9447 | .flags = GENL_ADMIN_PERM, |
| 9448 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9449 | NL80211_FLAG_NEED_RTNL, |
| 9450 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9451 | { |
| 9452 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9453 | .doit = nl80211_probe_client, |
| 9454 | .policy = nl80211_policy, |
| 9455 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9456 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9457 | NL80211_FLAG_NEED_RTNL, |
| 9458 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9459 | { |
| 9460 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9461 | .doit = nl80211_register_beacons, |
| 9462 | .policy = nl80211_policy, |
| 9463 | .flags = GENL_ADMIN_PERM, |
| 9464 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9465 | NL80211_FLAG_NEED_RTNL, |
| 9466 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9467 | { |
| 9468 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9469 | .doit = nl80211_set_noack_map, |
| 9470 | .policy = nl80211_policy, |
| 9471 | .flags = GENL_ADMIN_PERM, |
| 9472 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9473 | NL80211_FLAG_NEED_RTNL, |
| 9474 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9475 | { |
| 9476 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9477 | .doit = nl80211_start_p2p_device, |
| 9478 | .policy = nl80211_policy, |
| 9479 | .flags = GENL_ADMIN_PERM, |
| 9480 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9481 | NL80211_FLAG_NEED_RTNL, |
| 9482 | }, |
| 9483 | { |
| 9484 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9485 | .doit = nl80211_stop_p2p_device, |
| 9486 | .policy = nl80211_policy, |
| 9487 | .flags = GENL_ADMIN_PERM, |
| 9488 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9489 | NL80211_FLAG_NEED_RTNL, |
| 9490 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9491 | { |
| 9492 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9493 | .doit = nl80211_set_mcast_rate, |
| 9494 | .policy = nl80211_policy, |
| 9495 | .flags = GENL_ADMIN_PERM, |
| 9496 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9497 | NL80211_FLAG_NEED_RTNL, |
| 9498 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9499 | { |
| 9500 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9501 | .doit = nl80211_set_mac_acl, |
| 9502 | .policy = nl80211_policy, |
| 9503 | .flags = GENL_ADMIN_PERM, |
| 9504 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9505 | NL80211_FLAG_NEED_RTNL, |
| 9506 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9507 | { |
| 9508 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9509 | .doit = nl80211_start_radar_detection, |
| 9510 | .policy = nl80211_policy, |
| 9511 | .flags = GENL_ADMIN_PERM, |
| 9512 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9513 | NL80211_FLAG_NEED_RTNL, |
| 9514 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9515 | { |
| 9516 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9517 | .doit = nl80211_get_protocol_features, |
| 9518 | .policy = nl80211_policy, |
| 9519 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9520 | { |
| 9521 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9522 | .doit = nl80211_update_ft_ies, |
| 9523 | .policy = nl80211_policy, |
| 9524 | .flags = GENL_ADMIN_PERM, |
| 9525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9526 | NL80211_FLAG_NEED_RTNL, |
| 9527 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9528 | { |
| 9529 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9530 | .doit = nl80211_crit_protocol_start, |
| 9531 | .policy = nl80211_policy, |
| 9532 | .flags = GENL_ADMIN_PERM, |
| 9533 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9534 | NL80211_FLAG_NEED_RTNL, |
| 9535 | }, |
| 9536 | { |
| 9537 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9538 | .doit = nl80211_crit_protocol_stop, |
| 9539 | .policy = nl80211_policy, |
| 9540 | .flags = GENL_ADMIN_PERM, |
| 9541 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9542 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9543 | }, |
| 9544 | { |
| 9545 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9546 | .doit = nl80211_get_coalesce, |
| 9547 | .policy = nl80211_policy, |
| 9548 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9549 | NL80211_FLAG_NEED_RTNL, |
| 9550 | }, |
| 9551 | { |
| 9552 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9553 | .doit = nl80211_set_coalesce, |
| 9554 | .policy = nl80211_policy, |
| 9555 | .flags = GENL_ADMIN_PERM, |
| 9556 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9557 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9558 | }, |
| 9559 | { |
| 9560 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9561 | .doit = nl80211_channel_switch, |
| 9562 | .policy = nl80211_policy, |
| 9563 | .flags = GENL_ADMIN_PERM, |
| 9564 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9565 | NL80211_FLAG_NEED_RTNL, |
| 9566 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9567 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9568 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9569 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9570 | .name = "mlme", |
| 9571 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9572 | |
| 9573 | /* multicast groups */ |
| 9574 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9575 | .name = "config", |
| 9576 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9577 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9578 | .name = "scan", |
| 9579 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9580 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9581 | .name = "regulatory", |
| 9582 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9583 | |
| 9584 | /* notification functions */ |
| 9585 | |
| 9586 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9587 | { |
| 9588 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9589 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9590 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9591 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9592 | if (!msg) |
| 9593 | return; |
| 9594 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9595 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9596 | nlmsg_free(msg); |
| 9597 | return; |
| 9598 | } |
| 9599 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9600 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9601 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9602 | } |
| 9603 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9604 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9605 | struct cfg80211_registered_device *rdev) |
| 9606 | { |
| 9607 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9608 | struct nlattr *nest; |
| 9609 | int i; |
| 9610 | |
| 9611 | if (WARN_ON(!req)) |
| 9612 | return 0; |
| 9613 | |
| 9614 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9615 | if (!nest) |
| 9616 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9617 | for (i = 0; i < req->n_ssids; i++) { |
| 9618 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9619 | goto nla_put_failure; |
| 9620 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9621 | nla_nest_end(msg, nest); |
| 9622 | |
| 9623 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9624 | if (!nest) |
| 9625 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9626 | for (i = 0; i < req->n_channels; i++) { |
| 9627 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9628 | goto nla_put_failure; |
| 9629 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9630 | nla_nest_end(msg, nest); |
| 9631 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9632 | if (req->ie && |
| 9633 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9634 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9635 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9636 | if (req->flags) |
| 9637 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9638 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9639 | return 0; |
| 9640 | nla_put_failure: |
| 9641 | return -ENOBUFS; |
| 9642 | } |
| 9643 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9644 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9645 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9646 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9647 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9648 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9649 | { |
| 9650 | void *hdr; |
| 9651 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9652 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9653 | if (!hdr) |
| 9654 | return -1; |
| 9655 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9656 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9657 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9658 | wdev->netdev->ifindex)) || |
| 9659 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9660 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9661 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9662 | /* ignore errors and send incomplete event anyway */ |
| 9663 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9664 | |
| 9665 | return genlmsg_end(msg, hdr); |
| 9666 | |
| 9667 | nla_put_failure: |
| 9668 | genlmsg_cancel(msg, hdr); |
| 9669 | return -EMSGSIZE; |
| 9670 | } |
| 9671 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9672 | static int |
| 9673 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9674 | struct cfg80211_registered_device *rdev, |
| 9675 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9676 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9677 | { |
| 9678 | void *hdr; |
| 9679 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9680 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9681 | if (!hdr) |
| 9682 | return -1; |
| 9683 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9684 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9685 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9686 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9687 | |
| 9688 | return genlmsg_end(msg, hdr); |
| 9689 | |
| 9690 | nla_put_failure: |
| 9691 | genlmsg_cancel(msg, hdr); |
| 9692 | return -EMSGSIZE; |
| 9693 | } |
| 9694 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9695 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9696 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9697 | { |
| 9698 | struct sk_buff *msg; |
| 9699 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9700 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9701 | if (!msg) |
| 9702 | return; |
| 9703 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9704 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9705 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9706 | nlmsg_free(msg); |
| 9707 | return; |
| 9708 | } |
| 9709 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9710 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9711 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9712 | } |
| 9713 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9714 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9715 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9716 | { |
| 9717 | struct sk_buff *msg; |
| 9718 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9719 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9720 | if (!msg) |
| 9721 | return; |
| 9722 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9723 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9724 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9725 | nlmsg_free(msg); |
| 9726 | return; |
| 9727 | } |
| 9728 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9729 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9730 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9731 | } |
| 9732 | |
| 9733 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9734 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9735 | { |
| 9736 | struct sk_buff *msg; |
| 9737 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9738 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9739 | if (!msg) |
| 9740 | return; |
| 9741 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9742 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9743 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9744 | nlmsg_free(msg); |
| 9745 | return; |
| 9746 | } |
| 9747 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9748 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9749 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9750 | } |
| 9751 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9752 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9753 | struct net_device *netdev) |
| 9754 | { |
| 9755 | struct sk_buff *msg; |
| 9756 | |
| 9757 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9758 | if (!msg) |
| 9759 | return; |
| 9760 | |
| 9761 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9762 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9763 | nlmsg_free(msg); |
| 9764 | return; |
| 9765 | } |
| 9766 | |
| 9767 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9768 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9769 | } |
| 9770 | |
| 9771 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9772 | struct net_device *netdev, u32 cmd) |
| 9773 | { |
| 9774 | struct sk_buff *msg; |
| 9775 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9776 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9777 | if (!msg) |
| 9778 | return; |
| 9779 | |
| 9780 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9781 | nlmsg_free(msg); |
| 9782 | return; |
| 9783 | } |
| 9784 | |
| 9785 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9786 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9787 | } |
| 9788 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9789 | /* |
| 9790 | * This can happen on global regulatory changes or device specific settings |
| 9791 | * based on custom world regulatory domains. |
| 9792 | */ |
| 9793 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9794 | { |
| 9795 | struct sk_buff *msg; |
| 9796 | void *hdr; |
| 9797 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9799 | if (!msg) |
| 9800 | return; |
| 9801 | |
| 9802 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9803 | if (!hdr) { |
| 9804 | nlmsg_free(msg); |
| 9805 | return; |
| 9806 | } |
| 9807 | |
| 9808 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9809 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9810 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9811 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9812 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9813 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9814 | NL80211_REGDOM_TYPE_WORLD)) |
| 9815 | goto nla_put_failure; |
| 9816 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9817 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9818 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9819 | goto nla_put_failure; |
| 9820 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9821 | request->intersect) { |
| 9822 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9823 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9824 | goto nla_put_failure; |
| 9825 | } else { |
| 9826 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9827 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9828 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9829 | request->alpha2)) |
| 9830 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9831 | } |
| 9832 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9833 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9834 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9835 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9836 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9837 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9838 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9839 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9840 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9841 | GFP_ATOMIC); |
| 9842 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9843 | |
| 9844 | return; |
| 9845 | |
| 9846 | nla_put_failure: |
| 9847 | genlmsg_cancel(msg, hdr); |
| 9848 | nlmsg_free(msg); |
| 9849 | } |
| 9850 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9851 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9852 | struct net_device *netdev, |
| 9853 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9854 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9855 | { |
| 9856 | struct sk_buff *msg; |
| 9857 | void *hdr; |
| 9858 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9860 | if (!msg) |
| 9861 | return; |
| 9862 | |
| 9863 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9864 | if (!hdr) { |
| 9865 | nlmsg_free(msg); |
| 9866 | return; |
| 9867 | } |
| 9868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9869 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9870 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9871 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9872 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9873 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9874 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9875 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9876 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9877 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9878 | return; |
| 9879 | |
| 9880 | nla_put_failure: |
| 9881 | genlmsg_cancel(msg, hdr); |
| 9882 | nlmsg_free(msg); |
| 9883 | } |
| 9884 | |
| 9885 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9886 | struct net_device *netdev, const u8 *buf, |
| 9887 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9888 | { |
| 9889 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9890 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9891 | } |
| 9892 | |
| 9893 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9894 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9895 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9896 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9897 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9898 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9899 | } |
| 9900 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9901 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9902 | struct net_device *netdev, const u8 *buf, |
| 9903 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9904 | { |
| 9905 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9906 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9907 | } |
| 9908 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9909 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9910 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9911 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9912 | { |
| 9913 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9914 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9915 | } |
| 9916 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9917 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9918 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9919 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9920 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9921 | struct wiphy *wiphy = wdev->wiphy; |
| 9922 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9923 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9924 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9925 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9926 | if (WARN_ON(len < 2)) |
| 9927 | return; |
| 9928 | |
| 9929 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9930 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9931 | else |
| 9932 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9933 | |
| 9934 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9935 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9936 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9937 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9938 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9939 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9940 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9941 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9942 | { |
| 9943 | struct sk_buff *msg; |
| 9944 | void *hdr; |
| 9945 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9946 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9947 | if (!msg) |
| 9948 | return; |
| 9949 | |
| 9950 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9951 | if (!hdr) { |
| 9952 | nlmsg_free(msg); |
| 9953 | return; |
| 9954 | } |
| 9955 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9956 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9957 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9958 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9959 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9960 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9961 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9962 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9963 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9964 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9965 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9966 | return; |
| 9967 | |
| 9968 | nla_put_failure: |
| 9969 | genlmsg_cancel(msg, hdr); |
| 9970 | nlmsg_free(msg); |
| 9971 | } |
| 9972 | |
| 9973 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9974 | struct net_device *netdev, const u8 *addr, |
| 9975 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9976 | { |
| 9977 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9978 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9979 | } |
| 9980 | |
| 9981 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9982 | struct net_device *netdev, const u8 *addr, |
| 9983 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9984 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9985 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9986 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9987 | } |
| 9988 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9989 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9990 | struct net_device *netdev, const u8 *bssid, |
| 9991 | const u8 *req_ie, size_t req_ie_len, |
| 9992 | const u8 *resp_ie, size_t resp_ie_len, |
| 9993 | u16 status, gfp_t gfp) |
| 9994 | { |
| 9995 | struct sk_buff *msg; |
| 9996 | void *hdr; |
| 9997 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9998 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9999 | if (!msg) |
| 10000 | return; |
| 10001 | |
| 10002 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10003 | if (!hdr) { |
| 10004 | nlmsg_free(msg); |
| 10005 | return; |
| 10006 | } |
| 10007 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10008 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10009 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10010 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10011 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10012 | (req_ie && |
| 10013 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10014 | (resp_ie && |
| 10015 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10016 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10017 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10018 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10019 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10020 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10021 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10022 | return; |
| 10023 | |
| 10024 | nla_put_failure: |
| 10025 | genlmsg_cancel(msg, hdr); |
| 10026 | nlmsg_free(msg); |
| 10027 | |
| 10028 | } |
| 10029 | |
| 10030 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10031 | struct net_device *netdev, const u8 *bssid, |
| 10032 | const u8 *req_ie, size_t req_ie_len, |
| 10033 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10034 | { |
| 10035 | struct sk_buff *msg; |
| 10036 | void *hdr; |
| 10037 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10039 | if (!msg) |
| 10040 | return; |
| 10041 | |
| 10042 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10043 | if (!hdr) { |
| 10044 | nlmsg_free(msg); |
| 10045 | return; |
| 10046 | } |
| 10047 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10048 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10049 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10050 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10051 | (req_ie && |
| 10052 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10053 | (resp_ie && |
| 10054 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10055 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10056 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10057 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10058 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10059 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10060 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10061 | return; |
| 10062 | |
| 10063 | nla_put_failure: |
| 10064 | genlmsg_cancel(msg, hdr); |
| 10065 | nlmsg_free(msg); |
| 10066 | |
| 10067 | } |
| 10068 | |
| 10069 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10070 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10071 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10072 | { |
| 10073 | struct sk_buff *msg; |
| 10074 | void *hdr; |
| 10075 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10076 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10077 | if (!msg) |
| 10078 | return; |
| 10079 | |
| 10080 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10081 | if (!hdr) { |
| 10082 | nlmsg_free(msg); |
| 10083 | return; |
| 10084 | } |
| 10085 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10086 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10087 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10088 | (from_ap && reason && |
| 10089 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10090 | (from_ap && |
| 10091 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10092 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10093 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10094 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10095 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10096 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10097 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10098 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10099 | return; |
| 10100 | |
| 10101 | nla_put_failure: |
| 10102 | genlmsg_cancel(msg, hdr); |
| 10103 | nlmsg_free(msg); |
| 10104 | |
| 10105 | } |
| 10106 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10107 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10108 | struct net_device *netdev, const u8 *bssid, |
| 10109 | gfp_t gfp) |
| 10110 | { |
| 10111 | struct sk_buff *msg; |
| 10112 | void *hdr; |
| 10113 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10114 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10115 | if (!msg) |
| 10116 | return; |
| 10117 | |
| 10118 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10119 | if (!hdr) { |
| 10120 | nlmsg_free(msg); |
| 10121 | return; |
| 10122 | } |
| 10123 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10124 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10125 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10126 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10127 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10128 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10129 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10130 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10131 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10132 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10133 | return; |
| 10134 | |
| 10135 | nla_put_failure: |
| 10136 | genlmsg_cancel(msg, hdr); |
| 10137 | nlmsg_free(msg); |
| 10138 | } |
| 10139 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10140 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10141 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10142 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10143 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10144 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10145 | struct sk_buff *msg; |
| 10146 | void *hdr; |
| 10147 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10148 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10149 | return; |
| 10150 | |
| 10151 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10152 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10153 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10154 | if (!msg) |
| 10155 | return; |
| 10156 | |
| 10157 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10158 | if (!hdr) { |
| 10159 | nlmsg_free(msg); |
| 10160 | return; |
| 10161 | } |
| 10162 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10163 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10164 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10165 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10166 | (ie_len && ie && |
| 10167 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10168 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10169 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10170 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10171 | |
| 10172 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10173 | nl80211_mlme_mcgrp.id, gfp); |
| 10174 | return; |
| 10175 | |
| 10176 | nla_put_failure: |
| 10177 | genlmsg_cancel(msg, hdr); |
| 10178 | nlmsg_free(msg); |
| 10179 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10180 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10181 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10182 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10183 | struct net_device *netdev, const u8 *addr, |
| 10184 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10185 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10186 | { |
| 10187 | struct sk_buff *msg; |
| 10188 | void *hdr; |
| 10189 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10190 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10191 | if (!msg) |
| 10192 | return; |
| 10193 | |
| 10194 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10195 | if (!hdr) { |
| 10196 | nlmsg_free(msg); |
| 10197 | return; |
| 10198 | } |
| 10199 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10200 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10201 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10202 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10203 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10204 | (key_id != -1 && |
| 10205 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10206 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10207 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10208 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10209 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10210 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10211 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10212 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10213 | return; |
| 10214 | |
| 10215 | nla_put_failure: |
| 10216 | genlmsg_cancel(msg, hdr); |
| 10217 | nlmsg_free(msg); |
| 10218 | } |
| 10219 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10220 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10221 | struct ieee80211_channel *channel_before, |
| 10222 | struct ieee80211_channel *channel_after) |
| 10223 | { |
| 10224 | struct sk_buff *msg; |
| 10225 | void *hdr; |
| 10226 | struct nlattr *nl_freq; |
| 10227 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10228 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10229 | if (!msg) |
| 10230 | return; |
| 10231 | |
| 10232 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10233 | if (!hdr) { |
| 10234 | nlmsg_free(msg); |
| 10235 | return; |
| 10236 | } |
| 10237 | |
| 10238 | /* |
| 10239 | * Since we are applying the beacon hint to a wiphy we know its |
| 10240 | * wiphy_idx is valid |
| 10241 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10243 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10244 | |
| 10245 | /* Before */ |
| 10246 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10247 | if (!nl_freq) |
| 10248 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10249 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10250 | goto nla_put_failure; |
| 10251 | nla_nest_end(msg, nl_freq); |
| 10252 | |
| 10253 | /* After */ |
| 10254 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10255 | if (!nl_freq) |
| 10256 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10257 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10258 | goto nla_put_failure; |
| 10259 | nla_nest_end(msg, nl_freq); |
| 10260 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10261 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10262 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10263 | rcu_read_lock(); |
| 10264 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 10265 | GFP_ATOMIC); |
| 10266 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10267 | |
| 10268 | return; |
| 10269 | |
| 10270 | nla_put_failure: |
| 10271 | genlmsg_cancel(msg, hdr); |
| 10272 | nlmsg_free(msg); |
| 10273 | } |
| 10274 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10275 | static void nl80211_send_remain_on_chan_event( |
| 10276 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10277 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10278 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10279 | unsigned int duration, gfp_t gfp) |
| 10280 | { |
| 10281 | struct sk_buff *msg; |
| 10282 | void *hdr; |
| 10283 | |
| 10284 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10285 | if (!msg) |
| 10286 | return; |
| 10287 | |
| 10288 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10289 | if (!hdr) { |
| 10290 | nlmsg_free(msg); |
| 10291 | return; |
| 10292 | } |
| 10293 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10295 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10296 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10297 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10298 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10299 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10300 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10301 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10302 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10303 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10304 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10305 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10306 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10307 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10308 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10309 | |
| 10310 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10311 | nl80211_mlme_mcgrp.id, gfp); |
| 10312 | return; |
| 10313 | |
| 10314 | nla_put_failure: |
| 10315 | genlmsg_cancel(msg, hdr); |
| 10316 | nlmsg_free(msg); |
| 10317 | } |
| 10318 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10319 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10320 | struct ieee80211_channel *chan, |
| 10321 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10322 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10323 | struct wiphy *wiphy = wdev->wiphy; |
| 10324 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10325 | |
| 10326 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10327 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10328 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10329 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10330 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10331 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10332 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10333 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10334 | struct ieee80211_channel *chan, |
| 10335 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10336 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10337 | struct wiphy *wiphy = wdev->wiphy; |
| 10338 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10339 | |
| 10340 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10341 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10342 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10343 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10344 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10345 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10346 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10347 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10348 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10349 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10350 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10351 | struct sk_buff *msg; |
| 10352 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10353 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10354 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10355 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10356 | if (!msg) |
| 10357 | return; |
| 10358 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10359 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10360 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10361 | nlmsg_free(msg); |
| 10362 | return; |
| 10363 | } |
| 10364 | |
| 10365 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10366 | nl80211_mlme_mcgrp.id, gfp); |
| 10367 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10368 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10369 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10370 | 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] | 10371 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10372 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10373 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10374 | struct sk_buff *msg; |
| 10375 | void *hdr; |
| 10376 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10377 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10378 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10380 | if (!msg) |
| 10381 | return; |
| 10382 | |
| 10383 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10384 | if (!hdr) { |
| 10385 | nlmsg_free(msg); |
| 10386 | return; |
| 10387 | } |
| 10388 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10389 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10390 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10391 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10392 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10393 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10394 | |
| 10395 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10396 | nl80211_mlme_mcgrp.id, gfp); |
| 10397 | return; |
| 10398 | |
| 10399 | nla_put_failure: |
| 10400 | genlmsg_cancel(msg, hdr); |
| 10401 | nlmsg_free(msg); |
| 10402 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10403 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10404 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10405 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10406 | enum nl80211_connect_failed_reason reason, |
| 10407 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10408 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10409 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10410 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10411 | struct sk_buff *msg; |
| 10412 | void *hdr; |
| 10413 | |
| 10414 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10415 | if (!msg) |
| 10416 | return; |
| 10417 | |
| 10418 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10419 | if (!hdr) { |
| 10420 | nlmsg_free(msg); |
| 10421 | return; |
| 10422 | } |
| 10423 | |
| 10424 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10425 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10426 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10427 | goto nla_put_failure; |
| 10428 | |
| 10429 | genlmsg_end(msg, hdr); |
| 10430 | |
| 10431 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10432 | nl80211_mlme_mcgrp.id, gfp); |
| 10433 | return; |
| 10434 | |
| 10435 | nla_put_failure: |
| 10436 | genlmsg_cancel(msg, hdr); |
| 10437 | nlmsg_free(msg); |
| 10438 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10439 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10440 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10441 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10442 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10443 | { |
| 10444 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10445 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10446 | struct sk_buff *msg; |
| 10447 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10448 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10449 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10450 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10451 | return false; |
| 10452 | |
| 10453 | msg = nlmsg_new(100, gfp); |
| 10454 | if (!msg) |
| 10455 | return true; |
| 10456 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10457 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10458 | if (!hdr) { |
| 10459 | nlmsg_free(msg); |
| 10460 | return true; |
| 10461 | } |
| 10462 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10463 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10464 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10465 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10466 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10467 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10468 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10469 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10470 | return true; |
| 10471 | |
| 10472 | nla_put_failure: |
| 10473 | genlmsg_cancel(msg, hdr); |
| 10474 | nlmsg_free(msg); |
| 10475 | return true; |
| 10476 | } |
| 10477 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10478 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10479 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10480 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10481 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10482 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10483 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10484 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10485 | |
| 10486 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10487 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10488 | trace_cfg80211_return_bool(false); |
| 10489 | return false; |
| 10490 | } |
| 10491 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10492 | addr, gfp); |
| 10493 | trace_cfg80211_return_bool(ret); |
| 10494 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10495 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10496 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10497 | |
| 10498 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10499 | const u8 *addr, gfp_t gfp) |
| 10500 | { |
| 10501 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10502 | bool ret; |
| 10503 | |
| 10504 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10505 | |
| 10506 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10507 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10508 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10509 | trace_cfg80211_return_bool(false); |
| 10510 | return false; |
| 10511 | } |
| 10512 | ret = __nl80211_unexpected_frame(dev, |
| 10513 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10514 | addr, gfp); |
| 10515 | trace_cfg80211_return_bool(ret); |
| 10516 | return ret; |
| 10517 | } |
| 10518 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10519 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10520 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10521 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10522 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10523 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10524 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10525 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10526 | struct sk_buff *msg; |
| 10527 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10528 | |
| 10529 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10530 | if (!msg) |
| 10531 | return -ENOMEM; |
| 10532 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10533 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10534 | if (!hdr) { |
| 10535 | nlmsg_free(msg); |
| 10536 | return -ENOMEM; |
| 10537 | } |
| 10538 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10539 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10540 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10541 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10542 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10543 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10544 | (sig_dbm && |
| 10545 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10546 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10547 | (flags && |
| 10548 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10549 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10550 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10551 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10552 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10553 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10554 | |
| 10555 | nla_put_failure: |
| 10556 | genlmsg_cancel(msg, hdr); |
| 10557 | nlmsg_free(msg); |
| 10558 | return -ENOBUFS; |
| 10559 | } |
| 10560 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10561 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10562 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10563 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10564 | struct wiphy *wiphy = wdev->wiphy; |
| 10565 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10566 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10567 | struct sk_buff *msg; |
| 10568 | void *hdr; |
| 10569 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10570 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10571 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10572 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10573 | if (!msg) |
| 10574 | return; |
| 10575 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10576 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10577 | if (!hdr) { |
| 10578 | nlmsg_free(msg); |
| 10579 | return; |
| 10580 | } |
| 10581 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10582 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10583 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10584 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10585 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10586 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10587 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10588 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10589 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10590 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10591 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10592 | |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 10593 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10594 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10595 | return; |
| 10596 | |
| 10597 | nla_put_failure: |
| 10598 | genlmsg_cancel(msg, hdr); |
| 10599 | nlmsg_free(msg); |
| 10600 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10601 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10602 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10603 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10604 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10605 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10606 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10607 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10608 | struct wiphy *wiphy = wdev->wiphy; |
| 10609 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10610 | struct sk_buff *msg; |
| 10611 | struct nlattr *pinfoattr; |
| 10612 | void *hdr; |
| 10613 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10614 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10615 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10616 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10617 | if (!msg) |
| 10618 | return; |
| 10619 | |
| 10620 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10621 | if (!hdr) { |
| 10622 | nlmsg_free(msg); |
| 10623 | return; |
| 10624 | } |
| 10625 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10626 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10627 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10628 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10629 | |
| 10630 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10631 | if (!pinfoattr) |
| 10632 | goto nla_put_failure; |
| 10633 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10634 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10635 | rssi_event)) |
| 10636 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10637 | |
| 10638 | nla_nest_end(msg, pinfoattr); |
| 10639 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10640 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10641 | |
| 10642 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10643 | nl80211_mlme_mcgrp.id, gfp); |
| 10644 | return; |
| 10645 | |
| 10646 | nla_put_failure: |
| 10647 | genlmsg_cancel(msg, hdr); |
| 10648 | nlmsg_free(msg); |
| 10649 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10650 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10651 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10652 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10653 | struct net_device *netdev, const u8 *bssid, |
| 10654 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10655 | { |
| 10656 | struct sk_buff *msg; |
| 10657 | struct nlattr *rekey_attr; |
| 10658 | void *hdr; |
| 10659 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10660 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10661 | if (!msg) |
| 10662 | return; |
| 10663 | |
| 10664 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10665 | if (!hdr) { |
| 10666 | nlmsg_free(msg); |
| 10667 | return; |
| 10668 | } |
| 10669 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10670 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10671 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10672 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10673 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10674 | |
| 10675 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10676 | if (!rekey_attr) |
| 10677 | goto nla_put_failure; |
| 10678 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10679 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10680 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10681 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10682 | |
| 10683 | nla_nest_end(msg, rekey_attr); |
| 10684 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10685 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10686 | |
| 10687 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10688 | nl80211_mlme_mcgrp.id, gfp); |
| 10689 | return; |
| 10690 | |
| 10691 | nla_put_failure: |
| 10692 | genlmsg_cancel(msg, hdr); |
| 10693 | nlmsg_free(msg); |
| 10694 | } |
| 10695 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10696 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10697 | const u8 *replay_ctr, gfp_t gfp) |
| 10698 | { |
| 10699 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10700 | struct wiphy *wiphy = wdev->wiphy; |
| 10701 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10702 | |
| 10703 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10704 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10705 | } |
| 10706 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10707 | |
| 10708 | static void |
| 10709 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10710 | struct net_device *netdev, int index, |
| 10711 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10712 | { |
| 10713 | struct sk_buff *msg; |
| 10714 | struct nlattr *attr; |
| 10715 | void *hdr; |
| 10716 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10717 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10718 | if (!msg) |
| 10719 | return; |
| 10720 | |
| 10721 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10722 | if (!hdr) { |
| 10723 | nlmsg_free(msg); |
| 10724 | return; |
| 10725 | } |
| 10726 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10727 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10728 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10729 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10730 | |
| 10731 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10732 | if (!attr) |
| 10733 | goto nla_put_failure; |
| 10734 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10735 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10736 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10737 | (preauth && |
| 10738 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10739 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10740 | |
| 10741 | nla_nest_end(msg, attr); |
| 10742 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10743 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10744 | |
| 10745 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10746 | nl80211_mlme_mcgrp.id, gfp); |
| 10747 | return; |
| 10748 | |
| 10749 | nla_put_failure: |
| 10750 | genlmsg_cancel(msg, hdr); |
| 10751 | nlmsg_free(msg); |
| 10752 | } |
| 10753 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10754 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10755 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10756 | { |
| 10757 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10758 | struct wiphy *wiphy = wdev->wiphy; |
| 10759 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10760 | |
| 10761 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10762 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10763 | } |
| 10764 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10765 | |
| 10766 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10767 | struct net_device *netdev, |
| 10768 | struct cfg80211_chan_def *chandef, |
| 10769 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10770 | { |
| 10771 | struct sk_buff *msg; |
| 10772 | void *hdr; |
| 10773 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10775 | if (!msg) |
| 10776 | return; |
| 10777 | |
| 10778 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10779 | if (!hdr) { |
| 10780 | nlmsg_free(msg); |
| 10781 | return; |
| 10782 | } |
| 10783 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10784 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10785 | goto nla_put_failure; |
| 10786 | |
| 10787 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10788 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10789 | |
| 10790 | genlmsg_end(msg, hdr); |
| 10791 | |
| 10792 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10793 | nl80211_mlme_mcgrp.id, gfp); |
| 10794 | return; |
| 10795 | |
| 10796 | nla_put_failure: |
| 10797 | genlmsg_cancel(msg, hdr); |
| 10798 | nlmsg_free(msg); |
| 10799 | } |
| 10800 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10801 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10802 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10803 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10804 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10805 | struct wiphy *wiphy = wdev->wiphy; |
| 10806 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10807 | |
| 10808 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10809 | |
| 10810 | wdev_lock(wdev); |
| 10811 | |
| 10812 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 10813 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 10814 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 10815 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10816 | goto out; |
| 10817 | |
| 10818 | wdev->channel = chandef->chan; |
| 10819 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10820 | out: |
| 10821 | wdev_unlock(wdev); |
| 10822 | return; |
| 10823 | } |
| 10824 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10825 | |
| 10826 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10827 | const u8 *peer, u32 num_packets, |
| 10828 | u32 rate, u32 intvl, gfp_t gfp) |
| 10829 | { |
| 10830 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10831 | struct wiphy *wiphy = wdev->wiphy; |
| 10832 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10833 | struct sk_buff *msg; |
| 10834 | struct nlattr *pinfoattr; |
| 10835 | void *hdr; |
| 10836 | |
| 10837 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10838 | if (!msg) |
| 10839 | return; |
| 10840 | |
| 10841 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10842 | if (!hdr) { |
| 10843 | nlmsg_free(msg); |
| 10844 | return; |
| 10845 | } |
| 10846 | |
| 10847 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10848 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10849 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10850 | goto nla_put_failure; |
| 10851 | |
| 10852 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10853 | if (!pinfoattr) |
| 10854 | goto nla_put_failure; |
| 10855 | |
| 10856 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10857 | goto nla_put_failure; |
| 10858 | |
| 10859 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10860 | goto nla_put_failure; |
| 10861 | |
| 10862 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10863 | goto nla_put_failure; |
| 10864 | |
| 10865 | nla_nest_end(msg, pinfoattr); |
| 10866 | |
| 10867 | genlmsg_end(msg, hdr); |
| 10868 | |
| 10869 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10870 | nl80211_mlme_mcgrp.id, gfp); |
| 10871 | return; |
| 10872 | |
| 10873 | nla_put_failure: |
| 10874 | genlmsg_cancel(msg, hdr); |
| 10875 | nlmsg_free(msg); |
| 10876 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10877 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10878 | |
| 10879 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10880 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 10881 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10882 | enum nl80211_radar_event event, |
| 10883 | struct net_device *netdev, gfp_t gfp) |
| 10884 | { |
| 10885 | struct sk_buff *msg; |
| 10886 | void *hdr; |
| 10887 | |
| 10888 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10889 | if (!msg) |
| 10890 | return; |
| 10891 | |
| 10892 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10893 | if (!hdr) { |
| 10894 | nlmsg_free(msg); |
| 10895 | return; |
| 10896 | } |
| 10897 | |
| 10898 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10899 | goto nla_put_failure; |
| 10900 | |
| 10901 | /* NOP and radar events don't need a netdev parameter */ |
| 10902 | if (netdev) { |
| 10903 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10904 | |
| 10905 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10906 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10907 | goto nla_put_failure; |
| 10908 | } |
| 10909 | |
| 10910 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10911 | goto nla_put_failure; |
| 10912 | |
| 10913 | if (nl80211_send_chandef(msg, chandef)) |
| 10914 | goto nla_put_failure; |
| 10915 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10916 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10917 | |
| 10918 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10919 | nl80211_mlme_mcgrp.id, gfp); |
| 10920 | return; |
| 10921 | |
| 10922 | nla_put_failure: |
| 10923 | genlmsg_cancel(msg, hdr); |
| 10924 | nlmsg_free(msg); |
| 10925 | } |
| 10926 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10927 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10928 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10929 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10930 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10931 | struct wiphy *wiphy = wdev->wiphy; |
| 10932 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10933 | struct sk_buff *msg; |
| 10934 | struct nlattr *pinfoattr; |
| 10935 | void *hdr; |
| 10936 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10937 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10938 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10939 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10940 | if (!msg) |
| 10941 | return; |
| 10942 | |
| 10943 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10944 | if (!hdr) { |
| 10945 | nlmsg_free(msg); |
| 10946 | return; |
| 10947 | } |
| 10948 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10949 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10950 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10951 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10952 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10953 | |
| 10954 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10955 | if (!pinfoattr) |
| 10956 | goto nla_put_failure; |
| 10957 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10958 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10959 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10960 | |
| 10961 | nla_nest_end(msg, pinfoattr); |
| 10962 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10963 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10964 | |
| 10965 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10966 | nl80211_mlme_mcgrp.id, gfp); |
| 10967 | return; |
| 10968 | |
| 10969 | nla_put_failure: |
| 10970 | genlmsg_cancel(msg, hdr); |
| 10971 | nlmsg_free(msg); |
| 10972 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10973 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10974 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10975 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10976 | u64 cookie, bool acked, gfp_t gfp) |
| 10977 | { |
| 10978 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10979 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10980 | struct sk_buff *msg; |
| 10981 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10982 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10983 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10984 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10985 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10986 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10987 | if (!msg) |
| 10988 | return; |
| 10989 | |
| 10990 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10991 | if (!hdr) { |
| 10992 | nlmsg_free(msg); |
| 10993 | return; |
| 10994 | } |
| 10995 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10996 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10997 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10998 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10999 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11000 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11001 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11002 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11003 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11004 | |
| 11005 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11006 | nl80211_mlme_mcgrp.id, gfp); |
| 11007 | return; |
| 11008 | |
| 11009 | nla_put_failure: |
| 11010 | genlmsg_cancel(msg, hdr); |
| 11011 | nlmsg_free(msg); |
| 11012 | } |
| 11013 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11014 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11015 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11016 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11017 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11018 | { |
| 11019 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11020 | struct sk_buff *msg; |
| 11021 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11022 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11023 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11024 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11025 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11026 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11027 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11028 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11029 | if (!msg) { |
| 11030 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11031 | return; |
| 11032 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11033 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11034 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11035 | if (!hdr) |
| 11036 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11037 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11038 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11039 | (freq && |
| 11040 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11041 | (sig_dbm && |
| 11042 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11043 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11044 | goto nla_put_failure; |
| 11045 | |
| 11046 | genlmsg_end(msg, hdr); |
| 11047 | |
| 11048 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11049 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11050 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11051 | return; |
| 11052 | |
| 11053 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11054 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11055 | if (hdr) |
| 11056 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11057 | nlmsg_free(msg); |
| 11058 | } |
| 11059 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11060 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11061 | #ifdef CONFIG_PM |
| 11062 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11063 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11064 | gfp_t gfp) |
| 11065 | { |
| 11066 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11067 | struct sk_buff *msg; |
| 11068 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11069 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11070 | |
| 11071 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11072 | |
| 11073 | if (wakeup) |
| 11074 | size += wakeup->packet_present_len; |
| 11075 | |
| 11076 | msg = nlmsg_new(size, gfp); |
| 11077 | if (!msg) |
| 11078 | return; |
| 11079 | |
| 11080 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11081 | if (!hdr) |
| 11082 | goto free_msg; |
| 11083 | |
| 11084 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11085 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11086 | goto free_msg; |
| 11087 | |
| 11088 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11089 | wdev->netdev->ifindex)) |
| 11090 | goto free_msg; |
| 11091 | |
| 11092 | if (wakeup) { |
| 11093 | struct nlattr *reasons; |
| 11094 | |
| 11095 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 11096 | |
| 11097 | if (wakeup->disconnect && |
| 11098 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11099 | goto free_msg; |
| 11100 | if (wakeup->magic_pkt && |
| 11101 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11102 | goto free_msg; |
| 11103 | if (wakeup->gtk_rekey_failure && |
| 11104 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11105 | goto free_msg; |
| 11106 | if (wakeup->eap_identity_req && |
| 11107 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11108 | goto free_msg; |
| 11109 | if (wakeup->four_way_handshake && |
| 11110 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11111 | goto free_msg; |
| 11112 | if (wakeup->rfkill_release && |
| 11113 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11114 | goto free_msg; |
| 11115 | |
| 11116 | if (wakeup->pattern_idx >= 0 && |
| 11117 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11118 | wakeup->pattern_idx)) |
| 11119 | goto free_msg; |
| 11120 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11121 | if (wakeup->tcp_match) |
| 11122 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 11123 | |
| 11124 | if (wakeup->tcp_connlost) |
| 11125 | nla_put_flag(msg, |
| 11126 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 11127 | |
| 11128 | if (wakeup->tcp_nomoretokens) |
| 11129 | nla_put_flag(msg, |
| 11130 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 11131 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11132 | if (wakeup->packet) { |
| 11133 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11134 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11135 | |
| 11136 | if (!wakeup->packet_80211) { |
| 11137 | pkt_attr = |
| 11138 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11139 | len_attr = |
| 11140 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11141 | } |
| 11142 | |
| 11143 | if (wakeup->packet_len && |
| 11144 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11145 | goto free_msg; |
| 11146 | |
| 11147 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11148 | wakeup->packet)) |
| 11149 | goto free_msg; |
| 11150 | } |
| 11151 | |
| 11152 | nla_nest_end(msg, reasons); |
| 11153 | } |
| 11154 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11155 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11156 | |
| 11157 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11158 | nl80211_mlme_mcgrp.id, gfp); |
| 11159 | return; |
| 11160 | |
| 11161 | free_msg: |
| 11162 | nlmsg_free(msg); |
| 11163 | } |
| 11164 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11165 | #endif |
| 11166 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11167 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11168 | enum nl80211_tdls_operation oper, |
| 11169 | u16 reason_code, gfp_t gfp) |
| 11170 | { |
| 11171 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11172 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11173 | struct sk_buff *msg; |
| 11174 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11175 | |
| 11176 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11177 | reason_code); |
| 11178 | |
| 11179 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11180 | if (!msg) |
| 11181 | return; |
| 11182 | |
| 11183 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11184 | if (!hdr) { |
| 11185 | nlmsg_free(msg); |
| 11186 | return; |
| 11187 | } |
| 11188 | |
| 11189 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11190 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11191 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11192 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11193 | (reason_code > 0 && |
| 11194 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11195 | goto nla_put_failure; |
| 11196 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11197 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11198 | |
| 11199 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11200 | nl80211_mlme_mcgrp.id, gfp); |
| 11201 | return; |
| 11202 | |
| 11203 | nla_put_failure: |
| 11204 | genlmsg_cancel(msg, hdr); |
| 11205 | nlmsg_free(msg); |
| 11206 | } |
| 11207 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11208 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11209 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11210 | unsigned long state, |
| 11211 | void *_notify) |
| 11212 | { |
| 11213 | struct netlink_notify *notify = _notify; |
| 11214 | struct cfg80211_registered_device *rdev; |
| 11215 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11216 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11217 | |
| 11218 | if (state != NETLINK_URELEASE) |
| 11219 | return NOTIFY_DONE; |
| 11220 | |
| 11221 | rcu_read_lock(); |
| 11222 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11223 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11224 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11225 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11226 | |
| 11227 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11228 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11229 | list) { |
| 11230 | if (reg->nlportid == notify->portid) { |
| 11231 | list_del(®->list); |
| 11232 | kfree(reg); |
| 11233 | break; |
| 11234 | } |
| 11235 | } |
| 11236 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11237 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11238 | |
| 11239 | rcu_read_unlock(); |
| 11240 | |
| 11241 | return NOTIFY_DONE; |
| 11242 | } |
| 11243 | |
| 11244 | static struct notifier_block nl80211_netlink_notifier = { |
| 11245 | .notifier_call = nl80211_netlink_notify, |
| 11246 | }; |
| 11247 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11248 | void cfg80211_ft_event(struct net_device *netdev, |
| 11249 | struct cfg80211_ft_event_params *ft_event) |
| 11250 | { |
| 11251 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11252 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11253 | struct sk_buff *msg; |
| 11254 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11255 | |
| 11256 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11257 | |
| 11258 | if (!ft_event->target_ap) |
| 11259 | return; |
| 11260 | |
| 11261 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11262 | if (!msg) |
| 11263 | return; |
| 11264 | |
| 11265 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 11266 | if (!hdr) { |
| 11267 | nlmsg_free(msg); |
| 11268 | return; |
| 11269 | } |
| 11270 | |
| 11271 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 11272 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 11273 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 11274 | if (ft_event->ies) |
| 11275 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 11276 | if (ft_event->ric_ies) |
| 11277 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11278 | ft_event->ric_ies); |
| 11279 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11280 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11281 | |
| 11282 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11283 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 11284 | } |
| 11285 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11286 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11287 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11288 | { |
| 11289 | struct cfg80211_registered_device *rdev; |
| 11290 | struct sk_buff *msg; |
| 11291 | void *hdr; |
| 11292 | u32 nlportid; |
| 11293 | |
| 11294 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11295 | if (!rdev->crit_proto_nlportid) |
| 11296 | return; |
| 11297 | |
| 11298 | nlportid = rdev->crit_proto_nlportid; |
| 11299 | rdev->crit_proto_nlportid = 0; |
| 11300 | |
| 11301 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11302 | if (!msg) |
| 11303 | return; |
| 11304 | |
| 11305 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11306 | if (!hdr) |
| 11307 | goto nla_put_failure; |
| 11308 | |
| 11309 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11310 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11311 | goto nla_put_failure; |
| 11312 | |
| 11313 | genlmsg_end(msg, hdr); |
| 11314 | |
| 11315 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11316 | return; |
| 11317 | |
| 11318 | nla_put_failure: |
| 11319 | if (hdr) |
| 11320 | genlmsg_cancel(msg, hdr); |
| 11321 | nlmsg_free(msg); |
| 11322 | |
| 11323 | } |
| 11324 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11325 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11326 | /* initialisation/exit functions */ |
| 11327 | |
| 11328 | int nl80211_init(void) |
| 11329 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11330 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11331 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11332 | err = genl_register_family_with_ops(&nl80211_fam, |
| 11333 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11334 | if (err) |
| 11335 | return err; |
| 11336 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11337 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 11338 | if (err) |
| 11339 | goto err_out; |
| 11340 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11341 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 11342 | if (err) |
| 11343 | goto err_out; |
| 11344 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11345 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 11346 | if (err) |
| 11347 | goto err_out; |
| 11348 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11349 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 11350 | if (err) |
| 11351 | goto err_out; |
| 11352 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11353 | #ifdef CONFIG_NL80211_TESTMODE |
| 11354 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 11355 | if (err) |
| 11356 | goto err_out; |
| 11357 | #endif |
| 11358 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11359 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11360 | if (err) |
| 11361 | goto err_out; |
| 11362 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11363 | return 0; |
| 11364 | err_out: |
| 11365 | genl_unregister_family(&nl80211_fam); |
| 11366 | return err; |
| 11367 | } |
| 11368 | |
| 11369 | void nl80211_exit(void) |
| 11370 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11371 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11372 | genl_unregister_family(&nl80211_fam); |
| 11373 | } |