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 | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 272 | [NL80211_ATTR_STA_FLAGS2] = { |
| 273 | .len = sizeof(struct nl80211_sta_flag_update), |
| 274 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 284 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_DATA_LEN }, |
| 290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 327 | .len = NL80211_HT_CAPABILITY_LEN |
| 328 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 347 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 350 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
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; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1231 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1232 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1233 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1234 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1235 | state->split_start++; |
| 1236 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1237 | break; |
| 1238 | case 1: |
| 1239 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1240 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1241 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1242 | goto nla_put_failure; |
| 1243 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1244 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1245 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1246 | goto nla_put_failure; |
| 1247 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1248 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1249 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1250 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1251 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1252 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1253 | dev->wiphy.available_antennas_tx) || |
| 1254 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1255 | dev->wiphy.available_antennas_rx)) |
| 1256 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1257 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1258 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1259 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1260 | dev->wiphy.probe_resp_offload)) |
| 1261 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1262 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1263 | if ((dev->wiphy.available_antennas_tx || |
| 1264 | dev->wiphy.available_antennas_rx) && |
| 1265 | dev->ops->get_antenna) { |
| 1266 | u32 tx_ant = 0, rx_ant = 0; |
| 1267 | int res; |
| 1268 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1269 | if (!res) { |
| 1270 | if (nla_put_u32(msg, |
| 1271 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1272 | tx_ant) || |
| 1273 | nla_put_u32(msg, |
| 1274 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1275 | rx_ant)) |
| 1276 | goto nla_put_failure; |
| 1277 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1278 | } |
| 1279 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1280 | state->split_start++; |
| 1281 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1282 | break; |
| 1283 | case 2: |
| 1284 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1285 | dev->wiphy.interface_modes)) |
| 1286 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1287 | state->split_start++; |
| 1288 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1289 | break; |
| 1290 | case 3: |
| 1291 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1292 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1293 | goto nla_put_failure; |
| 1294 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1295 | for (band = state->band_start; |
| 1296 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1297 | struct ieee80211_supported_band *sband; |
| 1298 | |
| 1299 | sband = dev->wiphy.bands[band]; |
| 1300 | |
| 1301 | if (!sband) |
| 1302 | continue; |
| 1303 | |
| 1304 | nl_band = nla_nest_start(msg, band); |
| 1305 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1306 | goto nla_put_failure; |
| 1307 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1308 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1309 | case 0: |
| 1310 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1311 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1312 | state->chan_start++; |
| 1313 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1314 | break; |
| 1315 | default: |
| 1316 | /* add frequencies */ |
| 1317 | nl_freqs = nla_nest_start( |
| 1318 | msg, NL80211_BAND_ATTR_FREQS); |
| 1319 | if (!nl_freqs) |
| 1320 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1321 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1322 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1323 | i < sband->n_channels; |
| 1324 | i++) { |
| 1325 | nl_freq = nla_nest_start(msg, i); |
| 1326 | if (!nl_freq) |
| 1327 | goto nla_put_failure; |
| 1328 | |
| 1329 | chan = &sband->channels[i]; |
| 1330 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1331 | if (nl80211_msg_put_channel( |
| 1332 | msg, chan, |
| 1333 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1334 | goto nla_put_failure; |
| 1335 | |
| 1336 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1337 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1338 | break; |
| 1339 | } |
| 1340 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1341 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1342 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1343 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | nla_nest_end(msg, nl_freqs); |
| 1345 | } |
| 1346 | |
| 1347 | nla_nest_end(msg, nl_band); |
| 1348 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1349 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1351 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1352 | band--; |
| 1353 | break; |
| 1354 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1355 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1356 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1357 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1359 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1360 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1361 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1362 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1363 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1364 | if (state->band_start == 0 && state->chan_start == 0) |
| 1365 | state->split_start++; |
| 1366 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | break; |
| 1368 | case 4: |
| 1369 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1370 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1371 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | |
| 1373 | i = 0; |
| 1374 | #define CMD(op, n) \ |
| 1375 | do { \ |
| 1376 | if (dev->ops->op) { \ |
| 1377 | i++; \ |
| 1378 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1379 | goto nla_put_failure; \ |
| 1380 | } \ |
| 1381 | } while (0) |
| 1382 | |
| 1383 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1384 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1385 | CMD(add_key, NEW_KEY); |
| 1386 | CMD(start_ap, START_AP); |
| 1387 | CMD(add_station, NEW_STATION); |
| 1388 | CMD(add_mpath, NEW_MPATH); |
| 1389 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1390 | CMD(change_bss, SET_BSS); |
| 1391 | CMD(auth, AUTHENTICATE); |
| 1392 | CMD(assoc, ASSOCIATE); |
| 1393 | CMD(deauth, DEAUTHENTICATE); |
| 1394 | CMD(disassoc, DISASSOCIATE); |
| 1395 | CMD(join_ibss, JOIN_IBSS); |
| 1396 | CMD(join_mesh, JOIN_MESH); |
| 1397 | CMD(set_pmksa, SET_PMKSA); |
| 1398 | CMD(del_pmksa, DEL_PMKSA); |
| 1399 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1400 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1401 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1402 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1403 | CMD(mgmt_tx, FRAME); |
| 1404 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1405 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1406 | i++; |
| 1407 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1408 | goto nla_put_failure; |
| 1409 | } |
| 1410 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1411 | dev->ops->join_mesh) { |
| 1412 | i++; |
| 1413 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1414 | goto nla_put_failure; |
| 1415 | } |
| 1416 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1417 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1418 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1419 | CMD(tdls_oper, TDLS_OPER); |
| 1420 | } |
| 1421 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1422 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1423 | CMD(probe_client, PROBE_CLIENT); |
| 1424 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1425 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1426 | i++; |
| 1427 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1428 | goto nla_put_failure; |
| 1429 | } |
| 1430 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1431 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1432 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1433 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1434 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1435 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1436 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1437 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1438 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1439 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1441 | #endif |
| 1442 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1443 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1444 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1445 | if (dev->ops->connect || dev->ops->auth) { |
| 1446 | i++; |
| 1447 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1448 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1449 | } |
| 1450 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1451 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1452 | i++; |
| 1453 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1454 | goto nla_put_failure; |
| 1455 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1456 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1457 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1458 | state->split_start++; |
| 1459 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1460 | break; |
| 1461 | case 5: |
| 1462 | if (dev->ops->remain_on_channel && |
| 1463 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1464 | nla_put_u32(msg, |
| 1465 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1466 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1467 | goto nla_put_failure; |
| 1468 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1469 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1470 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1471 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1472 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1473 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1474 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1475 | state->split_start++; |
| 1476 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1477 | break; |
| 1478 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1479 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1480 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1481 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1482 | state->split_start++; |
| 1483 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1484 | break; |
| 1485 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1486 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | #endif |
| 1488 | case 7: |
| 1489 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1490 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1491 | goto nla_put_failure; |
| 1492 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1493 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1494 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1495 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1496 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1497 | state->split_start++; |
| 1498 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1499 | break; |
| 1500 | case 8: |
| 1501 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1502 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1503 | dev->wiphy.ap_sme_capa)) |
| 1504 | goto nla_put_failure; |
| 1505 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1506 | features = dev->wiphy.features; |
| 1507 | /* |
| 1508 | * We can only add the per-channel limit information if the |
| 1509 | * dump is split, otherwise it makes it too big. Therefore |
| 1510 | * only advertise it in that case. |
| 1511 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1512 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1513 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1514 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1515 | goto nla_put_failure; |
| 1516 | |
| 1517 | if (dev->wiphy.ht_capa_mod_mask && |
| 1518 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1519 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1520 | dev->wiphy.ht_capa_mod_mask)) |
| 1521 | goto nla_put_failure; |
| 1522 | |
| 1523 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1524 | dev->wiphy.max_acl_mac_addrs && |
| 1525 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1526 | dev->wiphy.max_acl_mac_addrs)) |
| 1527 | goto nla_put_failure; |
| 1528 | |
| 1529 | /* |
| 1530 | * Any information below this point is only available to |
| 1531 | * applications that can deal with it being split. This |
| 1532 | * helps ensure that newly added capabilities don't break |
| 1533 | * older tools by overrunning their buffers. |
| 1534 | * |
| 1535 | * We still increment split_start so that in the split |
| 1536 | * case we'll continue with more data in the next round, |
| 1537 | * but break unconditionally so unsplit data stops here. |
| 1538 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1539 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1540 | break; |
| 1541 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1542 | if (dev->wiphy.extended_capabilities && |
| 1543 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1544 | dev->wiphy.extended_capabilities_len, |
| 1545 | dev->wiphy.extended_capabilities) || |
| 1546 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1547 | dev->wiphy.extended_capabilities_len, |
| 1548 | dev->wiphy.extended_capabilities_mask))) |
| 1549 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1550 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1551 | if (dev->wiphy.vht_capa_mod_mask && |
| 1552 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1553 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1554 | dev->wiphy.vht_capa_mod_mask)) |
| 1555 | goto nla_put_failure; |
| 1556 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1557 | state->split_start++; |
| 1558 | break; |
| 1559 | case 10: |
| 1560 | if (nl80211_send_coalesce(msg, dev)) |
| 1561 | goto nla_put_failure; |
| 1562 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1563 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1564 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1566 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1567 | return genlmsg_end(msg, hdr); |
| 1568 | |
| 1569 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1570 | genlmsg_cancel(msg, hdr); |
| 1571 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1572 | } |
| 1573 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1574 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1575 | struct netlink_callback *cb, |
| 1576 | struct nl80211_dump_wiphy_state *state) |
| 1577 | { |
| 1578 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1579 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1580 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1581 | /* ignore parse errors for backward compatibility */ |
| 1582 | if (ret) |
| 1583 | return 0; |
| 1584 | |
| 1585 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1586 | if (tb[NL80211_ATTR_WIPHY]) |
| 1587 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1588 | if (tb[NL80211_ATTR_WDEV]) |
| 1589 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1590 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1591 | struct net_device *netdev; |
| 1592 | struct cfg80211_registered_device *rdev; |
| 1593 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1594 | |
| 1595 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1596 | if (!netdev) |
| 1597 | return -ENODEV; |
| 1598 | if (netdev->ieee80211_ptr) { |
| 1599 | rdev = wiphy_to_dev( |
| 1600 | netdev->ieee80211_ptr->wiphy); |
| 1601 | state->filter_wiphy = rdev->wiphy_idx; |
| 1602 | } |
| 1603 | dev_put(netdev); |
| 1604 | } |
| 1605 | |
| 1606 | return 0; |
| 1607 | } |
| 1608 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1609 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1610 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1611 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1612 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1613 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1614 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1615 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1616 | if (!state) { |
| 1617 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1618 | if (!state) { |
| 1619 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1620 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1621 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1622 | state->filter_wiphy = -1; |
| 1623 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1624 | if (ret) { |
| 1625 | kfree(state); |
| 1626 | rtnl_unlock(); |
| 1627 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1628 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1629 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1630 | } |
| 1631 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1632 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1633 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1634 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1635 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1636 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1637 | if (state->filter_wiphy != -1 && |
| 1638 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1639 | continue; |
| 1640 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1641 | do { |
| 1642 | ret = nl80211_send_wiphy(dev, skb, |
| 1643 | NETLINK_CB(cb->skb).portid, |
| 1644 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1645 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1646 | if (ret < 0) { |
| 1647 | /* |
| 1648 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1649 | * or EMSGSIZE returned), this SKB is still |
| 1650 | * empty (so it's not too big because another |
| 1651 | * wiphy dataset is already in the skb) and |
| 1652 | * we've not tried to adjust the dump allocation |
| 1653 | * yet ... then adjust the alloc size to be |
| 1654 | * bigger, and return 1 but with the empty skb. |
| 1655 | * This results in an empty message being RX'ed |
| 1656 | * in userspace, but that is ignored. |
| 1657 | * |
| 1658 | * We can then retry with the larger buffer. |
| 1659 | */ |
| 1660 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1661 | !skb->len && |
| 1662 | cb->min_dump_alloc < 4096) { |
| 1663 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1664 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1665 | return 1; |
| 1666 | } |
| 1667 | idx--; |
| 1668 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1669 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1670 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1671 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1672 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1673 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1674 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1675 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1676 | |
| 1677 | return skb->len; |
| 1678 | } |
| 1679 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1680 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1681 | { |
| 1682 | kfree((void *)cb->args[0]); |
| 1683 | return 0; |
| 1684 | } |
| 1685 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1686 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1687 | { |
| 1688 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1689 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1690 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1691 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1692 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1693 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1694 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1695 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1696 | 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] | 1697 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1698 | nlmsg_free(msg); |
| 1699 | return -ENOBUFS; |
| 1700 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1701 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1702 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1703 | } |
| 1704 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1705 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1706 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1707 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1708 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1709 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1710 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1711 | }; |
| 1712 | |
| 1713 | static int parse_txq_params(struct nlattr *tb[], |
| 1714 | struct ieee80211_txq_params *txq_params) |
| 1715 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1716 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1717 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1718 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1719 | return -EINVAL; |
| 1720 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1721 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1722 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1723 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1724 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1725 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1726 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1727 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1728 | return -EINVAL; |
| 1729 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1730 | return 0; |
| 1731 | } |
| 1732 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1733 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1734 | { |
| 1735 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1736 | * You can only set the channel explicitly for WDS interfaces, |
| 1737 | * all others have their channel managed via their respective |
| 1738 | * "establish a connection" command (connect, join, ...) |
| 1739 | * |
| 1740 | * For AP/GO and mesh mode, the channel can be set with the |
| 1741 | * channel userspace API, but is only stored and passed to the |
| 1742 | * low-level driver when the AP starts or the mesh is joined. |
| 1743 | * This is for backward compatibility, userspace can also give |
| 1744 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1745 | * |
| 1746 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1747 | * whatever else is going on, so they have their own special |
| 1748 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1749 | */ |
| 1750 | return !wdev || |
| 1751 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1752 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1753 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1754 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1755 | } |
| 1756 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1757 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1758 | struct genl_info *info, |
| 1759 | struct cfg80211_chan_def *chandef) |
| 1760 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1761 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1762 | |
| 1763 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1764 | return -EINVAL; |
| 1765 | |
| 1766 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1767 | |
| 1768 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1769 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1770 | chandef->center_freq1 = control_freq; |
| 1771 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1772 | |
| 1773 | /* Primary channel not allowed */ |
| 1774 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1775 | return -EINVAL; |
| 1776 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1777 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1778 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1779 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1780 | chantype = nla_get_u32( |
| 1781 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1782 | |
| 1783 | switch (chantype) { |
| 1784 | case NL80211_CHAN_NO_HT: |
| 1785 | case NL80211_CHAN_HT20: |
| 1786 | case NL80211_CHAN_HT40PLUS: |
| 1787 | case NL80211_CHAN_HT40MINUS: |
| 1788 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1789 | chantype); |
| 1790 | break; |
| 1791 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1792 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1793 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1794 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1795 | chandef->width = |
| 1796 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1797 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1798 | chandef->center_freq1 = |
| 1799 | nla_get_u32( |
| 1800 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1801 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1802 | chandef->center_freq2 = |
| 1803 | nla_get_u32( |
| 1804 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1805 | } |
| 1806 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1807 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1808 | return -EINVAL; |
| 1809 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1810 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1811 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1812 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1813 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1814 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1815 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1816 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1817 | return -EINVAL; |
| 1818 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1819 | return 0; |
| 1820 | } |
| 1821 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1822 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1823 | struct wireless_dev *wdev, |
| 1824 | struct genl_info *info) |
| 1825 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1826 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1827 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1828 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1829 | |
| 1830 | if (wdev) |
| 1831 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1832 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1833 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1834 | return -EOPNOTSUPP; |
| 1835 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1836 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1837 | if (result) |
| 1838 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1839 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1840 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1841 | case NL80211_IFTYPE_AP: |
| 1842 | case NL80211_IFTYPE_P2P_GO: |
| 1843 | if (wdev->beacon_interval) { |
| 1844 | result = -EBUSY; |
| 1845 | break; |
| 1846 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1847 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1848 | result = -EINVAL; |
| 1849 | break; |
| 1850 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1851 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1852 | result = 0; |
| 1853 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1854 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1855 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1856 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1857 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1858 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1859 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1860 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1861 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1862 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1863 | |
| 1864 | return result; |
| 1865 | } |
| 1866 | |
| 1867 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1868 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1869 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1870 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1872 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1873 | } |
| 1874 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1875 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1876 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1877 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1878 | struct net_device *dev = info->user_ptr[1]; |
| 1879 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1880 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1881 | |
| 1882 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1883 | return -EINVAL; |
| 1884 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1885 | if (netif_running(dev)) |
| 1886 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1887 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1888 | if (!rdev->ops->set_wds_peer) |
| 1889 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1890 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1891 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1892 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1893 | |
| 1894 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1895 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1899 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1900 | { |
| 1901 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1902 | struct net_device *netdev = NULL; |
| 1903 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1904 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1905 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1906 | u32 changed; |
| 1907 | u8 retry_short = 0, retry_long = 0; |
| 1908 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1909 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1910 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1911 | ASSERT_RTNL(); |
| 1912 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1913 | /* |
| 1914 | * Try to find the wiphy and netdev. Normally this |
| 1915 | * function shouldn't need the netdev, but this is |
| 1916 | * done for backward compatibility -- previously |
| 1917 | * setting the channel was done per wiphy, but now |
| 1918 | * it is per netdev. Previous userland like hostapd |
| 1919 | * also passed a netdev to set_wiphy, so that it is |
| 1920 | * possible to let that go to the right netdev! |
| 1921 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1922 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1923 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1924 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1925 | |
| 1926 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1927 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1928 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1929 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1930 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1931 | } |
| 1932 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1933 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1934 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1935 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1936 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1937 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1938 | wdev = NULL; |
| 1939 | netdev = NULL; |
| 1940 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1941 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1942 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1943 | |
| 1944 | /* |
| 1945 | * end workaround code, by now the rdev is available |
| 1946 | * and locked, and wdev may or may not be NULL. |
| 1947 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1948 | |
| 1949 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1950 | result = cfg80211_dev_rename( |
| 1951 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1952 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1953 | if (result) |
| 1954 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1955 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1956 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1957 | struct ieee80211_txq_params txq_params; |
| 1958 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1959 | |
| 1960 | if (!rdev->ops->set_txq_params) { |
| 1961 | result = -EOPNOTSUPP; |
| 1962 | goto bad_res; |
| 1963 | } |
| 1964 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1965 | if (!netdev) { |
| 1966 | result = -EINVAL; |
| 1967 | goto bad_res; |
| 1968 | } |
| 1969 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1970 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1971 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1972 | result = -EINVAL; |
| 1973 | goto bad_res; |
| 1974 | } |
| 1975 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1976 | if (!netif_running(netdev)) { |
| 1977 | result = -ENETDOWN; |
| 1978 | goto bad_res; |
| 1979 | } |
| 1980 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1981 | nla_for_each_nested(nl_txq_params, |
| 1982 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1983 | rem_txq_params) { |
| 1984 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1985 | nla_data(nl_txq_params), |
| 1986 | nla_len(nl_txq_params), |
| 1987 | txq_params_policy); |
| 1988 | result = parse_txq_params(tb, &txq_params); |
| 1989 | if (result) |
| 1990 | goto bad_res; |
| 1991 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1992 | result = rdev_set_txq_params(rdev, netdev, |
| 1993 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1994 | if (result) |
| 1995 | goto bad_res; |
| 1996 | } |
| 1997 | } |
| 1998 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1999 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2000 | result = __nl80211_set_channel(rdev, |
| 2001 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 2002 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2003 | if (result) |
| 2004 | goto bad_res; |
| 2005 | } |
| 2006 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2007 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2008 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2009 | enum nl80211_tx_power_setting type; |
| 2010 | int idx, mbm = 0; |
| 2011 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2012 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2013 | txp_wdev = NULL; |
| 2014 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2015 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2016 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2017 | goto bad_res; |
| 2018 | } |
| 2019 | |
| 2020 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2021 | type = nla_get_u32(info->attrs[idx]); |
| 2022 | |
| 2023 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2024 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2025 | result = -EINVAL; |
| 2026 | goto bad_res; |
| 2027 | } |
| 2028 | |
| 2029 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2030 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2031 | mbm = nla_get_u32(info->attrs[idx]); |
| 2032 | } |
| 2033 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2034 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2035 | if (result) |
| 2036 | goto bad_res; |
| 2037 | } |
| 2038 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2039 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2040 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2041 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2042 | if ((!rdev->wiphy.available_antennas_tx && |
| 2043 | !rdev->wiphy.available_antennas_rx) || |
| 2044 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2045 | result = -EOPNOTSUPP; |
| 2046 | goto bad_res; |
| 2047 | } |
| 2048 | |
| 2049 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2050 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2051 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2052 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2053 | * available antenna masks, except for the "all" mask */ |
| 2054 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2055 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2056 | result = -EINVAL; |
| 2057 | goto bad_res; |
| 2058 | } |
| 2059 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2060 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2061 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2062 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2063 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2064 | if (result) |
| 2065 | goto bad_res; |
| 2066 | } |
| 2067 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2068 | changed = 0; |
| 2069 | |
| 2070 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2071 | retry_short = nla_get_u8( |
| 2072 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2073 | if (retry_short == 0) { |
| 2074 | result = -EINVAL; |
| 2075 | goto bad_res; |
| 2076 | } |
| 2077 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2078 | } |
| 2079 | |
| 2080 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2081 | retry_long = nla_get_u8( |
| 2082 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2083 | if (retry_long == 0) { |
| 2084 | result = -EINVAL; |
| 2085 | goto bad_res; |
| 2086 | } |
| 2087 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2088 | } |
| 2089 | |
| 2090 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2091 | frag_threshold = nla_get_u32( |
| 2092 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2093 | if (frag_threshold < 256) { |
| 2094 | result = -EINVAL; |
| 2095 | goto bad_res; |
| 2096 | } |
| 2097 | if (frag_threshold != (u32) -1) { |
| 2098 | /* |
| 2099 | * Fragments (apart from the last one) are required to |
| 2100 | * have even length. Make the fragmentation code |
| 2101 | * simpler by stripping LSB should someone try to use |
| 2102 | * odd threshold value. |
| 2103 | */ |
| 2104 | frag_threshold &= ~0x1; |
| 2105 | } |
| 2106 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2107 | } |
| 2108 | |
| 2109 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2110 | rts_threshold = nla_get_u32( |
| 2111 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2112 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2113 | } |
| 2114 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2115 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2116 | coverage_class = nla_get_u8( |
| 2117 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2118 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2119 | } |
| 2120 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2121 | if (changed) { |
| 2122 | u8 old_retry_short, old_retry_long; |
| 2123 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2124 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2125 | |
| 2126 | if (!rdev->ops->set_wiphy_params) { |
| 2127 | result = -EOPNOTSUPP; |
| 2128 | goto bad_res; |
| 2129 | } |
| 2130 | |
| 2131 | old_retry_short = rdev->wiphy.retry_short; |
| 2132 | old_retry_long = rdev->wiphy.retry_long; |
| 2133 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2134 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2135 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2136 | |
| 2137 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2138 | rdev->wiphy.retry_short = retry_short; |
| 2139 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2140 | rdev->wiphy.retry_long = retry_long; |
| 2141 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2142 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2143 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2144 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2145 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2146 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2147 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2148 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2149 | if (result) { |
| 2150 | rdev->wiphy.retry_short = old_retry_short; |
| 2151 | rdev->wiphy.retry_long = old_retry_long; |
| 2152 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2153 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2154 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2155 | } |
| 2156 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2157 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2158 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2159 | if (netdev) |
| 2160 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2161 | return result; |
| 2162 | } |
| 2163 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2164 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2165 | { |
| 2166 | return (u64)wdev->identifier | |
| 2167 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2168 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2169 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2170 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2171 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2172 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2173 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2174 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2175 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2176 | chandef->chan->center_freq)) |
| 2177 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2178 | switch (chandef->width) { |
| 2179 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2180 | case NL80211_CHAN_WIDTH_20: |
| 2181 | case NL80211_CHAN_WIDTH_40: |
| 2182 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2183 | cfg80211_get_chandef_type(chandef))) |
| 2184 | return -ENOBUFS; |
| 2185 | break; |
| 2186 | default: |
| 2187 | break; |
| 2188 | } |
| 2189 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2190 | return -ENOBUFS; |
| 2191 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2192 | return -ENOBUFS; |
| 2193 | if (chandef->center_freq2 && |
| 2194 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2195 | return -ENOBUFS; |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2199 | 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] | 2200 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2201 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2202 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2203 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2204 | void *hdr; |
| 2205 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2206 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2207 | if (!hdr) |
| 2208 | return -1; |
| 2209 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2210 | if (dev && |
| 2211 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2212 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2213 | goto nla_put_failure; |
| 2214 | |
| 2215 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2216 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2217 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2218 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2219 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2220 | rdev->devlist_generation ^ |
| 2221 | (cfg80211_rdev_list_generation << 2))) |
| 2222 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2223 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2224 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2225 | int ret; |
| 2226 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2227 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2228 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2229 | if (ret == 0) { |
| 2230 | if (nl80211_send_chandef(msg, &chandef)) |
| 2231 | goto nla_put_failure; |
| 2232 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2233 | } |
| 2234 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2235 | if (wdev->ssid_len) { |
| 2236 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2237 | goto nla_put_failure; |
| 2238 | } |
| 2239 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2240 | return genlmsg_end(msg, hdr); |
| 2241 | |
| 2242 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2243 | genlmsg_cancel(msg, hdr); |
| 2244 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2248 | { |
| 2249 | int wp_idx = 0; |
| 2250 | int if_idx = 0; |
| 2251 | int wp_start = cb->args[0]; |
| 2252 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2253 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2254 | struct wireless_dev *wdev; |
| 2255 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2256 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2257 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2258 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2259 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2260 | if (wp_idx < wp_start) { |
| 2261 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2262 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2263 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2264 | if_idx = 0; |
| 2265 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2266 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2267 | if (if_idx < if_start) { |
| 2268 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2269 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2270 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2271 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2272 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2273 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2274 | goto out; |
| 2275 | } |
| 2276 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2277 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2278 | |
| 2279 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2280 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2281 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2282 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2283 | |
| 2284 | cb->args[0] = wp_idx; |
| 2285 | cb->args[1] = if_idx; |
| 2286 | |
| 2287 | return skb->len; |
| 2288 | } |
| 2289 | |
| 2290 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2291 | { |
| 2292 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2293 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2294 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2295 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2296 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2297 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2298 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2299 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2300 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2301 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2302 | nlmsg_free(msg); |
| 2303 | return -ENOBUFS; |
| 2304 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2305 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2306 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2307 | } |
| 2308 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2309 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2310 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2311 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2312 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2313 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2314 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2315 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2316 | }; |
| 2317 | |
| 2318 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2319 | { |
| 2320 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2321 | int flag; |
| 2322 | |
| 2323 | *mntrflags = 0; |
| 2324 | |
| 2325 | if (!nla) |
| 2326 | return -EINVAL; |
| 2327 | |
| 2328 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2329 | nla, mntr_flags_policy)) |
| 2330 | return -EINVAL; |
| 2331 | |
| 2332 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2333 | if (flags[flag]) |
| 2334 | *mntrflags |= (1<<flag); |
| 2335 | |
| 2336 | return 0; |
| 2337 | } |
| 2338 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2339 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2340 | struct net_device *netdev, u8 use_4addr, |
| 2341 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2342 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2343 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2344 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2345 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2346 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2347 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2348 | |
| 2349 | switch (iftype) { |
| 2350 | case NL80211_IFTYPE_AP_VLAN: |
| 2351 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2352 | return 0; |
| 2353 | break; |
| 2354 | case NL80211_IFTYPE_STATION: |
| 2355 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2356 | return 0; |
| 2357 | break; |
| 2358 | default: |
| 2359 | break; |
| 2360 | } |
| 2361 | |
| 2362 | return -EOPNOTSUPP; |
| 2363 | } |
| 2364 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2365 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2366 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2368 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2369 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2370 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2371 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2372 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2373 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2374 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2375 | memset(¶ms, 0, sizeof(params)); |
| 2376 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2377 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2378 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2379 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2380 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2381 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2382 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2383 | if (ntype > NL80211_IFTYPE_MAX) |
| 2384 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2385 | } |
| 2386 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2387 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2388 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2390 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2391 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2392 | if (netif_running(dev)) |
| 2393 | return -EBUSY; |
| 2394 | |
| 2395 | wdev_lock(wdev); |
| 2396 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2397 | IEEE80211_MAX_MESH_ID_LEN); |
| 2398 | wdev->mesh_id_up_len = |
| 2399 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2400 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2401 | wdev->mesh_id_up_len); |
| 2402 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2405 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2406 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2407 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2408 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2409 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2410 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2411 | } else { |
| 2412 | params.use_4addr = -1; |
| 2413 | } |
| 2414 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2415 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2416 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2417 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2418 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2419 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2420 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2421 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2422 | |
| 2423 | flags = &_flags; |
| 2424 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2425 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2426 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2427 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2428 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2429 | return -EOPNOTSUPP; |
| 2430 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2431 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2432 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2433 | else |
| 2434 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2435 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2436 | if (!err && params.use_4addr != -1) |
| 2437 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2438 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2439 | return err; |
| 2440 | } |
| 2441 | |
| 2442 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2443 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2445 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2446 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2447 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2448 | int err; |
| 2449 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2450 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2451 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2452 | memset(¶ms, 0, sizeof(params)); |
| 2453 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2454 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2455 | return -EINVAL; |
| 2456 | |
| 2457 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2458 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2459 | if (type > NL80211_IFTYPE_MAX) |
| 2460 | return -EINVAL; |
| 2461 | } |
| 2462 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2463 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2464 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2465 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2466 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2467 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2468 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2469 | ETH_ALEN); |
| 2470 | if (!is_valid_ether_addr(params.macaddr)) |
| 2471 | return -EADDRNOTAVAIL; |
| 2472 | } |
| 2473 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2474 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2475 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2476 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2477 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2478 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2479 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2480 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2481 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2482 | if (!msg) |
| 2483 | return -ENOMEM; |
| 2484 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2485 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2486 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2487 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2488 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2489 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2490 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2491 | return -EOPNOTSUPP; |
| 2492 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2493 | wdev = rdev_add_virtual_intf(rdev, |
| 2494 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2495 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2496 | if (IS_ERR(wdev)) { |
| 2497 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2498 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2499 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2500 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2501 | switch (type) { |
| 2502 | case NL80211_IFTYPE_MESH_POINT: |
| 2503 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2504 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2505 | wdev_lock(wdev); |
| 2506 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2507 | IEEE80211_MAX_MESH_ID_LEN); |
| 2508 | wdev->mesh_id_up_len = |
| 2509 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2510 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2511 | wdev->mesh_id_up_len); |
| 2512 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2513 | break; |
| 2514 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2515 | /* |
| 2516 | * P2P Device doesn't have a netdev, so doesn't go |
| 2517 | * through the netdev notifier and must be added here |
| 2518 | */ |
| 2519 | mutex_init(&wdev->mtx); |
| 2520 | INIT_LIST_HEAD(&wdev->event_list); |
| 2521 | spin_lock_init(&wdev->event_lock); |
| 2522 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2523 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2524 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2525 | wdev->identifier = ++rdev->wdev_id; |
| 2526 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2527 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2528 | break; |
| 2529 | default: |
| 2530 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2531 | } |
| 2532 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2533 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2534 | rdev, wdev) < 0) { |
| 2535 | nlmsg_free(msg); |
| 2536 | return -ENOBUFS; |
| 2537 | } |
| 2538 | |
| 2539 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2543 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2545 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2546 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2547 | if (!rdev->ops->del_virtual_intf) |
| 2548 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2549 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2550 | /* |
| 2551 | * If we remove a wireless device without a netdev then clear |
| 2552 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2553 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2554 | * since the wdev has been freed, unlike with a netdev where |
| 2555 | * we need the dev_put() for the netdev to really be freed. |
| 2556 | */ |
| 2557 | if (!wdev->netdev) |
| 2558 | info->user_ptr[1] = NULL; |
| 2559 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2560 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2561 | } |
| 2562 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2563 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2564 | { |
| 2565 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2566 | struct net_device *dev = info->user_ptr[1]; |
| 2567 | u16 noack_map; |
| 2568 | |
| 2569 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2570 | return -EINVAL; |
| 2571 | |
| 2572 | if (!rdev->ops->set_noack_map) |
| 2573 | return -EOPNOTSUPP; |
| 2574 | |
| 2575 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2576 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2577 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2578 | } |
| 2579 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2580 | struct get_key_cookie { |
| 2581 | struct sk_buff *msg; |
| 2582 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2583 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2584 | }; |
| 2585 | |
| 2586 | static void get_key_callback(void *c, struct key_params *params) |
| 2587 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2588 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2589 | struct get_key_cookie *cookie = c; |
| 2590 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2591 | if ((params->key && |
| 2592 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2593 | params->key_len, params->key)) || |
| 2594 | (params->seq && |
| 2595 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2596 | params->seq_len, params->seq)) || |
| 2597 | (params->cipher && |
| 2598 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2599 | params->cipher))) |
| 2600 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2601 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2602 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2603 | if (!key) |
| 2604 | goto nla_put_failure; |
| 2605 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2606 | if ((params->key && |
| 2607 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2608 | params->key_len, params->key)) || |
| 2609 | (params->seq && |
| 2610 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2611 | params->seq_len, params->seq)) || |
| 2612 | (params->cipher && |
| 2613 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2614 | params->cipher))) |
| 2615 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2616 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2617 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2618 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2619 | |
| 2620 | nla_nest_end(cookie->msg, key); |
| 2621 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2622 | return; |
| 2623 | nla_put_failure: |
| 2624 | cookie->error = 1; |
| 2625 | } |
| 2626 | |
| 2627 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2628 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2629 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2630 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2631 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2632 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2633 | const u8 *mac_addr = NULL; |
| 2634 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2635 | struct get_key_cookie cookie = { |
| 2636 | .error = 0, |
| 2637 | }; |
| 2638 | void *hdr; |
| 2639 | struct sk_buff *msg; |
| 2640 | |
| 2641 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2642 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2643 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2644 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2645 | return -EINVAL; |
| 2646 | |
| 2647 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2648 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2649 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2650 | pairwise = !!mac_addr; |
| 2651 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2652 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2653 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2654 | return -EINVAL; |
| 2655 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2656 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2657 | return -EINVAL; |
| 2658 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2659 | } |
| 2660 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2661 | if (!rdev->ops->get_key) |
| 2662 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2663 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2665 | if (!msg) |
| 2666 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2667 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2668 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2669 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2670 | if (!hdr) |
| 2671 | return -ENOBUFS; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2672 | |
| 2673 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2674 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2675 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2676 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2677 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2678 | goto nla_put_failure; |
| 2679 | if (mac_addr && |
| 2680 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2681 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2682 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2683 | if (pairwise && mac_addr && |
| 2684 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2685 | return -ENOENT; |
| 2686 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2687 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2688 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2689 | |
| 2690 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2691 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2692 | |
| 2693 | if (cookie.error) |
| 2694 | goto nla_put_failure; |
| 2695 | |
| 2696 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2697 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2698 | |
| 2699 | nla_put_failure: |
| 2700 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2701 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2702 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2703 | return err; |
| 2704 | } |
| 2705 | |
| 2706 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2707 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2709 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2710 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2711 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2712 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2713 | err = nl80211_parse_key(info, &key); |
| 2714 | if (err) |
| 2715 | return err; |
| 2716 | |
| 2717 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2718 | return -EINVAL; |
| 2719 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2720 | /* only support setting default key */ |
| 2721 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2722 | return -EINVAL; |
| 2723 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2724 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2725 | |
| 2726 | if (key.def) { |
| 2727 | if (!rdev->ops->set_default_key) { |
| 2728 | err = -EOPNOTSUPP; |
| 2729 | goto out; |
| 2730 | } |
| 2731 | |
| 2732 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2733 | if (err) |
| 2734 | goto out; |
| 2735 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2736 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2737 | key.def_uni, key.def_multi); |
| 2738 | |
| 2739 | if (err) |
| 2740 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2741 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2742 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2743 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2744 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2745 | } else { |
| 2746 | if (key.def_uni || !key.def_multi) { |
| 2747 | err = -EINVAL; |
| 2748 | goto out; |
| 2749 | } |
| 2750 | |
| 2751 | if (!rdev->ops->set_default_mgmt_key) { |
| 2752 | err = -EOPNOTSUPP; |
| 2753 | goto out; |
| 2754 | } |
| 2755 | |
| 2756 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2757 | if (err) |
| 2758 | goto out; |
| 2759 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2760 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2761 | if (err) |
| 2762 | goto out; |
| 2763 | |
| 2764 | #ifdef CONFIG_CFG80211_WEXT |
| 2765 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2766 | #endif |
| 2767 | } |
| 2768 | |
| 2769 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2770 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2771 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2772 | return err; |
| 2773 | } |
| 2774 | |
| 2775 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2776 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2778 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2779 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2780 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2781 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2782 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2783 | err = nl80211_parse_key(info, &key); |
| 2784 | if (err) |
| 2785 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2786 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2787 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2788 | return -EINVAL; |
| 2789 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2790 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2791 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2792 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2793 | if (key.type == -1) { |
| 2794 | if (mac_addr) |
| 2795 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2796 | else |
| 2797 | key.type = NL80211_KEYTYPE_GROUP; |
| 2798 | } |
| 2799 | |
| 2800 | /* for now */ |
| 2801 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2802 | key.type != NL80211_KEYTYPE_GROUP) |
| 2803 | return -EINVAL; |
| 2804 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2805 | if (!rdev->ops->add_key) |
| 2806 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2807 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2808 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2809 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2810 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2811 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2812 | |
| 2813 | wdev_lock(dev->ieee80211_ptr); |
| 2814 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2815 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2816 | err = rdev_add_key(rdev, dev, key.idx, |
| 2817 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2818 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2819 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2820 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2821 | return err; |
| 2822 | } |
| 2823 | |
| 2824 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2825 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2827 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2828 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2829 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2830 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2831 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2832 | err = nl80211_parse_key(info, &key); |
| 2833 | if (err) |
| 2834 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2835 | |
| 2836 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2837 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2838 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2839 | if (key.type == -1) { |
| 2840 | if (mac_addr) |
| 2841 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2842 | else |
| 2843 | key.type = NL80211_KEYTYPE_GROUP; |
| 2844 | } |
| 2845 | |
| 2846 | /* for now */ |
| 2847 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2848 | key.type != NL80211_KEYTYPE_GROUP) |
| 2849 | return -EINVAL; |
| 2850 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2851 | if (!rdev->ops->del_key) |
| 2852 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2853 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2854 | wdev_lock(dev->ieee80211_ptr); |
| 2855 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2856 | |
| 2857 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2858 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2859 | err = -ENOENT; |
| 2860 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2861 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2862 | err = rdev_del_key(rdev, dev, key.idx, |
| 2863 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2864 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2865 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2866 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2867 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2868 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2869 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2870 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2871 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2872 | } |
| 2873 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2874 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2875 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2876 | return err; |
| 2877 | } |
| 2878 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2879 | /* This function returns an error or the number of nested attributes */ |
| 2880 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2881 | { |
| 2882 | struct nlattr *attr; |
| 2883 | int n_entries = 0, tmp; |
| 2884 | |
| 2885 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2886 | if (nla_len(attr) != ETH_ALEN) |
| 2887 | return -EINVAL; |
| 2888 | |
| 2889 | n_entries++; |
| 2890 | } |
| 2891 | |
| 2892 | return n_entries; |
| 2893 | } |
| 2894 | |
| 2895 | /* |
| 2896 | * This function parses ACL information and allocates memory for ACL data. |
| 2897 | * On successful return, the calling function is responsible to free the |
| 2898 | * ACL buffer returned by this function. |
| 2899 | */ |
| 2900 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2901 | struct genl_info *info) |
| 2902 | { |
| 2903 | enum nl80211_acl_policy acl_policy; |
| 2904 | struct nlattr *attr; |
| 2905 | struct cfg80211_acl_data *acl; |
| 2906 | int i = 0, n_entries, tmp; |
| 2907 | |
| 2908 | if (!wiphy->max_acl_mac_addrs) |
| 2909 | return ERR_PTR(-EOPNOTSUPP); |
| 2910 | |
| 2911 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2912 | return ERR_PTR(-EINVAL); |
| 2913 | |
| 2914 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2915 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2916 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2917 | return ERR_PTR(-EINVAL); |
| 2918 | |
| 2919 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2920 | return ERR_PTR(-EINVAL); |
| 2921 | |
| 2922 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2923 | if (n_entries < 0) |
| 2924 | return ERR_PTR(n_entries); |
| 2925 | |
| 2926 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2927 | return ERR_PTR(-ENOTSUPP); |
| 2928 | |
| 2929 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2930 | GFP_KERNEL); |
| 2931 | if (!acl) |
| 2932 | return ERR_PTR(-ENOMEM); |
| 2933 | |
| 2934 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2935 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2936 | i++; |
| 2937 | } |
| 2938 | |
| 2939 | acl->n_acl_entries = n_entries; |
| 2940 | acl->acl_policy = acl_policy; |
| 2941 | |
| 2942 | return acl; |
| 2943 | } |
| 2944 | |
| 2945 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2946 | { |
| 2947 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2948 | struct net_device *dev = info->user_ptr[1]; |
| 2949 | struct cfg80211_acl_data *acl; |
| 2950 | int err; |
| 2951 | |
| 2952 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2953 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2954 | return -EOPNOTSUPP; |
| 2955 | |
| 2956 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2957 | return -EINVAL; |
| 2958 | |
| 2959 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2960 | if (IS_ERR(acl)) |
| 2961 | return PTR_ERR(acl); |
| 2962 | |
| 2963 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2964 | |
| 2965 | kfree(acl); |
| 2966 | |
| 2967 | return err; |
| 2968 | } |
| 2969 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2970 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2971 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2972 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2973 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2974 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2975 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2976 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2977 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2978 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2979 | return -EINVAL; |
| 2980 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2981 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2982 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2983 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2984 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2985 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2986 | if (!bcn->head_len) |
| 2987 | return -EINVAL; |
| 2988 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2989 | } |
| 2990 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2991 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2992 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2993 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2994 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2995 | } |
| 2996 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2997 | if (!haveinfo) |
| 2998 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2999 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3000 | if (attrs[NL80211_ATTR_IE]) { |
| 3001 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3002 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3003 | } |
| 3004 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3005 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3006 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3007 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3008 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3009 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3010 | } |
| 3011 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3012 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3013 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3014 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3015 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3016 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3017 | } |
| 3018 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3019 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3020 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3021 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3022 | } |
| 3023 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3024 | return 0; |
| 3025 | } |
| 3026 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3027 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3028 | struct cfg80211_ap_settings *params) |
| 3029 | { |
| 3030 | struct wireless_dev *wdev; |
| 3031 | bool ret = false; |
| 3032 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3033 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3034 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3035 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3036 | continue; |
| 3037 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3038 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3039 | continue; |
| 3040 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3041 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3042 | ret = true; |
| 3043 | break; |
| 3044 | } |
| 3045 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3046 | return ret; |
| 3047 | } |
| 3048 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3049 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3050 | enum nl80211_auth_type auth_type, |
| 3051 | enum nl80211_commands cmd) |
| 3052 | { |
| 3053 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3054 | return false; |
| 3055 | |
| 3056 | switch (cmd) { |
| 3057 | case NL80211_CMD_AUTHENTICATE: |
| 3058 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3059 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3060 | return false; |
| 3061 | return true; |
| 3062 | case NL80211_CMD_CONNECT: |
| 3063 | case NL80211_CMD_START_AP: |
| 3064 | /* SAE not supported yet */ |
| 3065 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3066 | return false; |
| 3067 | return true; |
| 3068 | default: |
| 3069 | return false; |
| 3070 | } |
| 3071 | } |
| 3072 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3073 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3074 | { |
| 3075 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3076 | struct net_device *dev = info->user_ptr[1]; |
| 3077 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3078 | struct cfg80211_ap_settings params; |
| 3079 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3080 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3081 | |
| 3082 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3083 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3084 | return -EOPNOTSUPP; |
| 3085 | |
| 3086 | if (!rdev->ops->start_ap) |
| 3087 | return -EOPNOTSUPP; |
| 3088 | |
| 3089 | if (wdev->beacon_interval) |
| 3090 | return -EALREADY; |
| 3091 | |
| 3092 | memset(¶ms, 0, sizeof(params)); |
| 3093 | |
| 3094 | /* these are required for START_AP */ |
| 3095 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3096 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3097 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3098 | return -EINVAL; |
| 3099 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3100 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3101 | if (err) |
| 3102 | return err; |
| 3103 | |
| 3104 | params.beacon_interval = |
| 3105 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3106 | params.dtim_period = |
| 3107 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3108 | |
| 3109 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3110 | if (err) |
| 3111 | return err; |
| 3112 | |
| 3113 | /* |
| 3114 | * In theory, some of these attributes should be required here |
| 3115 | * but since they were not used when the command was originally |
| 3116 | * added, keep them optional for old user space programs to let |
| 3117 | * them continue to work with drivers that do not need the |
| 3118 | * additional information -- drivers must check! |
| 3119 | */ |
| 3120 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3121 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3122 | params.ssid_len = |
| 3123 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3124 | if (params.ssid_len == 0 || |
| 3125 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3126 | return -EINVAL; |
| 3127 | } |
| 3128 | |
| 3129 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3130 | params.hidden_ssid = nla_get_u32( |
| 3131 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3132 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3133 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3134 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3135 | return -EINVAL; |
| 3136 | } |
| 3137 | |
| 3138 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3139 | |
| 3140 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3141 | params.auth_type = nla_get_u32( |
| 3142 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3143 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3144 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3145 | return -EINVAL; |
| 3146 | } else |
| 3147 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3148 | |
| 3149 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3150 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3151 | if (err) |
| 3152 | return err; |
| 3153 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3154 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3155 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3156 | return -EOPNOTSUPP; |
| 3157 | params.inactivity_timeout = nla_get_u16( |
| 3158 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3159 | } |
| 3160 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3161 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3162 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3163 | return -EINVAL; |
| 3164 | params.p2p_ctwindow = |
| 3165 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3166 | if (params.p2p_ctwindow > 127) |
| 3167 | return -EINVAL; |
| 3168 | if (params.p2p_ctwindow != 0 && |
| 3169 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3170 | return -EINVAL; |
| 3171 | } |
| 3172 | |
| 3173 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3174 | u8 tmp; |
| 3175 | |
| 3176 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3177 | return -EINVAL; |
| 3178 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3179 | if (tmp > 1) |
| 3180 | return -EINVAL; |
| 3181 | params.p2p_opp_ps = tmp; |
| 3182 | if (params.p2p_opp_ps != 0 && |
| 3183 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3184 | return -EINVAL; |
| 3185 | } |
| 3186 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3187 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3188 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3189 | if (err) |
| 3190 | return err; |
| 3191 | } else if (wdev->preset_chandef.chan) { |
| 3192 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3193 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3194 | return -EINVAL; |
| 3195 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3196 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3197 | return -EINVAL; |
| 3198 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3199 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3200 | if (err < 0) |
| 3201 | return err; |
| 3202 | if (err) { |
| 3203 | radar_detect_width = BIT(params.chandef.width); |
| 3204 | params.radar_required = true; |
| 3205 | } |
| 3206 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3207 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3208 | params.chandef.chan, |
| 3209 | CHAN_MODE_SHARED, |
| 3210 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3211 | if (err) |
| 3212 | return err; |
| 3213 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3214 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3215 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3216 | if (IS_ERR(params.acl)) |
| 3217 | return PTR_ERR(params.acl); |
| 3218 | } |
| 3219 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3220 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3221 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3222 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3223 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3224 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3225 | wdev->ssid_len = params.ssid_len; |
| 3226 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3227 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3228 | |
| 3229 | kfree(params.acl); |
| 3230 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3231 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3232 | } |
| 3233 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3234 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3235 | { |
| 3236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3237 | struct net_device *dev = info->user_ptr[1]; |
| 3238 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3239 | struct cfg80211_beacon_data params; |
| 3240 | int err; |
| 3241 | |
| 3242 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3243 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3244 | return -EOPNOTSUPP; |
| 3245 | |
| 3246 | if (!rdev->ops->change_beacon) |
| 3247 | return -EOPNOTSUPP; |
| 3248 | |
| 3249 | if (!wdev->beacon_interval) |
| 3250 | return -EINVAL; |
| 3251 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3252 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3253 | if (err) |
| 3254 | return err; |
| 3255 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3256 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | 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] | 3260 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3262 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3263 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3264 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3265 | } |
| 3266 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3267 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3268 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3269 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3270 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3271 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3272 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3273 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3274 | }; |
| 3275 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3276 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3277 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3278 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3279 | { |
| 3280 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3281 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3282 | int flag; |
| 3283 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3284 | /* |
| 3285 | * Try parsing the new attribute first so userspace |
| 3286 | * can specify both for older kernels. |
| 3287 | */ |
| 3288 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3289 | if (nla) { |
| 3290 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3291 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3292 | sta_flags = nla_data(nla); |
| 3293 | params->sta_flags_mask = sta_flags->mask; |
| 3294 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3295 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3296 | if ((params->sta_flags_mask | |
| 3297 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3298 | return -EINVAL; |
| 3299 | return 0; |
| 3300 | } |
| 3301 | |
| 3302 | /* if present, parse the old attribute */ |
| 3303 | |
| 3304 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3305 | if (!nla) |
| 3306 | return 0; |
| 3307 | |
| 3308 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3309 | nla, sta_flags_policy)) |
| 3310 | return -EINVAL; |
| 3311 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3312 | /* |
| 3313 | * Only allow certain flags for interface types so that |
| 3314 | * other attributes are silently ignored. Remember that |
| 3315 | * this is backward compatibility code with old userspace |
| 3316 | * and shouldn't be hit in other cases anyway. |
| 3317 | */ |
| 3318 | switch (iftype) { |
| 3319 | case NL80211_IFTYPE_AP: |
| 3320 | case NL80211_IFTYPE_AP_VLAN: |
| 3321 | case NL80211_IFTYPE_P2P_GO: |
| 3322 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3323 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3324 | BIT(NL80211_STA_FLAG_WME) | |
| 3325 | BIT(NL80211_STA_FLAG_MFP); |
| 3326 | break; |
| 3327 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3328 | case NL80211_IFTYPE_STATION: |
| 3329 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3330 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3331 | break; |
| 3332 | case NL80211_IFTYPE_MESH_POINT: |
| 3333 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3334 | BIT(NL80211_STA_FLAG_MFP) | |
| 3335 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3336 | default: |
| 3337 | return -EINVAL; |
| 3338 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3339 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3340 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3341 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3342 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3343 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3344 | /* no longer support new API additions in old API */ |
| 3345 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3346 | return -EINVAL; |
| 3347 | } |
| 3348 | } |
| 3349 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3350 | return 0; |
| 3351 | } |
| 3352 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3353 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3354 | int attr) |
| 3355 | { |
| 3356 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3357 | u32 bitrate; |
| 3358 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3359 | |
| 3360 | rate = nla_nest_start(msg, attr); |
| 3361 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3362 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3363 | |
| 3364 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3365 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3366 | /* report 16-bit bitrate only if we can */ |
| 3367 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3368 | if (bitrate > 0 && |
| 3369 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3370 | return false; |
| 3371 | if (bitrate_compat > 0 && |
| 3372 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3373 | return false; |
| 3374 | |
| 3375 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3376 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3377 | return false; |
| 3378 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3379 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3380 | return false; |
| 3381 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3382 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3383 | return false; |
| 3384 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3385 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3386 | return false; |
| 3387 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3388 | return false; |
| 3389 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3390 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3391 | return false; |
| 3392 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3393 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3394 | return false; |
| 3395 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3396 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3397 | return false; |
| 3398 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3399 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3400 | return false; |
| 3401 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3402 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3403 | return false; |
| 3404 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3405 | |
| 3406 | nla_nest_end(msg, rate); |
| 3407 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3408 | } |
| 3409 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3410 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3411 | int id) |
| 3412 | { |
| 3413 | void *attr; |
| 3414 | int i = 0; |
| 3415 | |
| 3416 | if (!mask) |
| 3417 | return true; |
| 3418 | |
| 3419 | attr = nla_nest_start(msg, id); |
| 3420 | if (!attr) |
| 3421 | return false; |
| 3422 | |
| 3423 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3424 | if (!(mask & BIT(i))) |
| 3425 | continue; |
| 3426 | |
| 3427 | if (nla_put_u8(msg, i, signal[i])) |
| 3428 | return false; |
| 3429 | } |
| 3430 | |
| 3431 | nla_nest_end(msg, attr); |
| 3432 | |
| 3433 | return true; |
| 3434 | } |
| 3435 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3436 | 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] | 3437 | int flags, |
| 3438 | struct cfg80211_registered_device *rdev, |
| 3439 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3440 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3441 | { |
| 3442 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3443 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3444 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3445 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3446 | if (!hdr) |
| 3447 | return -1; |
| 3448 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3449 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3450 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3451 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3452 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3453 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3454 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3455 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3456 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3457 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3458 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3459 | sinfo->connected_time)) |
| 3460 | goto nla_put_failure; |
| 3461 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3462 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3463 | sinfo->inactive_time)) |
| 3464 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3465 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3466 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3467 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3468 | (u32)sinfo->rx_bytes)) |
| 3469 | goto nla_put_failure; |
| 3470 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3471 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3472 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3473 | (u32)sinfo->tx_bytes)) |
| 3474 | goto nla_put_failure; |
| 3475 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3476 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3477 | sinfo->rx_bytes)) |
| 3478 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3479 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3480 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3481 | sinfo->tx_bytes)) |
| 3482 | goto nla_put_failure; |
| 3483 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3484 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3485 | goto nla_put_failure; |
| 3486 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3487 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3488 | goto nla_put_failure; |
| 3489 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3490 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3491 | sinfo->plink_state)) |
| 3492 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3493 | switch (rdev->wiphy.signal_type) { |
| 3494 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3495 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3496 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3497 | sinfo->signal)) |
| 3498 | goto nla_put_failure; |
| 3499 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3500 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3501 | sinfo->signal_avg)) |
| 3502 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3503 | break; |
| 3504 | default: |
| 3505 | break; |
| 3506 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3507 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3508 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3509 | sinfo->chain_signal, |
| 3510 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3511 | goto nla_put_failure; |
| 3512 | } |
| 3513 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3514 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3515 | sinfo->chain_signal_avg, |
| 3516 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3517 | goto nla_put_failure; |
| 3518 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3519 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3520 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3521 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3522 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3523 | } |
| 3524 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3525 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3526 | NL80211_STA_INFO_RX_BITRATE)) |
| 3527 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3528 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3529 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3530 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3531 | sinfo->rx_packets)) |
| 3532 | goto nla_put_failure; |
| 3533 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3534 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3535 | sinfo->tx_packets)) |
| 3536 | goto nla_put_failure; |
| 3537 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3538 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3539 | sinfo->tx_retries)) |
| 3540 | goto nla_put_failure; |
| 3541 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3542 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3543 | sinfo->tx_failed)) |
| 3544 | goto nla_put_failure; |
| 3545 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3546 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3547 | sinfo->beacon_loss_count)) |
| 3548 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3549 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3550 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3551 | sinfo->local_pm)) |
| 3552 | goto nla_put_failure; |
| 3553 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3554 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3555 | sinfo->peer_pm)) |
| 3556 | goto nla_put_failure; |
| 3557 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3558 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3559 | sinfo->nonpeer_pm)) |
| 3560 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3561 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3562 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3563 | if (!bss_param) |
| 3564 | goto nla_put_failure; |
| 3565 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3566 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3567 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3568 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3569 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3570 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3571 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3572 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3573 | sinfo->bss_param.dtim_period) || |
| 3574 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3575 | sinfo->bss_param.beacon_interval)) |
| 3576 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3577 | |
| 3578 | nla_nest_end(msg, bss_param); |
| 3579 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3580 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3581 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3582 | sizeof(struct nl80211_sta_flag_update), |
| 3583 | &sinfo->sta_flags)) |
| 3584 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3585 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3586 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3587 | sinfo->t_offset)) |
| 3588 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3589 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3590 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3591 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3592 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3593 | sinfo->assoc_req_ies)) |
| 3594 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3595 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3596 | return genlmsg_end(msg, hdr); |
| 3597 | |
| 3598 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3599 | genlmsg_cancel(msg, hdr); |
| 3600 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3601 | } |
| 3602 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3603 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3604 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3605 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3606 | struct station_info sinfo; |
| 3607 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3608 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3609 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3610 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3611 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3612 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3613 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3614 | if (err) |
| 3615 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3616 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3617 | if (!wdev->netdev) { |
| 3618 | err = -EINVAL; |
| 3619 | goto out_err; |
| 3620 | } |
| 3621 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3622 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3623 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3624 | goto out_err; |
| 3625 | } |
| 3626 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3627 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3628 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3629 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3630 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3631 | if (err == -ENOENT) |
| 3632 | break; |
| 3633 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3634 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3635 | |
| 3636 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3637 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3638 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3639 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3640 | &sinfo) < 0) |
| 3641 | goto out; |
| 3642 | |
| 3643 | sta_idx++; |
| 3644 | } |
| 3645 | |
| 3646 | |
| 3647 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3648 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3649 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3650 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3651 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3652 | |
| 3653 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3654 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3655 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3656 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3657 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3659 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3660 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3661 | struct sk_buff *msg; |
| 3662 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3663 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3664 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3665 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3666 | |
| 3667 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3668 | return -EINVAL; |
| 3669 | |
| 3670 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3671 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3672 | if (!rdev->ops->get_station) |
| 3673 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3674 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3675 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3676 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3677 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3678 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3680 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3681 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3682 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3683 | 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] | 3684 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3685 | nlmsg_free(msg); |
| 3686 | return -ENOBUFS; |
| 3687 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3688 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3689 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3690 | } |
| 3691 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3692 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3693 | struct station_parameters *params, |
| 3694 | enum cfg80211_station_type statype) |
| 3695 | { |
| 3696 | if (params->listen_interval != -1) |
| 3697 | return -EINVAL; |
| 3698 | if (params->aid) |
| 3699 | return -EINVAL; |
| 3700 | |
| 3701 | /* When you run into this, adjust the code below for the new flag */ |
| 3702 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3703 | |
| 3704 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3705 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3706 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3707 | /* |
| 3708 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3709 | * code doesn't have the bug of including TDLS in the |
| 3710 | * mask everywhere. |
| 3711 | */ |
| 3712 | if (params->sta_flags_mask & |
| 3713 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3714 | BIT(NL80211_STA_FLAG_MFP) | |
| 3715 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3716 | return -EINVAL; |
| 3717 | break; |
| 3718 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3719 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3720 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3721 | return -EINVAL; |
| 3722 | /* ignore since it can't change */ |
| 3723 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3724 | break; |
| 3725 | default: |
| 3726 | /* disallow mesh-specific things */ |
| 3727 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3728 | return -EINVAL; |
| 3729 | if (params->local_pm) |
| 3730 | return -EINVAL; |
| 3731 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3732 | return -EINVAL; |
| 3733 | } |
| 3734 | |
| 3735 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3736 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3737 | /* TDLS can't be set, ... */ |
| 3738 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3739 | return -EINVAL; |
| 3740 | /* |
| 3741 | * ... but don't bother the driver with it. This works around |
| 3742 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3743 | * TLDS_PEER flag in the mask even for AP mode. |
| 3744 | */ |
| 3745 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3746 | } |
| 3747 | |
| 3748 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3749 | /* reject other things that can't change */ |
| 3750 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3751 | return -EINVAL; |
| 3752 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3753 | return -EINVAL; |
| 3754 | if (params->supported_rates) |
| 3755 | return -EINVAL; |
| 3756 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3757 | return -EINVAL; |
| 3758 | } |
| 3759 | |
| 3760 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3761 | if (params->vlan) |
| 3762 | return -EINVAL; |
| 3763 | } |
| 3764 | |
| 3765 | switch (statype) { |
| 3766 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3767 | /* Use this only for authorizing/unauthorizing a station */ |
| 3768 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3769 | return -EOPNOTSUPP; |
| 3770 | break; |
| 3771 | case CFG80211_STA_AP_CLIENT: |
| 3772 | /* accept only the listed bits */ |
| 3773 | if (params->sta_flags_mask & |
| 3774 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3775 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3776 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3777 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3778 | BIT(NL80211_STA_FLAG_WME) | |
| 3779 | BIT(NL80211_STA_FLAG_MFP))) |
| 3780 | return -EINVAL; |
| 3781 | |
| 3782 | /* but authenticated/associated only if driver handles it */ |
| 3783 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3784 | params->sta_flags_mask & |
| 3785 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3786 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3787 | return -EINVAL; |
| 3788 | break; |
| 3789 | case CFG80211_STA_IBSS: |
| 3790 | case CFG80211_STA_AP_STA: |
| 3791 | /* reject any changes other than AUTHORIZED */ |
| 3792 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3793 | return -EINVAL; |
| 3794 | break; |
| 3795 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3796 | /* reject any changes other than AUTHORIZED or WME */ |
| 3797 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3798 | BIT(NL80211_STA_FLAG_WME))) |
| 3799 | return -EINVAL; |
| 3800 | /* force (at least) rates when authorizing */ |
| 3801 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3802 | !params->supported_rates) |
| 3803 | return -EINVAL; |
| 3804 | break; |
| 3805 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3806 | /* reject any changes */ |
| 3807 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3808 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3809 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3810 | return -EINVAL; |
| 3811 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3812 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3813 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3814 | return -EINVAL; |
| 3815 | break; |
| 3816 | } |
| 3817 | |
| 3818 | return 0; |
| 3819 | } |
| 3820 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3821 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3822 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3823 | * 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] | 3824 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3825 | static struct net_device *get_vlan(struct genl_info *info, |
| 3826 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3827 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3828 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3829 | struct net_device *v; |
| 3830 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3831 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3832 | if (!vlanattr) |
| 3833 | return NULL; |
| 3834 | |
| 3835 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3836 | if (!v) |
| 3837 | return ERR_PTR(-ENODEV); |
| 3838 | |
| 3839 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3840 | ret = -EINVAL; |
| 3841 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3842 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3843 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3844 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3845 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3846 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3847 | ret = -EINVAL; |
| 3848 | goto error; |
| 3849 | } |
| 3850 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3851 | if (!netif_running(v)) { |
| 3852 | ret = -ENETDOWN; |
| 3853 | goto error; |
| 3854 | } |
| 3855 | |
| 3856 | return v; |
| 3857 | error: |
| 3858 | dev_put(v); |
| 3859 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3860 | } |
| 3861 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3862 | static struct nla_policy |
| 3863 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3864 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3865 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3866 | }; |
| 3867 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3868 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3869 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3870 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3871 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3872 | struct nlattr *nla; |
| 3873 | int err; |
| 3874 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3875 | /* parse WME attributes if present */ |
| 3876 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3877 | return 0; |
| 3878 | |
| 3879 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3880 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3881 | nl80211_sta_wme_policy); |
| 3882 | if (err) |
| 3883 | return err; |
| 3884 | |
| 3885 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3886 | params->uapsd_queues = nla_get_u8( |
| 3887 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3888 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3889 | return -EINVAL; |
| 3890 | |
| 3891 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3892 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3893 | |
| 3894 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3895 | return -EINVAL; |
| 3896 | |
| 3897 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3898 | |
| 3899 | return 0; |
| 3900 | } |
| 3901 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3902 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 3903 | struct station_parameters *params) |
| 3904 | { |
| 3905 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 3906 | params->supported_channels = |
| 3907 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3908 | params->supported_channels_len = |
| 3909 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 3910 | /* |
| 3911 | * Need to include at least one (first channel, number of |
| 3912 | * channels) tuple for each subband, and must have proper |
| 3913 | * tuples for the rest of the data as well. |
| 3914 | */ |
| 3915 | if (params->supported_channels_len < 2) |
| 3916 | return -EINVAL; |
| 3917 | if (params->supported_channels_len % 2) |
| 3918 | return -EINVAL; |
| 3919 | } |
| 3920 | |
| 3921 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 3922 | params->supported_oper_classes = |
| 3923 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3924 | params->supported_oper_classes_len = |
| 3925 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 3926 | /* |
| 3927 | * The value of the Length field of the Supported Operating |
| 3928 | * Classes element is between 2 and 253. |
| 3929 | */ |
| 3930 | if (params->supported_oper_classes_len < 2 || |
| 3931 | params->supported_oper_classes_len > 253) |
| 3932 | return -EINVAL; |
| 3933 | } |
| 3934 | return 0; |
| 3935 | } |
| 3936 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3937 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3938 | struct station_parameters *params) |
| 3939 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3940 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3941 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3942 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3943 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3944 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3945 | params->ht_capa = |
| 3946 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3947 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3948 | params->vht_capa = |
| 3949 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3950 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 3951 | err = nl80211_parse_sta_channel_info(info, params); |
| 3952 | if (err) |
| 3953 | return err; |
| 3954 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3955 | return nl80211_parse_sta_wme(info, params); |
| 3956 | } |
| 3957 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3958 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3959 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3960 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3961 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3962 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3963 | u8 *mac_addr; |
| 3964 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3965 | |
| 3966 | memset(¶ms, 0, sizeof(params)); |
| 3967 | |
| 3968 | params.listen_interval = -1; |
| 3969 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3970 | if (!rdev->ops->change_station) |
| 3971 | return -EOPNOTSUPP; |
| 3972 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3973 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3974 | return -EINVAL; |
| 3975 | |
| 3976 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3977 | return -EINVAL; |
| 3978 | |
| 3979 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3980 | |
| 3981 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3982 | params.supported_rates = |
| 3983 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3984 | params.supported_rates_len = |
| 3985 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3986 | } |
| 3987 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3988 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3989 | params.capability = |
| 3990 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3991 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3992 | } |
| 3993 | |
| 3994 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3995 | params.ext_capab = |
| 3996 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3997 | params.ext_capab_len = |
| 3998 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3999 | } |
| 4000 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4001 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4002 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4003 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4004 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4005 | return -EINVAL; |
| 4006 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4007 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4008 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4009 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4010 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4011 | return -EINVAL; |
| 4012 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4013 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4014 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4015 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4016 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4017 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4018 | return -EINVAL; |
| 4019 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4020 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4021 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4022 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4023 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4024 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4025 | |
| 4026 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4027 | pm > NL80211_MESH_POWER_MAX) |
| 4028 | return -EINVAL; |
| 4029 | |
| 4030 | params.local_pm = pm; |
| 4031 | } |
| 4032 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4033 | /* Include parameters for TDLS peer (will check later) */ |
| 4034 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4035 | if (err) |
| 4036 | return err; |
| 4037 | |
| 4038 | params.vlan = get_vlan(info, rdev); |
| 4039 | if (IS_ERR(params.vlan)) |
| 4040 | return PTR_ERR(params.vlan); |
| 4041 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4042 | switch (dev->ieee80211_ptr->iftype) { |
| 4043 | case NL80211_IFTYPE_AP: |
| 4044 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4045 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4046 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4047 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4048 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4049 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4050 | break; |
| 4051 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4052 | err = -EOPNOTSUPP; |
| 4053 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4054 | } |
| 4055 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4056 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4057 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4058 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4059 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4060 | if (params.vlan) |
| 4061 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4062 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4063 | return err; |
| 4064 | } |
| 4065 | |
| 4066 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4067 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4068 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4069 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4070 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4071 | struct station_parameters params; |
| 4072 | u8 *mac_addr = NULL; |
| 4073 | |
| 4074 | memset(¶ms, 0, sizeof(params)); |
| 4075 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4076 | if (!rdev->ops->add_station) |
| 4077 | return -EOPNOTSUPP; |
| 4078 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4079 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4080 | return -EINVAL; |
| 4081 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4082 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4083 | return -EINVAL; |
| 4084 | |
| 4085 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4086 | return -EINVAL; |
| 4087 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4088 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4089 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4090 | return -EINVAL; |
| 4091 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4092 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4093 | params.supported_rates = |
| 4094 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4095 | params.supported_rates_len = |
| 4096 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4097 | params.listen_interval = |
| 4098 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4099 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4100 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4101 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4102 | else |
| 4103 | 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] | 4104 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4105 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4106 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4107 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4108 | params.capability = |
| 4109 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4110 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4111 | } |
| 4112 | |
| 4113 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4114 | params.ext_capab = |
| 4115 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4116 | params.ext_capab_len = |
| 4117 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4118 | } |
| 4119 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4120 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4121 | params.ht_capa = |
| 4122 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4123 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4124 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4125 | params.vht_capa = |
| 4126 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4127 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4128 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4129 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4130 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4131 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4132 | return -EINVAL; |
| 4133 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4134 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4135 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4136 | if (err) |
| 4137 | return err; |
| 4138 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4139 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4140 | if (err) |
| 4141 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4142 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4143 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4144 | return -EINVAL; |
| 4145 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4146 | /* When you run into this, adjust the code below for the new flag */ |
| 4147 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4148 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4149 | switch (dev->ieee80211_ptr->iftype) { |
| 4150 | case NL80211_IFTYPE_AP: |
| 4151 | case NL80211_IFTYPE_AP_VLAN: |
| 4152 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4153 | /* ignore WME attributes if iface/sta is not capable */ |
| 4154 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4155 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4156 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4157 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4158 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4159 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4160 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4161 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4162 | /* but don't bother the driver with it */ |
| 4163 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4164 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4165 | /* allow authenticated/associated only if driver handles it */ |
| 4166 | if (!(rdev->wiphy.features & |
| 4167 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4168 | params.sta_flags_mask & |
| 4169 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4170 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4171 | return -EINVAL; |
| 4172 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4173 | /* must be last in here for error handling */ |
| 4174 | params.vlan = get_vlan(info, rdev); |
| 4175 | if (IS_ERR(params.vlan)) |
| 4176 | return PTR_ERR(params.vlan); |
| 4177 | break; |
| 4178 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4179 | /* ignore uAPSD data */ |
| 4180 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4181 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4182 | /* associated is disallowed */ |
| 4183 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4184 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4185 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4186 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4187 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4188 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4189 | break; |
| 4190 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4191 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4192 | /* ignore uAPSD data */ |
| 4193 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4194 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4195 | /* these are disallowed */ |
| 4196 | if (params.sta_flags_mask & |
| 4197 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4198 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4199 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4200 | /* Only TDLS peers can be added */ |
| 4201 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4202 | return -EINVAL; |
| 4203 | /* Can only add if TDLS ... */ |
| 4204 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4205 | return -EOPNOTSUPP; |
| 4206 | /* ... with external setup is supported */ |
| 4207 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4208 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4209 | /* |
| 4210 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4211 | * as authorized, but it shouldn't yet be. |
| 4212 | */ |
| 4213 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4214 | break; |
| 4215 | default: |
| 4216 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4217 | } |
| 4218 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4219 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4220 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4221 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4222 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4223 | if (params.vlan) |
| 4224 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4225 | return err; |
| 4226 | } |
| 4227 | |
| 4228 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4231 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4232 | u8 *mac_addr = NULL; |
| 4233 | |
| 4234 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4235 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4236 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4237 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4238 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4239 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4240 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4241 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4242 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4243 | if (!rdev->ops->del_station) |
| 4244 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4245 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4246 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4247 | } |
| 4248 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4249 | 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] | 4250 | int flags, struct net_device *dev, |
| 4251 | u8 *dst, u8 *next_hop, |
| 4252 | struct mpath_info *pinfo) |
| 4253 | { |
| 4254 | void *hdr; |
| 4255 | struct nlattr *pinfoattr; |
| 4256 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4257 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4258 | if (!hdr) |
| 4259 | return -1; |
| 4260 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4261 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4262 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4263 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4264 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4265 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4266 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4267 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4268 | if (!pinfoattr) |
| 4269 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4270 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4271 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4272 | pinfo->frame_qlen)) |
| 4273 | goto nla_put_failure; |
| 4274 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4275 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4276 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4277 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4278 | pinfo->metric)) || |
| 4279 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4280 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4281 | pinfo->exptime)) || |
| 4282 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4283 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4284 | pinfo->flags)) || |
| 4285 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4286 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4287 | pinfo->discovery_timeout)) || |
| 4288 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4289 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4290 | pinfo->discovery_retries))) |
| 4291 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4292 | |
| 4293 | nla_nest_end(msg, pinfoattr); |
| 4294 | |
| 4295 | return genlmsg_end(msg, hdr); |
| 4296 | |
| 4297 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4298 | genlmsg_cancel(msg, hdr); |
| 4299 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4303 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4304 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4305 | struct mpath_info pinfo; |
| 4306 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4307 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4308 | u8 dst[ETH_ALEN]; |
| 4309 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4310 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4311 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4312 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4313 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4314 | if (err) |
| 4315 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4316 | |
| 4317 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4318 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4319 | goto out_err; |
| 4320 | } |
| 4321 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4322 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4323 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4324 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4325 | } |
| 4326 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4327 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4328 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4329 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4330 | if (err == -ENOENT) |
| 4331 | break; |
| 4332 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4333 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4334 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4335 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4336 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4337 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4338 | &pinfo) < 0) |
| 4339 | goto out; |
| 4340 | |
| 4341 | path_idx++; |
| 4342 | } |
| 4343 | |
| 4344 | |
| 4345 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4346 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4347 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4348 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4349 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4350 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4351 | } |
| 4352 | |
| 4353 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4354 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4356 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4357 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4358 | struct mpath_info pinfo; |
| 4359 | struct sk_buff *msg; |
| 4360 | u8 *dst = NULL; |
| 4361 | u8 next_hop[ETH_ALEN]; |
| 4362 | |
| 4363 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4364 | |
| 4365 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4366 | return -EINVAL; |
| 4367 | |
| 4368 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4369 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4370 | if (!rdev->ops->get_mpath) |
| 4371 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4372 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4373 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4374 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4375 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4376 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4377 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4378 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4379 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4380 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4381 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4382 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4383 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4384 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4385 | dev, dst, next_hop, &pinfo) < 0) { |
| 4386 | nlmsg_free(msg); |
| 4387 | return -ENOBUFS; |
| 4388 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4390 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4391 | } |
| 4392 | |
| 4393 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4394 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4396 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4397 | u8 *dst = NULL; |
| 4398 | u8 *next_hop = NULL; |
| 4399 | |
| 4400 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4401 | return -EINVAL; |
| 4402 | |
| 4403 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4404 | return -EINVAL; |
| 4405 | |
| 4406 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4407 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4408 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4409 | if (!rdev->ops->change_mpath) |
| 4410 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4411 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4412 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4413 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4414 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4415 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4416 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4417 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4418 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4419 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4420 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4421 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4422 | u8 *dst = NULL; |
| 4423 | u8 *next_hop = NULL; |
| 4424 | |
| 4425 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4426 | return -EINVAL; |
| 4427 | |
| 4428 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4429 | return -EINVAL; |
| 4430 | |
| 4431 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4432 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4433 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4434 | if (!rdev->ops->add_mpath) |
| 4435 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4436 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4437 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4438 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4439 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4440 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4441 | } |
| 4442 | |
| 4443 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4446 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4447 | u8 *dst = NULL; |
| 4448 | |
| 4449 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4450 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4451 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4452 | if (!rdev->ops->del_mpath) |
| 4453 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4454 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4455 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4456 | } |
| 4457 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4458 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4459 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4461 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4462 | struct bss_parameters params; |
| 4463 | |
| 4464 | memset(¶ms, 0, sizeof(params)); |
| 4465 | /* default to not changing parameters */ |
| 4466 | params.use_cts_prot = -1; |
| 4467 | params.use_short_preamble = -1; |
| 4468 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4469 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4470 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4471 | params.p2p_ctwindow = -1; |
| 4472 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4473 | |
| 4474 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4475 | params.use_cts_prot = |
| 4476 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4477 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4478 | params.use_short_preamble = |
| 4479 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4480 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4481 | params.use_short_slot_time = |
| 4482 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4483 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4484 | params.basic_rates = |
| 4485 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4486 | params.basic_rates_len = |
| 4487 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4488 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4489 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4490 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4491 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4492 | params.ht_opmode = |
| 4493 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4494 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4495 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4496 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4497 | return -EINVAL; |
| 4498 | params.p2p_ctwindow = |
| 4499 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4500 | if (params.p2p_ctwindow < 0) |
| 4501 | return -EINVAL; |
| 4502 | if (params.p2p_ctwindow != 0 && |
| 4503 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4504 | return -EINVAL; |
| 4505 | } |
| 4506 | |
| 4507 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4508 | u8 tmp; |
| 4509 | |
| 4510 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4511 | return -EINVAL; |
| 4512 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4513 | if (tmp > 1) |
| 4514 | return -EINVAL; |
| 4515 | params.p2p_opp_ps = tmp; |
| 4516 | if (params.p2p_opp_ps && |
| 4517 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4518 | return -EINVAL; |
| 4519 | } |
| 4520 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4521 | if (!rdev->ops->change_bss) |
| 4522 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4523 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4524 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4525 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4526 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4527 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4528 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4529 | } |
| 4530 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4531 | 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] | 4532 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4533 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4534 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4535 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4536 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4537 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4538 | }; |
| 4539 | |
| 4540 | static int parse_reg_rule(struct nlattr *tb[], |
| 4541 | struct ieee80211_reg_rule *reg_rule) |
| 4542 | { |
| 4543 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4544 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4545 | |
| 4546 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4547 | return -EINVAL; |
| 4548 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4549 | return -EINVAL; |
| 4550 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4551 | return -EINVAL; |
| 4552 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4553 | return -EINVAL; |
| 4554 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4555 | return -EINVAL; |
| 4556 | |
| 4557 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4558 | |
| 4559 | freq_range->start_freq_khz = |
| 4560 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4561 | freq_range->end_freq_khz = |
| 4562 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4563 | freq_range->max_bandwidth_khz = |
| 4564 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4565 | |
| 4566 | power_rule->max_eirp = |
| 4567 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4568 | |
| 4569 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4570 | power_rule->max_antenna_gain = |
| 4571 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4572 | |
| 4573 | return 0; |
| 4574 | } |
| 4575 | |
| 4576 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4577 | { |
| 4578 | int r; |
| 4579 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4580 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4581 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4582 | /* |
| 4583 | * You should only get this when cfg80211 hasn't yet initialized |
| 4584 | * completely when built-in to the kernel right between the time |
| 4585 | * window between nl80211_init() and regulatory_init(), if that is |
| 4586 | * even possible. |
| 4587 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4588 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4589 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4590 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4591 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4592 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4593 | |
| 4594 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4595 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4596 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4597 | user_reg_hint_type = |
| 4598 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4599 | else |
| 4600 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4601 | |
| 4602 | switch (user_reg_hint_type) { |
| 4603 | case NL80211_USER_REG_HINT_USER: |
| 4604 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4605 | break; |
| 4606 | default: |
| 4607 | return -EINVAL; |
| 4608 | } |
| 4609 | |
| 4610 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4611 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4612 | return r; |
| 4613 | } |
| 4614 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4615 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4616 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4617 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4620 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4621 | struct mesh_config cur_params; |
| 4622 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4623 | void *hdr; |
| 4624 | struct nlattr *pinfoattr; |
| 4625 | struct sk_buff *msg; |
| 4626 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4627 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4628 | return -EOPNOTSUPP; |
| 4629 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4630 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4631 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4632 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4633 | wdev_lock(wdev); |
| 4634 | /* If not connected, get default parameters */ |
| 4635 | if (!wdev->mesh_id_len) |
| 4636 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4637 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4638 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4639 | wdev_unlock(wdev); |
| 4640 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4641 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4642 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4643 | |
| 4644 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4645 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4646 | if (!msg) |
| 4647 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4648 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4649 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4650 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4651 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4652 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4653 | if (!pinfoattr) |
| 4654 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4655 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4656 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4657 | cur_params.dot11MeshRetryTimeout) || |
| 4658 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4659 | cur_params.dot11MeshConfirmTimeout) || |
| 4660 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4661 | cur_params.dot11MeshHoldingTimeout) || |
| 4662 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4663 | cur_params.dot11MeshMaxPeerLinks) || |
| 4664 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4665 | cur_params.dot11MeshMaxRetries) || |
| 4666 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4667 | cur_params.dot11MeshTTL) || |
| 4668 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4669 | cur_params.element_ttl) || |
| 4670 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4671 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4672 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4673 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4674 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4675 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4676 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4677 | cur_params.path_refresh_time) || |
| 4678 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4679 | cur_params.min_discovery_timeout) || |
| 4680 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4681 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4682 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4683 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4684 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4685 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4686 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4687 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4688 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4689 | cur_params.dot11MeshHWMPRootMode) || |
| 4690 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4691 | cur_params.dot11MeshHWMPRannInterval) || |
| 4692 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4693 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4694 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4695 | cur_params.dot11MeshForwarding) || |
| 4696 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4697 | cur_params.rssi_threshold) || |
| 4698 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4699 | cur_params.ht_opmode) || |
| 4700 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4701 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4702 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4703 | cur_params.dot11MeshHWMProotInterval) || |
| 4704 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4705 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4706 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4707 | cur_params.power_mode) || |
| 4708 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4709 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4710 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4711 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4712 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4713 | nla_nest_end(msg, pinfoattr); |
| 4714 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4715 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4716 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4717 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4718 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4719 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4720 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4721 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4722 | } |
| 4723 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4724 | 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] | 4725 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4726 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4727 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4728 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4729 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4730 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4731 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4732 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4733 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4734 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4735 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4736 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4737 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4738 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4739 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4740 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4741 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4742 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4743 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4744 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4745 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4746 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4747 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4748 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4749 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4750 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4751 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4752 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4753 | }; |
| 4754 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4755 | static const struct nla_policy |
| 4756 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4757 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4758 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4759 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4760 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4761 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4762 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4763 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4764 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4765 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4766 | }; |
| 4767 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4768 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4769 | struct mesh_config *cfg, |
| 4770 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4771 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4772 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4773 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4774 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4775 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4776 | do { \ |
| 4777 | if (tb[attr]) { \ |
| 4778 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4779 | return -EINVAL; \ |
| 4780 | cfg->param = fn(tb[attr]); \ |
| 4781 | mask |= (1 << (attr - 1)); \ |
| 4782 | } \ |
| 4783 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4784 | |
| 4785 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4786 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4787 | return -EINVAL; |
| 4788 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4789 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4790 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4791 | return -EINVAL; |
| 4792 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4793 | /* This makes sure that there aren't more than 32 mesh config |
| 4794 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4795 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4796 | |
| 4797 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4798 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4799 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4800 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4801 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4802 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4803 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4804 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4805 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4806 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4807 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4808 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4809 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4810 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4811 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4812 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4813 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4814 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4815 | 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] | 4816 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4817 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4818 | 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] | 4819 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4820 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4822 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4823 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4824 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4825 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4826 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4827 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4828 | 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] | 4829 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4830 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4831 | 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] | 4832 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4833 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4834 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4835 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4836 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4837 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4838 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4839 | 1, 65535, mask, |
| 4840 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4841 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4842 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4843 | 1, 65535, mask, |
| 4844 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4845 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4846 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4847 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4848 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4849 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4850 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4851 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4852 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4853 | nla_get_u8); |
| 4854 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4855 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4856 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4857 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4858 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4859 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4860 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4861 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4862 | mask, NL80211_MESHCONF_FORWARDING, |
| 4863 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4864 | 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] | 4865 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 4866 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4867 | 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] | 4868 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4869 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4870 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4871 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4872 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4873 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4874 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4875 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4876 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4877 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4878 | dot11MeshHWMPconfirmationInterval, |
| 4879 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4880 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4881 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4882 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4883 | NL80211_MESH_POWER_ACTIVE, |
| 4884 | NL80211_MESH_POWER_MAX, |
| 4885 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4886 | nla_get_u32); |
| 4887 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4888 | 0, 65535, mask, |
| 4889 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4890 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4891 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4892 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4893 | if (mask_out) |
| 4894 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4895 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4896 | return 0; |
| 4897 | |
| 4898 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4899 | } |
| 4900 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4901 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4902 | struct mesh_setup *setup) |
| 4903 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4905 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4906 | |
| 4907 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4908 | return -EINVAL; |
| 4909 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4910 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4911 | nl80211_mesh_setup_params_policy)) |
| 4912 | return -EINVAL; |
| 4913 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4914 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4915 | setup->sync_method = |
| 4916 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4917 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4918 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4919 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4920 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4921 | setup->path_sel_proto = |
| 4922 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4923 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4924 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4925 | |
| 4926 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4927 | setup->path_metric = |
| 4928 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4929 | IEEE80211_PATH_METRIC_VENDOR : |
| 4930 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4931 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4932 | |
| 4933 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4934 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4935 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4936 | if (!is_valid_ie_attr(ieattr)) |
| 4937 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4938 | setup->ie = nla_data(ieattr); |
| 4939 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4940 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4941 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4942 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4943 | return -EINVAL; |
| 4944 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4945 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4946 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4947 | if (setup->is_secure) |
| 4948 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4949 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4950 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4951 | if (!setup->user_mpm) |
| 4952 | return -EINVAL; |
| 4953 | setup->auth_id = |
| 4954 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4955 | } |
| 4956 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4957 | return 0; |
| 4958 | } |
| 4959 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4960 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4961 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4962 | { |
| 4963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4964 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4965 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4966 | struct mesh_config cfg; |
| 4967 | u32 mask; |
| 4968 | int err; |
| 4969 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4970 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4971 | return -EOPNOTSUPP; |
| 4972 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4973 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4974 | return -EOPNOTSUPP; |
| 4975 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4976 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4977 | if (err) |
| 4978 | return err; |
| 4979 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4980 | wdev_lock(wdev); |
| 4981 | if (!wdev->mesh_id_len) |
| 4982 | err = -ENOLINK; |
| 4983 | |
| 4984 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4985 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4986 | |
| 4987 | wdev_unlock(wdev); |
| 4988 | |
| 4989 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4992 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4993 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4994 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4995 | struct sk_buff *msg; |
| 4996 | void *hdr = NULL; |
| 4997 | struct nlattr *nl_reg_rules; |
| 4998 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4999 | |
| 5000 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5001 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5002 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5003 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5004 | if (!msg) |
| 5005 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5006 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5007 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5008 | NL80211_CMD_GET_REG); |
| 5009 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5010 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5011 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5012 | if (reg_last_request_cell_base() && |
| 5013 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5014 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5015 | goto nla_put_failure; |
| 5016 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5017 | rcu_read_lock(); |
| 5018 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5019 | |
| 5020 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5021 | (regdom->dfs_region && |
| 5022 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5023 | goto nla_put_failure_rcu; |
| 5024 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5025 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5026 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5027 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5028 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5029 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5030 | struct nlattr *nl_reg_rule; |
| 5031 | const struct ieee80211_reg_rule *reg_rule; |
| 5032 | const struct ieee80211_freq_range *freq_range; |
| 5033 | const struct ieee80211_power_rule *power_rule; |
| 5034 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5035 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5036 | freq_range = ®_rule->freq_range; |
| 5037 | power_rule = ®_rule->power_rule; |
| 5038 | |
| 5039 | nl_reg_rule = nla_nest_start(msg, i); |
| 5040 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5041 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5042 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5043 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5044 | reg_rule->flags) || |
| 5045 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5046 | freq_range->start_freq_khz) || |
| 5047 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5048 | freq_range->end_freq_khz) || |
| 5049 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5050 | freq_range->max_bandwidth_khz) || |
| 5051 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5052 | power_rule->max_antenna_gain) || |
| 5053 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5054 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5055 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5056 | |
| 5057 | nla_nest_end(msg, nl_reg_rule); |
| 5058 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5059 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5060 | |
| 5061 | nla_nest_end(msg, nl_reg_rules); |
| 5062 | |
| 5063 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5064 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5065 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5066 | nla_put_failure_rcu: |
| 5067 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5068 | nla_put_failure: |
| 5069 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5070 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5071 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5072 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5073 | } |
| 5074 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5075 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5076 | { |
| 5077 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5078 | struct nlattr *nl_reg_rule; |
| 5079 | char *alpha2 = NULL; |
| 5080 | int rem_reg_rules = 0, r = 0; |
| 5081 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame^] | 5082 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5083 | struct ieee80211_regdomain *rd = NULL; |
| 5084 | |
| 5085 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5086 | return -EINVAL; |
| 5087 | |
| 5088 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5089 | return -EINVAL; |
| 5090 | |
| 5091 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5092 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5093 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5094 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5095 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5096 | 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] | 5097 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5098 | num_rules++; |
| 5099 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5100 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5103 | if (!reg_is_valid_request(alpha2)) |
| 5104 | return -EINVAL; |
| 5105 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5106 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5107 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5108 | |
| 5109 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5110 | if (!rd) |
| 5111 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5112 | |
| 5113 | rd->n_reg_rules = num_rules; |
| 5114 | rd->alpha2[0] = alpha2[0]; |
| 5115 | rd->alpha2[1] = alpha2[1]; |
| 5116 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5117 | /* |
| 5118 | * Disable DFS master mode if the DFS region was |
| 5119 | * not supported or known on this kernel. |
| 5120 | */ |
| 5121 | if (reg_supported_dfs_region(dfs_region)) |
| 5122 | rd->dfs_region = dfs_region; |
| 5123 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5124 | 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] | 5125 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5126 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5127 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5128 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5129 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5130 | if (r) |
| 5131 | goto bad_reg; |
| 5132 | |
| 5133 | rule_idx++; |
| 5134 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5135 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5136 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5137 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5138 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5139 | } |
| 5140 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5141 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5142 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5143 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5144 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5145 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5146 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5147 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5148 | } |
| 5149 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5150 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5151 | { |
| 5152 | struct nlattr *attr1, *attr2; |
| 5153 | int n_channels = 0, tmp1, tmp2; |
| 5154 | |
| 5155 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5156 | n_channels++; |
| 5157 | /* |
| 5158 | * Some hardware has a limited channel list for |
| 5159 | * scanning, and it is pretty much nonsensical |
| 5160 | * to scan for a channel twice, so disallow that |
| 5161 | * and don't require drivers to check that the |
| 5162 | * channel list they get isn't longer than what |
| 5163 | * they can scan, as long as they can scan all |
| 5164 | * the channels they registered at once. |
| 5165 | */ |
| 5166 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5167 | if (attr1 != attr2 && |
| 5168 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5169 | return 0; |
| 5170 | } |
| 5171 | |
| 5172 | return n_channels; |
| 5173 | } |
| 5174 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5175 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5176 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5177 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5178 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5179 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5180 | struct nlattr *attr; |
| 5181 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5182 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5183 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5184 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5185 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5186 | return -EINVAL; |
| 5187 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5188 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5189 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5190 | if (!rdev->ops->scan) |
| 5191 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5192 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5193 | if (rdev->scan_req) { |
| 5194 | err = -EBUSY; |
| 5195 | goto unlock; |
| 5196 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5197 | |
| 5198 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5199 | n_channels = validate_scan_freqs( |
| 5200 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5201 | if (!n_channels) { |
| 5202 | err = -EINVAL; |
| 5203 | goto unlock; |
| 5204 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5205 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5206 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5207 | n_channels = 0; |
| 5208 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5209 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5210 | if (wiphy->bands[band]) |
| 5211 | n_channels += wiphy->bands[band]->n_channels; |
| 5212 | } |
| 5213 | |
| 5214 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5215 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5216 | n_ssids++; |
| 5217 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5218 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5219 | err = -EINVAL; |
| 5220 | goto unlock; |
| 5221 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5222 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5223 | if (info->attrs[NL80211_ATTR_IE]) |
| 5224 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5225 | else |
| 5226 | ie_len = 0; |
| 5227 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5228 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5229 | err = -EINVAL; |
| 5230 | goto unlock; |
| 5231 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5232 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5233 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5234 | + sizeof(*request->ssids) * n_ssids |
| 5235 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5236 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5237 | if (!request) { |
| 5238 | err = -ENOMEM; |
| 5239 | goto unlock; |
| 5240 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5241 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5242 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5243 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5244 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5245 | if (ie_len) { |
| 5246 | if (request->ssids) |
| 5247 | request->ie = (void *)(request->ssids + n_ssids); |
| 5248 | else |
| 5249 | request->ie = (void *)(request->channels + n_channels); |
| 5250 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5251 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5252 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5253 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5254 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5255 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5256 | struct ieee80211_channel *chan; |
| 5257 | |
| 5258 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5259 | |
| 5260 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5261 | err = -EINVAL; |
| 5262 | goto out_free; |
| 5263 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5264 | |
| 5265 | /* ignore disabled channels */ |
| 5266 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5267 | continue; |
| 5268 | |
| 5269 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5270 | i++; |
| 5271 | } |
| 5272 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5273 | enum ieee80211_band band; |
| 5274 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5275 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5276 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5277 | int j; |
| 5278 | if (!wiphy->bands[band]) |
| 5279 | continue; |
| 5280 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5281 | struct ieee80211_channel *chan; |
| 5282 | |
| 5283 | chan = &wiphy->bands[band]->channels[j]; |
| 5284 | |
| 5285 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5286 | continue; |
| 5287 | |
| 5288 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5289 | i++; |
| 5290 | } |
| 5291 | } |
| 5292 | } |
| 5293 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5294 | if (!i) { |
| 5295 | err = -EINVAL; |
| 5296 | goto out_free; |
| 5297 | } |
| 5298 | |
| 5299 | request->n_channels = i; |
| 5300 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5301 | i = 0; |
| 5302 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5303 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5304 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5305 | err = -EINVAL; |
| 5306 | goto out_free; |
| 5307 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5308 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5309 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5310 | i++; |
| 5311 | } |
| 5312 | } |
| 5313 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5314 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5315 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5316 | memcpy((void *)request->ie, |
| 5317 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5318 | request->ie_len); |
| 5319 | } |
| 5320 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5321 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5322 | if (wiphy->bands[i]) |
| 5323 | request->rates[i] = |
| 5324 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5325 | |
| 5326 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5327 | nla_for_each_nested(attr, |
| 5328 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5329 | tmp) { |
| 5330 | enum ieee80211_band band = nla_type(attr); |
| 5331 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5332 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5333 | err = -EINVAL; |
| 5334 | goto out_free; |
| 5335 | } |
| 5336 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5337 | nla_data(attr), |
| 5338 | nla_len(attr), |
| 5339 | &request->rates[band]); |
| 5340 | if (err) |
| 5341 | goto out_free; |
| 5342 | } |
| 5343 | } |
| 5344 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5345 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5346 | request->flags = nla_get_u32( |
| 5347 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5348 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5349 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5350 | err = -EOPNOTSUPP; |
| 5351 | goto out_free; |
| 5352 | } |
| 5353 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5354 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5355 | request->no_cck = |
| 5356 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5357 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5358 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5359 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5360 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5361 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5362 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5363 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5364 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5365 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5366 | nl80211_send_scan_start(rdev, wdev); |
| 5367 | if (wdev->netdev) |
| 5368 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5369 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5370 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5371 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5372 | kfree(request); |
| 5373 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5374 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5375 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5376 | return err; |
| 5377 | } |
| 5378 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5379 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5380 | struct genl_info *info) |
| 5381 | { |
| 5382 | struct cfg80211_sched_scan_request *request; |
| 5383 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5384 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5385 | struct nlattr *attr; |
| 5386 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5387 | 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] | 5388 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5389 | enum ieee80211_band band; |
| 5390 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5391 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5392 | |
| 5393 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5394 | !rdev->ops->sched_scan_start) |
| 5395 | return -EOPNOTSUPP; |
| 5396 | |
| 5397 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5398 | return -EINVAL; |
| 5399 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5400 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5401 | return -EINVAL; |
| 5402 | |
| 5403 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5404 | if (interval == 0) |
| 5405 | return -EINVAL; |
| 5406 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5407 | wiphy = &rdev->wiphy; |
| 5408 | |
| 5409 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5410 | n_channels = validate_scan_freqs( |
| 5411 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5412 | if (!n_channels) |
| 5413 | return -EINVAL; |
| 5414 | } else { |
| 5415 | n_channels = 0; |
| 5416 | |
| 5417 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5418 | if (wiphy->bands[band]) |
| 5419 | n_channels += wiphy->bands[band]->n_channels; |
| 5420 | } |
| 5421 | |
| 5422 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5423 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5424 | tmp) |
| 5425 | n_ssids++; |
| 5426 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5427 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5428 | return -EINVAL; |
| 5429 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5430 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5431 | nla_for_each_nested(attr, |
| 5432 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5433 | tmp) |
| 5434 | n_match_sets++; |
| 5435 | |
| 5436 | if (n_match_sets > wiphy->max_match_sets) |
| 5437 | return -EINVAL; |
| 5438 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5439 | if (info->attrs[NL80211_ATTR_IE]) |
| 5440 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5441 | else |
| 5442 | ie_len = 0; |
| 5443 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5444 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5445 | return -EINVAL; |
| 5446 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5447 | if (rdev->sched_scan_req) { |
| 5448 | err = -EINPROGRESS; |
| 5449 | goto out; |
| 5450 | } |
| 5451 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5452 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5453 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5454 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5455 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5456 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5457 | if (!request) { |
| 5458 | err = -ENOMEM; |
| 5459 | goto out; |
| 5460 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5461 | |
| 5462 | if (n_ssids) |
| 5463 | request->ssids = (void *)&request->channels[n_channels]; |
| 5464 | request->n_ssids = n_ssids; |
| 5465 | if (ie_len) { |
| 5466 | if (request->ssids) |
| 5467 | request->ie = (void *)(request->ssids + n_ssids); |
| 5468 | else |
| 5469 | request->ie = (void *)(request->channels + n_channels); |
| 5470 | } |
| 5471 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5472 | if (n_match_sets) { |
| 5473 | if (request->ie) |
| 5474 | request->match_sets = (void *)(request->ie + ie_len); |
| 5475 | else if (request->ssids) |
| 5476 | request->match_sets = |
| 5477 | (void *)(request->ssids + n_ssids); |
| 5478 | else |
| 5479 | request->match_sets = |
| 5480 | (void *)(request->channels + n_channels); |
| 5481 | } |
| 5482 | request->n_match_sets = n_match_sets; |
| 5483 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5484 | i = 0; |
| 5485 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5486 | /* user specified, bail out if channel not found */ |
| 5487 | nla_for_each_nested(attr, |
| 5488 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5489 | tmp) { |
| 5490 | struct ieee80211_channel *chan; |
| 5491 | |
| 5492 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5493 | |
| 5494 | if (!chan) { |
| 5495 | err = -EINVAL; |
| 5496 | goto out_free; |
| 5497 | } |
| 5498 | |
| 5499 | /* ignore disabled channels */ |
| 5500 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5501 | continue; |
| 5502 | |
| 5503 | request->channels[i] = chan; |
| 5504 | i++; |
| 5505 | } |
| 5506 | } else { |
| 5507 | /* all channels */ |
| 5508 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5509 | int j; |
| 5510 | if (!wiphy->bands[band]) |
| 5511 | continue; |
| 5512 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5513 | struct ieee80211_channel *chan; |
| 5514 | |
| 5515 | chan = &wiphy->bands[band]->channels[j]; |
| 5516 | |
| 5517 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5518 | continue; |
| 5519 | |
| 5520 | request->channels[i] = chan; |
| 5521 | i++; |
| 5522 | } |
| 5523 | } |
| 5524 | } |
| 5525 | |
| 5526 | if (!i) { |
| 5527 | err = -EINVAL; |
| 5528 | goto out_free; |
| 5529 | } |
| 5530 | |
| 5531 | request->n_channels = i; |
| 5532 | |
| 5533 | i = 0; |
| 5534 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5535 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5536 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5537 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5538 | err = -EINVAL; |
| 5539 | goto out_free; |
| 5540 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5541 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5542 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5543 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5544 | i++; |
| 5545 | } |
| 5546 | } |
| 5547 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5548 | i = 0; |
| 5549 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5550 | nla_for_each_nested(attr, |
| 5551 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5552 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5553 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5554 | |
| 5555 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5556 | nla_data(attr), nla_len(attr), |
| 5557 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5558 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5559 | if (ssid) { |
| 5560 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5561 | err = -EINVAL; |
| 5562 | goto out_free; |
| 5563 | } |
| 5564 | memcpy(request->match_sets[i].ssid.ssid, |
| 5565 | nla_data(ssid), nla_len(ssid)); |
| 5566 | request->match_sets[i].ssid.ssid_len = |
| 5567 | nla_len(ssid); |
| 5568 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5569 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5570 | if (rssi) |
| 5571 | request->rssi_thold = nla_get_u32(rssi); |
| 5572 | else |
| 5573 | request->rssi_thold = |
| 5574 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5575 | i++; |
| 5576 | } |
| 5577 | } |
| 5578 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5579 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5580 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5581 | memcpy((void *)request->ie, |
| 5582 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5583 | request->ie_len); |
| 5584 | } |
| 5585 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5586 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5587 | request->flags = nla_get_u32( |
| 5588 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5589 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5590 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5591 | err = -EOPNOTSUPP; |
| 5592 | goto out_free; |
| 5593 | } |
| 5594 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5595 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5596 | request->dev = dev; |
| 5597 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5598 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5599 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5600 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5601 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5602 | if (!err) { |
| 5603 | rdev->sched_scan_req = request; |
| 5604 | nl80211_send_sched_scan(rdev, dev, |
| 5605 | NL80211_CMD_START_SCHED_SCAN); |
| 5606 | goto out; |
| 5607 | } |
| 5608 | |
| 5609 | out_free: |
| 5610 | kfree(request); |
| 5611 | out: |
| 5612 | return err; |
| 5613 | } |
| 5614 | |
| 5615 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5616 | struct genl_info *info) |
| 5617 | { |
| 5618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5619 | |
| 5620 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5621 | !rdev->ops->sched_scan_stop) |
| 5622 | return -EOPNOTSUPP; |
| 5623 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5624 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5625 | } |
| 5626 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5627 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5628 | struct genl_info *info) |
| 5629 | { |
| 5630 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5631 | struct net_device *dev = info->user_ptr[1]; |
| 5632 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5633 | struct cfg80211_chan_def chandef; |
| 5634 | int err; |
| 5635 | |
| 5636 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5637 | if (err) |
| 5638 | return err; |
| 5639 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5640 | if (netif_carrier_ok(dev)) |
| 5641 | return -EBUSY; |
| 5642 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5643 | if (wdev->cac_started) |
| 5644 | return -EBUSY; |
| 5645 | |
| 5646 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5647 | if (err < 0) |
| 5648 | return err; |
| 5649 | |
| 5650 | if (err == 0) |
| 5651 | return -EINVAL; |
| 5652 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5653 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5654 | return -EINVAL; |
| 5655 | |
| 5656 | if (!rdev->ops->start_radar_detection) |
| 5657 | return -EOPNOTSUPP; |
| 5658 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5659 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5660 | chandef.chan, CHAN_MODE_SHARED, |
| 5661 | BIT(chandef.width)); |
| 5662 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5663 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5664 | |
| 5665 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5666 | if (!err) { |
| 5667 | wdev->channel = chandef.chan; |
| 5668 | wdev->cac_started = true; |
| 5669 | wdev->cac_start_time = jiffies; |
| 5670 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5671 | return err; |
| 5672 | } |
| 5673 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5674 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5675 | { |
| 5676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5677 | struct net_device *dev = info->user_ptr[1]; |
| 5678 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5679 | struct cfg80211_csa_settings params; |
| 5680 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5681 | * function is called under RTNL lock, so this should not be a problem. |
| 5682 | */ |
| 5683 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5684 | u8 radar_detect_width = 0; |
| 5685 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5686 | bool need_new_beacon = false; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5687 | |
| 5688 | if (!rdev->ops->channel_switch || |
| 5689 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5690 | return -EOPNOTSUPP; |
| 5691 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5692 | switch (dev->ieee80211_ptr->iftype) { |
| 5693 | case NL80211_IFTYPE_AP: |
| 5694 | case NL80211_IFTYPE_P2P_GO: |
| 5695 | need_new_beacon = true; |
| 5696 | |
| 5697 | /* useless if AP is not running */ |
| 5698 | if (!wdev->beacon_interval) |
| 5699 | return -EINVAL; |
| 5700 | break; |
| 5701 | case NL80211_IFTYPE_ADHOC: |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5702 | case NL80211_IFTYPE_MESH_POINT: |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5703 | break; |
| 5704 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5705 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5706 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5707 | |
| 5708 | memset(¶ms, 0, sizeof(params)); |
| 5709 | |
| 5710 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5711 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5712 | return -EINVAL; |
| 5713 | |
| 5714 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5715 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5716 | return -EINVAL; |
| 5717 | |
| 5718 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5719 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5720 | if (!need_new_beacon) |
| 5721 | goto skip_beacons; |
| 5722 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5723 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5724 | if (err) |
| 5725 | return err; |
| 5726 | |
| 5727 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5728 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5729 | nl80211_policy); |
| 5730 | if (err) |
| 5731 | return err; |
| 5732 | |
| 5733 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5734 | if (err) |
| 5735 | return err; |
| 5736 | |
| 5737 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5738 | return -EINVAL; |
| 5739 | |
| 5740 | params.counter_offset_beacon = |
| 5741 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5742 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5743 | return -EINVAL; |
| 5744 | |
| 5745 | /* sanity check - counters should be the same */ |
| 5746 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5747 | params.count) |
| 5748 | return -EINVAL; |
| 5749 | |
| 5750 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5751 | params.counter_offset_presp = |
| 5752 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5753 | if (params.counter_offset_presp >= |
| 5754 | params.beacon_csa.probe_resp_len) |
| 5755 | return -EINVAL; |
| 5756 | |
| 5757 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5758 | params.count) |
| 5759 | return -EINVAL; |
| 5760 | } |
| 5761 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5762 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5763 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5764 | if (err) |
| 5765 | return err; |
| 5766 | |
| 5767 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5768 | return -EINVAL; |
| 5769 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5770 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP || |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 5771 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO || |
| 5772 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_ADHOC) { |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5773 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 5774 | ¶ms.chandef); |
| 5775 | if (err < 0) { |
| 5776 | return err; |
| 5777 | } else if (err) { |
| 5778 | radar_detect_width = BIT(params.chandef.width); |
| 5779 | params.radar_required = true; |
| 5780 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5781 | } |
| 5782 | |
| 5783 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5784 | params.chandef.chan, |
| 5785 | CHAN_MODE_SHARED, |
| 5786 | radar_detect_width); |
| 5787 | if (err) |
| 5788 | return err; |
| 5789 | |
| 5790 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5791 | params.block_tx = true; |
| 5792 | |
| 5793 | return rdev_channel_switch(rdev, dev, ¶ms); |
| 5794 | } |
| 5795 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5796 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5797 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5798 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5799 | struct wireless_dev *wdev, |
| 5800 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5801 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5802 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5803 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5804 | void *hdr; |
| 5805 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5806 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5807 | |
| 5808 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5809 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5810 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5811 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5812 | if (!hdr) |
| 5813 | return -1; |
| 5814 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5815 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5816 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5817 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5818 | goto nla_put_failure; |
| 5819 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5820 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5821 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5822 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5823 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5824 | |
| 5825 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5826 | if (!bss) |
| 5827 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5828 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5829 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5830 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5831 | |
| 5832 | rcu_read_lock(); |
| 5833 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5834 | if (ies) { |
| 5835 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5836 | goto fail_unlock_rcu; |
| 5837 | tsf = true; |
| 5838 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5839 | ies->len, ies->data)) |
| 5840 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5841 | } |
| 5842 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5843 | if (ies) { |
| 5844 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5845 | goto fail_unlock_rcu; |
| 5846 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5847 | ies->len, ies->data)) |
| 5848 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5849 | } |
| 5850 | rcu_read_unlock(); |
| 5851 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5852 | if (res->beacon_interval && |
| 5853 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5854 | goto nla_put_failure; |
| 5855 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5856 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5857 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5858 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5859 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5860 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5861 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5862 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5863 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5864 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5865 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5866 | break; |
| 5867 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5868 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5869 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5870 | break; |
| 5871 | default: |
| 5872 | break; |
| 5873 | } |
| 5874 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5875 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5876 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5877 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5878 | if (intbss == wdev->current_bss && |
| 5879 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5880 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5881 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5882 | break; |
| 5883 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5884 | if (intbss == wdev->current_bss && |
| 5885 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5886 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5887 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5888 | break; |
| 5889 | default: |
| 5890 | break; |
| 5891 | } |
| 5892 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5893 | nla_nest_end(msg, bss); |
| 5894 | |
| 5895 | return genlmsg_end(msg, hdr); |
| 5896 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5897 | fail_unlock_rcu: |
| 5898 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5899 | nla_put_failure: |
| 5900 | genlmsg_cancel(msg, hdr); |
| 5901 | return -EMSGSIZE; |
| 5902 | } |
| 5903 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5904 | 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] | 5905 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5906 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5907 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5908 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5909 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5910 | int err; |
| 5911 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5912 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5913 | if (err) |
| 5914 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5915 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5916 | wdev_lock(wdev); |
| 5917 | spin_lock_bh(&rdev->bss_lock); |
| 5918 | cfg80211_bss_expire(rdev); |
| 5919 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5920 | cb->seq = rdev->bss_generation; |
| 5921 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5922 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5923 | if (++idx <= start) |
| 5924 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5925 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5926 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5927 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5928 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5929 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5930 | } |
| 5931 | } |
| 5932 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5933 | spin_unlock_bh(&rdev->bss_lock); |
| 5934 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5935 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5936 | cb->args[2] = idx; |
| 5937 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5938 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5939 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5940 | } |
| 5941 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5942 | 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] | 5943 | int flags, struct net_device *dev, |
| 5944 | struct survey_info *survey) |
| 5945 | { |
| 5946 | void *hdr; |
| 5947 | struct nlattr *infoattr; |
| 5948 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5949 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5950 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5951 | if (!hdr) |
| 5952 | return -ENOMEM; |
| 5953 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5954 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5955 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5956 | |
| 5957 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5958 | if (!infoattr) |
| 5959 | goto nla_put_failure; |
| 5960 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5961 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5962 | survey->channel->center_freq)) |
| 5963 | goto nla_put_failure; |
| 5964 | |
| 5965 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5966 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5967 | goto nla_put_failure; |
| 5968 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5969 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5970 | goto nla_put_failure; |
| 5971 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5972 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5973 | survey->channel_time)) |
| 5974 | goto nla_put_failure; |
| 5975 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5976 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5977 | survey->channel_time_busy)) |
| 5978 | goto nla_put_failure; |
| 5979 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5980 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5981 | survey->channel_time_ext_busy)) |
| 5982 | goto nla_put_failure; |
| 5983 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5984 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5985 | survey->channel_time_rx)) |
| 5986 | goto nla_put_failure; |
| 5987 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5988 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5989 | survey->channel_time_tx)) |
| 5990 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5991 | |
| 5992 | nla_nest_end(msg, infoattr); |
| 5993 | |
| 5994 | return genlmsg_end(msg, hdr); |
| 5995 | |
| 5996 | nla_put_failure: |
| 5997 | genlmsg_cancel(msg, hdr); |
| 5998 | return -EMSGSIZE; |
| 5999 | } |
| 6000 | |
| 6001 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6002 | struct netlink_callback *cb) |
| 6003 | { |
| 6004 | struct survey_info survey; |
| 6005 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6006 | struct wireless_dev *wdev; |
| 6007 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6008 | int res; |
| 6009 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6010 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6011 | if (res) |
| 6012 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6013 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6014 | if (!wdev->netdev) { |
| 6015 | res = -EINVAL; |
| 6016 | goto out_err; |
| 6017 | } |
| 6018 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6019 | if (!dev->ops->dump_survey) { |
| 6020 | res = -EOPNOTSUPP; |
| 6021 | goto out_err; |
| 6022 | } |
| 6023 | |
| 6024 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6025 | struct ieee80211_channel *chan; |
| 6026 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6027 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6028 | if (res == -ENOENT) |
| 6029 | break; |
| 6030 | if (res) |
| 6031 | goto out_err; |
| 6032 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6033 | /* Survey without a channel doesn't make sense */ |
| 6034 | if (!survey.channel) { |
| 6035 | res = -EINVAL; |
| 6036 | goto out; |
| 6037 | } |
| 6038 | |
| 6039 | chan = ieee80211_get_channel(&dev->wiphy, |
| 6040 | survey.channel->center_freq); |
| 6041 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6042 | survey_idx++; |
| 6043 | continue; |
| 6044 | } |
| 6045 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6046 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6047 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6048 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6049 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6050 | goto out; |
| 6051 | survey_idx++; |
| 6052 | } |
| 6053 | |
| 6054 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6055 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6056 | res = skb->len; |
| 6057 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6058 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6059 | return res; |
| 6060 | } |
| 6061 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6062 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6063 | { |
| 6064 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6065 | NL80211_WPA_VERSION_2)); |
| 6066 | } |
| 6067 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6068 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6069 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6070 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6071 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6072 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6073 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6074 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6075 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6076 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6077 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6078 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6079 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6080 | return -EINVAL; |
| 6081 | |
| 6082 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6083 | return -EINVAL; |
| 6084 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6085 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6086 | return -EINVAL; |
| 6087 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6088 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6089 | return -EINVAL; |
| 6090 | |
| 6091 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6092 | return -EINVAL; |
| 6093 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6094 | err = nl80211_parse_key(info, &key); |
| 6095 | if (err) |
| 6096 | return err; |
| 6097 | |
| 6098 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6099 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6100 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6101 | if (!key.p.key || !key.p.key_len) |
| 6102 | return -EINVAL; |
| 6103 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6104 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6105 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6106 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6107 | return -EINVAL; |
| 6108 | if (key.idx > 4) |
| 6109 | return -EINVAL; |
| 6110 | } else { |
| 6111 | key.p.key_len = 0; |
| 6112 | key.p.key = NULL; |
| 6113 | } |
| 6114 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6115 | if (key.idx >= 0) { |
| 6116 | int i; |
| 6117 | bool ok = false; |
| 6118 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6119 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6120 | ok = true; |
| 6121 | break; |
| 6122 | } |
| 6123 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6124 | if (!ok) |
| 6125 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6126 | } |
| 6127 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6128 | if (!rdev->ops->auth) |
| 6129 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6130 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6131 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6132 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6133 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6134 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6135 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6136 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6137 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6138 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6139 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6140 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6141 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6142 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6143 | |
| 6144 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6145 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6146 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6147 | } |
| 6148 | |
| 6149 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6150 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6151 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6152 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6153 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6154 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6155 | return -EINVAL; |
| 6156 | |
| 6157 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6158 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6159 | return -EINVAL; |
| 6160 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6161 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6162 | /* need to include at least Auth Transaction and Status Code */ |
| 6163 | if (sae_data_len < 4) |
| 6164 | return -EINVAL; |
| 6165 | } |
| 6166 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6167 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6168 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6169 | /* |
| 6170 | * Since we no longer track auth state, ignore |
| 6171 | * requests to only change local state. |
| 6172 | */ |
| 6173 | if (local_state_change) |
| 6174 | return 0; |
| 6175 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6176 | wdev_lock(dev->ieee80211_ptr); |
| 6177 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6178 | ssid, ssid_len, ie, ie_len, |
| 6179 | key.p.key, key.p.key_len, key.idx, |
| 6180 | sae_data, sae_data_len); |
| 6181 | wdev_unlock(dev->ieee80211_ptr); |
| 6182 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6183 | } |
| 6184 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6185 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6186 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6187 | struct cfg80211_crypto_settings *settings, |
| 6188 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6189 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6190 | memset(settings, 0, sizeof(*settings)); |
| 6191 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6192 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6193 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6194 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6195 | u16 proto; |
| 6196 | proto = nla_get_u16( |
| 6197 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6198 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6199 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6200 | proto != ETH_P_PAE) |
| 6201 | return -EINVAL; |
| 6202 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6203 | settings->control_port_no_encrypt = true; |
| 6204 | } else |
| 6205 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6206 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6207 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6208 | void *data; |
| 6209 | int len, i; |
| 6210 | |
| 6211 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6212 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6213 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6214 | |
| 6215 | if (len % sizeof(u32)) |
| 6216 | return -EINVAL; |
| 6217 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6218 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6219 | return -EINVAL; |
| 6220 | |
| 6221 | memcpy(settings->ciphers_pairwise, data, len); |
| 6222 | |
| 6223 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6224 | if (!cfg80211_supported_cipher_suite( |
| 6225 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6226 | settings->ciphers_pairwise[i])) |
| 6227 | return -EINVAL; |
| 6228 | } |
| 6229 | |
| 6230 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6231 | settings->cipher_group = |
| 6232 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6233 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6234 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6235 | return -EINVAL; |
| 6236 | } |
| 6237 | |
| 6238 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6239 | settings->wpa_versions = |
| 6240 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6241 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6242 | return -EINVAL; |
| 6243 | } |
| 6244 | |
| 6245 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6246 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6247 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6248 | |
| 6249 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6250 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6251 | settings->n_akm_suites = len / sizeof(u32); |
| 6252 | |
| 6253 | if (len % sizeof(u32)) |
| 6254 | return -EINVAL; |
| 6255 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6256 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6257 | return -EINVAL; |
| 6258 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6259 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6260 | } |
| 6261 | |
| 6262 | return 0; |
| 6263 | } |
| 6264 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6265 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6266 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6267 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6268 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6269 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6270 | struct cfg80211_assoc_request req = {}; |
| 6271 | const u8 *bssid, *ssid; |
| 6272 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6273 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6274 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6275 | return -EINVAL; |
| 6276 | |
| 6277 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6278 | !info->attrs[NL80211_ATTR_SSID] || |
| 6279 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6280 | return -EINVAL; |
| 6281 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6282 | if (!rdev->ops->assoc) |
| 6283 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6284 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6285 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6286 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6287 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6288 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6289 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6290 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6291 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6292 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6293 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6294 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6295 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6296 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6297 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6298 | |
| 6299 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6300 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6301 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6302 | } |
| 6303 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6304 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6305 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6306 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6307 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6308 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6309 | else if (mfp != NL80211_MFP_NO) |
| 6310 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6311 | } |
| 6312 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6313 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6314 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6315 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6316 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6317 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6318 | |
| 6319 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6320 | memcpy(&req.ht_capa_mask, |
| 6321 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6322 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6323 | |
| 6324 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6325 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6326 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6327 | memcpy(&req.ht_capa, |
| 6328 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6329 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6330 | } |
| 6331 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6332 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6333 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6334 | |
| 6335 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6336 | memcpy(&req.vht_capa_mask, |
| 6337 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6338 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6339 | |
| 6340 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6341 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6342 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6343 | memcpy(&req.vht_capa, |
| 6344 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6345 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6346 | } |
| 6347 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6348 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6349 | if (!err) { |
| 6350 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6351 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6352 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6353 | wdev_unlock(dev->ieee80211_ptr); |
| 6354 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6355 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6356 | return err; |
| 6357 | } |
| 6358 | |
| 6359 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6360 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6362 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6363 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6364 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6365 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6366 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6367 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6368 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6369 | return -EINVAL; |
| 6370 | |
| 6371 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6372 | return -EINVAL; |
| 6373 | |
| 6374 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6375 | return -EINVAL; |
| 6376 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6377 | if (!rdev->ops->deauth) |
| 6378 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6379 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6380 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6382 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6383 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6384 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6385 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6386 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6387 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6388 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6389 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6390 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6391 | |
| 6392 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6393 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6394 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6395 | } |
| 6396 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6397 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6398 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6399 | wdev_lock(dev->ieee80211_ptr); |
| 6400 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6401 | local_state_change); |
| 6402 | wdev_unlock(dev->ieee80211_ptr); |
| 6403 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6407 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6408 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6409 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6410 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6411 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6412 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6413 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6414 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6415 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6416 | return -EINVAL; |
| 6417 | |
| 6418 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6419 | return -EINVAL; |
| 6420 | |
| 6421 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6422 | return -EINVAL; |
| 6423 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6424 | if (!rdev->ops->disassoc) |
| 6425 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6426 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6427 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6428 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6429 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6430 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6431 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6432 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6433 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6434 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6435 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6436 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6437 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6438 | |
| 6439 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6440 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6441 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6442 | } |
| 6443 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6444 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6445 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6446 | wdev_lock(dev->ieee80211_ptr); |
| 6447 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6448 | local_state_change); |
| 6449 | wdev_unlock(dev->ieee80211_ptr); |
| 6450 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6451 | } |
| 6452 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6453 | static bool |
| 6454 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6455 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6456 | int rateval) |
| 6457 | { |
| 6458 | struct wiphy *wiphy = &rdev->wiphy; |
| 6459 | bool found = false; |
| 6460 | int band, i; |
| 6461 | |
| 6462 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6463 | struct ieee80211_supported_band *sband; |
| 6464 | |
| 6465 | sband = wiphy->bands[band]; |
| 6466 | if (!sband) |
| 6467 | continue; |
| 6468 | |
| 6469 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6470 | if (sband->bitrates[i].bitrate == rateval) { |
| 6471 | mcast_rate[band] = i + 1; |
| 6472 | found = true; |
| 6473 | break; |
| 6474 | } |
| 6475 | } |
| 6476 | } |
| 6477 | |
| 6478 | return found; |
| 6479 | } |
| 6480 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6481 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6482 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6484 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6485 | struct cfg80211_ibss_params ibss; |
| 6486 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6487 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6488 | int err; |
| 6489 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6490 | memset(&ibss, 0, sizeof(ibss)); |
| 6491 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6492 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6493 | return -EINVAL; |
| 6494 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6495 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6496 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6497 | return -EINVAL; |
| 6498 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6499 | ibss.beacon_interval = 100; |
| 6500 | |
| 6501 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6502 | ibss.beacon_interval = |
| 6503 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6504 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6505 | return -EINVAL; |
| 6506 | } |
| 6507 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6508 | if (!rdev->ops->join_ibss) |
| 6509 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6510 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6511 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6512 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6513 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6514 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6515 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6516 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6517 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6518 | |
| 6519 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6520 | return -EINVAL; |
| 6521 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6522 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6523 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6524 | |
| 6525 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6526 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6527 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6528 | } |
| 6529 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6530 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6531 | if (err) |
| 6532 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6533 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6534 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6535 | return -EINVAL; |
| 6536 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6537 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6538 | case NL80211_CHAN_WIDTH_5: |
| 6539 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6540 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6541 | break; |
| 6542 | case NL80211_CHAN_WIDTH_20: |
| 6543 | case NL80211_CHAN_WIDTH_40: |
| 6544 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6545 | break; |
| 6546 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6547 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6548 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6549 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6550 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6551 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6552 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6553 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6554 | u8 *rates = |
| 6555 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6556 | int n_rates = |
| 6557 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6558 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6559 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6560 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6561 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6562 | &ibss.basic_rates); |
| 6563 | if (err) |
| 6564 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6565 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6566 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6567 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6568 | memcpy(&ibss.ht_capa_mask, |
| 6569 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6570 | sizeof(ibss.ht_capa_mask)); |
| 6571 | |
| 6572 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6573 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6574 | return -EINVAL; |
| 6575 | memcpy(&ibss.ht_capa, |
| 6576 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6577 | sizeof(ibss.ht_capa)); |
| 6578 | } |
| 6579 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6580 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6581 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6582 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6583 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6584 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6585 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6586 | bool no_ht = false; |
| 6587 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6588 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6589 | info->attrs[NL80211_ATTR_KEYS], |
| 6590 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6591 | if (IS_ERR(connkeys)) |
| 6592 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6593 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6594 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6595 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6596 | kfree(connkeys); |
| 6597 | return -EINVAL; |
| 6598 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6599 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6600 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6601 | ibss.control_port = |
| 6602 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6603 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6604 | ibss.userspace_handles_dfs = |
| 6605 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6606 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6607 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6608 | if (err) |
| 6609 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6610 | return err; |
| 6611 | } |
| 6612 | |
| 6613 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6614 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6615 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6616 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6617 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6618 | if (!rdev->ops->leave_ibss) |
| 6619 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6620 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6621 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6622 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6623 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6624 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6625 | } |
| 6626 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6627 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6628 | { |
| 6629 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6630 | struct net_device *dev = info->user_ptr[1]; |
| 6631 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6632 | u32 nla_rate; |
| 6633 | int err; |
| 6634 | |
| 6635 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6636 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6637 | return -EOPNOTSUPP; |
| 6638 | |
| 6639 | if (!rdev->ops->set_mcast_rate) |
| 6640 | return -EOPNOTSUPP; |
| 6641 | |
| 6642 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6643 | |
| 6644 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6645 | return -EINVAL; |
| 6646 | |
| 6647 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6648 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6649 | return -EINVAL; |
| 6650 | |
| 6651 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6652 | |
| 6653 | return err; |
| 6654 | } |
| 6655 | |
| 6656 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6657 | #ifdef CONFIG_NL80211_TESTMODE |
| 6658 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6659 | .name = "testmode", |
| 6660 | }; |
| 6661 | |
| 6662 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6663 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6665 | struct wireless_dev *wdev = |
| 6666 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6667 | int err; |
| 6668 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6669 | if (!rdev->ops->testmode_cmd) |
| 6670 | return -EOPNOTSUPP; |
| 6671 | |
| 6672 | if (IS_ERR(wdev)) { |
| 6673 | err = PTR_ERR(wdev); |
| 6674 | if (err != -EINVAL) |
| 6675 | return err; |
| 6676 | wdev = NULL; |
| 6677 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6678 | return -EINVAL; |
| 6679 | } |
| 6680 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6681 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6682 | return -EINVAL; |
| 6683 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6684 | rdev->testmode_info = info; |
| 6685 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6686 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6687 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6688 | rdev->testmode_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6689 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6690 | return err; |
| 6691 | } |
| 6692 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6693 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6694 | struct netlink_callback *cb) |
| 6695 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6696 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6697 | int err; |
| 6698 | long phy_idx; |
| 6699 | void *data = NULL; |
| 6700 | int data_len = 0; |
| 6701 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6702 | rtnl_lock(); |
| 6703 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6704 | if (cb->args[0]) { |
| 6705 | /* |
| 6706 | * 0 is a valid index, but not valid for args[0], |
| 6707 | * so we need to offset by 1. |
| 6708 | */ |
| 6709 | phy_idx = cb->args[0] - 1; |
| 6710 | } else { |
| 6711 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6712 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6713 | nl80211_policy); |
| 6714 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6715 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6716 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6717 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6718 | nl80211_fam.attrbuf); |
| 6719 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6720 | err = PTR_ERR(rdev); |
| 6721 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6722 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6723 | phy_idx = rdev->wiphy_idx; |
| 6724 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6725 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6726 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6727 | cb->args[1] = |
| 6728 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6729 | } |
| 6730 | |
| 6731 | if (cb->args[1]) { |
| 6732 | data = nla_data((void *)cb->args[1]); |
| 6733 | data_len = nla_len((void *)cb->args[1]); |
| 6734 | } |
| 6735 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6736 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6737 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6738 | err = -ENOENT; |
| 6739 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6740 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6741 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6742 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6743 | err = -EOPNOTSUPP; |
| 6744 | goto out_err; |
| 6745 | } |
| 6746 | |
| 6747 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6748 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6749 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6750 | NL80211_CMD_TESTMODE); |
| 6751 | struct nlattr *tmdata; |
| 6752 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 6753 | if (!hdr) |
| 6754 | break; |
| 6755 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6756 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6757 | genlmsg_cancel(skb, hdr); |
| 6758 | break; |
| 6759 | } |
| 6760 | |
| 6761 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6762 | if (!tmdata) { |
| 6763 | genlmsg_cancel(skb, hdr); |
| 6764 | break; |
| 6765 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6766 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6767 | nla_nest_end(skb, tmdata); |
| 6768 | |
| 6769 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6770 | genlmsg_cancel(skb, hdr); |
| 6771 | break; |
| 6772 | } else if (err) { |
| 6773 | genlmsg_cancel(skb, hdr); |
| 6774 | goto out_err; |
| 6775 | } |
| 6776 | |
| 6777 | genlmsg_end(skb, hdr); |
| 6778 | } |
| 6779 | |
| 6780 | err = skb->len; |
| 6781 | /* see above */ |
| 6782 | cb->args[0] = phy_idx + 1; |
| 6783 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6784 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6785 | return err; |
| 6786 | } |
| 6787 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6788 | static struct sk_buff * |
| 6789 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6790 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6791 | { |
| 6792 | struct sk_buff *skb; |
| 6793 | void *hdr; |
| 6794 | struct nlattr *data; |
| 6795 | |
| 6796 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6797 | if (!skb) |
| 6798 | return NULL; |
| 6799 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6800 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6801 | if (!hdr) { |
| 6802 | kfree_skb(skb); |
| 6803 | return NULL; |
| 6804 | } |
| 6805 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6806 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6807 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6808 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6809 | |
| 6810 | ((void **)skb->cb)[0] = rdev; |
| 6811 | ((void **)skb->cb)[1] = hdr; |
| 6812 | ((void **)skb->cb)[2] = data; |
| 6813 | |
| 6814 | return skb; |
| 6815 | |
| 6816 | nla_put_failure: |
| 6817 | kfree_skb(skb); |
| 6818 | return NULL; |
| 6819 | } |
| 6820 | |
| 6821 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6822 | int approxlen) |
| 6823 | { |
| 6824 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6825 | |
| 6826 | if (WARN_ON(!rdev->testmode_info)) |
| 6827 | return NULL; |
| 6828 | |
| 6829 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6830 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6831 | rdev->testmode_info->snd_seq, |
| 6832 | GFP_KERNEL); |
| 6833 | } |
| 6834 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6835 | |
| 6836 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6837 | { |
| 6838 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6839 | void *hdr = ((void **)skb->cb)[1]; |
| 6840 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6841 | |
| 6842 | if (WARN_ON(!rdev->testmode_info)) { |
| 6843 | kfree_skb(skb); |
| 6844 | return -EINVAL; |
| 6845 | } |
| 6846 | |
| 6847 | nla_nest_end(skb, data); |
| 6848 | genlmsg_end(skb, hdr); |
| 6849 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6850 | } |
| 6851 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6852 | |
| 6853 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6854 | int approxlen, gfp_t gfp) |
| 6855 | { |
| 6856 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6857 | |
| 6858 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6859 | } |
| 6860 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6861 | |
| 6862 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6863 | { |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6864 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6865 | void *hdr = ((void **)skb->cb)[1]; |
| 6866 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6867 | |
| 6868 | nla_nest_end(skb, data); |
| 6869 | genlmsg_end(skb, hdr); |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 6870 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, |
| 6871 | nl80211_testmode_mcgrp.id, gfp); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6872 | } |
| 6873 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6874 | #endif |
| 6875 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6876 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6877 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6878 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6879 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6880 | struct cfg80211_connect_params connect; |
| 6881 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6882 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6883 | int err; |
| 6884 | |
| 6885 | memset(&connect, 0, sizeof(connect)); |
| 6886 | |
| 6887 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6888 | return -EINVAL; |
| 6889 | |
| 6890 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6891 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6892 | return -EINVAL; |
| 6893 | |
| 6894 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6895 | connect.auth_type = |
| 6896 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6897 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6898 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6899 | return -EINVAL; |
| 6900 | } else |
| 6901 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6902 | |
| 6903 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6904 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6905 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6906 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6907 | if (err) |
| 6908 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6909 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6910 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6911 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6912 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6913 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6914 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6915 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6916 | connect.bg_scan_period = -1; |
| 6917 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6918 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6919 | connect.bg_scan_period = |
| 6920 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6921 | } |
| 6922 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6923 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6924 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6925 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6926 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6927 | |
| 6928 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6929 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6930 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6931 | } |
| 6932 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6933 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6934 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6935 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6936 | connect.mfp != NL80211_MFP_NO) |
| 6937 | return -EINVAL; |
| 6938 | } else { |
| 6939 | connect.mfp = NL80211_MFP_NO; |
| 6940 | } |
| 6941 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6942 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6943 | connect.channel = |
| 6944 | ieee80211_get_channel(wiphy, |
| 6945 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6946 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6947 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6948 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6949 | } |
| 6950 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6951 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6952 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6953 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6954 | if (IS_ERR(connkeys)) |
| 6955 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6956 | } |
| 6957 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6958 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6959 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6960 | |
| 6961 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6962 | memcpy(&connect.ht_capa_mask, |
| 6963 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6964 | sizeof(connect.ht_capa_mask)); |
| 6965 | |
| 6966 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6967 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6968 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6969 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6970 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6971 | memcpy(&connect.ht_capa, |
| 6972 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6973 | sizeof(connect.ht_capa)); |
| 6974 | } |
| 6975 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6976 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6977 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6978 | |
| 6979 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6980 | memcpy(&connect.vht_capa_mask, |
| 6981 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6982 | sizeof(connect.vht_capa_mask)); |
| 6983 | |
| 6984 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6985 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6986 | kfree(connkeys); |
| 6987 | return -EINVAL; |
| 6988 | } |
| 6989 | memcpy(&connect.vht_capa, |
| 6990 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6991 | sizeof(connect.vht_capa)); |
| 6992 | } |
| 6993 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6994 | wdev_lock(dev->ieee80211_ptr); |
| 6995 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6996 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6997 | if (err) |
| 6998 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6999 | return err; |
| 7000 | } |
| 7001 | |
| 7002 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7003 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7005 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7006 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7007 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7008 | |
| 7009 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7010 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7011 | else |
| 7012 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7013 | |
| 7014 | if (reason == 0) |
| 7015 | return -EINVAL; |
| 7016 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7017 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7018 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7019 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7020 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7021 | wdev_lock(dev->ieee80211_ptr); |
| 7022 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7023 | wdev_unlock(dev->ieee80211_ptr); |
| 7024 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7025 | } |
| 7026 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7027 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7028 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7030 | struct net *net; |
| 7031 | int err; |
| 7032 | u32 pid; |
| 7033 | |
| 7034 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7035 | return -EINVAL; |
| 7036 | |
| 7037 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7038 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7039 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7040 | if (IS_ERR(net)) |
| 7041 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7042 | |
| 7043 | err = 0; |
| 7044 | |
| 7045 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7046 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7047 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7048 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7049 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7050 | return err; |
| 7051 | } |
| 7052 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7053 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7054 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7056 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7057 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7058 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7059 | struct cfg80211_pmksa pmksa; |
| 7060 | |
| 7061 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7062 | |
| 7063 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7064 | return -EINVAL; |
| 7065 | |
| 7066 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7067 | return -EINVAL; |
| 7068 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7069 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7070 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7071 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7072 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7073 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7074 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7075 | |
| 7076 | switch (info->genlhdr->cmd) { |
| 7077 | case NL80211_CMD_SET_PMKSA: |
| 7078 | rdev_ops = rdev->ops->set_pmksa; |
| 7079 | break; |
| 7080 | case NL80211_CMD_DEL_PMKSA: |
| 7081 | rdev_ops = rdev->ops->del_pmksa; |
| 7082 | break; |
| 7083 | default: |
| 7084 | WARN_ON(1); |
| 7085 | break; |
| 7086 | } |
| 7087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7088 | if (!rdev_ops) |
| 7089 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7090 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7091 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7092 | } |
| 7093 | |
| 7094 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7095 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7097 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7098 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7099 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7100 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7101 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7102 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7103 | if (!rdev->ops->flush_pmksa) |
| 7104 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7105 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7106 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7107 | } |
| 7108 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7109 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7110 | { |
| 7111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7112 | struct net_device *dev = info->user_ptr[1]; |
| 7113 | u8 action_code, dialog_token; |
| 7114 | u16 status_code; |
| 7115 | u8 *peer; |
| 7116 | |
| 7117 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7118 | !rdev->ops->tdls_mgmt) |
| 7119 | return -EOPNOTSUPP; |
| 7120 | |
| 7121 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7122 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7123 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7124 | !info->attrs[NL80211_ATTR_IE] || |
| 7125 | !info->attrs[NL80211_ATTR_MAC]) |
| 7126 | return -EINVAL; |
| 7127 | |
| 7128 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7129 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7130 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7131 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7132 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7133 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7134 | dialog_token, status_code, |
| 7135 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7136 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7137 | } |
| 7138 | |
| 7139 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7140 | { |
| 7141 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7142 | struct net_device *dev = info->user_ptr[1]; |
| 7143 | enum nl80211_tdls_operation operation; |
| 7144 | u8 *peer; |
| 7145 | |
| 7146 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7147 | !rdev->ops->tdls_oper) |
| 7148 | return -EOPNOTSUPP; |
| 7149 | |
| 7150 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7151 | !info->attrs[NL80211_ATTR_MAC]) |
| 7152 | return -EINVAL; |
| 7153 | |
| 7154 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7155 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7156 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7157 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7158 | } |
| 7159 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7160 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7161 | struct genl_info *info) |
| 7162 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7163 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7164 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7165 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7166 | struct sk_buff *msg; |
| 7167 | void *hdr; |
| 7168 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7169 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7170 | int err; |
| 7171 | |
| 7172 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7173 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7174 | return -EINVAL; |
| 7175 | |
| 7176 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7177 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7178 | if (!rdev->ops->remain_on_channel || |
| 7179 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7180 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7181 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7182 | /* |
| 7183 | * We should be on that channel for at least a minimum amount of |
| 7184 | * time (10ms) but no longer than the driver supports. |
| 7185 | */ |
| 7186 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7187 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7188 | return -EINVAL; |
| 7189 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7190 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7191 | if (err) |
| 7192 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7193 | |
| 7194 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7195 | if (!msg) |
| 7196 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7197 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7198 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7199 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7200 | if (!hdr) { |
| 7201 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7202 | goto free_msg; |
| 7203 | } |
| 7204 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7205 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7206 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7207 | |
| 7208 | if (err) |
| 7209 | goto free_msg; |
| 7210 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7211 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7212 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7213 | |
| 7214 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7215 | |
| 7216 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7217 | |
| 7218 | nla_put_failure: |
| 7219 | err = -ENOBUFS; |
| 7220 | free_msg: |
| 7221 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7222 | return err; |
| 7223 | } |
| 7224 | |
| 7225 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7226 | struct genl_info *info) |
| 7227 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7229 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7230 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7231 | |
| 7232 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7233 | return -EINVAL; |
| 7234 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7235 | if (!rdev->ops->cancel_remain_on_channel) |
| 7236 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7237 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7238 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7239 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7240 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7241 | } |
| 7242 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7243 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7244 | u8 *rates, u8 rates_len) |
| 7245 | { |
| 7246 | u8 i; |
| 7247 | u32 mask = 0; |
| 7248 | |
| 7249 | for (i = 0; i < rates_len; i++) { |
| 7250 | int rate = (rates[i] & 0x7f) * 5; |
| 7251 | int ridx; |
| 7252 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7253 | struct ieee80211_rate *srate = |
| 7254 | &sband->bitrates[ridx]; |
| 7255 | if (rate == srate->bitrate) { |
| 7256 | mask |= 1 << ridx; |
| 7257 | break; |
| 7258 | } |
| 7259 | } |
| 7260 | if (ridx == sband->n_bitrates) |
| 7261 | return 0; /* rate not found */ |
| 7262 | } |
| 7263 | |
| 7264 | return mask; |
| 7265 | } |
| 7266 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7267 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7268 | u8 *rates, u8 rates_len, |
| 7269 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7270 | { |
| 7271 | u8 i; |
| 7272 | |
| 7273 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7274 | |
| 7275 | for (i = 0; i < rates_len; i++) { |
| 7276 | int ridx, rbit; |
| 7277 | |
| 7278 | ridx = rates[i] / 8; |
| 7279 | rbit = BIT(rates[i] % 8); |
| 7280 | |
| 7281 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7282 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7283 | return false; |
| 7284 | |
| 7285 | /* check availability */ |
| 7286 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7287 | mcs[ridx] |= rbit; |
| 7288 | else |
| 7289 | return false; |
| 7290 | } |
| 7291 | |
| 7292 | return true; |
| 7293 | } |
| 7294 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7295 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7296 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7297 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7298 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7299 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7300 | }; |
| 7301 | |
| 7302 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7303 | struct genl_info *info) |
| 7304 | { |
| 7305 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7307 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7308 | int rem, i; |
| 7309 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7310 | struct nlattr *tx_rates; |
| 7311 | struct ieee80211_supported_band *sband; |
| 7312 | |
| 7313 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7314 | return -EINVAL; |
| 7315 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7316 | if (!rdev->ops->set_bitrate_mask) |
| 7317 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7318 | |
| 7319 | memset(&mask, 0, sizeof(mask)); |
| 7320 | /* Default to all rates enabled */ |
| 7321 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7322 | sband = rdev->wiphy.bands[i]; |
| 7323 | mask.control[i].legacy = |
| 7324 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7325 | if (sband) |
| 7326 | memcpy(mask.control[i].mcs, |
| 7327 | sband->ht_cap.mcs.rx_mask, |
| 7328 | sizeof(mask.control[i].mcs)); |
| 7329 | else |
| 7330 | memset(mask.control[i].mcs, 0, |
| 7331 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | /* |
| 7335 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7336 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7337 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7338 | 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] | 7339 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7340 | { |
| 7341 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7342 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7343 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7344 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7345 | if (sband == NULL) |
| 7346 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7347 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7348 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7349 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7350 | mask.control[band].legacy = rateset_to_mask( |
| 7351 | sband, |
| 7352 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7353 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7354 | if ((mask.control[band].legacy == 0) && |
| 7355 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7356 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7357 | } |
| 7358 | if (tb[NL80211_TXRATE_MCS]) { |
| 7359 | if (!ht_rateset_to_mask( |
| 7360 | sband, |
| 7361 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7362 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7363 | mask.control[band].mcs)) |
| 7364 | return -EINVAL; |
| 7365 | } |
| 7366 | |
| 7367 | if (mask.control[band].legacy == 0) { |
| 7368 | /* don't allow empty legacy rates if HT |
| 7369 | * is not even supported. */ |
| 7370 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7371 | return -EINVAL; |
| 7372 | |
| 7373 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7374 | if (mask.control[band].mcs[i]) |
| 7375 | break; |
| 7376 | |
| 7377 | /* legacy and mcs rates may not be both empty */ |
| 7378 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7379 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7380 | } |
| 7381 | } |
| 7382 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7383 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7384 | } |
| 7385 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7386 | 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] | 7387 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7388 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7389 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7390 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7391 | |
| 7392 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7393 | return -EINVAL; |
| 7394 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7395 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7396 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7397 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7398 | switch (wdev->iftype) { |
| 7399 | case NL80211_IFTYPE_STATION: |
| 7400 | case NL80211_IFTYPE_ADHOC: |
| 7401 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7402 | case NL80211_IFTYPE_AP: |
| 7403 | case NL80211_IFTYPE_AP_VLAN: |
| 7404 | case NL80211_IFTYPE_MESH_POINT: |
| 7405 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7406 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7407 | break; |
| 7408 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7409 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7410 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7411 | |
| 7412 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7413 | if (!rdev->ops->mgmt_tx) |
| 7414 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7415 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7416 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7417 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7418 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7419 | } |
| 7420 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7421 | 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] | 7422 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7423 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7424 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7425 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7426 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7427 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7428 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7429 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7430 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7431 | bool offchan, no_cck, dont_wait_for_ack; |
| 7432 | |
| 7433 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7434 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7435 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7436 | return -EINVAL; |
| 7437 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7438 | if (!rdev->ops->mgmt_tx) |
| 7439 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7440 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7441 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7442 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7443 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7444 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7445 | case NL80211_IFTYPE_STATION: |
| 7446 | case NL80211_IFTYPE_ADHOC: |
| 7447 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7448 | case NL80211_IFTYPE_AP: |
| 7449 | case NL80211_IFTYPE_AP_VLAN: |
| 7450 | case NL80211_IFTYPE_MESH_POINT: |
| 7451 | case NL80211_IFTYPE_P2P_GO: |
| 7452 | break; |
| 7453 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7454 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7455 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7456 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7457 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7458 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7459 | return -EINVAL; |
| 7460 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7461 | |
| 7462 | /* |
| 7463 | * We should wait on the channel for at least a minimum amount |
| 7464 | * of time (10ms) but no longer than the driver supports. |
| 7465 | */ |
| 7466 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7467 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7468 | return -EINVAL; |
| 7469 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7470 | } |
| 7471 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7472 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7473 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7474 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7475 | return -EINVAL; |
| 7476 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7477 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7478 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7479 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7480 | * the driver. The latter will use the current one |
| 7481 | */ |
| 7482 | chandef.chan = NULL; |
| 7483 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7484 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7485 | if (err) |
| 7486 | return err; |
| 7487 | } |
| 7488 | |
| 7489 | if (!chandef.chan && offchan) |
| 7490 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7491 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7492 | if (!dont_wait_for_ack) { |
| 7493 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7494 | if (!msg) |
| 7495 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7496 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7497 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7498 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7499 | if (!hdr) { |
| 7500 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7501 | goto free_msg; |
| 7502 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7503 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7504 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7505 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7506 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7507 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7508 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7509 | if (err) |
| 7510 | goto free_msg; |
| 7511 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7512 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7513 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7514 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7515 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7516 | genlmsg_end(msg, hdr); |
| 7517 | return genlmsg_reply(msg, info); |
| 7518 | } |
| 7519 | |
| 7520 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7521 | |
| 7522 | nla_put_failure: |
| 7523 | err = -ENOBUFS; |
| 7524 | free_msg: |
| 7525 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7526 | return err; |
| 7527 | } |
| 7528 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7529 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7530 | { |
| 7531 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7532 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7533 | u64 cookie; |
| 7534 | |
| 7535 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7536 | return -EINVAL; |
| 7537 | |
| 7538 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7539 | return -EOPNOTSUPP; |
| 7540 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7541 | switch (wdev->iftype) { |
| 7542 | case NL80211_IFTYPE_STATION: |
| 7543 | case NL80211_IFTYPE_ADHOC: |
| 7544 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7545 | case NL80211_IFTYPE_AP: |
| 7546 | case NL80211_IFTYPE_AP_VLAN: |
| 7547 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7548 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7549 | break; |
| 7550 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7551 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7552 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7553 | |
| 7554 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7555 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7556 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7557 | } |
| 7558 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7559 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7560 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7561 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7562 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7563 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7564 | u8 ps_state; |
| 7565 | bool state; |
| 7566 | int err; |
| 7567 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7568 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7569 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7570 | |
| 7571 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7572 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7573 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7574 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7575 | |
| 7576 | wdev = dev->ieee80211_ptr; |
| 7577 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7578 | if (!rdev->ops->set_power_mgmt) |
| 7579 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7580 | |
| 7581 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7582 | |
| 7583 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7584 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7585 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7586 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7587 | if (!err) |
| 7588 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7589 | return err; |
| 7590 | } |
| 7591 | |
| 7592 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7593 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7594 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7595 | enum nl80211_ps_state ps_state; |
| 7596 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7597 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7598 | struct sk_buff *msg; |
| 7599 | void *hdr; |
| 7600 | int err; |
| 7601 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7602 | wdev = dev->ieee80211_ptr; |
| 7603 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7604 | if (!rdev->ops->set_power_mgmt) |
| 7605 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7606 | |
| 7607 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7608 | if (!msg) |
| 7609 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7610 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7611 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7612 | NL80211_CMD_GET_POWER_SAVE); |
| 7613 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7614 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7615 | goto free_msg; |
| 7616 | } |
| 7617 | |
| 7618 | if (wdev->ps) |
| 7619 | ps_state = NL80211_PS_ENABLED; |
| 7620 | else |
| 7621 | ps_state = NL80211_PS_DISABLED; |
| 7622 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7623 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7624 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7625 | |
| 7626 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7627 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7628 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7629 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7630 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7631 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7632 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7633 | return err; |
| 7634 | } |
| 7635 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7636 | static struct nla_policy |
| 7637 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7638 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7639 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7640 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7641 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7642 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7643 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7644 | }; |
| 7645 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7646 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7647 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7648 | { |
| 7649 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7650 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7651 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7652 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7653 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7654 | return -EINVAL; |
| 7655 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7656 | if (!rdev->ops->set_cqm_txe_config) |
| 7657 | return -EOPNOTSUPP; |
| 7658 | |
| 7659 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7660 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7661 | return -EOPNOTSUPP; |
| 7662 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7663 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7664 | } |
| 7665 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7666 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7667 | s32 threshold, u32 hysteresis) |
| 7668 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7670 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7671 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7672 | |
| 7673 | if (threshold > 0) |
| 7674 | return -EINVAL; |
| 7675 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7676 | /* disabling - hysteresis should also be zero then */ |
| 7677 | if (threshold == 0) |
| 7678 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7680 | if (!rdev->ops->set_cqm_rssi_config) |
| 7681 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7682 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7683 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7684 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7685 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7686 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7687 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7688 | } |
| 7689 | |
| 7690 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7691 | { |
| 7692 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7693 | struct nlattr *cqm; |
| 7694 | int err; |
| 7695 | |
| 7696 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7697 | if (!cqm) |
| 7698 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7699 | |
| 7700 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7701 | nl80211_attr_cqm_policy); |
| 7702 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7703 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7704 | |
| 7705 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7706 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7707 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7708 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7709 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7710 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7711 | } |
| 7712 | |
| 7713 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7714 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7715 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7716 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7717 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7718 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7719 | |
| 7720 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7721 | } |
| 7722 | |
| 7723 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7724 | } |
| 7725 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7726 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7727 | { |
| 7728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7729 | struct net_device *dev = info->user_ptr[1]; |
| 7730 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7731 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7732 | int err; |
| 7733 | |
| 7734 | /* start with default */ |
| 7735 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7736 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7737 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7738 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7739 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7740 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7741 | if (err) |
| 7742 | return err; |
| 7743 | } |
| 7744 | |
| 7745 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7746 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7747 | return -EINVAL; |
| 7748 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7749 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7750 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7751 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7752 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7753 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7754 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7755 | return -EINVAL; |
| 7756 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7757 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7758 | setup.beacon_interval = |
| 7759 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7760 | if (setup.beacon_interval < 10 || |
| 7761 | setup.beacon_interval > 10000) |
| 7762 | return -EINVAL; |
| 7763 | } |
| 7764 | |
| 7765 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7766 | setup.dtim_period = |
| 7767 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7768 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7769 | return -EINVAL; |
| 7770 | } |
| 7771 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7772 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7773 | /* parse additional setup parameters if given */ |
| 7774 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7775 | if (err) |
| 7776 | return err; |
| 7777 | } |
| 7778 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7779 | if (setup.user_mpm) |
| 7780 | cfg.auto_open_plinks = false; |
| 7781 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7782 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7783 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7784 | if (err) |
| 7785 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7786 | } else { |
| 7787 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7788 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7789 | } |
| 7790 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7791 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7792 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7793 | int n_rates = |
| 7794 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7795 | struct ieee80211_supported_band *sband; |
| 7796 | |
| 7797 | if (!setup.chandef.chan) |
| 7798 | return -EINVAL; |
| 7799 | |
| 7800 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7801 | |
| 7802 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7803 | &setup.basic_rates); |
| 7804 | if (err) |
| 7805 | return err; |
| 7806 | } |
| 7807 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7808 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7809 | } |
| 7810 | |
| 7811 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7812 | { |
| 7813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7814 | struct net_device *dev = info->user_ptr[1]; |
| 7815 | |
| 7816 | return cfg80211_leave_mesh(rdev, dev); |
| 7817 | } |
| 7818 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7819 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7820 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7821 | struct cfg80211_registered_device *rdev) |
| 7822 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7823 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7824 | struct nlattr *nl_pats, *nl_pat; |
| 7825 | int i, pat_len; |
| 7826 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7827 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7828 | return 0; |
| 7829 | |
| 7830 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7831 | if (!nl_pats) |
| 7832 | return -ENOBUFS; |
| 7833 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7834 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7835 | nl_pat = nla_nest_start(msg, i + 1); |
| 7836 | if (!nl_pat) |
| 7837 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7838 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7839 | 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] | 7840 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7841 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7842 | wowlan->patterns[i].pattern) || |
| 7843 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7844 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7845 | return -ENOBUFS; |
| 7846 | nla_nest_end(msg, nl_pat); |
| 7847 | } |
| 7848 | nla_nest_end(msg, nl_pats); |
| 7849 | |
| 7850 | return 0; |
| 7851 | } |
| 7852 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7853 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7854 | struct cfg80211_wowlan_tcp *tcp) |
| 7855 | { |
| 7856 | struct nlattr *nl_tcp; |
| 7857 | |
| 7858 | if (!tcp) |
| 7859 | return 0; |
| 7860 | |
| 7861 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7862 | if (!nl_tcp) |
| 7863 | return -ENOBUFS; |
| 7864 | |
| 7865 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7866 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7867 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7868 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7869 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7870 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7871 | tcp->payload_len, tcp->payload) || |
| 7872 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7873 | tcp->data_interval) || |
| 7874 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7875 | tcp->wake_len, tcp->wake_data) || |
| 7876 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7877 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7878 | return -ENOBUFS; |
| 7879 | |
| 7880 | if (tcp->payload_seq.len && |
| 7881 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7882 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7883 | return -ENOBUFS; |
| 7884 | |
| 7885 | if (tcp->payload_tok.len && |
| 7886 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7887 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7888 | &tcp->payload_tok)) |
| 7889 | return -ENOBUFS; |
| 7890 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7891 | nla_nest_end(msg, nl_tcp); |
| 7892 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7893 | return 0; |
| 7894 | } |
| 7895 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7896 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7897 | { |
| 7898 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7899 | struct sk_buff *msg; |
| 7900 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7901 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7902 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7903 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7904 | return -EOPNOTSUPP; |
| 7905 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7906 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7907 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7908 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7909 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7910 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7911 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7912 | } |
| 7913 | |
| 7914 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7915 | if (!msg) |
| 7916 | return -ENOMEM; |
| 7917 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7918 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7919 | NL80211_CMD_GET_WOWLAN); |
| 7920 | if (!hdr) |
| 7921 | goto nla_put_failure; |
| 7922 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7923 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7924 | struct nlattr *nl_wowlan; |
| 7925 | |
| 7926 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7927 | if (!nl_wowlan) |
| 7928 | goto nla_put_failure; |
| 7929 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7930 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7931 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7932 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7933 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7934 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7935 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7936 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7937 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7938 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7939 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7940 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7941 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7942 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7943 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7944 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7945 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7946 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7947 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7948 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7949 | if (nl80211_send_wowlan_tcp(msg, |
| 7950 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7951 | goto nla_put_failure; |
| 7952 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7953 | nla_nest_end(msg, nl_wowlan); |
| 7954 | } |
| 7955 | |
| 7956 | genlmsg_end(msg, hdr); |
| 7957 | return genlmsg_reply(msg, info); |
| 7958 | |
| 7959 | nla_put_failure: |
| 7960 | nlmsg_free(msg); |
| 7961 | return -ENOBUFS; |
| 7962 | } |
| 7963 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7964 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7965 | struct nlattr *attr, |
| 7966 | struct cfg80211_wowlan *trig) |
| 7967 | { |
| 7968 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7969 | struct cfg80211_wowlan_tcp *cfg; |
| 7970 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7971 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7972 | u32 size; |
| 7973 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7974 | int err, port; |
| 7975 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7976 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7977 | return -EINVAL; |
| 7978 | |
| 7979 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7980 | nla_data(attr), nla_len(attr), |
| 7981 | nl80211_wowlan_tcp_policy); |
| 7982 | if (err) |
| 7983 | return err; |
| 7984 | |
| 7985 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7986 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7987 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7988 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7989 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7990 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7991 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7992 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7993 | return -EINVAL; |
| 7994 | |
| 7995 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7996 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7997 | return -EINVAL; |
| 7998 | |
| 7999 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8000 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8001 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8002 | return -EINVAL; |
| 8003 | |
| 8004 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8005 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8006 | return -EINVAL; |
| 8007 | |
| 8008 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8009 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8010 | return -EINVAL; |
| 8011 | |
| 8012 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8013 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8014 | |
| 8015 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8016 | tokens_size = tokln - sizeof(*tok); |
| 8017 | |
| 8018 | if (!tok->len || tokens_size % tok->len) |
| 8019 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8020 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8021 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8022 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8023 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8024 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8025 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8026 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8027 | return -EINVAL; |
| 8028 | if (tok->offset + tok->len > data_size) |
| 8029 | return -EINVAL; |
| 8030 | } |
| 8031 | |
| 8032 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8033 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8034 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8035 | return -EINVAL; |
| 8036 | if (seq->len == 0 || seq->len > 4) |
| 8037 | return -EINVAL; |
| 8038 | if (seq->len + seq->offset > data_size) |
| 8039 | return -EINVAL; |
| 8040 | } |
| 8041 | |
| 8042 | size = sizeof(*cfg); |
| 8043 | size += data_size; |
| 8044 | size += wake_size + wake_mask_size; |
| 8045 | size += tokens_size; |
| 8046 | |
| 8047 | cfg = kzalloc(size, GFP_KERNEL); |
| 8048 | if (!cfg) |
| 8049 | return -ENOMEM; |
| 8050 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8051 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8052 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8053 | ETH_ALEN); |
| 8054 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8055 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8056 | else |
| 8057 | port = 0; |
| 8058 | #ifdef CONFIG_INET |
| 8059 | /* allocate a socket and port for it and use it */ |
| 8060 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8061 | IPPROTO_TCP, &cfg->sock, 1); |
| 8062 | if (err) { |
| 8063 | kfree(cfg); |
| 8064 | return err; |
| 8065 | } |
| 8066 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8067 | sock_release(cfg->sock); |
| 8068 | kfree(cfg); |
| 8069 | return -EADDRINUSE; |
| 8070 | } |
| 8071 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8072 | #else |
| 8073 | if (!port) { |
| 8074 | kfree(cfg); |
| 8075 | return -EINVAL; |
| 8076 | } |
| 8077 | cfg->src_port = port; |
| 8078 | #endif |
| 8079 | |
| 8080 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8081 | cfg->payload_len = data_size; |
| 8082 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8083 | memcpy((void *)cfg->payload, |
| 8084 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8085 | data_size); |
| 8086 | if (seq) |
| 8087 | cfg->payload_seq = *seq; |
| 8088 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8089 | cfg->wake_len = wake_size; |
| 8090 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8091 | memcpy((void *)cfg->wake_data, |
| 8092 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8093 | wake_size); |
| 8094 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8095 | data_size + wake_size; |
| 8096 | memcpy((void *)cfg->wake_mask, |
| 8097 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8098 | wake_mask_size); |
| 8099 | if (tok) { |
| 8100 | cfg->tokens_size = tokens_size; |
| 8101 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8102 | } |
| 8103 | |
| 8104 | trig->tcp = cfg; |
| 8105 | |
| 8106 | return 0; |
| 8107 | } |
| 8108 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8109 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8110 | { |
| 8111 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8112 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8113 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8114 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8115 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8116 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8117 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8118 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8119 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8120 | return -EOPNOTSUPP; |
| 8121 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8122 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8123 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8124 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8125 | goto set_wakeup; |
| 8126 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8127 | |
| 8128 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8129 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8130 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8131 | nl80211_wowlan_policy); |
| 8132 | if (err) |
| 8133 | return err; |
| 8134 | |
| 8135 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8136 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8137 | return -EINVAL; |
| 8138 | new_triggers.any = true; |
| 8139 | } |
| 8140 | |
| 8141 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8142 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8143 | return -EINVAL; |
| 8144 | new_triggers.disconnect = true; |
| 8145 | } |
| 8146 | |
| 8147 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8148 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8149 | return -EINVAL; |
| 8150 | new_triggers.magic_pkt = true; |
| 8151 | } |
| 8152 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8153 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8154 | return -EINVAL; |
| 8155 | |
| 8156 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8157 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8158 | return -EINVAL; |
| 8159 | new_triggers.gtk_rekey_failure = true; |
| 8160 | } |
| 8161 | |
| 8162 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8163 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8164 | return -EINVAL; |
| 8165 | new_triggers.eap_identity_req = true; |
| 8166 | } |
| 8167 | |
| 8168 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8169 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8170 | return -EINVAL; |
| 8171 | new_triggers.four_way_handshake = true; |
| 8172 | } |
| 8173 | |
| 8174 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8175 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8176 | return -EINVAL; |
| 8177 | new_triggers.rfkill_release = true; |
| 8178 | } |
| 8179 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8180 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8181 | struct nlattr *pat; |
| 8182 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8183 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8184 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8185 | |
| 8186 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8187 | rem) |
| 8188 | n_patterns++; |
| 8189 | if (n_patterns > wowlan->n_patterns) |
| 8190 | return -EINVAL; |
| 8191 | |
| 8192 | new_triggers.patterns = kcalloc(n_patterns, |
| 8193 | sizeof(new_triggers.patterns[0]), |
| 8194 | GFP_KERNEL); |
| 8195 | if (!new_triggers.patterns) |
| 8196 | return -ENOMEM; |
| 8197 | |
| 8198 | new_triggers.n_patterns = n_patterns; |
| 8199 | i = 0; |
| 8200 | |
| 8201 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8202 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8203 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8204 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8205 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8206 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8207 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8208 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8209 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8210 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8211 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8212 | goto error; |
| 8213 | if (pat_len > wowlan->pattern_max_len || |
| 8214 | pat_len < wowlan->pattern_min_len) |
| 8215 | goto error; |
| 8216 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8217 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8218 | pkt_offset = 0; |
| 8219 | else |
| 8220 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8221 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8222 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8223 | goto error; |
| 8224 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8225 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8226 | new_triggers.patterns[i].mask = |
| 8227 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8228 | if (!new_triggers.patterns[i].mask) { |
| 8229 | err = -ENOMEM; |
| 8230 | goto error; |
| 8231 | } |
| 8232 | new_triggers.patterns[i].pattern = |
| 8233 | new_triggers.patterns[i].mask + mask_len; |
| 8234 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8235 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8236 | mask_len); |
| 8237 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8238 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8239 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8240 | pat_len); |
| 8241 | i++; |
| 8242 | } |
| 8243 | } |
| 8244 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8245 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8246 | err = nl80211_parse_wowlan_tcp( |
| 8247 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8248 | &new_triggers); |
| 8249 | if (err) |
| 8250 | goto error; |
| 8251 | } |
| 8252 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8253 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8254 | if (!ntrig) { |
| 8255 | err = -ENOMEM; |
| 8256 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8257 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8258 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8259 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8260 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8261 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8262 | if (rdev->ops->set_wakeup && |
| 8263 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8264 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8265 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8266 | return 0; |
| 8267 | error: |
| 8268 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8269 | kfree(new_triggers.patterns[i].mask); |
| 8270 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8271 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8272 | sock_release(new_triggers.tcp->sock); |
| 8273 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8274 | return err; |
| 8275 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8276 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8277 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8278 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8279 | struct cfg80211_registered_device *rdev) |
| 8280 | { |
| 8281 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8282 | int i, j, pat_len; |
| 8283 | struct cfg80211_coalesce_rules *rule; |
| 8284 | |
| 8285 | if (!rdev->coalesce->n_rules) |
| 8286 | return 0; |
| 8287 | |
| 8288 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8289 | if (!nl_rules) |
| 8290 | return -ENOBUFS; |
| 8291 | |
| 8292 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8293 | nl_rule = nla_nest_start(msg, i + 1); |
| 8294 | if (!nl_rule) |
| 8295 | return -ENOBUFS; |
| 8296 | |
| 8297 | rule = &rdev->coalesce->rules[i]; |
| 8298 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8299 | rule->delay)) |
| 8300 | return -ENOBUFS; |
| 8301 | |
| 8302 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8303 | rule->condition)) |
| 8304 | return -ENOBUFS; |
| 8305 | |
| 8306 | nl_pats = nla_nest_start(msg, |
| 8307 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8308 | if (!nl_pats) |
| 8309 | return -ENOBUFS; |
| 8310 | |
| 8311 | for (j = 0; j < rule->n_patterns; j++) { |
| 8312 | nl_pat = nla_nest_start(msg, j + 1); |
| 8313 | if (!nl_pat) |
| 8314 | return -ENOBUFS; |
| 8315 | pat_len = rule->patterns[j].pattern_len; |
| 8316 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8317 | DIV_ROUND_UP(pat_len, 8), |
| 8318 | rule->patterns[j].mask) || |
| 8319 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8320 | rule->patterns[j].pattern) || |
| 8321 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8322 | rule->patterns[j].pkt_offset)) |
| 8323 | return -ENOBUFS; |
| 8324 | nla_nest_end(msg, nl_pat); |
| 8325 | } |
| 8326 | nla_nest_end(msg, nl_pats); |
| 8327 | nla_nest_end(msg, nl_rule); |
| 8328 | } |
| 8329 | nla_nest_end(msg, nl_rules); |
| 8330 | |
| 8331 | return 0; |
| 8332 | } |
| 8333 | |
| 8334 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8335 | { |
| 8336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8337 | struct sk_buff *msg; |
| 8338 | void *hdr; |
| 8339 | |
| 8340 | if (!rdev->wiphy.coalesce) |
| 8341 | return -EOPNOTSUPP; |
| 8342 | |
| 8343 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8344 | if (!msg) |
| 8345 | return -ENOMEM; |
| 8346 | |
| 8347 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8348 | NL80211_CMD_GET_COALESCE); |
| 8349 | if (!hdr) |
| 8350 | goto nla_put_failure; |
| 8351 | |
| 8352 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8353 | goto nla_put_failure; |
| 8354 | |
| 8355 | genlmsg_end(msg, hdr); |
| 8356 | return genlmsg_reply(msg, info); |
| 8357 | |
| 8358 | nla_put_failure: |
| 8359 | nlmsg_free(msg); |
| 8360 | return -ENOBUFS; |
| 8361 | } |
| 8362 | |
| 8363 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8364 | { |
| 8365 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8366 | int i, j; |
| 8367 | struct cfg80211_coalesce_rules *rule; |
| 8368 | |
| 8369 | if (!coalesce) |
| 8370 | return; |
| 8371 | |
| 8372 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8373 | rule = &coalesce->rules[i]; |
| 8374 | for (j = 0; j < rule->n_patterns; j++) |
| 8375 | kfree(rule->patterns[j].mask); |
| 8376 | kfree(rule->patterns); |
| 8377 | } |
| 8378 | kfree(coalesce->rules); |
| 8379 | kfree(coalesce); |
| 8380 | rdev->coalesce = NULL; |
| 8381 | } |
| 8382 | |
| 8383 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8384 | struct nlattr *rule, |
| 8385 | struct cfg80211_coalesce_rules *new_rule) |
| 8386 | { |
| 8387 | int err, i; |
| 8388 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8389 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8390 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8391 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8392 | |
| 8393 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8394 | nla_len(rule), nl80211_coalesce_policy); |
| 8395 | if (err) |
| 8396 | return err; |
| 8397 | |
| 8398 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8399 | new_rule->delay = |
| 8400 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8401 | if (new_rule->delay > coalesce->max_delay) |
| 8402 | return -EINVAL; |
| 8403 | |
| 8404 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8405 | new_rule->condition = |
| 8406 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8407 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8408 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8409 | return -EINVAL; |
| 8410 | |
| 8411 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8412 | return -EINVAL; |
| 8413 | |
| 8414 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8415 | rem) |
| 8416 | n_patterns++; |
| 8417 | if (n_patterns > coalesce->n_patterns) |
| 8418 | return -EINVAL; |
| 8419 | |
| 8420 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8421 | GFP_KERNEL); |
| 8422 | if (!new_rule->patterns) |
| 8423 | return -ENOMEM; |
| 8424 | |
| 8425 | new_rule->n_patterns = n_patterns; |
| 8426 | i = 0; |
| 8427 | |
| 8428 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8429 | rem) { |
| 8430 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8431 | nla_len(pat), NULL); |
| 8432 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8433 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8434 | return -EINVAL; |
| 8435 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8436 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8437 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8438 | return -EINVAL; |
| 8439 | if (pat_len > coalesce->pattern_max_len || |
| 8440 | pat_len < coalesce->pattern_min_len) |
| 8441 | return -EINVAL; |
| 8442 | |
| 8443 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8444 | pkt_offset = 0; |
| 8445 | else |
| 8446 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8447 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8448 | return -EINVAL; |
| 8449 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8450 | |
| 8451 | new_rule->patterns[i].mask = |
| 8452 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8453 | if (!new_rule->patterns[i].mask) |
| 8454 | return -ENOMEM; |
| 8455 | new_rule->patterns[i].pattern = |
| 8456 | new_rule->patterns[i].mask + mask_len; |
| 8457 | memcpy(new_rule->patterns[i].mask, |
| 8458 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8459 | new_rule->patterns[i].pattern_len = pat_len; |
| 8460 | memcpy(new_rule->patterns[i].pattern, |
| 8461 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8462 | i++; |
| 8463 | } |
| 8464 | |
| 8465 | return 0; |
| 8466 | } |
| 8467 | |
| 8468 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8469 | { |
| 8470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8471 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8472 | struct cfg80211_coalesce new_coalesce = {}; |
| 8473 | struct cfg80211_coalesce *n_coalesce; |
| 8474 | int err, rem_rule, n_rules = 0, i, j; |
| 8475 | struct nlattr *rule; |
| 8476 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8477 | |
| 8478 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8479 | return -EOPNOTSUPP; |
| 8480 | |
| 8481 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8482 | cfg80211_rdev_free_coalesce(rdev); |
| 8483 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8484 | return 0; |
| 8485 | } |
| 8486 | |
| 8487 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8488 | rem_rule) |
| 8489 | n_rules++; |
| 8490 | if (n_rules > coalesce->n_rules) |
| 8491 | return -EINVAL; |
| 8492 | |
| 8493 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8494 | GFP_KERNEL); |
| 8495 | if (!new_coalesce.rules) |
| 8496 | return -ENOMEM; |
| 8497 | |
| 8498 | new_coalesce.n_rules = n_rules; |
| 8499 | i = 0; |
| 8500 | |
| 8501 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8502 | rem_rule) { |
| 8503 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8504 | &new_coalesce.rules[i]); |
| 8505 | if (err) |
| 8506 | goto error; |
| 8507 | |
| 8508 | i++; |
| 8509 | } |
| 8510 | |
| 8511 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8512 | if (err) |
| 8513 | goto error; |
| 8514 | |
| 8515 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8516 | if (!n_coalesce) { |
| 8517 | err = -ENOMEM; |
| 8518 | goto error; |
| 8519 | } |
| 8520 | cfg80211_rdev_free_coalesce(rdev); |
| 8521 | rdev->coalesce = n_coalesce; |
| 8522 | |
| 8523 | return 0; |
| 8524 | error: |
| 8525 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8526 | tmp_rule = &new_coalesce.rules[i]; |
| 8527 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8528 | kfree(tmp_rule->patterns[j].mask); |
| 8529 | kfree(tmp_rule->patterns); |
| 8530 | } |
| 8531 | kfree(new_coalesce.rules); |
| 8532 | |
| 8533 | return err; |
| 8534 | } |
| 8535 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8536 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8537 | { |
| 8538 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8539 | struct net_device *dev = info->user_ptr[1]; |
| 8540 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8541 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8542 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8543 | int err; |
| 8544 | |
| 8545 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8546 | return -EINVAL; |
| 8547 | |
| 8548 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8549 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8550 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8551 | nl80211_rekey_policy); |
| 8552 | if (err) |
| 8553 | return err; |
| 8554 | |
| 8555 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8556 | return -ERANGE; |
| 8557 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8558 | return -ERANGE; |
| 8559 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8560 | return -ERANGE; |
| 8561 | |
| 8562 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8563 | NL80211_KEK_LEN); |
| 8564 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8565 | NL80211_KCK_LEN); |
| 8566 | memcpy(rekey_data.replay_ctr, |
| 8567 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8568 | NL80211_REPLAY_CTR_LEN); |
| 8569 | |
| 8570 | wdev_lock(wdev); |
| 8571 | if (!wdev->current_bss) { |
| 8572 | err = -ENOTCONN; |
| 8573 | goto out; |
| 8574 | } |
| 8575 | |
| 8576 | if (!rdev->ops->set_rekey_data) { |
| 8577 | err = -EOPNOTSUPP; |
| 8578 | goto out; |
| 8579 | } |
| 8580 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8581 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8582 | out: |
| 8583 | wdev_unlock(wdev); |
| 8584 | return err; |
| 8585 | } |
| 8586 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8587 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8588 | struct genl_info *info) |
| 8589 | { |
| 8590 | struct net_device *dev = info->user_ptr[1]; |
| 8591 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8592 | |
| 8593 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8594 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8595 | return -EINVAL; |
| 8596 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8597 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8598 | return -EBUSY; |
| 8599 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8600 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8601 | return 0; |
| 8602 | } |
| 8603 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8604 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8605 | struct genl_info *info) |
| 8606 | { |
| 8607 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8608 | struct net_device *dev = info->user_ptr[1]; |
| 8609 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8610 | struct sk_buff *msg; |
| 8611 | void *hdr; |
| 8612 | const u8 *addr; |
| 8613 | u64 cookie; |
| 8614 | int err; |
| 8615 | |
| 8616 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8617 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8618 | return -EOPNOTSUPP; |
| 8619 | |
| 8620 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8621 | return -EINVAL; |
| 8622 | |
| 8623 | if (!rdev->ops->probe_client) |
| 8624 | return -EOPNOTSUPP; |
| 8625 | |
| 8626 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8627 | if (!msg) |
| 8628 | return -ENOMEM; |
| 8629 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8630 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8631 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8632 | if (!hdr) { |
| 8633 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8634 | goto free_msg; |
| 8635 | } |
| 8636 | |
| 8637 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8638 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8639 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8640 | if (err) |
| 8641 | goto free_msg; |
| 8642 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8643 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8644 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8645 | |
| 8646 | genlmsg_end(msg, hdr); |
| 8647 | |
| 8648 | return genlmsg_reply(msg, info); |
| 8649 | |
| 8650 | nla_put_failure: |
| 8651 | err = -ENOBUFS; |
| 8652 | free_msg: |
| 8653 | nlmsg_free(msg); |
| 8654 | return err; |
| 8655 | } |
| 8656 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8657 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8658 | { |
| 8659 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8660 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8661 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8662 | |
| 8663 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8664 | return -EOPNOTSUPP; |
| 8665 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8666 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8667 | if (!nreg) |
| 8668 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8669 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8670 | /* First, check if already registered. */ |
| 8671 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8672 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8673 | if (reg->nlportid == info->snd_portid) { |
| 8674 | rv = -EALREADY; |
| 8675 | goto out_err; |
| 8676 | } |
| 8677 | } |
| 8678 | /* Add it to the list */ |
| 8679 | nreg->nlportid = info->snd_portid; |
| 8680 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8681 | |
| 8682 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8683 | |
| 8684 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8685 | out_err: |
| 8686 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8687 | kfree(nreg); |
| 8688 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8689 | } |
| 8690 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8691 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8692 | { |
| 8693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8694 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8695 | int err; |
| 8696 | |
| 8697 | if (!rdev->ops->start_p2p_device) |
| 8698 | return -EOPNOTSUPP; |
| 8699 | |
| 8700 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8701 | return -EOPNOTSUPP; |
| 8702 | |
| 8703 | if (wdev->p2p_started) |
| 8704 | return 0; |
| 8705 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8706 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8707 | if (err) |
| 8708 | return err; |
| 8709 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8710 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8711 | if (err) |
| 8712 | return err; |
| 8713 | |
| 8714 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8715 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8716 | |
| 8717 | return 0; |
| 8718 | } |
| 8719 | |
| 8720 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8721 | { |
| 8722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8723 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8724 | |
| 8725 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8726 | return -EOPNOTSUPP; |
| 8727 | |
| 8728 | if (!rdev->ops->stop_p2p_device) |
| 8729 | return -EOPNOTSUPP; |
| 8730 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8731 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8732 | |
| 8733 | return 0; |
| 8734 | } |
| 8735 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8736 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8737 | struct genl_info *info) |
| 8738 | { |
| 8739 | void *hdr; |
| 8740 | struct sk_buff *msg; |
| 8741 | |
| 8742 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8743 | if (!msg) |
| 8744 | return -ENOMEM; |
| 8745 | |
| 8746 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8747 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8748 | if (!hdr) |
| 8749 | goto nla_put_failure; |
| 8750 | |
| 8751 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8752 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8753 | goto nla_put_failure; |
| 8754 | |
| 8755 | genlmsg_end(msg, hdr); |
| 8756 | return genlmsg_reply(msg, info); |
| 8757 | |
| 8758 | nla_put_failure: |
| 8759 | kfree_skb(msg); |
| 8760 | return -ENOBUFS; |
| 8761 | } |
| 8762 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8763 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8764 | { |
| 8765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8766 | struct cfg80211_update_ft_ies_params ft_params; |
| 8767 | struct net_device *dev = info->user_ptr[1]; |
| 8768 | |
| 8769 | if (!rdev->ops->update_ft_ies) |
| 8770 | return -EOPNOTSUPP; |
| 8771 | |
| 8772 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8773 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8774 | return -EINVAL; |
| 8775 | |
| 8776 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8777 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8778 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8779 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8780 | |
| 8781 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8782 | } |
| 8783 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8784 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8785 | struct genl_info *info) |
| 8786 | { |
| 8787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8788 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8789 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8790 | u16 duration; |
| 8791 | int ret; |
| 8792 | |
| 8793 | if (!rdev->ops->crit_proto_start) |
| 8794 | return -EOPNOTSUPP; |
| 8795 | |
| 8796 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8797 | return -EINVAL; |
| 8798 | |
| 8799 | if (rdev->crit_proto_nlportid) |
| 8800 | return -EBUSY; |
| 8801 | |
| 8802 | /* determine protocol if provided */ |
| 8803 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8804 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8805 | |
| 8806 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8807 | return -EINVAL; |
| 8808 | |
| 8809 | /* timeout must be provided */ |
| 8810 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8811 | return -EINVAL; |
| 8812 | |
| 8813 | duration = |
| 8814 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8815 | |
| 8816 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8817 | return -ERANGE; |
| 8818 | |
| 8819 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8820 | if (!ret) |
| 8821 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8822 | |
| 8823 | return ret; |
| 8824 | } |
| 8825 | |
| 8826 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8827 | struct genl_info *info) |
| 8828 | { |
| 8829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8830 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8831 | |
| 8832 | if (!rdev->ops->crit_proto_stop) |
| 8833 | return -EOPNOTSUPP; |
| 8834 | |
| 8835 | if (rdev->crit_proto_nlportid) { |
| 8836 | rdev->crit_proto_nlportid = 0; |
| 8837 | rdev_crit_proto_stop(rdev, wdev); |
| 8838 | } |
| 8839 | return 0; |
| 8840 | } |
| 8841 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8842 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8843 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8844 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8845 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8846 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8847 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8848 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8849 | /* 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] | 8850 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8851 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8852 | |
| 8853 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8854 | struct genl_info *info) |
| 8855 | { |
| 8856 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8857 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8858 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8859 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8860 | |
| 8861 | if (rtnl) |
| 8862 | rtnl_lock(); |
| 8863 | |
| 8864 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8865 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8866 | if (IS_ERR(rdev)) { |
| 8867 | if (rtnl) |
| 8868 | rtnl_unlock(); |
| 8869 | return PTR_ERR(rdev); |
| 8870 | } |
| 8871 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8872 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8873 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8874 | ASSERT_RTNL(); |
| 8875 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8876 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8877 | info->attrs); |
| 8878 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8879 | if (rtnl) |
| 8880 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8881 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8882 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8883 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8884 | dev = wdev->netdev; |
| 8885 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8886 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8887 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8888 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8889 | if (rtnl) |
| 8890 | rtnl_unlock(); |
| 8891 | return -EINVAL; |
| 8892 | } |
| 8893 | |
| 8894 | info->user_ptr[1] = dev; |
| 8895 | } else { |
| 8896 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8897 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8898 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8899 | if (dev) { |
| 8900 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8901 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8902 | if (rtnl) |
| 8903 | rtnl_unlock(); |
| 8904 | return -ENETDOWN; |
| 8905 | } |
| 8906 | |
| 8907 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8908 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8909 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8910 | if (rtnl) |
| 8911 | rtnl_unlock(); |
| 8912 | return -ENETDOWN; |
| 8913 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8914 | } |
| 8915 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8916 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8917 | } |
| 8918 | |
| 8919 | return 0; |
| 8920 | } |
| 8921 | |
| 8922 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8923 | struct genl_info *info) |
| 8924 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8925 | if (info->user_ptr[1]) { |
| 8926 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8927 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8928 | |
| 8929 | if (wdev->netdev) |
| 8930 | dev_put(wdev->netdev); |
| 8931 | } else { |
| 8932 | dev_put(info->user_ptr[1]); |
| 8933 | } |
| 8934 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8935 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8936 | rtnl_unlock(); |
| 8937 | } |
| 8938 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8939 | static struct genl_ops nl80211_ops[] = { |
| 8940 | { |
| 8941 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8942 | .doit = nl80211_get_wiphy, |
| 8943 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 8944 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8945 | .policy = nl80211_policy, |
| 8946 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8947 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8948 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8949 | }, |
| 8950 | { |
| 8951 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8952 | .doit = nl80211_set_wiphy, |
| 8953 | .policy = nl80211_policy, |
| 8954 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8955 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8956 | }, |
| 8957 | { |
| 8958 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8959 | .doit = nl80211_get_interface, |
| 8960 | .dumpit = nl80211_dump_interface, |
| 8961 | .policy = nl80211_policy, |
| 8962 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8963 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8964 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8965 | }, |
| 8966 | { |
| 8967 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8968 | .doit = nl80211_set_interface, |
| 8969 | .policy = nl80211_policy, |
| 8970 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8971 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8972 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8973 | }, |
| 8974 | { |
| 8975 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8976 | .doit = nl80211_new_interface, |
| 8977 | .policy = nl80211_policy, |
| 8978 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8979 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8980 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8981 | }, |
| 8982 | { |
| 8983 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8984 | .doit = nl80211_del_interface, |
| 8985 | .policy = nl80211_policy, |
| 8986 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8987 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8988 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8989 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8990 | { |
| 8991 | .cmd = NL80211_CMD_GET_KEY, |
| 8992 | .doit = nl80211_get_key, |
| 8993 | .policy = nl80211_policy, |
| 8994 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8995 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8996 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8997 | }, |
| 8998 | { |
| 8999 | .cmd = NL80211_CMD_SET_KEY, |
| 9000 | .doit = nl80211_set_key, |
| 9001 | .policy = nl80211_policy, |
| 9002 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9003 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9004 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9005 | }, |
| 9006 | { |
| 9007 | .cmd = NL80211_CMD_NEW_KEY, |
| 9008 | .doit = nl80211_new_key, |
| 9009 | .policy = nl80211_policy, |
| 9010 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9012 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9013 | }, |
| 9014 | { |
| 9015 | .cmd = NL80211_CMD_DEL_KEY, |
| 9016 | .doit = nl80211_del_key, |
| 9017 | .policy = nl80211_policy, |
| 9018 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9020 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9021 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9022 | { |
| 9023 | .cmd = NL80211_CMD_SET_BEACON, |
| 9024 | .policy = nl80211_policy, |
| 9025 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9026 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9028 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9029 | }, |
| 9030 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9031 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9032 | .policy = nl80211_policy, |
| 9033 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9034 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9036 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9037 | }, |
| 9038 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9039 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9040 | .policy = nl80211_policy, |
| 9041 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9042 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9043 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9044 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9045 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9046 | { |
| 9047 | .cmd = NL80211_CMD_GET_STATION, |
| 9048 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9049 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9050 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9051 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9052 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9053 | }, |
| 9054 | { |
| 9055 | .cmd = NL80211_CMD_SET_STATION, |
| 9056 | .doit = nl80211_set_station, |
| 9057 | .policy = nl80211_policy, |
| 9058 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9059 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9060 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9061 | }, |
| 9062 | { |
| 9063 | .cmd = NL80211_CMD_NEW_STATION, |
| 9064 | .doit = nl80211_new_station, |
| 9065 | .policy = nl80211_policy, |
| 9066 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9067 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9068 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9069 | }, |
| 9070 | { |
| 9071 | .cmd = NL80211_CMD_DEL_STATION, |
| 9072 | .doit = nl80211_del_station, |
| 9073 | .policy = nl80211_policy, |
| 9074 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9075 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9076 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9077 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9078 | { |
| 9079 | .cmd = NL80211_CMD_GET_MPATH, |
| 9080 | .doit = nl80211_get_mpath, |
| 9081 | .dumpit = nl80211_dump_mpath, |
| 9082 | .policy = nl80211_policy, |
| 9083 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9084 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9085 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9086 | }, |
| 9087 | { |
| 9088 | .cmd = NL80211_CMD_SET_MPATH, |
| 9089 | .doit = nl80211_set_mpath, |
| 9090 | .policy = nl80211_policy, |
| 9091 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9092 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9093 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9094 | }, |
| 9095 | { |
| 9096 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9097 | .doit = nl80211_new_mpath, |
| 9098 | .policy = nl80211_policy, |
| 9099 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9100 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9101 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9102 | }, |
| 9103 | { |
| 9104 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9105 | .doit = nl80211_del_mpath, |
| 9106 | .policy = nl80211_policy, |
| 9107 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9108 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9109 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9110 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9111 | { |
| 9112 | .cmd = NL80211_CMD_SET_BSS, |
| 9113 | .doit = nl80211_set_bss, |
| 9114 | .policy = nl80211_policy, |
| 9115 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9116 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9117 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9118 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9119 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9120 | .cmd = NL80211_CMD_GET_REG, |
| 9121 | .doit = nl80211_get_reg, |
| 9122 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9123 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9124 | /* can be retrieved by unprivileged users */ |
| 9125 | }, |
| 9126 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9127 | .cmd = NL80211_CMD_SET_REG, |
| 9128 | .doit = nl80211_set_reg, |
| 9129 | .policy = nl80211_policy, |
| 9130 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9131 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9132 | }, |
| 9133 | { |
| 9134 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9135 | .doit = nl80211_req_set_reg, |
| 9136 | .policy = nl80211_policy, |
| 9137 | .flags = GENL_ADMIN_PERM, |
| 9138 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9139 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9140 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9141 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9142 | .policy = nl80211_policy, |
| 9143 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9144 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9145 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9146 | }, |
| 9147 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9148 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9149 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9150 | .policy = nl80211_policy, |
| 9151 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9152 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9153 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9154 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9155 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9156 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9157 | .doit = nl80211_trigger_scan, |
| 9158 | .policy = nl80211_policy, |
| 9159 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9160 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9161 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9162 | }, |
| 9163 | { |
| 9164 | .cmd = NL80211_CMD_GET_SCAN, |
| 9165 | .policy = nl80211_policy, |
| 9166 | .dumpit = nl80211_dump_scan, |
| 9167 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9168 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9169 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9170 | .doit = nl80211_start_sched_scan, |
| 9171 | .policy = nl80211_policy, |
| 9172 | .flags = GENL_ADMIN_PERM, |
| 9173 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9174 | NL80211_FLAG_NEED_RTNL, |
| 9175 | }, |
| 9176 | { |
| 9177 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9178 | .doit = nl80211_stop_sched_scan, |
| 9179 | .policy = nl80211_policy, |
| 9180 | .flags = GENL_ADMIN_PERM, |
| 9181 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9182 | NL80211_FLAG_NEED_RTNL, |
| 9183 | }, |
| 9184 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9185 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9186 | .doit = nl80211_authenticate, |
| 9187 | .policy = nl80211_policy, |
| 9188 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9189 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9190 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9191 | }, |
| 9192 | { |
| 9193 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9194 | .doit = nl80211_associate, |
| 9195 | .policy = nl80211_policy, |
| 9196 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9197 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9198 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9199 | }, |
| 9200 | { |
| 9201 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9202 | .doit = nl80211_deauthenticate, |
| 9203 | .policy = nl80211_policy, |
| 9204 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9205 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9206 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9207 | }, |
| 9208 | { |
| 9209 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9210 | .doit = nl80211_disassociate, |
| 9211 | .policy = nl80211_policy, |
| 9212 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9213 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9214 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9215 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9216 | { |
| 9217 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9218 | .doit = nl80211_join_ibss, |
| 9219 | .policy = nl80211_policy, |
| 9220 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9221 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9222 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9223 | }, |
| 9224 | { |
| 9225 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9226 | .doit = nl80211_leave_ibss, |
| 9227 | .policy = nl80211_policy, |
| 9228 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9229 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9230 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9231 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9232 | #ifdef CONFIG_NL80211_TESTMODE |
| 9233 | { |
| 9234 | .cmd = NL80211_CMD_TESTMODE, |
| 9235 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9236 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9237 | .policy = nl80211_policy, |
| 9238 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9239 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9240 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9241 | }, |
| 9242 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9243 | { |
| 9244 | .cmd = NL80211_CMD_CONNECT, |
| 9245 | .doit = nl80211_connect, |
| 9246 | .policy = nl80211_policy, |
| 9247 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9248 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9249 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9250 | }, |
| 9251 | { |
| 9252 | .cmd = NL80211_CMD_DISCONNECT, |
| 9253 | .doit = nl80211_disconnect, |
| 9254 | .policy = nl80211_policy, |
| 9255 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9256 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9257 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9258 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9259 | { |
| 9260 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9261 | .doit = nl80211_wiphy_netns, |
| 9262 | .policy = nl80211_policy, |
| 9263 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9264 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9265 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9266 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9267 | { |
| 9268 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9269 | .policy = nl80211_policy, |
| 9270 | .dumpit = nl80211_dump_survey, |
| 9271 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9272 | { |
| 9273 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9274 | .doit = nl80211_setdel_pmksa, |
| 9275 | .policy = nl80211_policy, |
| 9276 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9277 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9278 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9279 | }, |
| 9280 | { |
| 9281 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9282 | .doit = nl80211_setdel_pmksa, |
| 9283 | .policy = nl80211_policy, |
| 9284 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9285 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9286 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9287 | }, |
| 9288 | { |
| 9289 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9290 | .doit = nl80211_flush_pmksa, |
| 9291 | .policy = nl80211_policy, |
| 9292 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9293 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9294 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9295 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9296 | { |
| 9297 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9298 | .doit = nl80211_remain_on_channel, |
| 9299 | .policy = nl80211_policy, |
| 9300 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9301 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9302 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9303 | }, |
| 9304 | { |
| 9305 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9306 | .doit = nl80211_cancel_remain_on_channel, |
| 9307 | .policy = nl80211_policy, |
| 9308 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9309 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9310 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9311 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9312 | { |
| 9313 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9314 | .doit = nl80211_set_tx_bitrate_mask, |
| 9315 | .policy = nl80211_policy, |
| 9316 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9317 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9318 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9319 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9320 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9321 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9322 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9323 | .policy = nl80211_policy, |
| 9324 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9325 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9326 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9327 | }, |
| 9328 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9329 | .cmd = NL80211_CMD_FRAME, |
| 9330 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9331 | .policy = nl80211_policy, |
| 9332 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9333 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9334 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9335 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9336 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9337 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9338 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9339 | .policy = nl80211_policy, |
| 9340 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9341 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9342 | NL80211_FLAG_NEED_RTNL, |
| 9343 | }, |
| 9344 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9345 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9346 | .doit = nl80211_set_power_save, |
| 9347 | .policy = nl80211_policy, |
| 9348 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9349 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9350 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9351 | }, |
| 9352 | { |
| 9353 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9354 | .doit = nl80211_get_power_save, |
| 9355 | .policy = nl80211_policy, |
| 9356 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9357 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9358 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9359 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9360 | { |
| 9361 | .cmd = NL80211_CMD_SET_CQM, |
| 9362 | .doit = nl80211_set_cqm, |
| 9363 | .policy = nl80211_policy, |
| 9364 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9365 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9366 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9367 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9368 | { |
| 9369 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9370 | .doit = nl80211_set_channel, |
| 9371 | .policy = nl80211_policy, |
| 9372 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9373 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9374 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9375 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9376 | { |
| 9377 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9378 | .doit = nl80211_set_wds_peer, |
| 9379 | .policy = nl80211_policy, |
| 9380 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9381 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9382 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9383 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9384 | { |
| 9385 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9386 | .doit = nl80211_join_mesh, |
| 9387 | .policy = nl80211_policy, |
| 9388 | .flags = GENL_ADMIN_PERM, |
| 9389 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9390 | NL80211_FLAG_NEED_RTNL, |
| 9391 | }, |
| 9392 | { |
| 9393 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9394 | .doit = nl80211_leave_mesh, |
| 9395 | .policy = nl80211_policy, |
| 9396 | .flags = GENL_ADMIN_PERM, |
| 9397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9398 | NL80211_FLAG_NEED_RTNL, |
| 9399 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9400 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9401 | { |
| 9402 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9403 | .doit = nl80211_get_wowlan, |
| 9404 | .policy = nl80211_policy, |
| 9405 | /* can be retrieved by unprivileged users */ |
| 9406 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9407 | NL80211_FLAG_NEED_RTNL, |
| 9408 | }, |
| 9409 | { |
| 9410 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9411 | .doit = nl80211_set_wowlan, |
| 9412 | .policy = nl80211_policy, |
| 9413 | .flags = GENL_ADMIN_PERM, |
| 9414 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9415 | NL80211_FLAG_NEED_RTNL, |
| 9416 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9417 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9418 | { |
| 9419 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9420 | .doit = nl80211_set_rekey_data, |
| 9421 | .policy = nl80211_policy, |
| 9422 | .flags = GENL_ADMIN_PERM, |
| 9423 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9424 | NL80211_FLAG_NEED_RTNL, |
| 9425 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9426 | { |
| 9427 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9428 | .doit = nl80211_tdls_mgmt, |
| 9429 | .policy = nl80211_policy, |
| 9430 | .flags = GENL_ADMIN_PERM, |
| 9431 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9432 | NL80211_FLAG_NEED_RTNL, |
| 9433 | }, |
| 9434 | { |
| 9435 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9436 | .doit = nl80211_tdls_oper, |
| 9437 | .policy = nl80211_policy, |
| 9438 | .flags = GENL_ADMIN_PERM, |
| 9439 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9440 | NL80211_FLAG_NEED_RTNL, |
| 9441 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9442 | { |
| 9443 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9444 | .doit = nl80211_register_unexpected_frame, |
| 9445 | .policy = nl80211_policy, |
| 9446 | .flags = GENL_ADMIN_PERM, |
| 9447 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9448 | NL80211_FLAG_NEED_RTNL, |
| 9449 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9450 | { |
| 9451 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9452 | .doit = nl80211_probe_client, |
| 9453 | .policy = nl80211_policy, |
| 9454 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9455 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9456 | NL80211_FLAG_NEED_RTNL, |
| 9457 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9458 | { |
| 9459 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9460 | .doit = nl80211_register_beacons, |
| 9461 | .policy = nl80211_policy, |
| 9462 | .flags = GENL_ADMIN_PERM, |
| 9463 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9464 | NL80211_FLAG_NEED_RTNL, |
| 9465 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9466 | { |
| 9467 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9468 | .doit = nl80211_set_noack_map, |
| 9469 | .policy = nl80211_policy, |
| 9470 | .flags = GENL_ADMIN_PERM, |
| 9471 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9472 | NL80211_FLAG_NEED_RTNL, |
| 9473 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9474 | { |
| 9475 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9476 | .doit = nl80211_start_p2p_device, |
| 9477 | .policy = nl80211_policy, |
| 9478 | .flags = GENL_ADMIN_PERM, |
| 9479 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9480 | NL80211_FLAG_NEED_RTNL, |
| 9481 | }, |
| 9482 | { |
| 9483 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9484 | .doit = nl80211_stop_p2p_device, |
| 9485 | .policy = nl80211_policy, |
| 9486 | .flags = GENL_ADMIN_PERM, |
| 9487 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9488 | NL80211_FLAG_NEED_RTNL, |
| 9489 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9490 | { |
| 9491 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9492 | .doit = nl80211_set_mcast_rate, |
| 9493 | .policy = nl80211_policy, |
| 9494 | .flags = GENL_ADMIN_PERM, |
| 9495 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9496 | NL80211_FLAG_NEED_RTNL, |
| 9497 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9498 | { |
| 9499 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9500 | .doit = nl80211_set_mac_acl, |
| 9501 | .policy = nl80211_policy, |
| 9502 | .flags = GENL_ADMIN_PERM, |
| 9503 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9504 | NL80211_FLAG_NEED_RTNL, |
| 9505 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9506 | { |
| 9507 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9508 | .doit = nl80211_start_radar_detection, |
| 9509 | .policy = nl80211_policy, |
| 9510 | .flags = GENL_ADMIN_PERM, |
| 9511 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9512 | NL80211_FLAG_NEED_RTNL, |
| 9513 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9514 | { |
| 9515 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9516 | .doit = nl80211_get_protocol_features, |
| 9517 | .policy = nl80211_policy, |
| 9518 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9519 | { |
| 9520 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9521 | .doit = nl80211_update_ft_ies, |
| 9522 | .policy = nl80211_policy, |
| 9523 | .flags = GENL_ADMIN_PERM, |
| 9524 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9525 | NL80211_FLAG_NEED_RTNL, |
| 9526 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9527 | { |
| 9528 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9529 | .doit = nl80211_crit_protocol_start, |
| 9530 | .policy = nl80211_policy, |
| 9531 | .flags = GENL_ADMIN_PERM, |
| 9532 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9533 | NL80211_FLAG_NEED_RTNL, |
| 9534 | }, |
| 9535 | { |
| 9536 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9537 | .doit = nl80211_crit_protocol_stop, |
| 9538 | .policy = nl80211_policy, |
| 9539 | .flags = GENL_ADMIN_PERM, |
| 9540 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9541 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9542 | }, |
| 9543 | { |
| 9544 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9545 | .doit = nl80211_get_coalesce, |
| 9546 | .policy = nl80211_policy, |
| 9547 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9548 | NL80211_FLAG_NEED_RTNL, |
| 9549 | }, |
| 9550 | { |
| 9551 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9552 | .doit = nl80211_set_coalesce, |
| 9553 | .policy = nl80211_policy, |
| 9554 | .flags = GENL_ADMIN_PERM, |
| 9555 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9556 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9557 | }, |
| 9558 | { |
| 9559 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9560 | .doit = nl80211_channel_switch, |
| 9561 | .policy = nl80211_policy, |
| 9562 | .flags = GENL_ADMIN_PERM, |
| 9563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9564 | NL80211_FLAG_NEED_RTNL, |
| 9565 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9566 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9567 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9568 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9569 | .name = "mlme", |
| 9570 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9571 | |
| 9572 | /* multicast groups */ |
| 9573 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9574 | .name = "config", |
| 9575 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9576 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9577 | .name = "scan", |
| 9578 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9579 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9580 | .name = "regulatory", |
| 9581 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9582 | |
| 9583 | /* notification functions */ |
| 9584 | |
| 9585 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9586 | { |
| 9587 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9588 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9589 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9590 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9591 | if (!msg) |
| 9592 | return; |
| 9593 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9594 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9595 | nlmsg_free(msg); |
| 9596 | return; |
| 9597 | } |
| 9598 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9599 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9600 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9601 | } |
| 9602 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9603 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9604 | struct cfg80211_registered_device *rdev) |
| 9605 | { |
| 9606 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9607 | struct nlattr *nest; |
| 9608 | int i; |
| 9609 | |
| 9610 | if (WARN_ON(!req)) |
| 9611 | return 0; |
| 9612 | |
| 9613 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9614 | if (!nest) |
| 9615 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9616 | for (i = 0; i < req->n_ssids; i++) { |
| 9617 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9618 | goto nla_put_failure; |
| 9619 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9620 | nla_nest_end(msg, nest); |
| 9621 | |
| 9622 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9623 | if (!nest) |
| 9624 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9625 | for (i = 0; i < req->n_channels; i++) { |
| 9626 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9627 | goto nla_put_failure; |
| 9628 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9629 | nla_nest_end(msg, nest); |
| 9630 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9631 | if (req->ie && |
| 9632 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9633 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9634 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9635 | if (req->flags) |
| 9636 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9637 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9638 | return 0; |
| 9639 | nla_put_failure: |
| 9640 | return -ENOBUFS; |
| 9641 | } |
| 9642 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9643 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9644 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9645 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9646 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9647 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9648 | { |
| 9649 | void *hdr; |
| 9650 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9651 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9652 | if (!hdr) |
| 9653 | return -1; |
| 9654 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9655 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9656 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9657 | wdev->netdev->ifindex)) || |
| 9658 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9659 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9660 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9661 | /* ignore errors and send incomplete event anyway */ |
| 9662 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9663 | |
| 9664 | return genlmsg_end(msg, hdr); |
| 9665 | |
| 9666 | nla_put_failure: |
| 9667 | genlmsg_cancel(msg, hdr); |
| 9668 | return -EMSGSIZE; |
| 9669 | } |
| 9670 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9671 | static int |
| 9672 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9673 | struct cfg80211_registered_device *rdev, |
| 9674 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9675 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9676 | { |
| 9677 | void *hdr; |
| 9678 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9679 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9680 | if (!hdr) |
| 9681 | return -1; |
| 9682 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9683 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9684 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9685 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9686 | |
| 9687 | return genlmsg_end(msg, hdr); |
| 9688 | |
| 9689 | nla_put_failure: |
| 9690 | genlmsg_cancel(msg, hdr); |
| 9691 | return -EMSGSIZE; |
| 9692 | } |
| 9693 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9694 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9695 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9696 | { |
| 9697 | struct sk_buff *msg; |
| 9698 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9699 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9700 | if (!msg) |
| 9701 | return; |
| 9702 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9703 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9704 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9705 | nlmsg_free(msg); |
| 9706 | return; |
| 9707 | } |
| 9708 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9709 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9710 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9711 | } |
| 9712 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9713 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9714 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9715 | { |
| 9716 | struct sk_buff *msg; |
| 9717 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9718 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9719 | if (!msg) |
| 9720 | return; |
| 9721 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9722 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9723 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9724 | nlmsg_free(msg); |
| 9725 | return; |
| 9726 | } |
| 9727 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9728 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9729 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9730 | } |
| 9731 | |
| 9732 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9733 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9734 | { |
| 9735 | struct sk_buff *msg; |
| 9736 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9737 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9738 | if (!msg) |
| 9739 | return; |
| 9740 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9741 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9742 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9743 | nlmsg_free(msg); |
| 9744 | return; |
| 9745 | } |
| 9746 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9747 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9748 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9749 | } |
| 9750 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9751 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9752 | struct net_device *netdev) |
| 9753 | { |
| 9754 | struct sk_buff *msg; |
| 9755 | |
| 9756 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9757 | if (!msg) |
| 9758 | return; |
| 9759 | |
| 9760 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9761 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9762 | nlmsg_free(msg); |
| 9763 | return; |
| 9764 | } |
| 9765 | |
| 9766 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9767 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9768 | } |
| 9769 | |
| 9770 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9771 | struct net_device *netdev, u32 cmd) |
| 9772 | { |
| 9773 | struct sk_buff *msg; |
| 9774 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9775 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9776 | if (!msg) |
| 9777 | return; |
| 9778 | |
| 9779 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9780 | nlmsg_free(msg); |
| 9781 | return; |
| 9782 | } |
| 9783 | |
| 9784 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9785 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9786 | } |
| 9787 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9788 | /* |
| 9789 | * This can happen on global regulatory changes or device specific settings |
| 9790 | * based on custom world regulatory domains. |
| 9791 | */ |
| 9792 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9793 | { |
| 9794 | struct sk_buff *msg; |
| 9795 | void *hdr; |
| 9796 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9797 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9798 | if (!msg) |
| 9799 | return; |
| 9800 | |
| 9801 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9802 | if (!hdr) { |
| 9803 | nlmsg_free(msg); |
| 9804 | return; |
| 9805 | } |
| 9806 | |
| 9807 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9808 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9809 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9810 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9811 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9812 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9813 | NL80211_REGDOM_TYPE_WORLD)) |
| 9814 | goto nla_put_failure; |
| 9815 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9816 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9817 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9818 | goto nla_put_failure; |
| 9819 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9820 | request->intersect) { |
| 9821 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9822 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9823 | goto nla_put_failure; |
| 9824 | } else { |
| 9825 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9826 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9827 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9828 | request->alpha2)) |
| 9829 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9830 | } |
| 9831 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9832 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9833 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9834 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9835 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9836 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9837 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9838 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9839 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9840 | GFP_ATOMIC); |
| 9841 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9842 | |
| 9843 | return; |
| 9844 | |
| 9845 | nla_put_failure: |
| 9846 | genlmsg_cancel(msg, hdr); |
| 9847 | nlmsg_free(msg); |
| 9848 | } |
| 9849 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9850 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9851 | struct net_device *netdev, |
| 9852 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9853 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9854 | { |
| 9855 | struct sk_buff *msg; |
| 9856 | void *hdr; |
| 9857 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9858 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9859 | if (!msg) |
| 9860 | return; |
| 9861 | |
| 9862 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9863 | if (!hdr) { |
| 9864 | nlmsg_free(msg); |
| 9865 | return; |
| 9866 | } |
| 9867 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9868 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9869 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9870 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9871 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9872 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9873 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9874 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9875 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9876 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9877 | return; |
| 9878 | |
| 9879 | nla_put_failure: |
| 9880 | genlmsg_cancel(msg, hdr); |
| 9881 | nlmsg_free(msg); |
| 9882 | } |
| 9883 | |
| 9884 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9885 | struct net_device *netdev, const u8 *buf, |
| 9886 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9887 | { |
| 9888 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9889 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9890 | } |
| 9891 | |
| 9892 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9893 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9894 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9895 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9896 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9897 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9898 | } |
| 9899 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9900 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9901 | struct net_device *netdev, const u8 *buf, |
| 9902 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9903 | { |
| 9904 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9905 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9906 | } |
| 9907 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9908 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9909 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9910 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9911 | { |
| 9912 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9913 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9914 | } |
| 9915 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9916 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9917 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9918 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9919 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9920 | struct wiphy *wiphy = wdev->wiphy; |
| 9921 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9922 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9923 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9924 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9925 | if (WARN_ON(len < 2)) |
| 9926 | return; |
| 9927 | |
| 9928 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9929 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9930 | else |
| 9931 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9932 | |
| 9933 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9934 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9935 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9936 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9937 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9938 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9939 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9940 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9941 | { |
| 9942 | struct sk_buff *msg; |
| 9943 | void *hdr; |
| 9944 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9945 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9946 | if (!msg) |
| 9947 | return; |
| 9948 | |
| 9949 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9950 | if (!hdr) { |
| 9951 | nlmsg_free(msg); |
| 9952 | return; |
| 9953 | } |
| 9954 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9955 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9956 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9957 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9958 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9959 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9960 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9961 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9962 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9963 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9964 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9965 | return; |
| 9966 | |
| 9967 | nla_put_failure: |
| 9968 | genlmsg_cancel(msg, hdr); |
| 9969 | nlmsg_free(msg); |
| 9970 | } |
| 9971 | |
| 9972 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9973 | struct net_device *netdev, const u8 *addr, |
| 9974 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9975 | { |
| 9976 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9977 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9978 | } |
| 9979 | |
| 9980 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9981 | struct net_device *netdev, const u8 *addr, |
| 9982 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9983 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9984 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9985 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9986 | } |
| 9987 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9988 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9989 | struct net_device *netdev, const u8 *bssid, |
| 9990 | const u8 *req_ie, size_t req_ie_len, |
| 9991 | const u8 *resp_ie, size_t resp_ie_len, |
| 9992 | u16 status, gfp_t gfp) |
| 9993 | { |
| 9994 | struct sk_buff *msg; |
| 9995 | void *hdr; |
| 9996 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9998 | if (!msg) |
| 9999 | return; |
| 10000 | |
| 10001 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10002 | if (!hdr) { |
| 10003 | nlmsg_free(msg); |
| 10004 | return; |
| 10005 | } |
| 10006 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10007 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10008 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10009 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10010 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10011 | (req_ie && |
| 10012 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10013 | (resp_ie && |
| 10014 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10015 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10016 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10017 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10018 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10019 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10020 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10021 | return; |
| 10022 | |
| 10023 | nla_put_failure: |
| 10024 | genlmsg_cancel(msg, hdr); |
| 10025 | nlmsg_free(msg); |
| 10026 | |
| 10027 | } |
| 10028 | |
| 10029 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10030 | struct net_device *netdev, const u8 *bssid, |
| 10031 | const u8 *req_ie, size_t req_ie_len, |
| 10032 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10033 | { |
| 10034 | struct sk_buff *msg; |
| 10035 | void *hdr; |
| 10036 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10038 | if (!msg) |
| 10039 | return; |
| 10040 | |
| 10041 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10042 | if (!hdr) { |
| 10043 | nlmsg_free(msg); |
| 10044 | return; |
| 10045 | } |
| 10046 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10047 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10048 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10049 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10050 | (req_ie && |
| 10051 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10052 | (resp_ie && |
| 10053 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10054 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10055 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10056 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10057 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10058 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10059 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10060 | return; |
| 10061 | |
| 10062 | nla_put_failure: |
| 10063 | genlmsg_cancel(msg, hdr); |
| 10064 | nlmsg_free(msg); |
| 10065 | |
| 10066 | } |
| 10067 | |
| 10068 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10069 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10070 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10071 | { |
| 10072 | struct sk_buff *msg; |
| 10073 | void *hdr; |
| 10074 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10075 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10076 | if (!msg) |
| 10077 | return; |
| 10078 | |
| 10079 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10080 | if (!hdr) { |
| 10081 | nlmsg_free(msg); |
| 10082 | return; |
| 10083 | } |
| 10084 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10085 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10086 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10087 | (from_ap && reason && |
| 10088 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10089 | (from_ap && |
| 10090 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10091 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10092 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10093 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10094 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10095 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10096 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10097 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10098 | return; |
| 10099 | |
| 10100 | nla_put_failure: |
| 10101 | genlmsg_cancel(msg, hdr); |
| 10102 | nlmsg_free(msg); |
| 10103 | |
| 10104 | } |
| 10105 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10106 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10107 | struct net_device *netdev, const u8 *bssid, |
| 10108 | gfp_t gfp) |
| 10109 | { |
| 10110 | struct sk_buff *msg; |
| 10111 | void *hdr; |
| 10112 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10113 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10114 | if (!msg) |
| 10115 | return; |
| 10116 | |
| 10117 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10118 | if (!hdr) { |
| 10119 | nlmsg_free(msg); |
| 10120 | return; |
| 10121 | } |
| 10122 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10123 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10124 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10125 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10126 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10127 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10128 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10129 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10130 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10131 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10132 | return; |
| 10133 | |
| 10134 | nla_put_failure: |
| 10135 | genlmsg_cancel(msg, hdr); |
| 10136 | nlmsg_free(msg); |
| 10137 | } |
| 10138 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10139 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10140 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10141 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10142 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10143 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10144 | struct sk_buff *msg; |
| 10145 | void *hdr; |
| 10146 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10147 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10148 | return; |
| 10149 | |
| 10150 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10151 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10153 | if (!msg) |
| 10154 | return; |
| 10155 | |
| 10156 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10157 | if (!hdr) { |
| 10158 | nlmsg_free(msg); |
| 10159 | return; |
| 10160 | } |
| 10161 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10162 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10163 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10164 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10165 | (ie_len && ie && |
| 10166 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10167 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10168 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10169 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10170 | |
| 10171 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10172 | nl80211_mlme_mcgrp.id, gfp); |
| 10173 | return; |
| 10174 | |
| 10175 | nla_put_failure: |
| 10176 | genlmsg_cancel(msg, hdr); |
| 10177 | nlmsg_free(msg); |
| 10178 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10179 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10180 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10181 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10182 | struct net_device *netdev, const u8 *addr, |
| 10183 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10184 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10185 | { |
| 10186 | struct sk_buff *msg; |
| 10187 | void *hdr; |
| 10188 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10189 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10190 | if (!msg) |
| 10191 | return; |
| 10192 | |
| 10193 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10194 | if (!hdr) { |
| 10195 | nlmsg_free(msg); |
| 10196 | return; |
| 10197 | } |
| 10198 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10199 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10200 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10201 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10202 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10203 | (key_id != -1 && |
| 10204 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10205 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10206 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10207 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10208 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10209 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10210 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10211 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10212 | return; |
| 10213 | |
| 10214 | nla_put_failure: |
| 10215 | genlmsg_cancel(msg, hdr); |
| 10216 | nlmsg_free(msg); |
| 10217 | } |
| 10218 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10219 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10220 | struct ieee80211_channel *channel_before, |
| 10221 | struct ieee80211_channel *channel_after) |
| 10222 | { |
| 10223 | struct sk_buff *msg; |
| 10224 | void *hdr; |
| 10225 | struct nlattr *nl_freq; |
| 10226 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10227 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10228 | if (!msg) |
| 10229 | return; |
| 10230 | |
| 10231 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10232 | if (!hdr) { |
| 10233 | nlmsg_free(msg); |
| 10234 | return; |
| 10235 | } |
| 10236 | |
| 10237 | /* |
| 10238 | * Since we are applying the beacon hint to a wiphy we know its |
| 10239 | * wiphy_idx is valid |
| 10240 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10241 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10242 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10243 | |
| 10244 | /* Before */ |
| 10245 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10246 | if (!nl_freq) |
| 10247 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10248 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10249 | goto nla_put_failure; |
| 10250 | nla_nest_end(msg, nl_freq); |
| 10251 | |
| 10252 | /* After */ |
| 10253 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10254 | if (!nl_freq) |
| 10255 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10256 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10257 | goto nla_put_failure; |
| 10258 | nla_nest_end(msg, nl_freq); |
| 10259 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10260 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10261 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10262 | rcu_read_lock(); |
| 10263 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 10264 | GFP_ATOMIC); |
| 10265 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10266 | |
| 10267 | return; |
| 10268 | |
| 10269 | nla_put_failure: |
| 10270 | genlmsg_cancel(msg, hdr); |
| 10271 | nlmsg_free(msg); |
| 10272 | } |
| 10273 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10274 | static void nl80211_send_remain_on_chan_event( |
| 10275 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10276 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10277 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10278 | unsigned int duration, gfp_t gfp) |
| 10279 | { |
| 10280 | struct sk_buff *msg; |
| 10281 | void *hdr; |
| 10282 | |
| 10283 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10284 | if (!msg) |
| 10285 | return; |
| 10286 | |
| 10287 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10288 | if (!hdr) { |
| 10289 | nlmsg_free(msg); |
| 10290 | return; |
| 10291 | } |
| 10292 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10293 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10294 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10295 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10296 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10297 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10298 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10299 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10300 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10301 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10302 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10303 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10304 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10305 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10306 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10307 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10308 | |
| 10309 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10310 | nl80211_mlme_mcgrp.id, gfp); |
| 10311 | return; |
| 10312 | |
| 10313 | nla_put_failure: |
| 10314 | genlmsg_cancel(msg, hdr); |
| 10315 | nlmsg_free(msg); |
| 10316 | } |
| 10317 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10318 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10319 | struct ieee80211_channel *chan, |
| 10320 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10321 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10322 | struct wiphy *wiphy = wdev->wiphy; |
| 10323 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10324 | |
| 10325 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10326 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10327 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10328 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10329 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10330 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10331 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10332 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10333 | struct ieee80211_channel *chan, |
| 10334 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10335 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10336 | struct wiphy *wiphy = wdev->wiphy; |
| 10337 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10338 | |
| 10339 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10340 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10341 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10342 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10343 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10344 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10345 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10346 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10347 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10348 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10349 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10350 | struct sk_buff *msg; |
| 10351 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10352 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10353 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10354 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10355 | if (!msg) |
| 10356 | return; |
| 10357 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10358 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10359 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10360 | nlmsg_free(msg); |
| 10361 | return; |
| 10362 | } |
| 10363 | |
| 10364 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10365 | nl80211_mlme_mcgrp.id, gfp); |
| 10366 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10367 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10368 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10369 | 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] | 10370 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10371 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10372 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10373 | struct sk_buff *msg; |
| 10374 | void *hdr; |
| 10375 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10376 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10377 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10378 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10379 | if (!msg) |
| 10380 | return; |
| 10381 | |
| 10382 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10383 | if (!hdr) { |
| 10384 | nlmsg_free(msg); |
| 10385 | return; |
| 10386 | } |
| 10387 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10388 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10389 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10390 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10391 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10392 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10393 | |
| 10394 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10395 | nl80211_mlme_mcgrp.id, gfp); |
| 10396 | return; |
| 10397 | |
| 10398 | nla_put_failure: |
| 10399 | genlmsg_cancel(msg, hdr); |
| 10400 | nlmsg_free(msg); |
| 10401 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10402 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10403 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10404 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10405 | enum nl80211_connect_failed_reason reason, |
| 10406 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10407 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10408 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10409 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10410 | struct sk_buff *msg; |
| 10411 | void *hdr; |
| 10412 | |
| 10413 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10414 | if (!msg) |
| 10415 | return; |
| 10416 | |
| 10417 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10418 | if (!hdr) { |
| 10419 | nlmsg_free(msg); |
| 10420 | return; |
| 10421 | } |
| 10422 | |
| 10423 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10424 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10425 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10426 | goto nla_put_failure; |
| 10427 | |
| 10428 | genlmsg_end(msg, hdr); |
| 10429 | |
| 10430 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10431 | nl80211_mlme_mcgrp.id, gfp); |
| 10432 | return; |
| 10433 | |
| 10434 | nla_put_failure: |
| 10435 | genlmsg_cancel(msg, hdr); |
| 10436 | nlmsg_free(msg); |
| 10437 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10438 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10439 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10440 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10441 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10442 | { |
| 10443 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10444 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10445 | struct sk_buff *msg; |
| 10446 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10447 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10448 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10449 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10450 | return false; |
| 10451 | |
| 10452 | msg = nlmsg_new(100, gfp); |
| 10453 | if (!msg) |
| 10454 | return true; |
| 10455 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10456 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10457 | if (!hdr) { |
| 10458 | nlmsg_free(msg); |
| 10459 | return true; |
| 10460 | } |
| 10461 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10462 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10463 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10464 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10465 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10466 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10467 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10468 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10469 | return true; |
| 10470 | |
| 10471 | nla_put_failure: |
| 10472 | genlmsg_cancel(msg, hdr); |
| 10473 | nlmsg_free(msg); |
| 10474 | return true; |
| 10475 | } |
| 10476 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10477 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10478 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10479 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10480 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10481 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10482 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10483 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10484 | |
| 10485 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10486 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10487 | trace_cfg80211_return_bool(false); |
| 10488 | return false; |
| 10489 | } |
| 10490 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10491 | addr, gfp); |
| 10492 | trace_cfg80211_return_bool(ret); |
| 10493 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10494 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10495 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10496 | |
| 10497 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10498 | const u8 *addr, gfp_t gfp) |
| 10499 | { |
| 10500 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10501 | bool ret; |
| 10502 | |
| 10503 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10504 | |
| 10505 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10506 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10507 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10508 | trace_cfg80211_return_bool(false); |
| 10509 | return false; |
| 10510 | } |
| 10511 | ret = __nl80211_unexpected_frame(dev, |
| 10512 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10513 | addr, gfp); |
| 10514 | trace_cfg80211_return_bool(ret); |
| 10515 | return ret; |
| 10516 | } |
| 10517 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10518 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10519 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10520 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10521 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10522 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10523 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10524 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10525 | struct sk_buff *msg; |
| 10526 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10527 | |
| 10528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10529 | if (!msg) |
| 10530 | return -ENOMEM; |
| 10531 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10532 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10533 | if (!hdr) { |
| 10534 | nlmsg_free(msg); |
| 10535 | return -ENOMEM; |
| 10536 | } |
| 10537 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10538 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10539 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10540 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10541 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10542 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10543 | (sig_dbm && |
| 10544 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 10545 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10546 | (flags && |
| 10547 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10548 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10549 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10550 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10551 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10552 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10553 | |
| 10554 | nla_put_failure: |
| 10555 | genlmsg_cancel(msg, hdr); |
| 10556 | nlmsg_free(msg); |
| 10557 | return -ENOBUFS; |
| 10558 | } |
| 10559 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10560 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10561 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10562 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10563 | struct wiphy *wiphy = wdev->wiphy; |
| 10564 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10565 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10566 | struct sk_buff *msg; |
| 10567 | void *hdr; |
| 10568 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10569 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10570 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10571 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10572 | if (!msg) |
| 10573 | return; |
| 10574 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10575 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10576 | if (!hdr) { |
| 10577 | nlmsg_free(msg); |
| 10578 | return; |
| 10579 | } |
| 10580 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10581 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10582 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10583 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10584 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10585 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10586 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10587 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10588 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10589 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10590 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10591 | |
Michal Kazior | a0ec570 | 2013-06-25 09:17:17 +0200 | [diff] [blame] | 10592 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10593 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10594 | return; |
| 10595 | |
| 10596 | nla_put_failure: |
| 10597 | genlmsg_cancel(msg, hdr); |
| 10598 | nlmsg_free(msg); |
| 10599 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10600 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10601 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10602 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10603 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10604 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10605 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10606 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10607 | struct wiphy *wiphy = wdev->wiphy; |
| 10608 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10609 | struct sk_buff *msg; |
| 10610 | struct nlattr *pinfoattr; |
| 10611 | void *hdr; |
| 10612 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10613 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10614 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10615 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10616 | if (!msg) |
| 10617 | return; |
| 10618 | |
| 10619 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10620 | if (!hdr) { |
| 10621 | nlmsg_free(msg); |
| 10622 | return; |
| 10623 | } |
| 10624 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10625 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10626 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10627 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10628 | |
| 10629 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10630 | if (!pinfoattr) |
| 10631 | goto nla_put_failure; |
| 10632 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10633 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10634 | rssi_event)) |
| 10635 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10636 | |
| 10637 | nla_nest_end(msg, pinfoattr); |
| 10638 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10639 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10640 | |
| 10641 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10642 | nl80211_mlme_mcgrp.id, gfp); |
| 10643 | return; |
| 10644 | |
| 10645 | nla_put_failure: |
| 10646 | genlmsg_cancel(msg, hdr); |
| 10647 | nlmsg_free(msg); |
| 10648 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10649 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10650 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10651 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10652 | struct net_device *netdev, const u8 *bssid, |
| 10653 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10654 | { |
| 10655 | struct sk_buff *msg; |
| 10656 | struct nlattr *rekey_attr; |
| 10657 | void *hdr; |
| 10658 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10659 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10660 | if (!msg) |
| 10661 | return; |
| 10662 | |
| 10663 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10664 | if (!hdr) { |
| 10665 | nlmsg_free(msg); |
| 10666 | return; |
| 10667 | } |
| 10668 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10669 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10670 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10671 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10672 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10673 | |
| 10674 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10675 | if (!rekey_attr) |
| 10676 | goto nla_put_failure; |
| 10677 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10678 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10679 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10680 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10681 | |
| 10682 | nla_nest_end(msg, rekey_attr); |
| 10683 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10684 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10685 | |
| 10686 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10687 | nl80211_mlme_mcgrp.id, gfp); |
| 10688 | return; |
| 10689 | |
| 10690 | nla_put_failure: |
| 10691 | genlmsg_cancel(msg, hdr); |
| 10692 | nlmsg_free(msg); |
| 10693 | } |
| 10694 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10695 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10696 | const u8 *replay_ctr, gfp_t gfp) |
| 10697 | { |
| 10698 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10699 | struct wiphy *wiphy = wdev->wiphy; |
| 10700 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10701 | |
| 10702 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10703 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10704 | } |
| 10705 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10706 | |
| 10707 | static void |
| 10708 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10709 | struct net_device *netdev, int index, |
| 10710 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10711 | { |
| 10712 | struct sk_buff *msg; |
| 10713 | struct nlattr *attr; |
| 10714 | void *hdr; |
| 10715 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10716 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10717 | if (!msg) |
| 10718 | return; |
| 10719 | |
| 10720 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10721 | if (!hdr) { |
| 10722 | nlmsg_free(msg); |
| 10723 | return; |
| 10724 | } |
| 10725 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10726 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10727 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10728 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10729 | |
| 10730 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10731 | if (!attr) |
| 10732 | goto nla_put_failure; |
| 10733 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10734 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10735 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10736 | (preauth && |
| 10737 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10738 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10739 | |
| 10740 | nla_nest_end(msg, attr); |
| 10741 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10742 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10743 | |
| 10744 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10745 | nl80211_mlme_mcgrp.id, gfp); |
| 10746 | return; |
| 10747 | |
| 10748 | nla_put_failure: |
| 10749 | genlmsg_cancel(msg, hdr); |
| 10750 | nlmsg_free(msg); |
| 10751 | } |
| 10752 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10753 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10754 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10755 | { |
| 10756 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10757 | struct wiphy *wiphy = wdev->wiphy; |
| 10758 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10759 | |
| 10760 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10761 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10762 | } |
| 10763 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10764 | |
| 10765 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10766 | struct net_device *netdev, |
| 10767 | struct cfg80211_chan_def *chandef, |
| 10768 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10769 | { |
| 10770 | struct sk_buff *msg; |
| 10771 | void *hdr; |
| 10772 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10773 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10774 | if (!msg) |
| 10775 | return; |
| 10776 | |
| 10777 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10778 | if (!hdr) { |
| 10779 | nlmsg_free(msg); |
| 10780 | return; |
| 10781 | } |
| 10782 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10783 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10784 | goto nla_put_failure; |
| 10785 | |
| 10786 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10787 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10788 | |
| 10789 | genlmsg_end(msg, hdr); |
| 10790 | |
| 10791 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10792 | nl80211_mlme_mcgrp.id, gfp); |
| 10793 | return; |
| 10794 | |
| 10795 | nla_put_failure: |
| 10796 | genlmsg_cancel(msg, hdr); |
| 10797 | nlmsg_free(msg); |
| 10798 | } |
| 10799 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10800 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10801 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10802 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10803 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10804 | struct wiphy *wiphy = wdev->wiphy; |
| 10805 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10806 | |
| 10807 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10808 | |
| 10809 | wdev_lock(wdev); |
| 10810 | |
| 10811 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 10812 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 10813 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 10814 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10815 | goto out; |
| 10816 | |
| 10817 | wdev->channel = chandef->chan; |
| 10818 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10819 | out: |
| 10820 | wdev_unlock(wdev); |
| 10821 | return; |
| 10822 | } |
| 10823 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10824 | |
| 10825 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10826 | const u8 *peer, u32 num_packets, |
| 10827 | u32 rate, u32 intvl, gfp_t gfp) |
| 10828 | { |
| 10829 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10830 | struct wiphy *wiphy = wdev->wiphy; |
| 10831 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10832 | struct sk_buff *msg; |
| 10833 | struct nlattr *pinfoattr; |
| 10834 | void *hdr; |
| 10835 | |
| 10836 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10837 | if (!msg) |
| 10838 | return; |
| 10839 | |
| 10840 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10841 | if (!hdr) { |
| 10842 | nlmsg_free(msg); |
| 10843 | return; |
| 10844 | } |
| 10845 | |
| 10846 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10847 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10848 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10849 | goto nla_put_failure; |
| 10850 | |
| 10851 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10852 | if (!pinfoattr) |
| 10853 | goto nla_put_failure; |
| 10854 | |
| 10855 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10856 | goto nla_put_failure; |
| 10857 | |
| 10858 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10859 | goto nla_put_failure; |
| 10860 | |
| 10861 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10862 | goto nla_put_failure; |
| 10863 | |
| 10864 | nla_nest_end(msg, pinfoattr); |
| 10865 | |
| 10866 | genlmsg_end(msg, hdr); |
| 10867 | |
| 10868 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10869 | nl80211_mlme_mcgrp.id, gfp); |
| 10870 | return; |
| 10871 | |
| 10872 | nla_put_failure: |
| 10873 | genlmsg_cancel(msg, hdr); |
| 10874 | nlmsg_free(msg); |
| 10875 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10876 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10877 | |
| 10878 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10879 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 10880 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10881 | enum nl80211_radar_event event, |
| 10882 | struct net_device *netdev, gfp_t gfp) |
| 10883 | { |
| 10884 | struct sk_buff *msg; |
| 10885 | void *hdr; |
| 10886 | |
| 10887 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10888 | if (!msg) |
| 10889 | return; |
| 10890 | |
| 10891 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10892 | if (!hdr) { |
| 10893 | nlmsg_free(msg); |
| 10894 | return; |
| 10895 | } |
| 10896 | |
| 10897 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10898 | goto nla_put_failure; |
| 10899 | |
| 10900 | /* NOP and radar events don't need a netdev parameter */ |
| 10901 | if (netdev) { |
| 10902 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10903 | |
| 10904 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10905 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10906 | goto nla_put_failure; |
| 10907 | } |
| 10908 | |
| 10909 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10910 | goto nla_put_failure; |
| 10911 | |
| 10912 | if (nl80211_send_chandef(msg, chandef)) |
| 10913 | goto nla_put_failure; |
| 10914 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10915 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10916 | |
| 10917 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10918 | nl80211_mlme_mcgrp.id, gfp); |
| 10919 | return; |
| 10920 | |
| 10921 | nla_put_failure: |
| 10922 | genlmsg_cancel(msg, hdr); |
| 10923 | nlmsg_free(msg); |
| 10924 | } |
| 10925 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10926 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10927 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10928 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10929 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10930 | struct wiphy *wiphy = wdev->wiphy; |
| 10931 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10932 | struct sk_buff *msg; |
| 10933 | struct nlattr *pinfoattr; |
| 10934 | void *hdr; |
| 10935 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10936 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10937 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10938 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10939 | if (!msg) |
| 10940 | return; |
| 10941 | |
| 10942 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10943 | if (!hdr) { |
| 10944 | nlmsg_free(msg); |
| 10945 | return; |
| 10946 | } |
| 10947 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10948 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10949 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10950 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10951 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10952 | |
| 10953 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10954 | if (!pinfoattr) |
| 10955 | goto nla_put_failure; |
| 10956 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10957 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10958 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10959 | |
| 10960 | nla_nest_end(msg, pinfoattr); |
| 10961 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10962 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10963 | |
| 10964 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10965 | nl80211_mlme_mcgrp.id, gfp); |
| 10966 | return; |
| 10967 | |
| 10968 | nla_put_failure: |
| 10969 | genlmsg_cancel(msg, hdr); |
| 10970 | nlmsg_free(msg); |
| 10971 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10972 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10973 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10974 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10975 | u64 cookie, bool acked, gfp_t gfp) |
| 10976 | { |
| 10977 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10978 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10979 | struct sk_buff *msg; |
| 10980 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10981 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10982 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10983 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10984 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10985 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10986 | if (!msg) |
| 10987 | return; |
| 10988 | |
| 10989 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10990 | if (!hdr) { |
| 10991 | nlmsg_free(msg); |
| 10992 | return; |
| 10993 | } |
| 10994 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10995 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10996 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10997 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10998 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10999 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11000 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11001 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11002 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11003 | |
| 11004 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11005 | nl80211_mlme_mcgrp.id, gfp); |
| 11006 | return; |
| 11007 | |
| 11008 | nla_put_failure: |
| 11009 | genlmsg_cancel(msg, hdr); |
| 11010 | nlmsg_free(msg); |
| 11011 | } |
| 11012 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11013 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11014 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11015 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11016 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11017 | { |
| 11018 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11019 | struct sk_buff *msg; |
| 11020 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11021 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11022 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11023 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11024 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11025 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11026 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11027 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11028 | if (!msg) { |
| 11029 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11030 | return; |
| 11031 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11032 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11033 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11034 | if (!hdr) |
| 11035 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11036 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11037 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11038 | (freq && |
| 11039 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11040 | (sig_dbm && |
| 11041 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11042 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11043 | goto nla_put_failure; |
| 11044 | |
| 11045 | genlmsg_end(msg, hdr); |
| 11046 | |
| 11047 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11048 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11049 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11050 | return; |
| 11051 | |
| 11052 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11053 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11054 | if (hdr) |
| 11055 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11056 | nlmsg_free(msg); |
| 11057 | } |
| 11058 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11059 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11060 | #ifdef CONFIG_PM |
| 11061 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11062 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11063 | gfp_t gfp) |
| 11064 | { |
| 11065 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11066 | struct sk_buff *msg; |
| 11067 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11068 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11069 | |
| 11070 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11071 | |
| 11072 | if (wakeup) |
| 11073 | size += wakeup->packet_present_len; |
| 11074 | |
| 11075 | msg = nlmsg_new(size, gfp); |
| 11076 | if (!msg) |
| 11077 | return; |
| 11078 | |
| 11079 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11080 | if (!hdr) |
| 11081 | goto free_msg; |
| 11082 | |
| 11083 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11084 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11085 | goto free_msg; |
| 11086 | |
| 11087 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11088 | wdev->netdev->ifindex)) |
| 11089 | goto free_msg; |
| 11090 | |
| 11091 | if (wakeup) { |
| 11092 | struct nlattr *reasons; |
| 11093 | |
| 11094 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 11095 | |
| 11096 | if (wakeup->disconnect && |
| 11097 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11098 | goto free_msg; |
| 11099 | if (wakeup->magic_pkt && |
| 11100 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11101 | goto free_msg; |
| 11102 | if (wakeup->gtk_rekey_failure && |
| 11103 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11104 | goto free_msg; |
| 11105 | if (wakeup->eap_identity_req && |
| 11106 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11107 | goto free_msg; |
| 11108 | if (wakeup->four_way_handshake && |
| 11109 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11110 | goto free_msg; |
| 11111 | if (wakeup->rfkill_release && |
| 11112 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11113 | goto free_msg; |
| 11114 | |
| 11115 | if (wakeup->pattern_idx >= 0 && |
| 11116 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11117 | wakeup->pattern_idx)) |
| 11118 | goto free_msg; |
| 11119 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11120 | if (wakeup->tcp_match) |
| 11121 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 11122 | |
| 11123 | if (wakeup->tcp_connlost) |
| 11124 | nla_put_flag(msg, |
| 11125 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 11126 | |
| 11127 | if (wakeup->tcp_nomoretokens) |
| 11128 | nla_put_flag(msg, |
| 11129 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 11130 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11131 | if (wakeup->packet) { |
| 11132 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11133 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11134 | |
| 11135 | if (!wakeup->packet_80211) { |
| 11136 | pkt_attr = |
| 11137 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11138 | len_attr = |
| 11139 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11140 | } |
| 11141 | |
| 11142 | if (wakeup->packet_len && |
| 11143 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11144 | goto free_msg; |
| 11145 | |
| 11146 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11147 | wakeup->packet)) |
| 11148 | goto free_msg; |
| 11149 | } |
| 11150 | |
| 11151 | nla_nest_end(msg, reasons); |
| 11152 | } |
| 11153 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11154 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11155 | |
| 11156 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11157 | nl80211_mlme_mcgrp.id, gfp); |
| 11158 | return; |
| 11159 | |
| 11160 | free_msg: |
| 11161 | nlmsg_free(msg); |
| 11162 | } |
| 11163 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11164 | #endif |
| 11165 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11166 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11167 | enum nl80211_tdls_operation oper, |
| 11168 | u16 reason_code, gfp_t gfp) |
| 11169 | { |
| 11170 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11171 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11172 | struct sk_buff *msg; |
| 11173 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11174 | |
| 11175 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11176 | reason_code); |
| 11177 | |
| 11178 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11179 | if (!msg) |
| 11180 | return; |
| 11181 | |
| 11182 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11183 | if (!hdr) { |
| 11184 | nlmsg_free(msg); |
| 11185 | return; |
| 11186 | } |
| 11187 | |
| 11188 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11189 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11190 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11191 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11192 | (reason_code > 0 && |
| 11193 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11194 | goto nla_put_failure; |
| 11195 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11196 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11197 | |
| 11198 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11199 | nl80211_mlme_mcgrp.id, gfp); |
| 11200 | return; |
| 11201 | |
| 11202 | nla_put_failure: |
| 11203 | genlmsg_cancel(msg, hdr); |
| 11204 | nlmsg_free(msg); |
| 11205 | } |
| 11206 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11207 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11208 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11209 | unsigned long state, |
| 11210 | void *_notify) |
| 11211 | { |
| 11212 | struct netlink_notify *notify = _notify; |
| 11213 | struct cfg80211_registered_device *rdev; |
| 11214 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11215 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11216 | |
| 11217 | if (state != NETLINK_URELEASE) |
| 11218 | return NOTIFY_DONE; |
| 11219 | |
| 11220 | rcu_read_lock(); |
| 11221 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11222 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11223 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11224 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11225 | |
| 11226 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11227 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11228 | list) { |
| 11229 | if (reg->nlportid == notify->portid) { |
| 11230 | list_del(®->list); |
| 11231 | kfree(reg); |
| 11232 | break; |
| 11233 | } |
| 11234 | } |
| 11235 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11236 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11237 | |
| 11238 | rcu_read_unlock(); |
| 11239 | |
| 11240 | return NOTIFY_DONE; |
| 11241 | } |
| 11242 | |
| 11243 | static struct notifier_block nl80211_netlink_notifier = { |
| 11244 | .notifier_call = nl80211_netlink_notify, |
| 11245 | }; |
| 11246 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11247 | void cfg80211_ft_event(struct net_device *netdev, |
| 11248 | struct cfg80211_ft_event_params *ft_event) |
| 11249 | { |
| 11250 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11251 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11252 | struct sk_buff *msg; |
| 11253 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11254 | |
| 11255 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11256 | |
| 11257 | if (!ft_event->target_ap) |
| 11258 | return; |
| 11259 | |
| 11260 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11261 | if (!msg) |
| 11262 | return; |
| 11263 | |
| 11264 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 11265 | if (!hdr) { |
| 11266 | nlmsg_free(msg); |
| 11267 | return; |
| 11268 | } |
| 11269 | |
| 11270 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 11271 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 11272 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 11273 | if (ft_event->ies) |
| 11274 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 11275 | if (ft_event->ric_ies) |
| 11276 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11277 | ft_event->ric_ies); |
| 11278 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11279 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11280 | |
| 11281 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11282 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 11283 | } |
| 11284 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11285 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11286 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11287 | { |
| 11288 | struct cfg80211_registered_device *rdev; |
| 11289 | struct sk_buff *msg; |
| 11290 | void *hdr; |
| 11291 | u32 nlportid; |
| 11292 | |
| 11293 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11294 | if (!rdev->crit_proto_nlportid) |
| 11295 | return; |
| 11296 | |
| 11297 | nlportid = rdev->crit_proto_nlportid; |
| 11298 | rdev->crit_proto_nlportid = 0; |
| 11299 | |
| 11300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11301 | if (!msg) |
| 11302 | return; |
| 11303 | |
| 11304 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11305 | if (!hdr) |
| 11306 | goto nla_put_failure; |
| 11307 | |
| 11308 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11309 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11310 | goto nla_put_failure; |
| 11311 | |
| 11312 | genlmsg_end(msg, hdr); |
| 11313 | |
| 11314 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11315 | return; |
| 11316 | |
| 11317 | nla_put_failure: |
| 11318 | if (hdr) |
| 11319 | genlmsg_cancel(msg, hdr); |
| 11320 | nlmsg_free(msg); |
| 11321 | |
| 11322 | } |
| 11323 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11324 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11325 | /* initialisation/exit functions */ |
| 11326 | |
| 11327 | int nl80211_init(void) |
| 11328 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11329 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11330 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11331 | err = genl_register_family_with_ops(&nl80211_fam, |
| 11332 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11333 | if (err) |
| 11334 | return err; |
| 11335 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11336 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 11337 | if (err) |
| 11338 | goto err_out; |
| 11339 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11340 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 11341 | if (err) |
| 11342 | goto err_out; |
| 11343 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11344 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 11345 | if (err) |
| 11346 | goto err_out; |
| 11347 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11348 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 11349 | if (err) |
| 11350 | goto err_out; |
| 11351 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11352 | #ifdef CONFIG_NL80211_TESTMODE |
| 11353 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 11354 | if (err) |
| 11355 | goto err_out; |
| 11356 | #endif |
| 11357 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11358 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11359 | if (err) |
| 11360 | goto err_out; |
| 11361 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11362 | return 0; |
| 11363 | err_out: |
| 11364 | genl_unregister_family(&nl80211_fam); |
| 11365 | return err; |
| 11366 | } |
| 11367 | |
| 11368 | void nl80211_exit(void) |
| 11369 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11370 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11371 | genl_unregister_family(&nl80211_fam); |
| 11372 | } |