Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 62 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 94 | |
| 95 | if (result) |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | if (result) |
| 100 | return result; |
| 101 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 104 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 108 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 109 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 110 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 113 | !attrs[NL80211_ATTR_IFINDEX] && |
| 114 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 115 | return ERR_PTR(-EINVAL); |
| 116 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 121 | if (attrs[NL80211_ATTR_WDEV]) { |
| 122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 123 | struct wireless_dev *wdev; |
| 124 | bool found = false; |
| 125 | |
| 126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 127 | if (tmp) { |
| 128 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 129 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 130 | if (wdev->identifier != (u32)wdev_id) |
| 131 | continue; |
| 132 | found = true; |
| 133 | break; |
| 134 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | |
| 136 | if (!found) |
| 137 | tmp = NULL; |
| 138 | |
| 139 | if (rdev && tmp != rdev) |
| 140 | return ERR_PTR(-EINVAL); |
| 141 | rdev = tmp; |
| 142 | } |
| 143 | } |
| 144 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 145 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 146 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 147 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 148 | if (netdev) { |
| 149 | if (netdev->ieee80211_ptr) |
| 150 | tmp = wiphy_to_dev( |
| 151 | netdev->ieee80211_ptr->wiphy); |
| 152 | else |
| 153 | tmp = NULL; |
| 154 | |
| 155 | dev_put(netdev); |
| 156 | |
| 157 | /* not wireless device -- return error */ |
| 158 | if (!tmp) |
| 159 | return ERR_PTR(-EINVAL); |
| 160 | |
| 161 | /* mismatch -- return error */ |
| 162 | if (rdev && tmp != rdev) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 166 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 169 | if (!rdev) |
| 170 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (netns != wiphy_net(&rdev->wiphy)) |
| 173 | return ERR_PTR(-ENODEV); |
| 174 | |
| 175 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
| 179 | * This function returns a pointer to the driver |
| 180 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | * |
| 182 | * The result of this can be a PTR_ERR and hence must |
| 183 | * be checked with IS_ERR() for errors. |
| 184 | */ |
| 185 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 186 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 188 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 191 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 192 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 193 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 194 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 195 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 196 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 197 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 198 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 199 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 200 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 201 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 202 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 203 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 204 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 205 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 206 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 207 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 208 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 209 | |
| 210 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 211 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 212 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 213 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 214 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 215 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 216 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 218 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 219 | .len = WLAN_MAX_KEY_LEN }, |
| 220 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 221 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 225 | |
| 226 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 228 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 229 | .len = IEEE80211_MAX_DATA_LEN }, |
| 230 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 231 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 232 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 233 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 234 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 235 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 236 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 239 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 240 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 241 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 242 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 243 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 244 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 245 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 246 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 247 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 248 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 249 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 250 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 251 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 252 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 253 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 256 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 258 | |
| 259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 264 | |
| 265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 266 | .len = IEEE80211_MAX_SSID_LEN }, |
| 267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 272 | [NL80211_ATTR_STA_FLAGS2] = { |
| 273 | .len = sizeof(struct nl80211_sta_flag_update), |
| 274 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 284 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_DATA_LEN }, |
| 290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 327 | .len = NL80211_HT_CAPABILITY_LEN |
| 328 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 347 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 350 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 352 | }; |
| 353 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 354 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 355 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 356 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 357 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 358 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 359 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 360 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 361 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 362 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 363 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 364 | }; |
| 365 | |
| 366 | /* policy for the key default flags */ |
| 367 | static const struct nla_policy |
| 368 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 369 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 370 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 371 | }; |
| 372 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 373 | /* policy for WoWLAN attributes */ |
| 374 | static const struct nla_policy |
| 375 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 376 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 377 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 378 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 379 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 380 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 381 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 382 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 383 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 384 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 385 | }; |
| 386 | |
| 387 | static const struct nla_policy |
| 388 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 389 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 390 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 391 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 392 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 393 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 394 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 395 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 396 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 397 | }, |
| 398 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 399 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 400 | }, |
| 401 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 402 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 403 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 404 | }; |
| 405 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 406 | /* policy for GTK rekey offload attributes */ |
| 407 | static const struct nla_policy |
| 408 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 409 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 410 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 411 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 412 | }; |
| 413 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 414 | static const struct nla_policy |
| 415 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 416 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 417 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 418 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 419 | }; |
| 420 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 421 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 422 | struct netlink_callback *cb, |
| 423 | struct cfg80211_registered_device **rdev, |
| 424 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 425 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 426 | int err; |
| 427 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 428 | rtnl_lock(); |
| 429 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 430 | if (!cb->args[0]) { |
| 431 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 432 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 433 | nl80211_policy); |
| 434 | if (err) |
| 435 | goto out_unlock; |
| 436 | |
| 437 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 438 | nl80211_fam.attrbuf); |
| 439 | if (IS_ERR(*wdev)) { |
| 440 | err = PTR_ERR(*wdev); |
| 441 | goto out_unlock; |
| 442 | } |
| 443 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
| 444 | cb->args[0] = (*rdev)->wiphy_idx; |
| 445 | cb->args[1] = (*wdev)->identifier; |
| 446 | } else { |
| 447 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); |
| 448 | struct wireless_dev *tmp; |
| 449 | |
| 450 | if (!wiphy) { |
| 451 | err = -ENODEV; |
| 452 | goto out_unlock; |
| 453 | } |
| 454 | *rdev = wiphy_to_dev(wiphy); |
| 455 | *wdev = NULL; |
| 456 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 457 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 458 | if (tmp->identifier == cb->args[1]) { |
| 459 | *wdev = tmp; |
| 460 | break; |
| 461 | } |
| 462 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 463 | |
| 464 | if (!*wdev) { |
| 465 | err = -ENODEV; |
| 466 | goto out_unlock; |
| 467 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 470 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 471 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 472 | rtnl_unlock(); |
| 473 | return err; |
| 474 | } |
| 475 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 476 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 477 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 478 | rtnl_unlock(); |
| 479 | } |
| 480 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 481 | /* IE validation */ |
| 482 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 483 | { |
| 484 | const u8 *pos; |
| 485 | int len; |
| 486 | |
| 487 | if (!attr) |
| 488 | return true; |
| 489 | |
| 490 | pos = nla_data(attr); |
| 491 | len = nla_len(attr); |
| 492 | |
| 493 | while (len) { |
| 494 | u8 elemlen; |
| 495 | |
| 496 | if (len < 2) |
| 497 | return false; |
| 498 | len -= 2; |
| 499 | |
| 500 | elemlen = pos[1]; |
| 501 | if (elemlen > len) |
| 502 | return false; |
| 503 | |
| 504 | len -= elemlen; |
| 505 | pos += 2 + elemlen; |
| 506 | } |
| 507 | |
| 508 | return true; |
| 509 | } |
| 510 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 511 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 512 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 513 | int flags, u8 cmd) |
| 514 | { |
| 515 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 516 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 517 | } |
| 518 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 519 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 520 | struct ieee80211_channel *chan, |
| 521 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 522 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 523 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 524 | chan->center_freq)) |
| 525 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 526 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 527 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 528 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 529 | goto nla_put_failure; |
| 530 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 531 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 532 | goto nla_put_failure; |
| 533 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 534 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 535 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 536 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 537 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 538 | goto nla_put_failure; |
| 539 | if (large) { |
| 540 | u32 time; |
| 541 | |
| 542 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 543 | |
| 544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 545 | chan->dfs_state)) |
| 546 | goto nla_put_failure; |
| 547 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 548 | time)) |
| 549 | goto nla_put_failure; |
| 550 | } |
| 551 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 552 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 553 | if (large) { |
| 554 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 556 | goto nla_put_failure; |
| 557 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 559 | goto nla_put_failure; |
| 560 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 561 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 562 | goto nla_put_failure; |
| 563 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 564 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 565 | goto nla_put_failure; |
| 566 | } |
| 567 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 568 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 569 | DBM_TO_MBM(chan->max_power))) |
| 570 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 571 | |
| 572 | return 0; |
| 573 | |
| 574 | nla_put_failure: |
| 575 | return -ENOBUFS; |
| 576 | } |
| 577 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 578 | /* netlink command implementations */ |
| 579 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 580 | struct key_parse { |
| 581 | struct key_params p; |
| 582 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 583 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 584 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 585 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 589 | { |
| 590 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 591 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 592 | nl80211_key_policy); |
| 593 | if (err) |
| 594 | return err; |
| 595 | |
| 596 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 597 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 598 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 599 | if (k->def) { |
| 600 | k->def_uni = true; |
| 601 | k->def_multi = true; |
| 602 | } |
| 603 | if (k->defmgmt) |
| 604 | k->def_multi = true; |
| 605 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 606 | if (tb[NL80211_KEY_IDX]) |
| 607 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 608 | |
| 609 | if (tb[NL80211_KEY_DATA]) { |
| 610 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 611 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 612 | } |
| 613 | |
| 614 | if (tb[NL80211_KEY_SEQ]) { |
| 615 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 616 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 617 | } |
| 618 | |
| 619 | if (tb[NL80211_KEY_CIPHER]) |
| 620 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 621 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 622 | if (tb[NL80211_KEY_TYPE]) { |
| 623 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 624 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 625 | return -EINVAL; |
| 626 | } |
| 627 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 628 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 629 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 630 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 631 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 632 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 633 | if (err) |
| 634 | return err; |
| 635 | |
| 636 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 637 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 638 | } |
| 639 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 644 | { |
| 645 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 646 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 647 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 648 | } |
| 649 | |
| 650 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 651 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 652 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 653 | } |
| 654 | |
| 655 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 656 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 657 | |
| 658 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 659 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 660 | |
| 661 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 662 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 663 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 664 | if (k->def) { |
| 665 | k->def_uni = true; |
| 666 | k->def_multi = true; |
| 667 | } |
| 668 | if (k->defmgmt) |
| 669 | k->def_multi = true; |
| 670 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 671 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 672 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 673 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 674 | return -EINVAL; |
| 675 | } |
| 676 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 677 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 678 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 679 | int err = nla_parse_nested( |
| 680 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 681 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 682 | nl80211_key_default_policy); |
| 683 | if (err) |
| 684 | return err; |
| 685 | |
| 686 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 687 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 688 | } |
| 689 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 694 | { |
| 695 | int err; |
| 696 | |
| 697 | memset(k, 0, sizeof(*k)); |
| 698 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 699 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 700 | |
| 701 | if (info->attrs[NL80211_ATTR_KEY]) |
| 702 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 703 | else |
| 704 | err = nl80211_parse_key_old(info, k); |
| 705 | |
| 706 | if (err) |
| 707 | return err; |
| 708 | |
| 709 | if (k->def && k->defmgmt) |
| 710 | return -EINVAL; |
| 711 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 712 | if (k->defmgmt) { |
| 713 | if (k->def_uni || !k->def_multi) |
| 714 | return -EINVAL; |
| 715 | } |
| 716 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 717 | if (k->idx != -1) { |
| 718 | if (k->defmgmt) { |
| 719 | if (k->idx < 4 || k->idx > 5) |
| 720 | return -EINVAL; |
| 721 | } else if (k->def) { |
| 722 | if (k->idx < 0 || k->idx > 3) |
| 723 | return -EINVAL; |
| 724 | } else { |
| 725 | if (k->idx < 0 || k->idx > 5) |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 733 | static struct cfg80211_cached_keys * |
| 734 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 735 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 736 | { |
| 737 | struct key_parse parse; |
| 738 | struct nlattr *key; |
| 739 | struct cfg80211_cached_keys *result; |
| 740 | int rem, err, def = 0; |
| 741 | |
| 742 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 743 | if (!result) |
| 744 | return ERR_PTR(-ENOMEM); |
| 745 | |
| 746 | result->def = -1; |
| 747 | result->defmgmt = -1; |
| 748 | |
| 749 | nla_for_each_nested(key, keys, rem) { |
| 750 | memset(&parse, 0, sizeof(parse)); |
| 751 | parse.idx = -1; |
| 752 | |
| 753 | err = nl80211_parse_key_new(key, &parse); |
| 754 | if (err) |
| 755 | goto error; |
| 756 | err = -EINVAL; |
| 757 | if (!parse.p.key) |
| 758 | goto error; |
| 759 | if (parse.idx < 0 || parse.idx > 4) |
| 760 | goto error; |
| 761 | if (parse.def) { |
| 762 | if (def) |
| 763 | goto error; |
| 764 | def = 1; |
| 765 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 766 | if (!parse.def_uni || !parse.def_multi) |
| 767 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 768 | } else if (parse.defmgmt) |
| 769 | goto error; |
| 770 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 771 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 772 | if (err) |
| 773 | goto error; |
| 774 | result->params[parse.idx].cipher = parse.p.cipher; |
| 775 | result->params[parse.idx].key_len = parse.p.key_len; |
| 776 | result->params[parse.idx].key = result->data[parse.idx]; |
| 777 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 778 | |
| 779 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 780 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 781 | if (no_ht) |
| 782 | *no_ht = true; |
| 783 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | return result; |
| 787 | error: |
| 788 | kfree(result); |
| 789 | return ERR_PTR(err); |
| 790 | } |
| 791 | |
| 792 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 793 | { |
| 794 | ASSERT_WDEV_LOCK(wdev); |
| 795 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 796 | switch (wdev->iftype) { |
| 797 | case NL80211_IFTYPE_AP: |
| 798 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 799 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 800 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 801 | break; |
| 802 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 803 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 804 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 805 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 806 | return -ENOLINK; |
| 807 | break; |
| 808 | default: |
| 809 | return -EINVAL; |
| 810 | } |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 815 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 816 | { |
| 817 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 818 | int i; |
| 819 | |
| 820 | if (!nl_modes) |
| 821 | goto nla_put_failure; |
| 822 | |
| 823 | i = 0; |
| 824 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 825 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 826 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 827 | ifmodes >>= 1; |
| 828 | i++; |
| 829 | } |
| 830 | |
| 831 | nla_nest_end(msg, nl_modes); |
| 832 | return 0; |
| 833 | |
| 834 | nla_put_failure: |
| 835 | return -ENOBUFS; |
| 836 | } |
| 837 | |
| 838 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 839 | struct sk_buff *msg, |
| 840 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 841 | { |
| 842 | struct nlattr *nl_combis; |
| 843 | int i, j; |
| 844 | |
| 845 | nl_combis = nla_nest_start(msg, |
| 846 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 847 | if (!nl_combis) |
| 848 | goto nla_put_failure; |
| 849 | |
| 850 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 851 | const struct ieee80211_iface_combination *c; |
| 852 | struct nlattr *nl_combi, *nl_limits; |
| 853 | |
| 854 | c = &wiphy->iface_combinations[i]; |
| 855 | |
| 856 | nl_combi = nla_nest_start(msg, i + 1); |
| 857 | if (!nl_combi) |
| 858 | goto nla_put_failure; |
| 859 | |
| 860 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 861 | if (!nl_limits) |
| 862 | goto nla_put_failure; |
| 863 | |
| 864 | for (j = 0; j < c->n_limits; j++) { |
| 865 | struct nlattr *nl_limit; |
| 866 | |
| 867 | nl_limit = nla_nest_start(msg, j + 1); |
| 868 | if (!nl_limit) |
| 869 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 870 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 871 | c->limits[j].max)) |
| 872 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 873 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 874 | c->limits[j].types)) |
| 875 | goto nla_put_failure; |
| 876 | nla_nest_end(msg, nl_limit); |
| 877 | } |
| 878 | |
| 879 | nla_nest_end(msg, nl_limits); |
| 880 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 881 | if (c->beacon_int_infra_match && |
| 882 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 883 | goto nla_put_failure; |
| 884 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 885 | c->num_different_channels) || |
| 886 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 887 | c->max_interfaces)) |
| 888 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 889 | if (large && |
| 890 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 891 | c->radar_detect_widths)) |
| 892 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 893 | |
| 894 | nla_nest_end(msg, nl_combi); |
| 895 | } |
| 896 | |
| 897 | nla_nest_end(msg, nl_combis); |
| 898 | |
| 899 | return 0; |
| 900 | nla_put_failure: |
| 901 | return -ENOBUFS; |
| 902 | } |
| 903 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 904 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 905 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 906 | struct sk_buff *msg) |
| 907 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 908 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 909 | struct nlattr *nl_tcp; |
| 910 | |
| 911 | if (!tcp) |
| 912 | return 0; |
| 913 | |
| 914 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 915 | if (!nl_tcp) |
| 916 | return -ENOBUFS; |
| 917 | |
| 918 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 919 | tcp->data_payload_max)) |
| 920 | return -ENOBUFS; |
| 921 | |
| 922 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 923 | tcp->data_payload_max)) |
| 924 | return -ENOBUFS; |
| 925 | |
| 926 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 927 | return -ENOBUFS; |
| 928 | |
| 929 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 930 | sizeof(*tcp->tok), tcp->tok)) |
| 931 | return -ENOBUFS; |
| 932 | |
| 933 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 934 | tcp->data_interval_max)) |
| 935 | return -ENOBUFS; |
| 936 | |
| 937 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 938 | tcp->wake_payload_max)) |
| 939 | return -ENOBUFS; |
| 940 | |
| 941 | nla_nest_end(msg, nl_tcp); |
| 942 | return 0; |
| 943 | } |
| 944 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 945 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 946 | struct cfg80211_registered_device *dev, |
| 947 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 948 | { |
| 949 | struct nlattr *nl_wowlan; |
| 950 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 951 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 952 | return 0; |
| 953 | |
| 954 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 955 | if (!nl_wowlan) |
| 956 | return -ENOBUFS; |
| 957 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 958 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 959 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 960 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 961 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 962 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 963 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 964 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 965 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 966 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 967 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 968 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 969 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 970 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 971 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 972 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 973 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 974 | return -ENOBUFS; |
| 975 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 976 | if (dev->wiphy.wowlan->n_patterns) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 977 | struct nl80211_wowlan_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 978 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 979 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 980 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 981 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 982 | }; |
| 983 | |
| 984 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 985 | sizeof(pat), &pat)) |
| 986 | return -ENOBUFS; |
| 987 | } |
| 988 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 989 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 990 | return -ENOBUFS; |
| 991 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 992 | nla_nest_end(msg, nl_wowlan); |
| 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | #endif |
| 997 | |
| 998 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 999 | struct ieee80211_supported_band *sband) |
| 1000 | { |
| 1001 | struct nlattr *nl_rates, *nl_rate; |
| 1002 | struct ieee80211_rate *rate; |
| 1003 | int i; |
| 1004 | |
| 1005 | /* add HT info */ |
| 1006 | if (sband->ht_cap.ht_supported && |
| 1007 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1008 | sizeof(sband->ht_cap.mcs), |
| 1009 | &sband->ht_cap.mcs) || |
| 1010 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1011 | sband->ht_cap.cap) || |
| 1012 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1013 | sband->ht_cap.ampdu_factor) || |
| 1014 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1015 | sband->ht_cap.ampdu_density))) |
| 1016 | return -ENOBUFS; |
| 1017 | |
| 1018 | /* add VHT info */ |
| 1019 | if (sband->vht_cap.vht_supported && |
| 1020 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1021 | sizeof(sband->vht_cap.vht_mcs), |
| 1022 | &sband->vht_cap.vht_mcs) || |
| 1023 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1024 | sband->vht_cap.cap))) |
| 1025 | return -ENOBUFS; |
| 1026 | |
| 1027 | /* add bitrates */ |
| 1028 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1029 | if (!nl_rates) |
| 1030 | return -ENOBUFS; |
| 1031 | |
| 1032 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1033 | nl_rate = nla_nest_start(msg, i); |
| 1034 | if (!nl_rate) |
| 1035 | return -ENOBUFS; |
| 1036 | |
| 1037 | rate = &sband->bitrates[i]; |
| 1038 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1039 | rate->bitrate)) |
| 1040 | return -ENOBUFS; |
| 1041 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1042 | nla_put_flag(msg, |
| 1043 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1044 | return -ENOBUFS; |
| 1045 | |
| 1046 | nla_nest_end(msg, nl_rate); |
| 1047 | } |
| 1048 | |
| 1049 | nla_nest_end(msg, nl_rates); |
| 1050 | |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | static int |
| 1055 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1056 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1057 | { |
| 1058 | u16 stypes; |
| 1059 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1060 | enum nl80211_iftype ift; |
| 1061 | int i; |
| 1062 | |
| 1063 | if (!mgmt_stypes) |
| 1064 | return 0; |
| 1065 | |
| 1066 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1067 | if (!nl_ifs) |
| 1068 | return -ENOBUFS; |
| 1069 | |
| 1070 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1071 | nl_ftypes = nla_nest_start(msg, ift); |
| 1072 | if (!nl_ftypes) |
| 1073 | return -ENOBUFS; |
| 1074 | i = 0; |
| 1075 | stypes = mgmt_stypes[ift].tx; |
| 1076 | while (stypes) { |
| 1077 | if ((stypes & 1) && |
| 1078 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1079 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1080 | return -ENOBUFS; |
| 1081 | stypes >>= 1; |
| 1082 | i++; |
| 1083 | } |
| 1084 | nla_nest_end(msg, nl_ftypes); |
| 1085 | } |
| 1086 | |
| 1087 | nla_nest_end(msg, nl_ifs); |
| 1088 | |
| 1089 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1090 | if (!nl_ifs) |
| 1091 | return -ENOBUFS; |
| 1092 | |
| 1093 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1094 | nl_ftypes = nla_nest_start(msg, ift); |
| 1095 | if (!nl_ftypes) |
| 1096 | return -ENOBUFS; |
| 1097 | i = 0; |
| 1098 | stypes = mgmt_stypes[ift].rx; |
| 1099 | while (stypes) { |
| 1100 | if ((stypes & 1) && |
| 1101 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1102 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1103 | return -ENOBUFS; |
| 1104 | stypes >>= 1; |
| 1105 | i++; |
| 1106 | } |
| 1107 | nla_nest_end(msg, nl_ftypes); |
| 1108 | } |
| 1109 | nla_nest_end(msg, nl_ifs); |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1115 | struct sk_buff *msg, u32 portid, u32 seq, |
| 1116 | int flags, bool split, long *split_start, |
| 1117 | long *band_start, long *chan_start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1118 | { |
| 1119 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1120 | struct nlattr *nl_bands, *nl_band; |
| 1121 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1122 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1123 | enum ieee80211_band band; |
| 1124 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1125 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1126 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1127 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1128 | long start = 0, start_chan = 0, start_band = 0; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1129 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1130 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1131 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1132 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1133 | return -ENOBUFS; |
| 1134 | |
| 1135 | /* allow always using the variables */ |
| 1136 | if (!split) { |
| 1137 | split_start = &start; |
| 1138 | band_start = &start_band; |
| 1139 | chan_start = &start_chan; |
| 1140 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1141 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1143 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1144 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1145 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1146 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1147 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1148 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1149 | switch (*split_start) { |
| 1150 | case 0: |
| 1151 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1152 | dev->wiphy.retry_short) || |
| 1153 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1154 | dev->wiphy.retry_long) || |
| 1155 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1156 | dev->wiphy.frag_threshold) || |
| 1157 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1158 | dev->wiphy.rts_threshold) || |
| 1159 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1160 | dev->wiphy.coverage_class) || |
| 1161 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1162 | dev->wiphy.max_scan_ssids) || |
| 1163 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1164 | dev->wiphy.max_sched_scan_ssids) || |
| 1165 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1166 | dev->wiphy.max_scan_ie_len) || |
| 1167 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1168 | dev->wiphy.max_sched_scan_ie_len) || |
| 1169 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1170 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1171 | goto nla_put_failure; |
| 1172 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1173 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1174 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1175 | goto nla_put_failure; |
| 1176 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1177 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1178 | goto nla_put_failure; |
| 1179 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1180 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1181 | goto nla_put_failure; |
| 1182 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1183 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1184 | goto nla_put_failure; |
| 1185 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1186 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1187 | goto nla_put_failure; |
| 1188 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1189 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1190 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1191 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1192 | (*split_start)++; |
| 1193 | if (split) |
| 1194 | break; |
| 1195 | case 1: |
| 1196 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1197 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1198 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1199 | goto nla_put_failure; |
| 1200 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1201 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1202 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1203 | goto nla_put_failure; |
| 1204 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1205 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1206 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1207 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1208 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1209 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1210 | dev->wiphy.available_antennas_tx) || |
| 1211 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1212 | dev->wiphy.available_antennas_rx)) |
| 1213 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1214 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1215 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1216 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1217 | dev->wiphy.probe_resp_offload)) |
| 1218 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1219 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1220 | if ((dev->wiphy.available_antennas_tx || |
| 1221 | dev->wiphy.available_antennas_rx) && |
| 1222 | dev->ops->get_antenna) { |
| 1223 | u32 tx_ant = 0, rx_ant = 0; |
| 1224 | int res; |
| 1225 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1226 | if (!res) { |
| 1227 | if (nla_put_u32(msg, |
| 1228 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1229 | tx_ant) || |
| 1230 | nla_put_u32(msg, |
| 1231 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1232 | rx_ant)) |
| 1233 | goto nla_put_failure; |
| 1234 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1237 | (*split_start)++; |
| 1238 | if (split) |
| 1239 | break; |
| 1240 | case 2: |
| 1241 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1242 | dev->wiphy.interface_modes)) |
| 1243 | goto nla_put_failure; |
| 1244 | (*split_start)++; |
| 1245 | if (split) |
| 1246 | break; |
| 1247 | case 3: |
| 1248 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1249 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1250 | goto nla_put_failure; |
| 1251 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1252 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
| 1253 | struct ieee80211_supported_band *sband; |
| 1254 | |
| 1255 | sband = dev->wiphy.bands[band]; |
| 1256 | |
| 1257 | if (!sband) |
| 1258 | continue; |
| 1259 | |
| 1260 | nl_band = nla_nest_start(msg, band); |
| 1261 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1262 | goto nla_put_failure; |
| 1263 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1264 | switch (*chan_start) { |
| 1265 | case 0: |
| 1266 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1267 | goto nla_put_failure; |
| 1268 | (*chan_start)++; |
| 1269 | if (split) |
| 1270 | break; |
| 1271 | default: |
| 1272 | /* add frequencies */ |
| 1273 | nl_freqs = nla_nest_start( |
| 1274 | msg, NL80211_BAND_ATTR_FREQS); |
| 1275 | if (!nl_freqs) |
| 1276 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1277 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | for (i = *chan_start - 1; |
| 1279 | i < sband->n_channels; |
| 1280 | i++) { |
| 1281 | nl_freq = nla_nest_start(msg, i); |
| 1282 | if (!nl_freq) |
| 1283 | goto nla_put_failure; |
| 1284 | |
| 1285 | chan = &sband->channels[i]; |
| 1286 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1287 | if (nl80211_msg_put_channel(msg, chan, |
| 1288 | split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1289 | goto nla_put_failure; |
| 1290 | |
| 1291 | nla_nest_end(msg, nl_freq); |
| 1292 | if (split) |
| 1293 | break; |
| 1294 | } |
| 1295 | if (i < sband->n_channels) |
| 1296 | *chan_start = i + 2; |
| 1297 | else |
| 1298 | *chan_start = 0; |
| 1299 | nla_nest_end(msg, nl_freqs); |
| 1300 | } |
| 1301 | |
| 1302 | nla_nest_end(msg, nl_band); |
| 1303 | |
| 1304 | if (split) { |
| 1305 | /* start again here */ |
| 1306 | if (*chan_start) |
| 1307 | band--; |
| 1308 | break; |
| 1309 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1310 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1312 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | if (band < IEEE80211_NUM_BANDS) |
| 1314 | *band_start = band + 1; |
| 1315 | else |
| 1316 | *band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1317 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | /* if bands & channels are done, continue outside */ |
| 1319 | if (*band_start == 0 && *chan_start == 0) |
| 1320 | (*split_start)++; |
| 1321 | if (split) |
| 1322 | break; |
| 1323 | case 4: |
| 1324 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1325 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1326 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1327 | |
| 1328 | i = 0; |
| 1329 | #define CMD(op, n) \ |
| 1330 | do { \ |
| 1331 | if (dev->ops->op) { \ |
| 1332 | i++; \ |
| 1333 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1334 | goto nla_put_failure; \ |
| 1335 | } \ |
| 1336 | } while (0) |
| 1337 | |
| 1338 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1339 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1340 | CMD(add_key, NEW_KEY); |
| 1341 | CMD(start_ap, START_AP); |
| 1342 | CMD(add_station, NEW_STATION); |
| 1343 | CMD(add_mpath, NEW_MPATH); |
| 1344 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1345 | CMD(change_bss, SET_BSS); |
| 1346 | CMD(auth, AUTHENTICATE); |
| 1347 | CMD(assoc, ASSOCIATE); |
| 1348 | CMD(deauth, DEAUTHENTICATE); |
| 1349 | CMD(disassoc, DISASSOCIATE); |
| 1350 | CMD(join_ibss, JOIN_IBSS); |
| 1351 | CMD(join_mesh, JOIN_MESH); |
| 1352 | CMD(set_pmksa, SET_PMKSA); |
| 1353 | CMD(del_pmksa, DEL_PMKSA); |
| 1354 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1355 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1356 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1357 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1358 | CMD(mgmt_tx, FRAME); |
| 1359 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1360 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1361 | i++; |
| 1362 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1363 | goto nla_put_failure; |
| 1364 | } |
| 1365 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1366 | dev->ops->join_mesh) { |
| 1367 | i++; |
| 1368 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1369 | goto nla_put_failure; |
| 1370 | } |
| 1371 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1372 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1373 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1374 | CMD(tdls_oper, TDLS_OPER); |
| 1375 | } |
| 1376 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1377 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1378 | CMD(probe_client, PROBE_CLIENT); |
| 1379 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1380 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1381 | i++; |
| 1382 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1383 | goto nla_put_failure; |
| 1384 | } |
| 1385 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1386 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1387 | if (split) { |
| 1388 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1389 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
| 1390 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1391 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1392 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1393 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1394 | #endif |
| 1395 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1396 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1397 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1398 | if (dev->ops->connect || dev->ops->auth) { |
| 1399 | i++; |
| 1400 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1401 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1402 | } |
| 1403 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1404 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1405 | i++; |
| 1406 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1407 | goto nla_put_failure; |
| 1408 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1409 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1410 | nla_nest_end(msg, nl_cmds); |
| 1411 | (*split_start)++; |
| 1412 | if (split) |
| 1413 | break; |
| 1414 | case 5: |
| 1415 | if (dev->ops->remain_on_channel && |
| 1416 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1417 | nla_put_u32(msg, |
| 1418 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1419 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1420 | goto nla_put_failure; |
| 1421 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1422 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1423 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1424 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1425 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1426 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1427 | goto nla_put_failure; |
| 1428 | (*split_start)++; |
| 1429 | if (split) |
| 1430 | break; |
| 1431 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1432 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1433 | if (nl80211_send_wowlan(msg, dev, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1434 | goto nla_put_failure; |
| 1435 | (*split_start)++; |
| 1436 | if (split) |
| 1437 | break; |
| 1438 | #else |
| 1439 | (*split_start)++; |
| 1440 | #endif |
| 1441 | case 7: |
| 1442 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1443 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1444 | goto nla_put_failure; |
| 1445 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1446 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1447 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1448 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1449 | (*split_start)++; |
| 1450 | if (split) |
| 1451 | break; |
| 1452 | case 8: |
| 1453 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1454 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1455 | dev->wiphy.ap_sme_capa)) |
| 1456 | goto nla_put_failure; |
| 1457 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1458 | features = dev->wiphy.features; |
| 1459 | /* |
| 1460 | * We can only add the per-channel limit information if the |
| 1461 | * dump is split, otherwise it makes it too big. Therefore |
| 1462 | * only advertise it in that case. |
| 1463 | */ |
| 1464 | if (split) |
| 1465 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1466 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1467 | goto nla_put_failure; |
| 1468 | |
| 1469 | if (dev->wiphy.ht_capa_mod_mask && |
| 1470 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1471 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1472 | dev->wiphy.ht_capa_mod_mask)) |
| 1473 | goto nla_put_failure; |
| 1474 | |
| 1475 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1476 | dev->wiphy.max_acl_mac_addrs && |
| 1477 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1478 | dev->wiphy.max_acl_mac_addrs)) |
| 1479 | goto nla_put_failure; |
| 1480 | |
| 1481 | /* |
| 1482 | * Any information below this point is only available to |
| 1483 | * applications that can deal with it being split. This |
| 1484 | * helps ensure that newly added capabilities don't break |
| 1485 | * older tools by overrunning their buffers. |
| 1486 | * |
| 1487 | * We still increment split_start so that in the split |
| 1488 | * case we'll continue with more data in the next round, |
| 1489 | * but break unconditionally so unsplit data stops here. |
| 1490 | */ |
| 1491 | (*split_start)++; |
| 1492 | break; |
| 1493 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1494 | if (dev->wiphy.extended_capabilities && |
| 1495 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1496 | dev->wiphy.extended_capabilities_len, |
| 1497 | dev->wiphy.extended_capabilities) || |
| 1498 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1499 | dev->wiphy.extended_capabilities_len, |
| 1500 | dev->wiphy.extended_capabilities_mask))) |
| 1501 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1502 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1503 | if (dev->wiphy.vht_capa_mod_mask && |
| 1504 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1505 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1506 | dev->wiphy.vht_capa_mod_mask)) |
| 1507 | goto nla_put_failure; |
| 1508 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1509 | /* done */ |
| 1510 | *split_start = 0; |
| 1511 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1512 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1513 | return genlmsg_end(msg, hdr); |
| 1514 | |
| 1515 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1516 | genlmsg_cancel(msg, hdr); |
| 1517 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1521 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1522 | int idx = 0, ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1523 | int start = cb->args[0]; |
| 1524 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1525 | s64 filter_wiphy = -1; |
| 1526 | bool split = false; |
| 1527 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1528 | int res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1529 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1530 | rtnl_lock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1532 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1533 | if (res == 0) { |
| 1534 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1535 | if (tb[NL80211_ATTR_WIPHY]) |
| 1536 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1537 | if (tb[NL80211_ATTR_WDEV]) |
| 1538 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1539 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1540 | struct net_device *netdev; |
| 1541 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1542 | |
| 1543 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1544 | if (!netdev) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1545 | return -ENODEV; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | if (netdev->ieee80211_ptr) { |
| 1547 | dev = wiphy_to_dev( |
| 1548 | netdev->ieee80211_ptr->wiphy); |
| 1549 | filter_wiphy = dev->wiphy_idx; |
| 1550 | } |
| 1551 | dev_put(netdev); |
| 1552 | } |
| 1553 | } |
| 1554 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1555 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1556 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1557 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1558 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1559 | continue; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
| 1561 | continue; |
| 1562 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1563 | do { |
| 1564 | ret = nl80211_send_wiphy(dev, skb, |
| 1565 | NETLINK_CB(cb->skb).portid, |
| 1566 | cb->nlh->nlmsg_seq, |
| 1567 | NLM_F_MULTI, |
| 1568 | split, &cb->args[1], |
| 1569 | &cb->args[2], |
| 1570 | &cb->args[3]); |
| 1571 | if (ret < 0) { |
| 1572 | /* |
| 1573 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1574 | * or EMSGSIZE returned), this SKB is still |
| 1575 | * empty (so it's not too big because another |
| 1576 | * wiphy dataset is already in the skb) and |
| 1577 | * we've not tried to adjust the dump allocation |
| 1578 | * yet ... then adjust the alloc size to be |
| 1579 | * bigger, and return 1 but with the empty skb. |
| 1580 | * This results in an empty message being RX'ed |
| 1581 | * in userspace, but that is ignored. |
| 1582 | * |
| 1583 | * We can then retry with the larger buffer. |
| 1584 | */ |
| 1585 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1586 | !skb->len && |
| 1587 | cb->min_dump_alloc < 4096) { |
| 1588 | cb->min_dump_alloc = 4096; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1589 | return 1; |
| 1590 | } |
| 1591 | idx--; |
| 1592 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1593 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1594 | } while (cb->args[1] > 0); |
| 1595 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1596 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1597 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1598 | |
| 1599 | cb->args[0] = idx; |
| 1600 | |
| 1601 | return skb->len; |
| 1602 | } |
| 1603 | |
| 1604 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1605 | { |
| 1606 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1607 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1608 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1609 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1610 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1611 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1612 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1613 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
| 1614 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1615 | nlmsg_free(msg); |
| 1616 | return -ENOBUFS; |
| 1617 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1618 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1619 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1620 | } |
| 1621 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1622 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1623 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1624 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1625 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1626 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1627 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1628 | }; |
| 1629 | |
| 1630 | static int parse_txq_params(struct nlattr *tb[], |
| 1631 | struct ieee80211_txq_params *txq_params) |
| 1632 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1633 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1634 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1635 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1636 | return -EINVAL; |
| 1637 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1638 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1639 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1640 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1641 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1642 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1643 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1644 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1645 | return -EINVAL; |
| 1646 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1647 | return 0; |
| 1648 | } |
| 1649 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1650 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1651 | { |
| 1652 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1653 | * You can only set the channel explicitly for WDS interfaces, |
| 1654 | * all others have their channel managed via their respective |
| 1655 | * "establish a connection" command (connect, join, ...) |
| 1656 | * |
| 1657 | * For AP/GO and mesh mode, the channel can be set with the |
| 1658 | * channel userspace API, but is only stored and passed to the |
| 1659 | * low-level driver when the AP starts or the mesh is joined. |
| 1660 | * This is for backward compatibility, userspace can also give |
| 1661 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1662 | * |
| 1663 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1664 | * whatever else is going on, so they have their own special |
| 1665 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1666 | */ |
| 1667 | return !wdev || |
| 1668 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1669 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1670 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1671 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1672 | } |
| 1673 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1674 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1675 | struct genl_info *info, |
| 1676 | struct cfg80211_chan_def *chandef) |
| 1677 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1678 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1679 | |
| 1680 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1681 | return -EINVAL; |
| 1682 | |
| 1683 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1684 | |
| 1685 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1686 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1687 | chandef->center_freq1 = control_freq; |
| 1688 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1689 | |
| 1690 | /* Primary channel not allowed */ |
| 1691 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1692 | return -EINVAL; |
| 1693 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1694 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1695 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1696 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1697 | chantype = nla_get_u32( |
| 1698 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1699 | |
| 1700 | switch (chantype) { |
| 1701 | case NL80211_CHAN_NO_HT: |
| 1702 | case NL80211_CHAN_HT20: |
| 1703 | case NL80211_CHAN_HT40PLUS: |
| 1704 | case NL80211_CHAN_HT40MINUS: |
| 1705 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1706 | chantype); |
| 1707 | break; |
| 1708 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1709 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1710 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1711 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1712 | chandef->width = |
| 1713 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1714 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1715 | chandef->center_freq1 = |
| 1716 | nla_get_u32( |
| 1717 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1718 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1719 | chandef->center_freq2 = |
| 1720 | nla_get_u32( |
| 1721 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1722 | } |
| 1723 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1724 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1725 | return -EINVAL; |
| 1726 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1727 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1728 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1729 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1730 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1731 | return 0; |
| 1732 | } |
| 1733 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1734 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1735 | struct wireless_dev *wdev, |
| 1736 | struct genl_info *info) |
| 1737 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1738 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1739 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1740 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1741 | |
| 1742 | if (wdev) |
| 1743 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1744 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1745 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1746 | return -EOPNOTSUPP; |
| 1747 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1748 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1749 | if (result) |
| 1750 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1751 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1752 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1753 | case NL80211_IFTYPE_AP: |
| 1754 | case NL80211_IFTYPE_P2P_GO: |
| 1755 | if (wdev->beacon_interval) { |
| 1756 | result = -EBUSY; |
| 1757 | break; |
| 1758 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1759 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1760 | result = -EINVAL; |
| 1761 | break; |
| 1762 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1763 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1764 | result = 0; |
| 1765 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1766 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1767 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1768 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1769 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1770 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1771 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1772 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1773 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1774 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1775 | |
| 1776 | return result; |
| 1777 | } |
| 1778 | |
| 1779 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1780 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1781 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1782 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1783 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1784 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1785 | } |
| 1786 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1787 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1788 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1789 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1790 | struct net_device *dev = info->user_ptr[1]; |
| 1791 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1792 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1793 | |
| 1794 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1795 | return -EINVAL; |
| 1796 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1797 | if (netif_running(dev)) |
| 1798 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1799 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1800 | if (!rdev->ops->set_wds_peer) |
| 1801 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1802 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1803 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1804 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1805 | |
| 1806 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1807 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1811 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1812 | { |
| 1813 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1814 | struct net_device *netdev = NULL; |
| 1815 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1816 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1817 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1818 | u32 changed; |
| 1819 | u8 retry_short = 0, retry_long = 0; |
| 1820 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1821 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1822 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1823 | ASSERT_RTNL(); |
| 1824 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1825 | /* |
| 1826 | * Try to find the wiphy and netdev. Normally this |
| 1827 | * function shouldn't need the netdev, but this is |
| 1828 | * done for backward compatibility -- previously |
| 1829 | * setting the channel was done per wiphy, but now |
| 1830 | * it is per netdev. Previous userland like hostapd |
| 1831 | * also passed a netdev to set_wiphy, so that it is |
| 1832 | * possible to let that go to the right netdev! |
| 1833 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1834 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1835 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1836 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1837 | |
| 1838 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1839 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1840 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1841 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1842 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1843 | } |
| 1844 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1845 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1846 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1847 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1848 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1849 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1850 | wdev = NULL; |
| 1851 | netdev = NULL; |
| 1852 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1853 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1854 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1855 | |
| 1856 | /* |
| 1857 | * end workaround code, by now the rdev is available |
| 1858 | * and locked, and wdev may or may not be NULL. |
| 1859 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1860 | |
| 1861 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1862 | result = cfg80211_dev_rename( |
| 1863 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1864 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1865 | if (result) |
| 1866 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1867 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1868 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1869 | struct ieee80211_txq_params txq_params; |
| 1870 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1871 | |
| 1872 | if (!rdev->ops->set_txq_params) { |
| 1873 | result = -EOPNOTSUPP; |
| 1874 | goto bad_res; |
| 1875 | } |
| 1876 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1877 | if (!netdev) { |
| 1878 | result = -EINVAL; |
| 1879 | goto bad_res; |
| 1880 | } |
| 1881 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1882 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1883 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1884 | result = -EINVAL; |
| 1885 | goto bad_res; |
| 1886 | } |
| 1887 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1888 | if (!netif_running(netdev)) { |
| 1889 | result = -ENETDOWN; |
| 1890 | goto bad_res; |
| 1891 | } |
| 1892 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1893 | nla_for_each_nested(nl_txq_params, |
| 1894 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1895 | rem_txq_params) { |
| 1896 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1897 | nla_data(nl_txq_params), |
| 1898 | nla_len(nl_txq_params), |
| 1899 | txq_params_policy); |
| 1900 | result = parse_txq_params(tb, &txq_params); |
| 1901 | if (result) |
| 1902 | goto bad_res; |
| 1903 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1904 | result = rdev_set_txq_params(rdev, netdev, |
| 1905 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1906 | if (result) |
| 1907 | goto bad_res; |
| 1908 | } |
| 1909 | } |
| 1910 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1911 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1912 | result = __nl80211_set_channel(rdev, |
| 1913 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1914 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1915 | if (result) |
| 1916 | goto bad_res; |
| 1917 | } |
| 1918 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1919 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1920 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1921 | enum nl80211_tx_power_setting type; |
| 1922 | int idx, mbm = 0; |
| 1923 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1924 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1925 | txp_wdev = NULL; |
| 1926 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1927 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1928 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1929 | goto bad_res; |
| 1930 | } |
| 1931 | |
| 1932 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1933 | type = nla_get_u32(info->attrs[idx]); |
| 1934 | |
| 1935 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1936 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1937 | result = -EINVAL; |
| 1938 | goto bad_res; |
| 1939 | } |
| 1940 | |
| 1941 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1942 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1943 | mbm = nla_get_u32(info->attrs[idx]); |
| 1944 | } |
| 1945 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1946 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1947 | if (result) |
| 1948 | goto bad_res; |
| 1949 | } |
| 1950 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1951 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1952 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1953 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1954 | if ((!rdev->wiphy.available_antennas_tx && |
| 1955 | !rdev->wiphy.available_antennas_rx) || |
| 1956 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1957 | result = -EOPNOTSUPP; |
| 1958 | goto bad_res; |
| 1959 | } |
| 1960 | |
| 1961 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1962 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1963 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1964 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1965 | * available antenna masks, except for the "all" mask */ |
| 1966 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1967 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1968 | result = -EINVAL; |
| 1969 | goto bad_res; |
| 1970 | } |
| 1971 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1972 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1973 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1974 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1975 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1976 | if (result) |
| 1977 | goto bad_res; |
| 1978 | } |
| 1979 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1980 | changed = 0; |
| 1981 | |
| 1982 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1983 | retry_short = nla_get_u8( |
| 1984 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1985 | if (retry_short == 0) { |
| 1986 | result = -EINVAL; |
| 1987 | goto bad_res; |
| 1988 | } |
| 1989 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1990 | } |
| 1991 | |
| 1992 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1993 | retry_long = nla_get_u8( |
| 1994 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1995 | if (retry_long == 0) { |
| 1996 | result = -EINVAL; |
| 1997 | goto bad_res; |
| 1998 | } |
| 1999 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2000 | } |
| 2001 | |
| 2002 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2003 | frag_threshold = nla_get_u32( |
| 2004 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2005 | if (frag_threshold < 256) { |
| 2006 | result = -EINVAL; |
| 2007 | goto bad_res; |
| 2008 | } |
| 2009 | if (frag_threshold != (u32) -1) { |
| 2010 | /* |
| 2011 | * Fragments (apart from the last one) are required to |
| 2012 | * have even length. Make the fragmentation code |
| 2013 | * simpler by stripping LSB should someone try to use |
| 2014 | * odd threshold value. |
| 2015 | */ |
| 2016 | frag_threshold &= ~0x1; |
| 2017 | } |
| 2018 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2019 | } |
| 2020 | |
| 2021 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2022 | rts_threshold = nla_get_u32( |
| 2023 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2024 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2025 | } |
| 2026 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2027 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2028 | coverage_class = nla_get_u8( |
| 2029 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2030 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2031 | } |
| 2032 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2033 | if (changed) { |
| 2034 | u8 old_retry_short, old_retry_long; |
| 2035 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2036 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2037 | |
| 2038 | if (!rdev->ops->set_wiphy_params) { |
| 2039 | result = -EOPNOTSUPP; |
| 2040 | goto bad_res; |
| 2041 | } |
| 2042 | |
| 2043 | old_retry_short = rdev->wiphy.retry_short; |
| 2044 | old_retry_long = rdev->wiphy.retry_long; |
| 2045 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2046 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2047 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2048 | |
| 2049 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2050 | rdev->wiphy.retry_short = retry_short; |
| 2051 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2052 | rdev->wiphy.retry_long = retry_long; |
| 2053 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2054 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2055 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2056 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2057 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2058 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2059 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2060 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2061 | if (result) { |
| 2062 | rdev->wiphy.retry_short = old_retry_short; |
| 2063 | rdev->wiphy.retry_long = old_retry_long; |
| 2064 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2065 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2066 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2067 | } |
| 2068 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2069 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2070 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2071 | if (netdev) |
| 2072 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2073 | return result; |
| 2074 | } |
| 2075 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2076 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2077 | { |
| 2078 | return (u64)wdev->identifier | |
| 2079 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2080 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2081 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2082 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2083 | struct cfg80211_chan_def *chandef) |
| 2084 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2085 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2086 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2087 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2088 | chandef->chan->center_freq)) |
| 2089 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2090 | switch (chandef->width) { |
| 2091 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2092 | case NL80211_CHAN_WIDTH_20: |
| 2093 | case NL80211_CHAN_WIDTH_40: |
| 2094 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2095 | cfg80211_get_chandef_type(chandef))) |
| 2096 | return -ENOBUFS; |
| 2097 | break; |
| 2098 | default: |
| 2099 | break; |
| 2100 | } |
| 2101 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2102 | return -ENOBUFS; |
| 2103 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2104 | return -ENOBUFS; |
| 2105 | if (chandef->center_freq2 && |
| 2106 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2107 | return -ENOBUFS; |
| 2108 | return 0; |
| 2109 | } |
| 2110 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2111 | 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] | 2112 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2113 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2114 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2115 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2116 | void *hdr; |
| 2117 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2118 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2119 | if (!hdr) |
| 2120 | return -1; |
| 2121 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2122 | if (dev && |
| 2123 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2124 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2125 | goto nla_put_failure; |
| 2126 | |
| 2127 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2128 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2129 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2130 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2131 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2132 | rdev->devlist_generation ^ |
| 2133 | (cfg80211_rdev_list_generation << 2))) |
| 2134 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2135 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2136 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2137 | int ret; |
| 2138 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2139 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2140 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2141 | if (ret == 0) { |
| 2142 | if (nl80211_send_chandef(msg, &chandef)) |
| 2143 | goto nla_put_failure; |
| 2144 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2145 | } |
| 2146 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2147 | if (wdev->ssid_len) { |
| 2148 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2149 | goto nla_put_failure; |
| 2150 | } |
| 2151 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2152 | return genlmsg_end(msg, hdr); |
| 2153 | |
| 2154 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2155 | genlmsg_cancel(msg, hdr); |
| 2156 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2160 | { |
| 2161 | int wp_idx = 0; |
| 2162 | int if_idx = 0; |
| 2163 | int wp_start = cb->args[0]; |
| 2164 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2165 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2166 | struct wireless_dev *wdev; |
| 2167 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2168 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2169 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2170 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2171 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2172 | if (wp_idx < wp_start) { |
| 2173 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2174 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2175 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2176 | if_idx = 0; |
| 2177 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2178 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2179 | if (if_idx < if_start) { |
| 2180 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2181 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2182 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2183 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2184 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2185 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2186 | goto out; |
| 2187 | } |
| 2188 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2189 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2190 | |
| 2191 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2192 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2193 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2194 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2195 | |
| 2196 | cb->args[0] = wp_idx; |
| 2197 | cb->args[1] = if_idx; |
| 2198 | |
| 2199 | return skb->len; |
| 2200 | } |
| 2201 | |
| 2202 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2203 | { |
| 2204 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2205 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2206 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2207 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2208 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2209 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2210 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2211 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2212 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2213 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2214 | nlmsg_free(msg); |
| 2215 | return -ENOBUFS; |
| 2216 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2217 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2218 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2219 | } |
| 2220 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2221 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2222 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2223 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2224 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2225 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2226 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2227 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2228 | }; |
| 2229 | |
| 2230 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2231 | { |
| 2232 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2233 | int flag; |
| 2234 | |
| 2235 | *mntrflags = 0; |
| 2236 | |
| 2237 | if (!nla) |
| 2238 | return -EINVAL; |
| 2239 | |
| 2240 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2241 | nla, mntr_flags_policy)) |
| 2242 | return -EINVAL; |
| 2243 | |
| 2244 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2245 | if (flags[flag]) |
| 2246 | *mntrflags |= (1<<flag); |
| 2247 | |
| 2248 | return 0; |
| 2249 | } |
| 2250 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2251 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2252 | struct net_device *netdev, u8 use_4addr, |
| 2253 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2254 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2255 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2256 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2257 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2258 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2259 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2260 | |
| 2261 | switch (iftype) { |
| 2262 | case NL80211_IFTYPE_AP_VLAN: |
| 2263 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2264 | return 0; |
| 2265 | break; |
| 2266 | case NL80211_IFTYPE_STATION: |
| 2267 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2268 | return 0; |
| 2269 | break; |
| 2270 | default: |
| 2271 | break; |
| 2272 | } |
| 2273 | |
| 2274 | return -EOPNOTSUPP; |
| 2275 | } |
| 2276 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2277 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2278 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2280 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2281 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2282 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2283 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2284 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2285 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2286 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2287 | memset(¶ms, 0, sizeof(params)); |
| 2288 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2289 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2290 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2291 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2292 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2293 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2294 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2295 | if (ntype > NL80211_IFTYPE_MAX) |
| 2296 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2297 | } |
| 2298 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2299 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2300 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2301 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2302 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2303 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2304 | if (netif_running(dev)) |
| 2305 | return -EBUSY; |
| 2306 | |
| 2307 | wdev_lock(wdev); |
| 2308 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2309 | IEEE80211_MAX_MESH_ID_LEN); |
| 2310 | wdev->mesh_id_up_len = |
| 2311 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2312 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2313 | wdev->mesh_id_up_len); |
| 2314 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2315 | } |
| 2316 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2317 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2318 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2319 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2320 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2321 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2322 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2323 | } else { |
| 2324 | params.use_4addr = -1; |
| 2325 | } |
| 2326 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2327 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2328 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2329 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2330 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2331 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2332 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2333 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2334 | |
| 2335 | flags = &_flags; |
| 2336 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2337 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2338 | |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2339 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2340 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2341 | return -EOPNOTSUPP; |
| 2342 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2343 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2344 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2345 | else |
| 2346 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2347 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2348 | if (!err && params.use_4addr != -1) |
| 2349 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2350 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2351 | return err; |
| 2352 | } |
| 2353 | |
| 2354 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2355 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2357 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2358 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2359 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2360 | int err; |
| 2361 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2362 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2363 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2364 | memset(¶ms, 0, sizeof(params)); |
| 2365 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2366 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2367 | return -EINVAL; |
| 2368 | |
| 2369 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2370 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2371 | if (type > NL80211_IFTYPE_MAX) |
| 2372 | return -EINVAL; |
| 2373 | } |
| 2374 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2375 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2376 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2377 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2378 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2379 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2380 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2381 | ETH_ALEN); |
| 2382 | if (!is_valid_ether_addr(params.macaddr)) |
| 2383 | return -EADDRNOTAVAIL; |
| 2384 | } |
| 2385 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2386 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2387 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2388 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2389 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2390 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2391 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2392 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2393 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2394 | if (!msg) |
| 2395 | return -ENOMEM; |
| 2396 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2397 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2398 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2399 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2400 | |
| 2401 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2402 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2403 | return -EOPNOTSUPP; |
| 2404 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2405 | wdev = rdev_add_virtual_intf(rdev, |
| 2406 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2407 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2408 | if (IS_ERR(wdev)) { |
| 2409 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2410 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2411 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2412 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2413 | switch (type) { |
| 2414 | case NL80211_IFTYPE_MESH_POINT: |
| 2415 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2416 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2417 | wdev_lock(wdev); |
| 2418 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2419 | IEEE80211_MAX_MESH_ID_LEN); |
| 2420 | wdev->mesh_id_up_len = |
| 2421 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2422 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2423 | wdev->mesh_id_up_len); |
| 2424 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2425 | break; |
| 2426 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2427 | /* |
| 2428 | * P2P Device doesn't have a netdev, so doesn't go |
| 2429 | * through the netdev notifier and must be added here |
| 2430 | */ |
| 2431 | mutex_init(&wdev->mtx); |
| 2432 | INIT_LIST_HEAD(&wdev->event_list); |
| 2433 | spin_lock_init(&wdev->event_lock); |
| 2434 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2435 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2436 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2437 | wdev->identifier = ++rdev->wdev_id; |
| 2438 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2439 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2440 | break; |
| 2441 | default: |
| 2442 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2443 | } |
| 2444 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2445 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2446 | rdev, wdev) < 0) { |
| 2447 | nlmsg_free(msg); |
| 2448 | return -ENOBUFS; |
| 2449 | } |
| 2450 | |
| 2451 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2455 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2456 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2457 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2458 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2459 | if (!rdev->ops->del_virtual_intf) |
| 2460 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2461 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2462 | /* |
| 2463 | * If we remove a wireless device without a netdev then clear |
| 2464 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2465 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2466 | * since the wdev has been freed, unlike with a netdev where |
| 2467 | * we need the dev_put() for the netdev to really be freed. |
| 2468 | */ |
| 2469 | if (!wdev->netdev) |
| 2470 | info->user_ptr[1] = NULL; |
| 2471 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2472 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2473 | } |
| 2474 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2475 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2476 | { |
| 2477 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2478 | struct net_device *dev = info->user_ptr[1]; |
| 2479 | u16 noack_map; |
| 2480 | |
| 2481 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2482 | return -EINVAL; |
| 2483 | |
| 2484 | if (!rdev->ops->set_noack_map) |
| 2485 | return -EOPNOTSUPP; |
| 2486 | |
| 2487 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2488 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2489 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2490 | } |
| 2491 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2492 | struct get_key_cookie { |
| 2493 | struct sk_buff *msg; |
| 2494 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2495 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2496 | }; |
| 2497 | |
| 2498 | static void get_key_callback(void *c, struct key_params *params) |
| 2499 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2500 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2501 | struct get_key_cookie *cookie = c; |
| 2502 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2503 | if ((params->key && |
| 2504 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2505 | params->key_len, params->key)) || |
| 2506 | (params->seq && |
| 2507 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2508 | params->seq_len, params->seq)) || |
| 2509 | (params->cipher && |
| 2510 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2511 | params->cipher))) |
| 2512 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2513 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2514 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2515 | if (!key) |
| 2516 | goto nla_put_failure; |
| 2517 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2518 | if ((params->key && |
| 2519 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2520 | params->key_len, params->key)) || |
| 2521 | (params->seq && |
| 2522 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2523 | params->seq_len, params->seq)) || |
| 2524 | (params->cipher && |
| 2525 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2526 | params->cipher))) |
| 2527 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2528 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2529 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2530 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2531 | |
| 2532 | nla_nest_end(cookie->msg, key); |
| 2533 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2534 | return; |
| 2535 | nla_put_failure: |
| 2536 | cookie->error = 1; |
| 2537 | } |
| 2538 | |
| 2539 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2540 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2542 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2543 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2544 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2545 | const u8 *mac_addr = NULL; |
| 2546 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2547 | struct get_key_cookie cookie = { |
| 2548 | .error = 0, |
| 2549 | }; |
| 2550 | void *hdr; |
| 2551 | struct sk_buff *msg; |
| 2552 | |
| 2553 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2554 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2555 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2556 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2557 | return -EINVAL; |
| 2558 | |
| 2559 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2560 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2561 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2562 | pairwise = !!mac_addr; |
| 2563 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2564 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2565 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2566 | return -EINVAL; |
| 2567 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2568 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2569 | return -EINVAL; |
| 2570 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2571 | } |
| 2572 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2573 | if (!rdev->ops->get_key) |
| 2574 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2575 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2576 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2577 | if (!msg) |
| 2578 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2579 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2580 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2581 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2582 | if (IS_ERR(hdr)) |
| 2583 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2584 | |
| 2585 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2586 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2587 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2588 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2589 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2590 | goto nla_put_failure; |
| 2591 | if (mac_addr && |
| 2592 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2593 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2594 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2595 | if (pairwise && mac_addr && |
| 2596 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2597 | return -ENOENT; |
| 2598 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2599 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2600 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2601 | |
| 2602 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2603 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2604 | |
| 2605 | if (cookie.error) |
| 2606 | goto nla_put_failure; |
| 2607 | |
| 2608 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2609 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2610 | |
| 2611 | nla_put_failure: |
| 2612 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2613 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2614 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2615 | return err; |
| 2616 | } |
| 2617 | |
| 2618 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2619 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2621 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2622 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2623 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2624 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2625 | err = nl80211_parse_key(info, &key); |
| 2626 | if (err) |
| 2627 | return err; |
| 2628 | |
| 2629 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2630 | return -EINVAL; |
| 2631 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2632 | /* only support setting default key */ |
| 2633 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2634 | return -EINVAL; |
| 2635 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2636 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2637 | |
| 2638 | if (key.def) { |
| 2639 | if (!rdev->ops->set_default_key) { |
| 2640 | err = -EOPNOTSUPP; |
| 2641 | goto out; |
| 2642 | } |
| 2643 | |
| 2644 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2645 | if (err) |
| 2646 | goto out; |
| 2647 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2648 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2649 | key.def_uni, key.def_multi); |
| 2650 | |
| 2651 | if (err) |
| 2652 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2653 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2654 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2655 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2656 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2657 | } else { |
| 2658 | if (key.def_uni || !key.def_multi) { |
| 2659 | err = -EINVAL; |
| 2660 | goto out; |
| 2661 | } |
| 2662 | |
| 2663 | if (!rdev->ops->set_default_mgmt_key) { |
| 2664 | err = -EOPNOTSUPP; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | |
| 2668 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2669 | if (err) |
| 2670 | goto out; |
| 2671 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2672 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2673 | if (err) |
| 2674 | goto out; |
| 2675 | |
| 2676 | #ifdef CONFIG_CFG80211_WEXT |
| 2677 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2678 | #endif |
| 2679 | } |
| 2680 | |
| 2681 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2682 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2683 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2684 | return err; |
| 2685 | } |
| 2686 | |
| 2687 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2688 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2690 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2692 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2693 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2694 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2695 | err = nl80211_parse_key(info, &key); |
| 2696 | if (err) |
| 2697 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2698 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2699 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2700 | return -EINVAL; |
| 2701 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2702 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2703 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2704 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2705 | if (key.type == -1) { |
| 2706 | if (mac_addr) |
| 2707 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2708 | else |
| 2709 | key.type = NL80211_KEYTYPE_GROUP; |
| 2710 | } |
| 2711 | |
| 2712 | /* for now */ |
| 2713 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2714 | key.type != NL80211_KEYTYPE_GROUP) |
| 2715 | return -EINVAL; |
| 2716 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2717 | if (!rdev->ops->add_key) |
| 2718 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2719 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2720 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2721 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2722 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2723 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2724 | |
| 2725 | wdev_lock(dev->ieee80211_ptr); |
| 2726 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2727 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2728 | err = rdev_add_key(rdev, dev, key.idx, |
| 2729 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2730 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2731 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2732 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2733 | return err; |
| 2734 | } |
| 2735 | |
| 2736 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2737 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2739 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2740 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2741 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2742 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2743 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2744 | err = nl80211_parse_key(info, &key); |
| 2745 | if (err) |
| 2746 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2747 | |
| 2748 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2749 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2750 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2751 | if (key.type == -1) { |
| 2752 | if (mac_addr) |
| 2753 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2754 | else |
| 2755 | key.type = NL80211_KEYTYPE_GROUP; |
| 2756 | } |
| 2757 | |
| 2758 | /* for now */ |
| 2759 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2760 | key.type != NL80211_KEYTYPE_GROUP) |
| 2761 | return -EINVAL; |
| 2762 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2763 | if (!rdev->ops->del_key) |
| 2764 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2765 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2766 | wdev_lock(dev->ieee80211_ptr); |
| 2767 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2768 | |
| 2769 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2770 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2771 | err = -ENOENT; |
| 2772 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2773 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2774 | err = rdev_del_key(rdev, dev, key.idx, |
| 2775 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2776 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2777 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2778 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2779 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2780 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2781 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2782 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2783 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2784 | } |
| 2785 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2786 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2787 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2788 | return err; |
| 2789 | } |
| 2790 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2791 | /* This function returns an error or the number of nested attributes */ |
| 2792 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2793 | { |
| 2794 | struct nlattr *attr; |
| 2795 | int n_entries = 0, tmp; |
| 2796 | |
| 2797 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2798 | if (nla_len(attr) != ETH_ALEN) |
| 2799 | return -EINVAL; |
| 2800 | |
| 2801 | n_entries++; |
| 2802 | } |
| 2803 | |
| 2804 | return n_entries; |
| 2805 | } |
| 2806 | |
| 2807 | /* |
| 2808 | * This function parses ACL information and allocates memory for ACL data. |
| 2809 | * On successful return, the calling function is responsible to free the |
| 2810 | * ACL buffer returned by this function. |
| 2811 | */ |
| 2812 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2813 | struct genl_info *info) |
| 2814 | { |
| 2815 | enum nl80211_acl_policy acl_policy; |
| 2816 | struct nlattr *attr; |
| 2817 | struct cfg80211_acl_data *acl; |
| 2818 | int i = 0, n_entries, tmp; |
| 2819 | |
| 2820 | if (!wiphy->max_acl_mac_addrs) |
| 2821 | return ERR_PTR(-EOPNOTSUPP); |
| 2822 | |
| 2823 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2824 | return ERR_PTR(-EINVAL); |
| 2825 | |
| 2826 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2827 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2828 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2829 | return ERR_PTR(-EINVAL); |
| 2830 | |
| 2831 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2832 | return ERR_PTR(-EINVAL); |
| 2833 | |
| 2834 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2835 | if (n_entries < 0) |
| 2836 | return ERR_PTR(n_entries); |
| 2837 | |
| 2838 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2839 | return ERR_PTR(-ENOTSUPP); |
| 2840 | |
| 2841 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2842 | GFP_KERNEL); |
| 2843 | if (!acl) |
| 2844 | return ERR_PTR(-ENOMEM); |
| 2845 | |
| 2846 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2847 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2848 | i++; |
| 2849 | } |
| 2850 | |
| 2851 | acl->n_acl_entries = n_entries; |
| 2852 | acl->acl_policy = acl_policy; |
| 2853 | |
| 2854 | return acl; |
| 2855 | } |
| 2856 | |
| 2857 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2858 | { |
| 2859 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2860 | struct net_device *dev = info->user_ptr[1]; |
| 2861 | struct cfg80211_acl_data *acl; |
| 2862 | int err; |
| 2863 | |
| 2864 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2865 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2866 | return -EOPNOTSUPP; |
| 2867 | |
| 2868 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2869 | return -EINVAL; |
| 2870 | |
| 2871 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2872 | if (IS_ERR(acl)) |
| 2873 | return PTR_ERR(acl); |
| 2874 | |
| 2875 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2876 | |
| 2877 | kfree(acl); |
| 2878 | |
| 2879 | return err; |
| 2880 | } |
| 2881 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2882 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2883 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2884 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2885 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2886 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2887 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2888 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2889 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2890 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2891 | return -EINVAL; |
| 2892 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2893 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2894 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2895 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2896 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2897 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2898 | if (!bcn->head_len) |
| 2899 | return -EINVAL; |
| 2900 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2904 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2905 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2906 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2907 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2908 | } |
| 2909 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2910 | if (!haveinfo) |
| 2911 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2912 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2913 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2914 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2915 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2919 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2920 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2921 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2922 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2923 | } |
| 2924 | |
| 2925 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2926 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2927 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2928 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2929 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2930 | } |
| 2931 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2932 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2933 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2934 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2935 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2936 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2937 | } |
| 2938 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2939 | return 0; |
| 2940 | } |
| 2941 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2942 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2943 | struct cfg80211_ap_settings *params) |
| 2944 | { |
| 2945 | struct wireless_dev *wdev; |
| 2946 | bool ret = false; |
| 2947 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2948 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2949 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2950 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2951 | continue; |
| 2952 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2953 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2954 | continue; |
| 2955 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2956 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2957 | ret = true; |
| 2958 | break; |
| 2959 | } |
| 2960 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2961 | return ret; |
| 2962 | } |
| 2963 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2964 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2965 | enum nl80211_auth_type auth_type, |
| 2966 | enum nl80211_commands cmd) |
| 2967 | { |
| 2968 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2969 | return false; |
| 2970 | |
| 2971 | switch (cmd) { |
| 2972 | case NL80211_CMD_AUTHENTICATE: |
| 2973 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2974 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2975 | return false; |
| 2976 | return true; |
| 2977 | case NL80211_CMD_CONNECT: |
| 2978 | case NL80211_CMD_START_AP: |
| 2979 | /* SAE not supported yet */ |
| 2980 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2981 | return false; |
| 2982 | return true; |
| 2983 | default: |
| 2984 | return false; |
| 2985 | } |
| 2986 | } |
| 2987 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2988 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2989 | { |
| 2990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2991 | struct net_device *dev = info->user_ptr[1]; |
| 2992 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2993 | struct cfg80211_ap_settings params; |
| 2994 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2995 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2996 | |
| 2997 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2998 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2999 | return -EOPNOTSUPP; |
| 3000 | |
| 3001 | if (!rdev->ops->start_ap) |
| 3002 | return -EOPNOTSUPP; |
| 3003 | |
| 3004 | if (wdev->beacon_interval) |
| 3005 | return -EALREADY; |
| 3006 | |
| 3007 | memset(¶ms, 0, sizeof(params)); |
| 3008 | |
| 3009 | /* these are required for START_AP */ |
| 3010 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3011 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3012 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3013 | return -EINVAL; |
| 3014 | |
| 3015 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 3016 | if (err) |
| 3017 | return err; |
| 3018 | |
| 3019 | params.beacon_interval = |
| 3020 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3021 | params.dtim_period = |
| 3022 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3023 | |
| 3024 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3025 | if (err) |
| 3026 | return err; |
| 3027 | |
| 3028 | /* |
| 3029 | * In theory, some of these attributes should be required here |
| 3030 | * but since they were not used when the command was originally |
| 3031 | * added, keep them optional for old user space programs to let |
| 3032 | * them continue to work with drivers that do not need the |
| 3033 | * additional information -- drivers must check! |
| 3034 | */ |
| 3035 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3036 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3037 | params.ssid_len = |
| 3038 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3039 | if (params.ssid_len == 0 || |
| 3040 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3041 | return -EINVAL; |
| 3042 | } |
| 3043 | |
| 3044 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3045 | params.hidden_ssid = nla_get_u32( |
| 3046 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3047 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3048 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3049 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3050 | return -EINVAL; |
| 3051 | } |
| 3052 | |
| 3053 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3054 | |
| 3055 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3056 | params.auth_type = nla_get_u32( |
| 3057 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3058 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3059 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3060 | return -EINVAL; |
| 3061 | } else |
| 3062 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3063 | |
| 3064 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3065 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3066 | if (err) |
| 3067 | return err; |
| 3068 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3069 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3070 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3071 | return -EOPNOTSUPP; |
| 3072 | params.inactivity_timeout = nla_get_u16( |
| 3073 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3074 | } |
| 3075 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3076 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3077 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3078 | return -EINVAL; |
| 3079 | params.p2p_ctwindow = |
| 3080 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3081 | if (params.p2p_ctwindow > 127) |
| 3082 | return -EINVAL; |
| 3083 | if (params.p2p_ctwindow != 0 && |
| 3084 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3085 | return -EINVAL; |
| 3086 | } |
| 3087 | |
| 3088 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3089 | u8 tmp; |
| 3090 | |
| 3091 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3092 | return -EINVAL; |
| 3093 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3094 | if (tmp > 1) |
| 3095 | return -EINVAL; |
| 3096 | params.p2p_opp_ps = tmp; |
| 3097 | if (params.p2p_opp_ps != 0 && |
| 3098 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3099 | return -EINVAL; |
| 3100 | } |
| 3101 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3102 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3103 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3104 | if (err) |
| 3105 | return err; |
| 3106 | } else if (wdev->preset_chandef.chan) { |
| 3107 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3108 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3109 | return -EINVAL; |
| 3110 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3111 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3112 | return -EINVAL; |
| 3113 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3114 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3115 | if (err < 0) |
| 3116 | return err; |
| 3117 | if (err) { |
| 3118 | radar_detect_width = BIT(params.chandef.width); |
| 3119 | params.radar_required = true; |
| 3120 | } |
| 3121 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3122 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3123 | params.chandef.chan, |
| 3124 | CHAN_MODE_SHARED, |
| 3125 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3126 | if (err) |
| 3127 | return err; |
| 3128 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3129 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3130 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3131 | if (IS_ERR(params.acl)) |
| 3132 | return PTR_ERR(params.acl); |
| 3133 | } |
| 3134 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3135 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3136 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3137 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3138 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3139 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3140 | wdev->ssid_len = params.ssid_len; |
| 3141 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3142 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3143 | |
| 3144 | kfree(params.acl); |
| 3145 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3146 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3147 | } |
| 3148 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3149 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3150 | { |
| 3151 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3152 | struct net_device *dev = info->user_ptr[1]; |
| 3153 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3154 | struct cfg80211_beacon_data params; |
| 3155 | int err; |
| 3156 | |
| 3157 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3158 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3159 | return -EOPNOTSUPP; |
| 3160 | |
| 3161 | if (!rdev->ops->change_beacon) |
| 3162 | return -EOPNOTSUPP; |
| 3163 | |
| 3164 | if (!wdev->beacon_interval) |
| 3165 | return -EINVAL; |
| 3166 | |
| 3167 | err = nl80211_parse_beacon(info, ¶ms); |
| 3168 | if (err) |
| 3169 | return err; |
| 3170 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3171 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | 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] | 3175 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3177 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3178 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3179 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3180 | } |
| 3181 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3182 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3183 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3184 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3185 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3186 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3187 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3188 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3189 | }; |
| 3190 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3191 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3192 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3193 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3194 | { |
| 3195 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3196 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3197 | int flag; |
| 3198 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3199 | /* |
| 3200 | * Try parsing the new attribute first so userspace |
| 3201 | * can specify both for older kernels. |
| 3202 | */ |
| 3203 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3204 | if (nla) { |
| 3205 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3206 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3207 | sta_flags = nla_data(nla); |
| 3208 | params->sta_flags_mask = sta_flags->mask; |
| 3209 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3210 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3211 | if ((params->sta_flags_mask | |
| 3212 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3213 | return -EINVAL; |
| 3214 | return 0; |
| 3215 | } |
| 3216 | |
| 3217 | /* if present, parse the old attribute */ |
| 3218 | |
| 3219 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3220 | if (!nla) |
| 3221 | return 0; |
| 3222 | |
| 3223 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3224 | nla, sta_flags_policy)) |
| 3225 | return -EINVAL; |
| 3226 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3227 | /* |
| 3228 | * Only allow certain flags for interface types so that |
| 3229 | * other attributes are silently ignored. Remember that |
| 3230 | * this is backward compatibility code with old userspace |
| 3231 | * and shouldn't be hit in other cases anyway. |
| 3232 | */ |
| 3233 | switch (iftype) { |
| 3234 | case NL80211_IFTYPE_AP: |
| 3235 | case NL80211_IFTYPE_AP_VLAN: |
| 3236 | case NL80211_IFTYPE_P2P_GO: |
| 3237 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3238 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3239 | BIT(NL80211_STA_FLAG_WME) | |
| 3240 | BIT(NL80211_STA_FLAG_MFP); |
| 3241 | break; |
| 3242 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3243 | case NL80211_IFTYPE_STATION: |
| 3244 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3245 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3246 | break; |
| 3247 | case NL80211_IFTYPE_MESH_POINT: |
| 3248 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3249 | BIT(NL80211_STA_FLAG_MFP) | |
| 3250 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3251 | default: |
| 3252 | return -EINVAL; |
| 3253 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3254 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3255 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3256 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3257 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3258 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3259 | /* no longer support new API additions in old API */ |
| 3260 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3261 | return -EINVAL; |
| 3262 | } |
| 3263 | } |
| 3264 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3265 | return 0; |
| 3266 | } |
| 3267 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3268 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3269 | int attr) |
| 3270 | { |
| 3271 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3272 | u32 bitrate; |
| 3273 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3274 | |
| 3275 | rate = nla_nest_start(msg, attr); |
| 3276 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3277 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3278 | |
| 3279 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3280 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3281 | /* report 16-bit bitrate only if we can */ |
| 3282 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3283 | if (bitrate > 0 && |
| 3284 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3285 | return false; |
| 3286 | if (bitrate_compat > 0 && |
| 3287 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3288 | return false; |
| 3289 | |
| 3290 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3291 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3292 | return false; |
| 3293 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3294 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3295 | return false; |
| 3296 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3297 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3298 | return false; |
| 3299 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3300 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3301 | return false; |
| 3302 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3303 | return false; |
| 3304 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3305 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3306 | return false; |
| 3307 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3308 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3309 | return false; |
| 3310 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3311 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3312 | return false; |
| 3313 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3314 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3315 | return false; |
| 3316 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3317 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3318 | return false; |
| 3319 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3320 | |
| 3321 | nla_nest_end(msg, rate); |
| 3322 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3323 | } |
| 3324 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3325 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3326 | int id) |
| 3327 | { |
| 3328 | void *attr; |
| 3329 | int i = 0; |
| 3330 | |
| 3331 | if (!mask) |
| 3332 | return true; |
| 3333 | |
| 3334 | attr = nla_nest_start(msg, id); |
| 3335 | if (!attr) |
| 3336 | return false; |
| 3337 | |
| 3338 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3339 | if (!(mask & BIT(i))) |
| 3340 | continue; |
| 3341 | |
| 3342 | if (nla_put_u8(msg, i, signal[i])) |
| 3343 | return false; |
| 3344 | } |
| 3345 | |
| 3346 | nla_nest_end(msg, attr); |
| 3347 | |
| 3348 | return true; |
| 3349 | } |
| 3350 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3351 | 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] | 3352 | int flags, |
| 3353 | struct cfg80211_registered_device *rdev, |
| 3354 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3355 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3356 | { |
| 3357 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3358 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3359 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3360 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3361 | if (!hdr) |
| 3362 | return -1; |
| 3363 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3364 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3365 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3366 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3367 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3368 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3369 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3370 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3371 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3372 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3373 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3374 | sinfo->connected_time)) |
| 3375 | goto nla_put_failure; |
| 3376 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3377 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3378 | sinfo->inactive_time)) |
| 3379 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3380 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3381 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3382 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3383 | (u32)sinfo->rx_bytes)) |
| 3384 | goto nla_put_failure; |
| 3385 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3386 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3387 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3388 | (u32)sinfo->tx_bytes)) |
| 3389 | goto nla_put_failure; |
| 3390 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3391 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3392 | sinfo->rx_bytes)) |
| 3393 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3394 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3395 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3396 | sinfo->tx_bytes)) |
| 3397 | goto nla_put_failure; |
| 3398 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3399 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3400 | goto nla_put_failure; |
| 3401 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3402 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3403 | goto nla_put_failure; |
| 3404 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3405 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3406 | sinfo->plink_state)) |
| 3407 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3408 | switch (rdev->wiphy.signal_type) { |
| 3409 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3410 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3411 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3412 | sinfo->signal)) |
| 3413 | goto nla_put_failure; |
| 3414 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3415 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3416 | sinfo->signal_avg)) |
| 3417 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3418 | break; |
| 3419 | default: |
| 3420 | break; |
| 3421 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3422 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3423 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3424 | sinfo->chain_signal, |
| 3425 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3426 | goto nla_put_failure; |
| 3427 | } |
| 3428 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3429 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3430 | sinfo->chain_signal_avg, |
| 3431 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3432 | goto nla_put_failure; |
| 3433 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3434 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3435 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3436 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3437 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3438 | } |
| 3439 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3440 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3441 | NL80211_STA_INFO_RX_BITRATE)) |
| 3442 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3443 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3444 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3445 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3446 | sinfo->rx_packets)) |
| 3447 | goto nla_put_failure; |
| 3448 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3449 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3450 | sinfo->tx_packets)) |
| 3451 | goto nla_put_failure; |
| 3452 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3453 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3454 | sinfo->tx_retries)) |
| 3455 | goto nla_put_failure; |
| 3456 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3457 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3458 | sinfo->tx_failed)) |
| 3459 | goto nla_put_failure; |
| 3460 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3461 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3462 | sinfo->beacon_loss_count)) |
| 3463 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3464 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3465 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3466 | sinfo->local_pm)) |
| 3467 | goto nla_put_failure; |
| 3468 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3469 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3470 | sinfo->peer_pm)) |
| 3471 | goto nla_put_failure; |
| 3472 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3473 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3474 | sinfo->nonpeer_pm)) |
| 3475 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3476 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3477 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3478 | if (!bss_param) |
| 3479 | goto nla_put_failure; |
| 3480 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3481 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3482 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3483 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3484 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3485 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3486 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3487 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3488 | sinfo->bss_param.dtim_period) || |
| 3489 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3490 | sinfo->bss_param.beacon_interval)) |
| 3491 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3492 | |
| 3493 | nla_nest_end(msg, bss_param); |
| 3494 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3495 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3496 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3497 | sizeof(struct nl80211_sta_flag_update), |
| 3498 | &sinfo->sta_flags)) |
| 3499 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3500 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3501 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3502 | sinfo->t_offset)) |
| 3503 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3504 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3505 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3506 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3507 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3508 | sinfo->assoc_req_ies)) |
| 3509 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3510 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3511 | return genlmsg_end(msg, hdr); |
| 3512 | |
| 3513 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3514 | genlmsg_cancel(msg, hdr); |
| 3515 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3516 | } |
| 3517 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3518 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3519 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3520 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3521 | struct station_info sinfo; |
| 3522 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3523 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3524 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3525 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3526 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3527 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3528 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3529 | if (err) |
| 3530 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3531 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3532 | if (!wdev->netdev) { |
| 3533 | err = -EINVAL; |
| 3534 | goto out_err; |
| 3535 | } |
| 3536 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3537 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3538 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3539 | goto out_err; |
| 3540 | } |
| 3541 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3542 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3543 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3544 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3545 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3546 | if (err == -ENOENT) |
| 3547 | break; |
| 3548 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3549 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3550 | |
| 3551 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3552 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3553 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3554 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3555 | &sinfo) < 0) |
| 3556 | goto out; |
| 3557 | |
| 3558 | sta_idx++; |
| 3559 | } |
| 3560 | |
| 3561 | |
| 3562 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3563 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3564 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3565 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3566 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3567 | |
| 3568 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3569 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3570 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3571 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3572 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3573 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3574 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3575 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3576 | struct sk_buff *msg; |
| 3577 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3578 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3579 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3580 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3581 | |
| 3582 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3583 | return -EINVAL; |
| 3584 | |
| 3585 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3586 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3587 | if (!rdev->ops->get_station) |
| 3588 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3589 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3590 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3591 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3592 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3593 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3594 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3595 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3596 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3597 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3598 | 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] | 3599 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3600 | nlmsg_free(msg); |
| 3601 | return -ENOBUFS; |
| 3602 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3603 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3604 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3607 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3608 | struct station_parameters *params, |
| 3609 | enum cfg80211_station_type statype) |
| 3610 | { |
| 3611 | if (params->listen_interval != -1) |
| 3612 | return -EINVAL; |
| 3613 | if (params->aid) |
| 3614 | return -EINVAL; |
| 3615 | |
| 3616 | /* When you run into this, adjust the code below for the new flag */ |
| 3617 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3618 | |
| 3619 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3620 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3621 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3622 | /* |
| 3623 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3624 | * code doesn't have the bug of including TDLS in the |
| 3625 | * mask everywhere. |
| 3626 | */ |
| 3627 | if (params->sta_flags_mask & |
| 3628 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3629 | BIT(NL80211_STA_FLAG_MFP) | |
| 3630 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3631 | return -EINVAL; |
| 3632 | break; |
| 3633 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3634 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3635 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3636 | return -EINVAL; |
| 3637 | /* ignore since it can't change */ |
| 3638 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3639 | break; |
| 3640 | default: |
| 3641 | /* disallow mesh-specific things */ |
| 3642 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3643 | return -EINVAL; |
| 3644 | if (params->local_pm) |
| 3645 | return -EINVAL; |
| 3646 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3647 | return -EINVAL; |
| 3648 | } |
| 3649 | |
| 3650 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3651 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3652 | /* TDLS can't be set, ... */ |
| 3653 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3654 | return -EINVAL; |
| 3655 | /* |
| 3656 | * ... but don't bother the driver with it. This works around |
| 3657 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3658 | * TLDS_PEER flag in the mask even for AP mode. |
| 3659 | */ |
| 3660 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3661 | } |
| 3662 | |
| 3663 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3664 | /* reject other things that can't change */ |
| 3665 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3666 | return -EINVAL; |
| 3667 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3668 | return -EINVAL; |
| 3669 | if (params->supported_rates) |
| 3670 | return -EINVAL; |
| 3671 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3672 | return -EINVAL; |
| 3673 | } |
| 3674 | |
| 3675 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3676 | if (params->vlan) |
| 3677 | return -EINVAL; |
| 3678 | } |
| 3679 | |
| 3680 | switch (statype) { |
| 3681 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3682 | /* Use this only for authorizing/unauthorizing a station */ |
| 3683 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3684 | return -EOPNOTSUPP; |
| 3685 | break; |
| 3686 | case CFG80211_STA_AP_CLIENT: |
| 3687 | /* accept only the listed bits */ |
| 3688 | if (params->sta_flags_mask & |
| 3689 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3690 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3691 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3692 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3693 | BIT(NL80211_STA_FLAG_WME) | |
| 3694 | BIT(NL80211_STA_FLAG_MFP))) |
| 3695 | return -EINVAL; |
| 3696 | |
| 3697 | /* but authenticated/associated only if driver handles it */ |
| 3698 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3699 | params->sta_flags_mask & |
| 3700 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3701 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3702 | return -EINVAL; |
| 3703 | break; |
| 3704 | case CFG80211_STA_IBSS: |
| 3705 | case CFG80211_STA_AP_STA: |
| 3706 | /* reject any changes other than AUTHORIZED */ |
| 3707 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3708 | return -EINVAL; |
| 3709 | break; |
| 3710 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3711 | /* reject any changes other than AUTHORIZED or WME */ |
| 3712 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3713 | BIT(NL80211_STA_FLAG_WME))) |
| 3714 | return -EINVAL; |
| 3715 | /* force (at least) rates when authorizing */ |
| 3716 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3717 | !params->supported_rates) |
| 3718 | return -EINVAL; |
| 3719 | break; |
| 3720 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3721 | /* reject any changes */ |
| 3722 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3723 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3724 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3725 | return -EINVAL; |
| 3726 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3727 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3728 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3729 | return -EINVAL; |
| 3730 | break; |
| 3731 | } |
| 3732 | |
| 3733 | return 0; |
| 3734 | } |
| 3735 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3736 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3737 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3738 | * 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] | 3739 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3740 | static struct net_device *get_vlan(struct genl_info *info, |
| 3741 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3742 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3743 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3744 | struct net_device *v; |
| 3745 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3746 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3747 | if (!vlanattr) |
| 3748 | return NULL; |
| 3749 | |
| 3750 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3751 | if (!v) |
| 3752 | return ERR_PTR(-ENODEV); |
| 3753 | |
| 3754 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3755 | ret = -EINVAL; |
| 3756 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3757 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3758 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3759 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3760 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3761 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3762 | ret = -EINVAL; |
| 3763 | goto error; |
| 3764 | } |
| 3765 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3766 | if (!netif_running(v)) { |
| 3767 | ret = -ENETDOWN; |
| 3768 | goto error; |
| 3769 | } |
| 3770 | |
| 3771 | return v; |
| 3772 | error: |
| 3773 | dev_put(v); |
| 3774 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3775 | } |
| 3776 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3777 | static struct nla_policy |
| 3778 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3779 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3780 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3781 | }; |
| 3782 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3783 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3784 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3785 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3786 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3787 | struct nlattr *nla; |
| 3788 | int err; |
| 3789 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3790 | /* parse WME attributes if present */ |
| 3791 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3792 | return 0; |
| 3793 | |
| 3794 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3795 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3796 | nl80211_sta_wme_policy); |
| 3797 | if (err) |
| 3798 | return err; |
| 3799 | |
| 3800 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3801 | params->uapsd_queues = nla_get_u8( |
| 3802 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3803 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3804 | return -EINVAL; |
| 3805 | |
| 3806 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3807 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3808 | |
| 3809 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3810 | return -EINVAL; |
| 3811 | |
| 3812 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3813 | |
| 3814 | return 0; |
| 3815 | } |
| 3816 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3817 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3818 | struct station_parameters *params) |
| 3819 | { |
| 3820 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3821 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3822 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3823 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3824 | params->ht_capa = |
| 3825 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3826 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3827 | params->vht_capa = |
| 3828 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3829 | |
| 3830 | return nl80211_parse_sta_wme(info, params); |
| 3831 | } |
| 3832 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3833 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3834 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3835 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3836 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3837 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3838 | u8 *mac_addr; |
| 3839 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3840 | |
| 3841 | memset(¶ms, 0, sizeof(params)); |
| 3842 | |
| 3843 | params.listen_interval = -1; |
| 3844 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3845 | if (!rdev->ops->change_station) |
| 3846 | return -EOPNOTSUPP; |
| 3847 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3848 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3849 | return -EINVAL; |
| 3850 | |
| 3851 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3852 | return -EINVAL; |
| 3853 | |
| 3854 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3855 | |
| 3856 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3857 | params.supported_rates = |
| 3858 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3859 | params.supported_rates_len = |
| 3860 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3861 | } |
| 3862 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3863 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3864 | params.capability = |
| 3865 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3866 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3867 | } |
| 3868 | |
| 3869 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3870 | params.ext_capab = |
| 3871 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3872 | params.ext_capab_len = |
| 3873 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3874 | } |
| 3875 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3876 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3877 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3878 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3879 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3880 | return -EINVAL; |
| 3881 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3882 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3883 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3884 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3885 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3886 | return -EINVAL; |
| 3887 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3888 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3889 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3890 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3891 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3892 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3893 | return -EINVAL; |
| 3894 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3895 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3896 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3897 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3898 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3899 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3900 | |
| 3901 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3902 | pm > NL80211_MESH_POWER_MAX) |
| 3903 | return -EINVAL; |
| 3904 | |
| 3905 | params.local_pm = pm; |
| 3906 | } |
| 3907 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3908 | /* Include parameters for TDLS peer (will check later) */ |
| 3909 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3910 | if (err) |
| 3911 | return err; |
| 3912 | |
| 3913 | params.vlan = get_vlan(info, rdev); |
| 3914 | if (IS_ERR(params.vlan)) |
| 3915 | return PTR_ERR(params.vlan); |
| 3916 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3917 | switch (dev->ieee80211_ptr->iftype) { |
| 3918 | case NL80211_IFTYPE_AP: |
| 3919 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3920 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3921 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3922 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3923 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3924 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3925 | break; |
| 3926 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3927 | err = -EOPNOTSUPP; |
| 3928 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3929 | } |
| 3930 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3931 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3932 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3933 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3934 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3935 | if (params.vlan) |
| 3936 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3937 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3938 | return err; |
| 3939 | } |
| 3940 | |
| 3941 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3942 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3943 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3944 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3945 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3946 | struct station_parameters params; |
| 3947 | u8 *mac_addr = NULL; |
| 3948 | |
| 3949 | memset(¶ms, 0, sizeof(params)); |
| 3950 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3951 | if (!rdev->ops->add_station) |
| 3952 | return -EOPNOTSUPP; |
| 3953 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3954 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3955 | return -EINVAL; |
| 3956 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3957 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3958 | return -EINVAL; |
| 3959 | |
| 3960 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3961 | return -EINVAL; |
| 3962 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3963 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 3964 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3965 | return -EINVAL; |
| 3966 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3967 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3968 | params.supported_rates = |
| 3969 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3970 | params.supported_rates_len = |
| 3971 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3972 | params.listen_interval = |
| 3973 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3974 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3975 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3976 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3977 | else |
| 3978 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3979 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3980 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3981 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3982 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3983 | params.capability = |
| 3984 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3985 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3986 | } |
| 3987 | |
| 3988 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3989 | params.ext_capab = |
| 3990 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3991 | params.ext_capab_len = |
| 3992 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3993 | } |
| 3994 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3995 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3996 | params.ht_capa = |
| 3997 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3998 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3999 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4000 | params.vht_capa = |
| 4001 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4002 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4003 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4004 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4005 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4006 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4007 | return -EINVAL; |
| 4008 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4009 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4010 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4011 | if (err) |
| 4012 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4013 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4014 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4015 | return -EINVAL; |
| 4016 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4017 | /* When you run into this, adjust the code below for the new flag */ |
| 4018 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4019 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4020 | switch (dev->ieee80211_ptr->iftype) { |
| 4021 | case NL80211_IFTYPE_AP: |
| 4022 | case NL80211_IFTYPE_AP_VLAN: |
| 4023 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4024 | /* ignore WME attributes if iface/sta is not capable */ |
| 4025 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4026 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4027 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4028 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4029 | /* TDLS peers cannot be added */ |
| 4030 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4031 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4032 | /* but don't bother the driver with it */ |
| 4033 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4034 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4035 | /* allow authenticated/associated only if driver handles it */ |
| 4036 | if (!(rdev->wiphy.features & |
| 4037 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4038 | params.sta_flags_mask & |
| 4039 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4040 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4041 | return -EINVAL; |
| 4042 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4043 | /* must be last in here for error handling */ |
| 4044 | params.vlan = get_vlan(info, rdev); |
| 4045 | if (IS_ERR(params.vlan)) |
| 4046 | return PTR_ERR(params.vlan); |
| 4047 | break; |
| 4048 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4049 | /* ignore uAPSD data */ |
| 4050 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4051 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4052 | /* associated is disallowed */ |
| 4053 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4054 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4055 | /* TDLS peers cannot be added */ |
| 4056 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4057 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4058 | break; |
| 4059 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4060 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4061 | /* ignore uAPSD data */ |
| 4062 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4063 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4064 | /* these are disallowed */ |
| 4065 | if (params.sta_flags_mask & |
| 4066 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4067 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4068 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4069 | /* Only TDLS peers can be added */ |
| 4070 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4071 | return -EINVAL; |
| 4072 | /* Can only add if TDLS ... */ |
| 4073 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4074 | return -EOPNOTSUPP; |
| 4075 | /* ... with external setup is supported */ |
| 4076 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4077 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4078 | /* |
| 4079 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4080 | * as authorized, but it shouldn't yet be. |
| 4081 | */ |
| 4082 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4083 | break; |
| 4084 | default: |
| 4085 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4086 | } |
| 4087 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4088 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4089 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4090 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4091 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4092 | if (params.vlan) |
| 4093 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4094 | return err; |
| 4095 | } |
| 4096 | |
| 4097 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4098 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4099 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4100 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4101 | u8 *mac_addr = NULL; |
| 4102 | |
| 4103 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4104 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4105 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4106 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4107 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4108 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4109 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4110 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4111 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4112 | if (!rdev->ops->del_station) |
| 4113 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4114 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4115 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4116 | } |
| 4117 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4118 | 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] | 4119 | int flags, struct net_device *dev, |
| 4120 | u8 *dst, u8 *next_hop, |
| 4121 | struct mpath_info *pinfo) |
| 4122 | { |
| 4123 | void *hdr; |
| 4124 | struct nlattr *pinfoattr; |
| 4125 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4126 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4127 | if (!hdr) |
| 4128 | return -1; |
| 4129 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4130 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4131 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4132 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4133 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4134 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4135 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4136 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4137 | if (!pinfoattr) |
| 4138 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4139 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4140 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4141 | pinfo->frame_qlen)) |
| 4142 | goto nla_put_failure; |
| 4143 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4144 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4145 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4146 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4147 | pinfo->metric)) || |
| 4148 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4149 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4150 | pinfo->exptime)) || |
| 4151 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4152 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4153 | pinfo->flags)) || |
| 4154 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4155 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4156 | pinfo->discovery_timeout)) || |
| 4157 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4158 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4159 | pinfo->discovery_retries))) |
| 4160 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4161 | |
| 4162 | nla_nest_end(msg, pinfoattr); |
| 4163 | |
| 4164 | return genlmsg_end(msg, hdr); |
| 4165 | |
| 4166 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4167 | genlmsg_cancel(msg, hdr); |
| 4168 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4169 | } |
| 4170 | |
| 4171 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4172 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4173 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4174 | struct mpath_info pinfo; |
| 4175 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4176 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4177 | u8 dst[ETH_ALEN]; |
| 4178 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4179 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4180 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4181 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4182 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4183 | if (err) |
| 4184 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4185 | |
| 4186 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4187 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4188 | goto out_err; |
| 4189 | } |
| 4190 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4191 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4192 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4193 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4194 | } |
| 4195 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4196 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4197 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4198 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4199 | if (err == -ENOENT) |
| 4200 | break; |
| 4201 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4202 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4203 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4204 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4205 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4206 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4207 | &pinfo) < 0) |
| 4208 | goto out; |
| 4209 | |
| 4210 | path_idx++; |
| 4211 | } |
| 4212 | |
| 4213 | |
| 4214 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4215 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4216 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4217 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4218 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4219 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4223 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4225 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4226 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4227 | struct mpath_info pinfo; |
| 4228 | struct sk_buff *msg; |
| 4229 | u8 *dst = NULL; |
| 4230 | u8 next_hop[ETH_ALEN]; |
| 4231 | |
| 4232 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4233 | |
| 4234 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4235 | return -EINVAL; |
| 4236 | |
| 4237 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4238 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4239 | if (!rdev->ops->get_mpath) |
| 4240 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4241 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4242 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4243 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4244 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4245 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4246 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4247 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4248 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4250 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4251 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4252 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4253 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4254 | dev, dst, next_hop, &pinfo) < 0) { |
| 4255 | nlmsg_free(msg); |
| 4256 | return -ENOBUFS; |
| 4257 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4258 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4259 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4263 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4265 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4266 | u8 *dst = NULL; |
| 4267 | u8 *next_hop = NULL; |
| 4268 | |
| 4269 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4270 | return -EINVAL; |
| 4271 | |
| 4272 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4273 | return -EINVAL; |
| 4274 | |
| 4275 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4276 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4277 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4278 | if (!rdev->ops->change_mpath) |
| 4279 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4280 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4281 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4282 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4283 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4284 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4285 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4286 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4287 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4288 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4289 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4290 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4291 | u8 *dst = NULL; |
| 4292 | u8 *next_hop = NULL; |
| 4293 | |
| 4294 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4295 | return -EINVAL; |
| 4296 | |
| 4297 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4298 | return -EINVAL; |
| 4299 | |
| 4300 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4301 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4303 | if (!rdev->ops->add_mpath) |
| 4304 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4305 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4306 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4307 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4308 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4309 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4313 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4315 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4316 | u8 *dst = NULL; |
| 4317 | |
| 4318 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4319 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4320 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4321 | if (!rdev->ops->del_mpath) |
| 4322 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4323 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4324 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4325 | } |
| 4326 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4327 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4330 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4331 | struct bss_parameters params; |
| 4332 | |
| 4333 | memset(¶ms, 0, sizeof(params)); |
| 4334 | /* default to not changing parameters */ |
| 4335 | params.use_cts_prot = -1; |
| 4336 | params.use_short_preamble = -1; |
| 4337 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4338 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4339 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4340 | params.p2p_ctwindow = -1; |
| 4341 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4342 | |
| 4343 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4344 | params.use_cts_prot = |
| 4345 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4346 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4347 | params.use_short_preamble = |
| 4348 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4349 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4350 | params.use_short_slot_time = |
| 4351 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4352 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4353 | params.basic_rates = |
| 4354 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4355 | params.basic_rates_len = |
| 4356 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4357 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4358 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4359 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4360 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4361 | params.ht_opmode = |
| 4362 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4363 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4364 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4365 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4366 | return -EINVAL; |
| 4367 | params.p2p_ctwindow = |
| 4368 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4369 | if (params.p2p_ctwindow < 0) |
| 4370 | return -EINVAL; |
| 4371 | if (params.p2p_ctwindow != 0 && |
| 4372 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4373 | return -EINVAL; |
| 4374 | } |
| 4375 | |
| 4376 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4377 | u8 tmp; |
| 4378 | |
| 4379 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4380 | return -EINVAL; |
| 4381 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4382 | if (tmp > 1) |
| 4383 | return -EINVAL; |
| 4384 | params.p2p_opp_ps = tmp; |
| 4385 | if (params.p2p_opp_ps && |
| 4386 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4387 | return -EINVAL; |
| 4388 | } |
| 4389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4390 | if (!rdev->ops->change_bss) |
| 4391 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4392 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4393 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4394 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4395 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4396 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4397 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4398 | } |
| 4399 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4400 | 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] | 4401 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4402 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4403 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4404 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4405 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4406 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4407 | }; |
| 4408 | |
| 4409 | static int parse_reg_rule(struct nlattr *tb[], |
| 4410 | struct ieee80211_reg_rule *reg_rule) |
| 4411 | { |
| 4412 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4413 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4414 | |
| 4415 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4416 | return -EINVAL; |
| 4417 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4418 | return -EINVAL; |
| 4419 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4420 | return -EINVAL; |
| 4421 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4422 | return -EINVAL; |
| 4423 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4424 | return -EINVAL; |
| 4425 | |
| 4426 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4427 | |
| 4428 | freq_range->start_freq_khz = |
| 4429 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4430 | freq_range->end_freq_khz = |
| 4431 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4432 | freq_range->max_bandwidth_khz = |
| 4433 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4434 | |
| 4435 | power_rule->max_eirp = |
| 4436 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4437 | |
| 4438 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4439 | power_rule->max_antenna_gain = |
| 4440 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4441 | |
| 4442 | return 0; |
| 4443 | } |
| 4444 | |
| 4445 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4446 | { |
| 4447 | int r; |
| 4448 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4449 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4450 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4451 | /* |
| 4452 | * You should only get this when cfg80211 hasn't yet initialized |
| 4453 | * completely when built-in to the kernel right between the time |
| 4454 | * window between nl80211_init() and regulatory_init(), if that is |
| 4455 | * even possible. |
| 4456 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4457 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4458 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4459 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4460 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4461 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4462 | |
| 4463 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4464 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4465 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4466 | user_reg_hint_type = |
| 4467 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4468 | else |
| 4469 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4470 | |
| 4471 | switch (user_reg_hint_type) { |
| 4472 | case NL80211_USER_REG_HINT_USER: |
| 4473 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4474 | break; |
| 4475 | default: |
| 4476 | return -EINVAL; |
| 4477 | } |
| 4478 | |
| 4479 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4480 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4481 | return r; |
| 4482 | } |
| 4483 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4484 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4485 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4486 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4488 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4489 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4490 | struct mesh_config cur_params; |
| 4491 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4492 | void *hdr; |
| 4493 | struct nlattr *pinfoattr; |
| 4494 | struct sk_buff *msg; |
| 4495 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4496 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4497 | return -EOPNOTSUPP; |
| 4498 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4499 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4500 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4501 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4502 | wdev_lock(wdev); |
| 4503 | /* If not connected, get default parameters */ |
| 4504 | if (!wdev->mesh_id_len) |
| 4505 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4506 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4507 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4508 | wdev_unlock(wdev); |
| 4509 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4510 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4511 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4512 | |
| 4513 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4514 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4515 | if (!msg) |
| 4516 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4517 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4518 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4519 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4520 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4521 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4522 | if (!pinfoattr) |
| 4523 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4524 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4525 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4526 | cur_params.dot11MeshRetryTimeout) || |
| 4527 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4528 | cur_params.dot11MeshConfirmTimeout) || |
| 4529 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4530 | cur_params.dot11MeshHoldingTimeout) || |
| 4531 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4532 | cur_params.dot11MeshMaxPeerLinks) || |
| 4533 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4534 | cur_params.dot11MeshMaxRetries) || |
| 4535 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4536 | cur_params.dot11MeshTTL) || |
| 4537 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4538 | cur_params.element_ttl) || |
| 4539 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4540 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4541 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4542 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4543 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4544 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4545 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4546 | cur_params.path_refresh_time) || |
| 4547 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4548 | cur_params.min_discovery_timeout) || |
| 4549 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4550 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4551 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4552 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4553 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4554 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4555 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4556 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4557 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4558 | cur_params.dot11MeshHWMPRootMode) || |
| 4559 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4560 | cur_params.dot11MeshHWMPRannInterval) || |
| 4561 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4562 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4563 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4564 | cur_params.dot11MeshForwarding) || |
| 4565 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4566 | cur_params.rssi_threshold) || |
| 4567 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4568 | cur_params.ht_opmode) || |
| 4569 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4570 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4571 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4572 | cur_params.dot11MeshHWMProotInterval) || |
| 4573 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4574 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4575 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4576 | cur_params.power_mode) || |
| 4577 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4578 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4579 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4580 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4581 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4582 | nla_nest_end(msg, pinfoattr); |
| 4583 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4584 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4585 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4586 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4587 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4588 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4589 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4590 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4591 | } |
| 4592 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4593 | 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] | 4594 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4595 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4596 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4597 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4598 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4599 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4600 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4601 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4602 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4603 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4604 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4605 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4606 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4607 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4608 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4609 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4610 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4611 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4612 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4613 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4614 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4615 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4616 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4617 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4618 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4619 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4620 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4621 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4622 | }; |
| 4623 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4624 | static const struct nla_policy |
| 4625 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4626 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4627 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4628 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4629 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4630 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4631 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4632 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4633 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4634 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4635 | }; |
| 4636 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4637 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4638 | struct mesh_config *cfg, |
| 4639 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4640 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4641 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4642 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4643 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4644 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4645 | do { \ |
| 4646 | if (tb[attr]) { \ |
| 4647 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4648 | return -EINVAL; \ |
| 4649 | cfg->param = fn(tb[attr]); \ |
| 4650 | mask |= (1 << (attr - 1)); \ |
| 4651 | } \ |
| 4652 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4653 | |
| 4654 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4655 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4656 | return -EINVAL; |
| 4657 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4658 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4659 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4660 | return -EINVAL; |
| 4661 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4662 | /* This makes sure that there aren't more than 32 mesh config |
| 4663 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4664 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4665 | |
| 4666 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4667 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4668 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4669 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4670 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4671 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4672 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4673 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4674 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4675 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4676 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4677 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4678 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4679 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4680 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4681 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4682 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4683 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4684 | 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] | 4685 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4686 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4687 | 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] | 4688 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4689 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4690 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4691 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4692 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4693 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4694 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4695 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4696 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4697 | 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] | 4698 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4699 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4700 | 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] | 4701 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4702 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4703 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4704 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4705 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4706 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4707 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4708 | 1, 65535, mask, |
| 4709 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4710 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4711 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4712 | 1, 65535, mask, |
| 4713 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4714 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4715 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4716 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4717 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4718 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4719 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4720 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4721 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4722 | nla_get_u8); |
| 4723 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4724 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4725 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4726 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4727 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4728 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4729 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4730 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4731 | mask, NL80211_MESHCONF_FORWARDING, |
| 4732 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4733 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4734 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4735 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4736 | 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] | 4737 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4738 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4739 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4740 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4741 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4742 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4743 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4744 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4745 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4746 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4747 | dot11MeshHWMPconfirmationInterval, |
| 4748 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4749 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4750 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4751 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4752 | NL80211_MESH_POWER_ACTIVE, |
| 4753 | NL80211_MESH_POWER_MAX, |
| 4754 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4755 | nla_get_u32); |
| 4756 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4757 | 0, 65535, mask, |
| 4758 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4759 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4760 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4761 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4762 | if (mask_out) |
| 4763 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4764 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4765 | return 0; |
| 4766 | |
| 4767 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4768 | } |
| 4769 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4770 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4771 | struct mesh_setup *setup) |
| 4772 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4773 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4774 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4775 | |
| 4776 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4777 | return -EINVAL; |
| 4778 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4779 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4780 | nl80211_mesh_setup_params_policy)) |
| 4781 | return -EINVAL; |
| 4782 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4783 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4784 | setup->sync_method = |
| 4785 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4786 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4787 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4788 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4789 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4790 | setup->path_sel_proto = |
| 4791 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4792 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4793 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4794 | |
| 4795 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4796 | setup->path_metric = |
| 4797 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4798 | IEEE80211_PATH_METRIC_VENDOR : |
| 4799 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4800 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4801 | |
| 4802 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4803 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4804 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4805 | if (!is_valid_ie_attr(ieattr)) |
| 4806 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4807 | setup->ie = nla_data(ieattr); |
| 4808 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4809 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4810 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4811 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4812 | return -EINVAL; |
| 4813 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4814 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4815 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4816 | if (setup->is_secure) |
| 4817 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4818 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4819 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4820 | if (!setup->user_mpm) |
| 4821 | return -EINVAL; |
| 4822 | setup->auth_id = |
| 4823 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4824 | } |
| 4825 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4826 | return 0; |
| 4827 | } |
| 4828 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4829 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4830 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4831 | { |
| 4832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4833 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4834 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4835 | struct mesh_config cfg; |
| 4836 | u32 mask; |
| 4837 | int err; |
| 4838 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4839 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4840 | return -EOPNOTSUPP; |
| 4841 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4842 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4843 | return -EOPNOTSUPP; |
| 4844 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4845 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4846 | if (err) |
| 4847 | return err; |
| 4848 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4849 | wdev_lock(wdev); |
| 4850 | if (!wdev->mesh_id_len) |
| 4851 | err = -ENOLINK; |
| 4852 | |
| 4853 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4854 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4855 | |
| 4856 | wdev_unlock(wdev); |
| 4857 | |
| 4858 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4859 | } |
| 4860 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4861 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4862 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4863 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4864 | struct sk_buff *msg; |
| 4865 | void *hdr = NULL; |
| 4866 | struct nlattr *nl_reg_rules; |
| 4867 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4868 | |
| 4869 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4870 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4871 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4873 | if (!msg) |
| 4874 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4875 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4876 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4877 | NL80211_CMD_GET_REG); |
| 4878 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4879 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4880 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4881 | if (reg_last_request_cell_base() && |
| 4882 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4883 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4884 | goto nla_put_failure; |
| 4885 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4886 | rcu_read_lock(); |
| 4887 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4888 | |
| 4889 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4890 | (regdom->dfs_region && |
| 4891 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4892 | goto nla_put_failure_rcu; |
| 4893 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4894 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4895 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4896 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4897 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4898 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4899 | struct nlattr *nl_reg_rule; |
| 4900 | const struct ieee80211_reg_rule *reg_rule; |
| 4901 | const struct ieee80211_freq_range *freq_range; |
| 4902 | const struct ieee80211_power_rule *power_rule; |
| 4903 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4904 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4905 | freq_range = ®_rule->freq_range; |
| 4906 | power_rule = ®_rule->power_rule; |
| 4907 | |
| 4908 | nl_reg_rule = nla_nest_start(msg, i); |
| 4909 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4910 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4911 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4912 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4913 | reg_rule->flags) || |
| 4914 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4915 | freq_range->start_freq_khz) || |
| 4916 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4917 | freq_range->end_freq_khz) || |
| 4918 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4919 | freq_range->max_bandwidth_khz) || |
| 4920 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4921 | power_rule->max_antenna_gain) || |
| 4922 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4923 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4924 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4925 | |
| 4926 | nla_nest_end(msg, nl_reg_rule); |
| 4927 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4928 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4929 | |
| 4930 | nla_nest_end(msg, nl_reg_rules); |
| 4931 | |
| 4932 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4933 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4934 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4935 | nla_put_failure_rcu: |
| 4936 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4937 | nla_put_failure: |
| 4938 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4939 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4940 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4941 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4942 | } |
| 4943 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4944 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4945 | { |
| 4946 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4947 | struct nlattr *nl_reg_rule; |
| 4948 | char *alpha2 = NULL; |
| 4949 | int rem_reg_rules = 0, r = 0; |
| 4950 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4951 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4952 | struct ieee80211_regdomain *rd = NULL; |
| 4953 | |
| 4954 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4955 | return -EINVAL; |
| 4956 | |
| 4957 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4958 | return -EINVAL; |
| 4959 | |
| 4960 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4961 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4962 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4963 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4964 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4965 | 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] | 4966 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4967 | num_rules++; |
| 4968 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4969 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4972 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4973 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4974 | |
| 4975 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4976 | if (!rd) |
| 4977 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4978 | |
| 4979 | rd->n_reg_rules = num_rules; |
| 4980 | rd->alpha2[0] = alpha2[0]; |
| 4981 | rd->alpha2[1] = alpha2[1]; |
| 4982 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4983 | /* |
| 4984 | * Disable DFS master mode if the DFS region was |
| 4985 | * not supported or known on this kernel. |
| 4986 | */ |
| 4987 | if (reg_supported_dfs_region(dfs_region)) |
| 4988 | rd->dfs_region = dfs_region; |
| 4989 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4990 | 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] | 4991 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4992 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4993 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4994 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4995 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4996 | if (r) |
| 4997 | goto bad_reg; |
| 4998 | |
| 4999 | rule_idx++; |
| 5000 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5001 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5002 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5003 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5004 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5007 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5008 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5009 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5010 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5011 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5012 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5013 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5014 | } |
| 5015 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5016 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5017 | { |
| 5018 | struct nlattr *attr1, *attr2; |
| 5019 | int n_channels = 0, tmp1, tmp2; |
| 5020 | |
| 5021 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5022 | n_channels++; |
| 5023 | /* |
| 5024 | * Some hardware has a limited channel list for |
| 5025 | * scanning, and it is pretty much nonsensical |
| 5026 | * to scan for a channel twice, so disallow that |
| 5027 | * and don't require drivers to check that the |
| 5028 | * channel list they get isn't longer than what |
| 5029 | * they can scan, as long as they can scan all |
| 5030 | * the channels they registered at once. |
| 5031 | */ |
| 5032 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5033 | if (attr1 != attr2 && |
| 5034 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5035 | return 0; |
| 5036 | } |
| 5037 | |
| 5038 | return n_channels; |
| 5039 | } |
| 5040 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5041 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5042 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5044 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5045 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5046 | struct nlattr *attr; |
| 5047 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5048 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5049 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5050 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5051 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5052 | return -EINVAL; |
| 5053 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5054 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5055 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5056 | if (!rdev->ops->scan) |
| 5057 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5058 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5059 | if (rdev->scan_req) { |
| 5060 | err = -EBUSY; |
| 5061 | goto unlock; |
| 5062 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5063 | |
| 5064 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5065 | n_channels = validate_scan_freqs( |
| 5066 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5067 | if (!n_channels) { |
| 5068 | err = -EINVAL; |
| 5069 | goto unlock; |
| 5070 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5071 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5072 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5073 | n_channels = 0; |
| 5074 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5075 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5076 | if (wiphy->bands[band]) |
| 5077 | n_channels += wiphy->bands[band]->n_channels; |
| 5078 | } |
| 5079 | |
| 5080 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5081 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5082 | n_ssids++; |
| 5083 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5084 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5085 | err = -EINVAL; |
| 5086 | goto unlock; |
| 5087 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5088 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5089 | if (info->attrs[NL80211_ATTR_IE]) |
| 5090 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5091 | else |
| 5092 | ie_len = 0; |
| 5093 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5094 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5095 | err = -EINVAL; |
| 5096 | goto unlock; |
| 5097 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5098 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5099 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5100 | + sizeof(*request->ssids) * n_ssids |
| 5101 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5102 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5103 | if (!request) { |
| 5104 | err = -ENOMEM; |
| 5105 | goto unlock; |
| 5106 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5107 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5108 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5109 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5110 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5111 | if (ie_len) { |
| 5112 | if (request->ssids) |
| 5113 | request->ie = (void *)(request->ssids + n_ssids); |
| 5114 | else |
| 5115 | request->ie = (void *)(request->channels + n_channels); |
| 5116 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5117 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5118 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5119 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5120 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5121 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5122 | struct ieee80211_channel *chan; |
| 5123 | |
| 5124 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5125 | |
| 5126 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5127 | err = -EINVAL; |
| 5128 | goto out_free; |
| 5129 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5130 | |
| 5131 | /* ignore disabled channels */ |
| 5132 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5133 | continue; |
| 5134 | |
| 5135 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5136 | i++; |
| 5137 | } |
| 5138 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5139 | enum ieee80211_band band; |
| 5140 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5141 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5142 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5143 | int j; |
| 5144 | if (!wiphy->bands[band]) |
| 5145 | continue; |
| 5146 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5147 | struct ieee80211_channel *chan; |
| 5148 | |
| 5149 | chan = &wiphy->bands[band]->channels[j]; |
| 5150 | |
| 5151 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5152 | continue; |
| 5153 | |
| 5154 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5155 | i++; |
| 5156 | } |
| 5157 | } |
| 5158 | } |
| 5159 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5160 | if (!i) { |
| 5161 | err = -EINVAL; |
| 5162 | goto out_free; |
| 5163 | } |
| 5164 | |
| 5165 | request->n_channels = i; |
| 5166 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5167 | i = 0; |
| 5168 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5169 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5170 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5171 | err = -EINVAL; |
| 5172 | goto out_free; |
| 5173 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5174 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5175 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5176 | i++; |
| 5177 | } |
| 5178 | } |
| 5179 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5180 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5181 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5182 | memcpy((void *)request->ie, |
| 5183 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5184 | request->ie_len); |
| 5185 | } |
| 5186 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5187 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5188 | if (wiphy->bands[i]) |
| 5189 | request->rates[i] = |
| 5190 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5191 | |
| 5192 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5193 | nla_for_each_nested(attr, |
| 5194 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5195 | tmp) { |
| 5196 | enum ieee80211_band band = nla_type(attr); |
| 5197 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5198 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5199 | err = -EINVAL; |
| 5200 | goto out_free; |
| 5201 | } |
| 5202 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5203 | nla_data(attr), |
| 5204 | nla_len(attr), |
| 5205 | &request->rates[band]); |
| 5206 | if (err) |
| 5207 | goto out_free; |
| 5208 | } |
| 5209 | } |
| 5210 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5211 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5212 | request->flags = nla_get_u32( |
| 5213 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5214 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5215 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5216 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5217 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5218 | err = -EOPNOTSUPP; |
| 5219 | goto out_free; |
| 5220 | } |
| 5221 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5222 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5223 | request->no_cck = |
| 5224 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5225 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5226 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5227 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5228 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5229 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5230 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5231 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5232 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5233 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5234 | nl80211_send_scan_start(rdev, wdev); |
| 5235 | if (wdev->netdev) |
| 5236 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5237 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5238 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5239 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5240 | kfree(request); |
| 5241 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5242 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5243 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5244 | return err; |
| 5245 | } |
| 5246 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5247 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5248 | struct genl_info *info) |
| 5249 | { |
| 5250 | struct cfg80211_sched_scan_request *request; |
| 5251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5252 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5253 | struct nlattr *attr; |
| 5254 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5255 | 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] | 5256 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5257 | enum ieee80211_band band; |
| 5258 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5259 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5260 | |
| 5261 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5262 | !rdev->ops->sched_scan_start) |
| 5263 | return -EOPNOTSUPP; |
| 5264 | |
| 5265 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5266 | return -EINVAL; |
| 5267 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5268 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5269 | return -EINVAL; |
| 5270 | |
| 5271 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5272 | if (interval == 0) |
| 5273 | return -EINVAL; |
| 5274 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5275 | wiphy = &rdev->wiphy; |
| 5276 | |
| 5277 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5278 | n_channels = validate_scan_freqs( |
| 5279 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5280 | if (!n_channels) |
| 5281 | return -EINVAL; |
| 5282 | } else { |
| 5283 | n_channels = 0; |
| 5284 | |
| 5285 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5286 | if (wiphy->bands[band]) |
| 5287 | n_channels += wiphy->bands[band]->n_channels; |
| 5288 | } |
| 5289 | |
| 5290 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5291 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5292 | tmp) |
| 5293 | n_ssids++; |
| 5294 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5295 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5296 | return -EINVAL; |
| 5297 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5298 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5299 | nla_for_each_nested(attr, |
| 5300 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5301 | tmp) |
| 5302 | n_match_sets++; |
| 5303 | |
| 5304 | if (n_match_sets > wiphy->max_match_sets) |
| 5305 | return -EINVAL; |
| 5306 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5307 | if (info->attrs[NL80211_ATTR_IE]) |
| 5308 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5309 | else |
| 5310 | ie_len = 0; |
| 5311 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5312 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5313 | return -EINVAL; |
| 5314 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5315 | if (rdev->sched_scan_req) { |
| 5316 | err = -EINPROGRESS; |
| 5317 | goto out; |
| 5318 | } |
| 5319 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5320 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5321 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5322 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5323 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5324 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5325 | if (!request) { |
| 5326 | err = -ENOMEM; |
| 5327 | goto out; |
| 5328 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5329 | |
| 5330 | if (n_ssids) |
| 5331 | request->ssids = (void *)&request->channels[n_channels]; |
| 5332 | request->n_ssids = n_ssids; |
| 5333 | if (ie_len) { |
| 5334 | if (request->ssids) |
| 5335 | request->ie = (void *)(request->ssids + n_ssids); |
| 5336 | else |
| 5337 | request->ie = (void *)(request->channels + n_channels); |
| 5338 | } |
| 5339 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5340 | if (n_match_sets) { |
| 5341 | if (request->ie) |
| 5342 | request->match_sets = (void *)(request->ie + ie_len); |
| 5343 | else if (request->ssids) |
| 5344 | request->match_sets = |
| 5345 | (void *)(request->ssids + n_ssids); |
| 5346 | else |
| 5347 | request->match_sets = |
| 5348 | (void *)(request->channels + n_channels); |
| 5349 | } |
| 5350 | request->n_match_sets = n_match_sets; |
| 5351 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5352 | i = 0; |
| 5353 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5354 | /* user specified, bail out if channel not found */ |
| 5355 | nla_for_each_nested(attr, |
| 5356 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5357 | tmp) { |
| 5358 | struct ieee80211_channel *chan; |
| 5359 | |
| 5360 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5361 | |
| 5362 | if (!chan) { |
| 5363 | err = -EINVAL; |
| 5364 | goto out_free; |
| 5365 | } |
| 5366 | |
| 5367 | /* ignore disabled channels */ |
| 5368 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5369 | continue; |
| 5370 | |
| 5371 | request->channels[i] = chan; |
| 5372 | i++; |
| 5373 | } |
| 5374 | } else { |
| 5375 | /* all channels */ |
| 5376 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5377 | int j; |
| 5378 | if (!wiphy->bands[band]) |
| 5379 | continue; |
| 5380 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5381 | struct ieee80211_channel *chan; |
| 5382 | |
| 5383 | chan = &wiphy->bands[band]->channels[j]; |
| 5384 | |
| 5385 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5386 | continue; |
| 5387 | |
| 5388 | request->channels[i] = chan; |
| 5389 | i++; |
| 5390 | } |
| 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | if (!i) { |
| 5395 | err = -EINVAL; |
| 5396 | goto out_free; |
| 5397 | } |
| 5398 | |
| 5399 | request->n_channels = i; |
| 5400 | |
| 5401 | i = 0; |
| 5402 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5403 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5404 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5405 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5406 | err = -EINVAL; |
| 5407 | goto out_free; |
| 5408 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5409 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5410 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5411 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5412 | i++; |
| 5413 | } |
| 5414 | } |
| 5415 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5416 | i = 0; |
| 5417 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5418 | nla_for_each_nested(attr, |
| 5419 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5420 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5421 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5422 | |
| 5423 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5424 | nla_data(attr), nla_len(attr), |
| 5425 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5426 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5427 | if (ssid) { |
| 5428 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5429 | err = -EINVAL; |
| 5430 | goto out_free; |
| 5431 | } |
| 5432 | memcpy(request->match_sets[i].ssid.ssid, |
| 5433 | nla_data(ssid), nla_len(ssid)); |
| 5434 | request->match_sets[i].ssid.ssid_len = |
| 5435 | nla_len(ssid); |
| 5436 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5437 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5438 | if (rssi) |
| 5439 | request->rssi_thold = nla_get_u32(rssi); |
| 5440 | else |
| 5441 | request->rssi_thold = |
| 5442 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5443 | i++; |
| 5444 | } |
| 5445 | } |
| 5446 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5447 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5448 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5449 | memcpy((void *)request->ie, |
| 5450 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5451 | request->ie_len); |
| 5452 | } |
| 5453 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5454 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5455 | request->flags = nla_get_u32( |
| 5456 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5457 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5458 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5459 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5460 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5461 | err = -EOPNOTSUPP; |
| 5462 | goto out_free; |
| 5463 | } |
| 5464 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5465 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5466 | request->dev = dev; |
| 5467 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5468 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5469 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5470 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5471 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5472 | if (!err) { |
| 5473 | rdev->sched_scan_req = request; |
| 5474 | nl80211_send_sched_scan(rdev, dev, |
| 5475 | NL80211_CMD_START_SCHED_SCAN); |
| 5476 | goto out; |
| 5477 | } |
| 5478 | |
| 5479 | out_free: |
| 5480 | kfree(request); |
| 5481 | out: |
| 5482 | return err; |
| 5483 | } |
| 5484 | |
| 5485 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5486 | struct genl_info *info) |
| 5487 | { |
| 5488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5489 | |
| 5490 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5491 | !rdev->ops->sched_scan_stop) |
| 5492 | return -EOPNOTSUPP; |
| 5493 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5494 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5495 | } |
| 5496 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5497 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5498 | struct genl_info *info) |
| 5499 | { |
| 5500 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5501 | struct net_device *dev = info->user_ptr[1]; |
| 5502 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5503 | struct cfg80211_chan_def chandef; |
| 5504 | int err; |
| 5505 | |
| 5506 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5507 | if (err) |
| 5508 | return err; |
| 5509 | |
| 5510 | if (wdev->cac_started) |
| 5511 | return -EBUSY; |
| 5512 | |
| 5513 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5514 | if (err < 0) |
| 5515 | return err; |
| 5516 | |
| 5517 | if (err == 0) |
| 5518 | return -EINVAL; |
| 5519 | |
| 5520 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5521 | return -EINVAL; |
| 5522 | |
| 5523 | if (!rdev->ops->start_radar_detection) |
| 5524 | return -EOPNOTSUPP; |
| 5525 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5526 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5527 | chandef.chan, CHAN_MODE_SHARED, |
| 5528 | BIT(chandef.width)); |
| 5529 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5530 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5531 | |
| 5532 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5533 | if (!err) { |
| 5534 | wdev->channel = chandef.chan; |
| 5535 | wdev->cac_started = true; |
| 5536 | wdev->cac_start_time = jiffies; |
| 5537 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5538 | return err; |
| 5539 | } |
| 5540 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5541 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5542 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5543 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5544 | struct wireless_dev *wdev, |
| 5545 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5546 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5547 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5548 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5549 | void *hdr; |
| 5550 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5551 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5552 | |
| 5553 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5554 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5555 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5556 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5557 | if (!hdr) |
| 5558 | return -1; |
| 5559 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5560 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5561 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5562 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5563 | goto nla_put_failure; |
| 5564 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5565 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5566 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5567 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5568 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5569 | |
| 5570 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5571 | if (!bss) |
| 5572 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5573 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5574 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5575 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5576 | |
| 5577 | rcu_read_lock(); |
| 5578 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5579 | if (ies) { |
| 5580 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5581 | goto fail_unlock_rcu; |
| 5582 | tsf = true; |
| 5583 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5584 | ies->len, ies->data)) |
| 5585 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5586 | } |
| 5587 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5588 | if (ies) { |
| 5589 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5590 | goto fail_unlock_rcu; |
| 5591 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5592 | ies->len, ies->data)) |
| 5593 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5594 | } |
| 5595 | rcu_read_unlock(); |
| 5596 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5597 | if (res->beacon_interval && |
| 5598 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5599 | goto nla_put_failure; |
| 5600 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5601 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5602 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5603 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5604 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5605 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5606 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5607 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5608 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5609 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5610 | break; |
| 5611 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5612 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5613 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5614 | break; |
| 5615 | default: |
| 5616 | break; |
| 5617 | } |
| 5618 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5619 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5620 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5621 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5622 | if (intbss == wdev->current_bss && |
| 5623 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5624 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5625 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5626 | break; |
| 5627 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5628 | if (intbss == wdev->current_bss && |
| 5629 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5630 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5631 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5632 | break; |
| 5633 | default: |
| 5634 | break; |
| 5635 | } |
| 5636 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5637 | nla_nest_end(msg, bss); |
| 5638 | |
| 5639 | return genlmsg_end(msg, hdr); |
| 5640 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5641 | fail_unlock_rcu: |
| 5642 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5643 | nla_put_failure: |
| 5644 | genlmsg_cancel(msg, hdr); |
| 5645 | return -EMSGSIZE; |
| 5646 | } |
| 5647 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5648 | 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] | 5649 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5650 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5651 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5652 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5653 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5654 | int err; |
| 5655 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5656 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5657 | if (err) |
| 5658 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5659 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5660 | wdev_lock(wdev); |
| 5661 | spin_lock_bh(&rdev->bss_lock); |
| 5662 | cfg80211_bss_expire(rdev); |
| 5663 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5664 | cb->seq = rdev->bss_generation; |
| 5665 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5666 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5667 | if (++idx <= start) |
| 5668 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5669 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5670 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5671 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5672 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5673 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5674 | } |
| 5675 | } |
| 5676 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5677 | spin_unlock_bh(&rdev->bss_lock); |
| 5678 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5679 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5680 | cb->args[2] = idx; |
| 5681 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5682 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5683 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5684 | } |
| 5685 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5686 | 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] | 5687 | int flags, struct net_device *dev, |
| 5688 | struct survey_info *survey) |
| 5689 | { |
| 5690 | void *hdr; |
| 5691 | struct nlattr *infoattr; |
| 5692 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5693 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5694 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5695 | if (!hdr) |
| 5696 | return -ENOMEM; |
| 5697 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5698 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5699 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5700 | |
| 5701 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5702 | if (!infoattr) |
| 5703 | goto nla_put_failure; |
| 5704 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5705 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5706 | survey->channel->center_freq)) |
| 5707 | goto nla_put_failure; |
| 5708 | |
| 5709 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5710 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5711 | goto nla_put_failure; |
| 5712 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5713 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5714 | goto nla_put_failure; |
| 5715 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5716 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5717 | survey->channel_time)) |
| 5718 | goto nla_put_failure; |
| 5719 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5720 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5721 | survey->channel_time_busy)) |
| 5722 | goto nla_put_failure; |
| 5723 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5724 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5725 | survey->channel_time_ext_busy)) |
| 5726 | goto nla_put_failure; |
| 5727 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5728 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5729 | survey->channel_time_rx)) |
| 5730 | goto nla_put_failure; |
| 5731 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5732 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5733 | survey->channel_time_tx)) |
| 5734 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5735 | |
| 5736 | nla_nest_end(msg, infoattr); |
| 5737 | |
| 5738 | return genlmsg_end(msg, hdr); |
| 5739 | |
| 5740 | nla_put_failure: |
| 5741 | genlmsg_cancel(msg, hdr); |
| 5742 | return -EMSGSIZE; |
| 5743 | } |
| 5744 | |
| 5745 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5746 | struct netlink_callback *cb) |
| 5747 | { |
| 5748 | struct survey_info survey; |
| 5749 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5750 | struct wireless_dev *wdev; |
| 5751 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5752 | int res; |
| 5753 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5754 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5755 | if (res) |
| 5756 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5757 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5758 | if (!wdev->netdev) { |
| 5759 | res = -EINVAL; |
| 5760 | goto out_err; |
| 5761 | } |
| 5762 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5763 | if (!dev->ops->dump_survey) { |
| 5764 | res = -EOPNOTSUPP; |
| 5765 | goto out_err; |
| 5766 | } |
| 5767 | |
| 5768 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5769 | struct ieee80211_channel *chan; |
| 5770 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5771 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5772 | if (res == -ENOENT) |
| 5773 | break; |
| 5774 | if (res) |
| 5775 | goto out_err; |
| 5776 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5777 | /* Survey without a channel doesn't make sense */ |
| 5778 | if (!survey.channel) { |
| 5779 | res = -EINVAL; |
| 5780 | goto out; |
| 5781 | } |
| 5782 | |
| 5783 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5784 | survey.channel->center_freq); |
| 5785 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5786 | survey_idx++; |
| 5787 | continue; |
| 5788 | } |
| 5789 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5790 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5791 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5792 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5793 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5794 | goto out; |
| 5795 | survey_idx++; |
| 5796 | } |
| 5797 | |
| 5798 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5799 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5800 | res = skb->len; |
| 5801 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5802 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5803 | return res; |
| 5804 | } |
| 5805 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5806 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5807 | { |
| 5808 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5809 | NL80211_WPA_VERSION_2)); |
| 5810 | } |
| 5811 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5812 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5813 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5815 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5816 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5817 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5818 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5819 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5820 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5821 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5822 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5823 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5824 | return -EINVAL; |
| 5825 | |
| 5826 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5827 | return -EINVAL; |
| 5828 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5829 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5830 | return -EINVAL; |
| 5831 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5832 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5833 | return -EINVAL; |
| 5834 | |
| 5835 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5836 | return -EINVAL; |
| 5837 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5838 | err = nl80211_parse_key(info, &key); |
| 5839 | if (err) |
| 5840 | return err; |
| 5841 | |
| 5842 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5843 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5844 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5845 | if (!key.p.key || !key.p.key_len) |
| 5846 | return -EINVAL; |
| 5847 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5848 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5849 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5850 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5851 | return -EINVAL; |
| 5852 | if (key.idx > 4) |
| 5853 | return -EINVAL; |
| 5854 | } else { |
| 5855 | key.p.key_len = 0; |
| 5856 | key.p.key = NULL; |
| 5857 | } |
| 5858 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5859 | if (key.idx >= 0) { |
| 5860 | int i; |
| 5861 | bool ok = false; |
| 5862 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5863 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5864 | ok = true; |
| 5865 | break; |
| 5866 | } |
| 5867 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5868 | if (!ok) |
| 5869 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5870 | } |
| 5871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5872 | if (!rdev->ops->auth) |
| 5873 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5874 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5875 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5876 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5877 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5878 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5879 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5880 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5881 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5882 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5883 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5884 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5885 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5886 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5887 | |
| 5888 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5889 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5890 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5891 | } |
| 5892 | |
| 5893 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5894 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5895 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5896 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5897 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5898 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5899 | return -EINVAL; |
| 5900 | |
| 5901 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5902 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5903 | return -EINVAL; |
| 5904 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5905 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5906 | /* need to include at least Auth Transaction and Status Code */ |
| 5907 | if (sae_data_len < 4) |
| 5908 | return -EINVAL; |
| 5909 | } |
| 5910 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5911 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5912 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5913 | /* |
| 5914 | * Since we no longer track auth state, ignore |
| 5915 | * requests to only change local state. |
| 5916 | */ |
| 5917 | if (local_state_change) |
| 5918 | return 0; |
| 5919 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 5920 | wdev_lock(dev->ieee80211_ptr); |
| 5921 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5922 | ssid, ssid_len, ie, ie_len, |
| 5923 | key.p.key, key.p.key_len, key.idx, |
| 5924 | sae_data, sae_data_len); |
| 5925 | wdev_unlock(dev->ieee80211_ptr); |
| 5926 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5927 | } |
| 5928 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5929 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5930 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5931 | struct cfg80211_crypto_settings *settings, |
| 5932 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5933 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5934 | memset(settings, 0, sizeof(*settings)); |
| 5935 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5936 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5937 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5938 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5939 | u16 proto; |
| 5940 | proto = nla_get_u16( |
| 5941 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5942 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5943 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5944 | proto != ETH_P_PAE) |
| 5945 | return -EINVAL; |
| 5946 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5947 | settings->control_port_no_encrypt = true; |
| 5948 | } else |
| 5949 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5950 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5951 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5952 | void *data; |
| 5953 | int len, i; |
| 5954 | |
| 5955 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5956 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5957 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5958 | |
| 5959 | if (len % sizeof(u32)) |
| 5960 | return -EINVAL; |
| 5961 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5962 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5963 | return -EINVAL; |
| 5964 | |
| 5965 | memcpy(settings->ciphers_pairwise, data, len); |
| 5966 | |
| 5967 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5968 | if (!cfg80211_supported_cipher_suite( |
| 5969 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5970 | settings->ciphers_pairwise[i])) |
| 5971 | return -EINVAL; |
| 5972 | } |
| 5973 | |
| 5974 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5975 | settings->cipher_group = |
| 5976 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5977 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5978 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5979 | return -EINVAL; |
| 5980 | } |
| 5981 | |
| 5982 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5983 | settings->wpa_versions = |
| 5984 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5985 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5986 | return -EINVAL; |
| 5987 | } |
| 5988 | |
| 5989 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5990 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5991 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5992 | |
| 5993 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5994 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5995 | settings->n_akm_suites = len / sizeof(u32); |
| 5996 | |
| 5997 | if (len % sizeof(u32)) |
| 5998 | return -EINVAL; |
| 5999 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6000 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6001 | return -EINVAL; |
| 6002 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6003 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | return 0; |
| 6007 | } |
| 6008 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6009 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6010 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6011 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6012 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6013 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6014 | struct cfg80211_assoc_request req = {}; |
| 6015 | const u8 *bssid, *ssid; |
| 6016 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6017 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6018 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6019 | return -EINVAL; |
| 6020 | |
| 6021 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6022 | !info->attrs[NL80211_ATTR_SSID] || |
| 6023 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6024 | return -EINVAL; |
| 6025 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6026 | if (!rdev->ops->assoc) |
| 6027 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6028 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6029 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6030 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6031 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6032 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6033 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6034 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6035 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6036 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6037 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6038 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6039 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6040 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6041 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6042 | |
| 6043 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6044 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6045 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6046 | } |
| 6047 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6048 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6049 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6050 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6051 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6052 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6053 | else if (mfp != NL80211_MFP_NO) |
| 6054 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6055 | } |
| 6056 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6057 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6058 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6059 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6060 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6061 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6062 | |
| 6063 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6064 | memcpy(&req.ht_capa_mask, |
| 6065 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6066 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6067 | |
| 6068 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6069 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6070 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6071 | memcpy(&req.ht_capa, |
| 6072 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6073 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6074 | } |
| 6075 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6076 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6077 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6078 | |
| 6079 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6080 | memcpy(&req.vht_capa_mask, |
| 6081 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6082 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6083 | |
| 6084 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6085 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6086 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6087 | memcpy(&req.vht_capa, |
| 6088 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6089 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6090 | } |
| 6091 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6092 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6093 | if (!err) { |
| 6094 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6095 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6096 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6097 | wdev_unlock(dev->ieee80211_ptr); |
| 6098 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6099 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6100 | return err; |
| 6101 | } |
| 6102 | |
| 6103 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6104 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6106 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6107 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6108 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6109 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6110 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6111 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6112 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6113 | return -EINVAL; |
| 6114 | |
| 6115 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6116 | return -EINVAL; |
| 6117 | |
| 6118 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6119 | return -EINVAL; |
| 6120 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6121 | if (!rdev->ops->deauth) |
| 6122 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6123 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6124 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6125 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6126 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6127 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6128 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6129 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6130 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6131 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6132 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6133 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6134 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6135 | |
| 6136 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6137 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6138 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6139 | } |
| 6140 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6141 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6142 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6143 | wdev_lock(dev->ieee80211_ptr); |
| 6144 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6145 | local_state_change); |
| 6146 | wdev_unlock(dev->ieee80211_ptr); |
| 6147 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6151 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6153 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6154 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6155 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6156 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6157 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6158 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6159 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6160 | return -EINVAL; |
| 6161 | |
| 6162 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6163 | return -EINVAL; |
| 6164 | |
| 6165 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6166 | return -EINVAL; |
| 6167 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6168 | if (!rdev->ops->disassoc) |
| 6169 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6170 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6171 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6172 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6173 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6174 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6175 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6176 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6177 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6178 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6179 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6180 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6181 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6182 | |
| 6183 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6184 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6185 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6186 | } |
| 6187 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6188 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6189 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6190 | wdev_lock(dev->ieee80211_ptr); |
| 6191 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6192 | local_state_change); |
| 6193 | wdev_unlock(dev->ieee80211_ptr); |
| 6194 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6195 | } |
| 6196 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6197 | static bool |
| 6198 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6199 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6200 | int rateval) |
| 6201 | { |
| 6202 | struct wiphy *wiphy = &rdev->wiphy; |
| 6203 | bool found = false; |
| 6204 | int band, i; |
| 6205 | |
| 6206 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6207 | struct ieee80211_supported_band *sband; |
| 6208 | |
| 6209 | sband = wiphy->bands[band]; |
| 6210 | if (!sband) |
| 6211 | continue; |
| 6212 | |
| 6213 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6214 | if (sband->bitrates[i].bitrate == rateval) { |
| 6215 | mcast_rate[band] = i + 1; |
| 6216 | found = true; |
| 6217 | break; |
| 6218 | } |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | return found; |
| 6223 | } |
| 6224 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6225 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6226 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6228 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6229 | struct cfg80211_ibss_params ibss; |
| 6230 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6231 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6232 | int err; |
| 6233 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6234 | memset(&ibss, 0, sizeof(ibss)); |
| 6235 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6236 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6237 | return -EINVAL; |
| 6238 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6239 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6240 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6241 | return -EINVAL; |
| 6242 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6243 | ibss.beacon_interval = 100; |
| 6244 | |
| 6245 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6246 | ibss.beacon_interval = |
| 6247 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6248 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6249 | return -EINVAL; |
| 6250 | } |
| 6251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6252 | if (!rdev->ops->join_ibss) |
| 6253 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6254 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6255 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6256 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6257 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6258 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6259 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6260 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6261 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6262 | |
| 6263 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6264 | return -EINVAL; |
| 6265 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6266 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6267 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6268 | |
| 6269 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6270 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6271 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6272 | } |
| 6273 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6274 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6275 | if (err) |
| 6276 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6277 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6278 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6279 | return -EINVAL; |
| 6280 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6281 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 6282 | return -EINVAL; |
| 6283 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 6284 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 6285 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6286 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6287 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6288 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6289 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6290 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6291 | u8 *rates = |
| 6292 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6293 | int n_rates = |
| 6294 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6295 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6296 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6297 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6298 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6299 | &ibss.basic_rates); |
| 6300 | if (err) |
| 6301 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6302 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6303 | |
| 6304 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6305 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6306 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6307 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6309 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6310 | bool no_ht = false; |
| 6311 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6312 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6313 | info->attrs[NL80211_ATTR_KEYS], |
| 6314 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6315 | if (IS_ERR(connkeys)) |
| 6316 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6317 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6318 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6319 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6320 | kfree(connkeys); |
| 6321 | return -EINVAL; |
| 6322 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6323 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6324 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6325 | ibss.control_port = |
| 6326 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6327 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6328 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6329 | if (err) |
| 6330 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6331 | return err; |
| 6332 | } |
| 6333 | |
| 6334 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6335 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6337 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6339 | if (!rdev->ops->leave_ibss) |
| 6340 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6341 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6342 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6343 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6344 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6345 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6346 | } |
| 6347 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6348 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6349 | { |
| 6350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6351 | struct net_device *dev = info->user_ptr[1]; |
| 6352 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6353 | u32 nla_rate; |
| 6354 | int err; |
| 6355 | |
| 6356 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6357 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6358 | return -EOPNOTSUPP; |
| 6359 | |
| 6360 | if (!rdev->ops->set_mcast_rate) |
| 6361 | return -EOPNOTSUPP; |
| 6362 | |
| 6363 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6364 | |
| 6365 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6366 | return -EINVAL; |
| 6367 | |
| 6368 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6369 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6370 | return -EINVAL; |
| 6371 | |
| 6372 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6373 | |
| 6374 | return err; |
| 6375 | } |
| 6376 | |
| 6377 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6378 | #ifdef CONFIG_NL80211_TESTMODE |
| 6379 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6380 | .name = "testmode", |
| 6381 | }; |
| 6382 | |
| 6383 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6384 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6385 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6386 | int err; |
| 6387 | |
| 6388 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6389 | return -EINVAL; |
| 6390 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6391 | err = -EOPNOTSUPP; |
| 6392 | if (rdev->ops->testmode_cmd) { |
| 6393 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6394 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6395 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6396 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6397 | rdev->testmode_info = NULL; |
| 6398 | } |
| 6399 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6400 | return err; |
| 6401 | } |
| 6402 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6403 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6404 | struct netlink_callback *cb) |
| 6405 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6406 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6407 | int err; |
| 6408 | long phy_idx; |
| 6409 | void *data = NULL; |
| 6410 | int data_len = 0; |
| 6411 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6412 | rtnl_lock(); |
| 6413 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6414 | if (cb->args[0]) { |
| 6415 | /* |
| 6416 | * 0 is a valid index, but not valid for args[0], |
| 6417 | * so we need to offset by 1. |
| 6418 | */ |
| 6419 | phy_idx = cb->args[0] - 1; |
| 6420 | } else { |
| 6421 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6422 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6423 | nl80211_policy); |
| 6424 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6425 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6426 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6427 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6428 | nl80211_fam.attrbuf); |
| 6429 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6430 | err = PTR_ERR(rdev); |
| 6431 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6432 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6433 | phy_idx = rdev->wiphy_idx; |
| 6434 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6435 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6436 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6437 | cb->args[1] = |
| 6438 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6439 | } |
| 6440 | |
| 6441 | if (cb->args[1]) { |
| 6442 | data = nla_data((void *)cb->args[1]); |
| 6443 | data_len = nla_len((void *)cb->args[1]); |
| 6444 | } |
| 6445 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6446 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6447 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6448 | err = -ENOENT; |
| 6449 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6450 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6451 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6452 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6453 | err = -EOPNOTSUPP; |
| 6454 | goto out_err; |
| 6455 | } |
| 6456 | |
| 6457 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6458 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6459 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6460 | NL80211_CMD_TESTMODE); |
| 6461 | struct nlattr *tmdata; |
| 6462 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6463 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6464 | genlmsg_cancel(skb, hdr); |
| 6465 | break; |
| 6466 | } |
| 6467 | |
| 6468 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6469 | if (!tmdata) { |
| 6470 | genlmsg_cancel(skb, hdr); |
| 6471 | break; |
| 6472 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6473 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6474 | nla_nest_end(skb, tmdata); |
| 6475 | |
| 6476 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6477 | genlmsg_cancel(skb, hdr); |
| 6478 | break; |
| 6479 | } else if (err) { |
| 6480 | genlmsg_cancel(skb, hdr); |
| 6481 | goto out_err; |
| 6482 | } |
| 6483 | |
| 6484 | genlmsg_end(skb, hdr); |
| 6485 | } |
| 6486 | |
| 6487 | err = skb->len; |
| 6488 | /* see above */ |
| 6489 | cb->args[0] = phy_idx + 1; |
| 6490 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6491 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6492 | return err; |
| 6493 | } |
| 6494 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6495 | static struct sk_buff * |
| 6496 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6497 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6498 | { |
| 6499 | struct sk_buff *skb; |
| 6500 | void *hdr; |
| 6501 | struct nlattr *data; |
| 6502 | |
| 6503 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6504 | if (!skb) |
| 6505 | return NULL; |
| 6506 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6507 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6508 | if (!hdr) { |
| 6509 | kfree_skb(skb); |
| 6510 | return NULL; |
| 6511 | } |
| 6512 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6513 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6514 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6515 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6516 | |
| 6517 | ((void **)skb->cb)[0] = rdev; |
| 6518 | ((void **)skb->cb)[1] = hdr; |
| 6519 | ((void **)skb->cb)[2] = data; |
| 6520 | |
| 6521 | return skb; |
| 6522 | |
| 6523 | nla_put_failure: |
| 6524 | kfree_skb(skb); |
| 6525 | return NULL; |
| 6526 | } |
| 6527 | |
| 6528 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6529 | int approxlen) |
| 6530 | { |
| 6531 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6532 | |
| 6533 | if (WARN_ON(!rdev->testmode_info)) |
| 6534 | return NULL; |
| 6535 | |
| 6536 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6537 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6538 | rdev->testmode_info->snd_seq, |
| 6539 | GFP_KERNEL); |
| 6540 | } |
| 6541 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6542 | |
| 6543 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6544 | { |
| 6545 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6546 | void *hdr = ((void **)skb->cb)[1]; |
| 6547 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6548 | |
| 6549 | if (WARN_ON(!rdev->testmode_info)) { |
| 6550 | kfree_skb(skb); |
| 6551 | return -EINVAL; |
| 6552 | } |
| 6553 | |
| 6554 | nla_nest_end(skb, data); |
| 6555 | genlmsg_end(skb, hdr); |
| 6556 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6557 | } |
| 6558 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6559 | |
| 6560 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6561 | int approxlen, gfp_t gfp) |
| 6562 | { |
| 6563 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6564 | |
| 6565 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6566 | } |
| 6567 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6568 | |
| 6569 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6570 | { |
| 6571 | void *hdr = ((void **)skb->cb)[1]; |
| 6572 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6573 | |
| 6574 | nla_nest_end(skb, data); |
| 6575 | genlmsg_end(skb, hdr); |
| 6576 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6577 | } |
| 6578 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6579 | #endif |
| 6580 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6581 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6582 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6583 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6584 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6585 | struct cfg80211_connect_params connect; |
| 6586 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6587 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6588 | int err; |
| 6589 | |
| 6590 | memset(&connect, 0, sizeof(connect)); |
| 6591 | |
| 6592 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6593 | return -EINVAL; |
| 6594 | |
| 6595 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6596 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6597 | return -EINVAL; |
| 6598 | |
| 6599 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6600 | connect.auth_type = |
| 6601 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6602 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6603 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6604 | return -EINVAL; |
| 6605 | } else |
| 6606 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6607 | |
| 6608 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6609 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6610 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6611 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6612 | if (err) |
| 6613 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6614 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6615 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6616 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6617 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6618 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6619 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6620 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6621 | connect.bg_scan_period = -1; |
| 6622 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6623 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6624 | connect.bg_scan_period = |
| 6625 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6626 | } |
| 6627 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6628 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6629 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6630 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6631 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6632 | |
| 6633 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6634 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6635 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6636 | } |
| 6637 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6638 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6639 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6640 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6641 | connect.mfp != NL80211_MFP_NO) |
| 6642 | return -EINVAL; |
| 6643 | } else { |
| 6644 | connect.mfp = NL80211_MFP_NO; |
| 6645 | } |
| 6646 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6647 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6648 | connect.channel = |
| 6649 | ieee80211_get_channel(wiphy, |
| 6650 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6651 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6652 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6653 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6654 | } |
| 6655 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6656 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6657 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6658 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6659 | if (IS_ERR(connkeys)) |
| 6660 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6661 | } |
| 6662 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6663 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6664 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6665 | |
| 6666 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6667 | memcpy(&connect.ht_capa_mask, |
| 6668 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6669 | sizeof(connect.ht_capa_mask)); |
| 6670 | |
| 6671 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6672 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6673 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6674 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6675 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6676 | memcpy(&connect.ht_capa, |
| 6677 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6678 | sizeof(connect.ht_capa)); |
| 6679 | } |
| 6680 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6681 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6682 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6683 | |
| 6684 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6685 | memcpy(&connect.vht_capa_mask, |
| 6686 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6687 | sizeof(connect.vht_capa_mask)); |
| 6688 | |
| 6689 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6690 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6691 | kfree(connkeys); |
| 6692 | return -EINVAL; |
| 6693 | } |
| 6694 | memcpy(&connect.vht_capa, |
| 6695 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6696 | sizeof(connect.vht_capa)); |
| 6697 | } |
| 6698 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6699 | wdev_lock(dev->ieee80211_ptr); |
| 6700 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6701 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6702 | if (err) |
| 6703 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6704 | return err; |
| 6705 | } |
| 6706 | |
| 6707 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6708 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6710 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6711 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6712 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6713 | |
| 6714 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6715 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6716 | else |
| 6717 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6718 | |
| 6719 | if (reason == 0) |
| 6720 | return -EINVAL; |
| 6721 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6722 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6723 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6724 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6725 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6726 | wdev_lock(dev->ieee80211_ptr); |
| 6727 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 6728 | wdev_unlock(dev->ieee80211_ptr); |
| 6729 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6730 | } |
| 6731 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6732 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6733 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6734 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6735 | struct net *net; |
| 6736 | int err; |
| 6737 | u32 pid; |
| 6738 | |
| 6739 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6740 | return -EINVAL; |
| 6741 | |
| 6742 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6743 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6744 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6745 | if (IS_ERR(net)) |
| 6746 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6747 | |
| 6748 | err = 0; |
| 6749 | |
| 6750 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6751 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6752 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6753 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6754 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6755 | return err; |
| 6756 | } |
| 6757 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6758 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6759 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6761 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6762 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6763 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6764 | struct cfg80211_pmksa pmksa; |
| 6765 | |
| 6766 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6767 | |
| 6768 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6769 | return -EINVAL; |
| 6770 | |
| 6771 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6772 | return -EINVAL; |
| 6773 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6774 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6775 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6776 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6777 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6778 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6779 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6780 | |
| 6781 | switch (info->genlhdr->cmd) { |
| 6782 | case NL80211_CMD_SET_PMKSA: |
| 6783 | rdev_ops = rdev->ops->set_pmksa; |
| 6784 | break; |
| 6785 | case NL80211_CMD_DEL_PMKSA: |
| 6786 | rdev_ops = rdev->ops->del_pmksa; |
| 6787 | break; |
| 6788 | default: |
| 6789 | WARN_ON(1); |
| 6790 | break; |
| 6791 | } |
| 6792 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6793 | if (!rdev_ops) |
| 6794 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6795 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6796 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6797 | } |
| 6798 | |
| 6799 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6800 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6801 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6802 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6803 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6804 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6805 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6806 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6807 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6808 | if (!rdev->ops->flush_pmksa) |
| 6809 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6810 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6811 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6812 | } |
| 6813 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6814 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6815 | { |
| 6816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6817 | struct net_device *dev = info->user_ptr[1]; |
| 6818 | u8 action_code, dialog_token; |
| 6819 | u16 status_code; |
| 6820 | u8 *peer; |
| 6821 | |
| 6822 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6823 | !rdev->ops->tdls_mgmt) |
| 6824 | return -EOPNOTSUPP; |
| 6825 | |
| 6826 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6827 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6828 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6829 | !info->attrs[NL80211_ATTR_IE] || |
| 6830 | !info->attrs[NL80211_ATTR_MAC]) |
| 6831 | return -EINVAL; |
| 6832 | |
| 6833 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6834 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6835 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6836 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6837 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6838 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6839 | dialog_token, status_code, |
| 6840 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6841 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6845 | { |
| 6846 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6847 | struct net_device *dev = info->user_ptr[1]; |
| 6848 | enum nl80211_tdls_operation operation; |
| 6849 | u8 *peer; |
| 6850 | |
| 6851 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6852 | !rdev->ops->tdls_oper) |
| 6853 | return -EOPNOTSUPP; |
| 6854 | |
| 6855 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6856 | !info->attrs[NL80211_ATTR_MAC]) |
| 6857 | return -EINVAL; |
| 6858 | |
| 6859 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6860 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6861 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6862 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6863 | } |
| 6864 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6865 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6866 | struct genl_info *info) |
| 6867 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6868 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6869 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6870 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6871 | struct sk_buff *msg; |
| 6872 | void *hdr; |
| 6873 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6874 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6875 | int err; |
| 6876 | |
| 6877 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6878 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6879 | return -EINVAL; |
| 6880 | |
| 6881 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6882 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6883 | if (!rdev->ops->remain_on_channel || |
| 6884 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6885 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6886 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6887 | /* |
| 6888 | * We should be on that channel for at least a minimum amount of |
| 6889 | * time (10ms) but no longer than the driver supports. |
| 6890 | */ |
| 6891 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6892 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6893 | return -EINVAL; |
| 6894 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6895 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6896 | if (err) |
| 6897 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6898 | |
| 6899 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6900 | if (!msg) |
| 6901 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6902 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6903 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6904 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6905 | |
| 6906 | if (IS_ERR(hdr)) { |
| 6907 | err = PTR_ERR(hdr); |
| 6908 | goto free_msg; |
| 6909 | } |
| 6910 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6911 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6912 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6913 | |
| 6914 | if (err) |
| 6915 | goto free_msg; |
| 6916 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6917 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6918 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6919 | |
| 6920 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6921 | |
| 6922 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6923 | |
| 6924 | nla_put_failure: |
| 6925 | err = -ENOBUFS; |
| 6926 | free_msg: |
| 6927 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6928 | return err; |
| 6929 | } |
| 6930 | |
| 6931 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6932 | struct genl_info *info) |
| 6933 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6934 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6935 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6936 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6937 | |
| 6938 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6939 | return -EINVAL; |
| 6940 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6941 | if (!rdev->ops->cancel_remain_on_channel) |
| 6942 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6943 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6944 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6945 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6946 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6947 | } |
| 6948 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6949 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6950 | u8 *rates, u8 rates_len) |
| 6951 | { |
| 6952 | u8 i; |
| 6953 | u32 mask = 0; |
| 6954 | |
| 6955 | for (i = 0; i < rates_len; i++) { |
| 6956 | int rate = (rates[i] & 0x7f) * 5; |
| 6957 | int ridx; |
| 6958 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6959 | struct ieee80211_rate *srate = |
| 6960 | &sband->bitrates[ridx]; |
| 6961 | if (rate == srate->bitrate) { |
| 6962 | mask |= 1 << ridx; |
| 6963 | break; |
| 6964 | } |
| 6965 | } |
| 6966 | if (ridx == sband->n_bitrates) |
| 6967 | return 0; /* rate not found */ |
| 6968 | } |
| 6969 | |
| 6970 | return mask; |
| 6971 | } |
| 6972 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6973 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6974 | u8 *rates, u8 rates_len, |
| 6975 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6976 | { |
| 6977 | u8 i; |
| 6978 | |
| 6979 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6980 | |
| 6981 | for (i = 0; i < rates_len; i++) { |
| 6982 | int ridx, rbit; |
| 6983 | |
| 6984 | ridx = rates[i] / 8; |
| 6985 | rbit = BIT(rates[i] % 8); |
| 6986 | |
| 6987 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6988 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6989 | return false; |
| 6990 | |
| 6991 | /* check availability */ |
| 6992 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6993 | mcs[ridx] |= rbit; |
| 6994 | else |
| 6995 | return false; |
| 6996 | } |
| 6997 | |
| 6998 | return true; |
| 6999 | } |
| 7000 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7001 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7002 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7003 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7004 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7005 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7006 | }; |
| 7007 | |
| 7008 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7009 | struct genl_info *info) |
| 7010 | { |
| 7011 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7012 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7013 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7014 | int rem, i; |
| 7015 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7016 | struct nlattr *tx_rates; |
| 7017 | struct ieee80211_supported_band *sband; |
| 7018 | |
| 7019 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7020 | return -EINVAL; |
| 7021 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7022 | if (!rdev->ops->set_bitrate_mask) |
| 7023 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7024 | |
| 7025 | memset(&mask, 0, sizeof(mask)); |
| 7026 | /* Default to all rates enabled */ |
| 7027 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7028 | sband = rdev->wiphy.bands[i]; |
| 7029 | mask.control[i].legacy = |
| 7030 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7031 | if (sband) |
| 7032 | memcpy(mask.control[i].mcs, |
| 7033 | sband->ht_cap.mcs.rx_mask, |
| 7034 | sizeof(mask.control[i].mcs)); |
| 7035 | else |
| 7036 | memset(mask.control[i].mcs, 0, |
| 7037 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7038 | } |
| 7039 | |
| 7040 | /* |
| 7041 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7042 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7043 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7044 | 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] | 7045 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7046 | { |
| 7047 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7048 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7049 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7050 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7051 | if (sband == NULL) |
| 7052 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7053 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7054 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7055 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7056 | mask.control[band].legacy = rateset_to_mask( |
| 7057 | sband, |
| 7058 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7059 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7060 | if ((mask.control[band].legacy == 0) && |
| 7061 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7062 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7063 | } |
| 7064 | if (tb[NL80211_TXRATE_MCS]) { |
| 7065 | if (!ht_rateset_to_mask( |
| 7066 | sband, |
| 7067 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7068 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7069 | mask.control[band].mcs)) |
| 7070 | return -EINVAL; |
| 7071 | } |
| 7072 | |
| 7073 | if (mask.control[band].legacy == 0) { |
| 7074 | /* don't allow empty legacy rates if HT |
| 7075 | * is not even supported. */ |
| 7076 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7077 | return -EINVAL; |
| 7078 | |
| 7079 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7080 | if (mask.control[band].mcs[i]) |
| 7081 | break; |
| 7082 | |
| 7083 | /* legacy and mcs rates may not be both empty */ |
| 7084 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7085 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7086 | } |
| 7087 | } |
| 7088 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7089 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7090 | } |
| 7091 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7092 | 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] | 7093 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7094 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7095 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7096 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7097 | |
| 7098 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7099 | return -EINVAL; |
| 7100 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7101 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7102 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7103 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7104 | switch (wdev->iftype) { |
| 7105 | case NL80211_IFTYPE_STATION: |
| 7106 | case NL80211_IFTYPE_ADHOC: |
| 7107 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7108 | case NL80211_IFTYPE_AP: |
| 7109 | case NL80211_IFTYPE_AP_VLAN: |
| 7110 | case NL80211_IFTYPE_MESH_POINT: |
| 7111 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7112 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7113 | break; |
| 7114 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7115 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7116 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7117 | |
| 7118 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7119 | if (!rdev->ops->mgmt_tx) |
| 7120 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7121 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7122 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7123 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7124 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7125 | } |
| 7126 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7127 | 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] | 7128 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7130 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7131 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7132 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7133 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7134 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7135 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7136 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7137 | bool offchan, no_cck, dont_wait_for_ack; |
| 7138 | |
| 7139 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7140 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7141 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7142 | return -EINVAL; |
| 7143 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7144 | if (!rdev->ops->mgmt_tx) |
| 7145 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7146 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7147 | switch (wdev->iftype) { |
| 7148 | case NL80211_IFTYPE_STATION: |
| 7149 | case NL80211_IFTYPE_ADHOC: |
| 7150 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7151 | case NL80211_IFTYPE_AP: |
| 7152 | case NL80211_IFTYPE_AP_VLAN: |
| 7153 | case NL80211_IFTYPE_MESH_POINT: |
| 7154 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7155 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7156 | break; |
| 7157 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7158 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7159 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7160 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7161 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7162 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7163 | return -EINVAL; |
| 7164 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7165 | |
| 7166 | /* |
| 7167 | * We should wait on the channel for at least a minimum amount |
| 7168 | * of time (10ms) but no longer than the driver supports. |
| 7169 | */ |
| 7170 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7171 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7172 | return -EINVAL; |
| 7173 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7174 | } |
| 7175 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7176 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7177 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7178 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7179 | return -EINVAL; |
| 7180 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7181 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7182 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7183 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7184 | if (err) |
| 7185 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7186 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7187 | if (!dont_wait_for_ack) { |
| 7188 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7189 | if (!msg) |
| 7190 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7191 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7192 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7193 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7194 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7195 | if (IS_ERR(hdr)) { |
| 7196 | err = PTR_ERR(hdr); |
| 7197 | goto free_msg; |
| 7198 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7199 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7200 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7201 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7202 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7203 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7204 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7205 | if (err) |
| 7206 | goto free_msg; |
| 7207 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7208 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7209 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7210 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7211 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7212 | genlmsg_end(msg, hdr); |
| 7213 | return genlmsg_reply(msg, info); |
| 7214 | } |
| 7215 | |
| 7216 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7217 | |
| 7218 | nla_put_failure: |
| 7219 | err = -ENOBUFS; |
| 7220 | free_msg: |
| 7221 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7222 | return err; |
| 7223 | } |
| 7224 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7225 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7226 | { |
| 7227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7228 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7229 | u64 cookie; |
| 7230 | |
| 7231 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7232 | return -EINVAL; |
| 7233 | |
| 7234 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7235 | return -EOPNOTSUPP; |
| 7236 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7237 | switch (wdev->iftype) { |
| 7238 | case NL80211_IFTYPE_STATION: |
| 7239 | case NL80211_IFTYPE_ADHOC: |
| 7240 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7241 | case NL80211_IFTYPE_AP: |
| 7242 | case NL80211_IFTYPE_AP_VLAN: |
| 7243 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7244 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7245 | break; |
| 7246 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7247 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7248 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7249 | |
| 7250 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7251 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7252 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7253 | } |
| 7254 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7255 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7256 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7258 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7259 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7260 | u8 ps_state; |
| 7261 | bool state; |
| 7262 | int err; |
| 7263 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7264 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7265 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7266 | |
| 7267 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7268 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7269 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7270 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7271 | |
| 7272 | wdev = dev->ieee80211_ptr; |
| 7273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7274 | if (!rdev->ops->set_power_mgmt) |
| 7275 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7276 | |
| 7277 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7278 | |
| 7279 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7280 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7281 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7282 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7283 | if (!err) |
| 7284 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7285 | return err; |
| 7286 | } |
| 7287 | |
| 7288 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7289 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7291 | enum nl80211_ps_state ps_state; |
| 7292 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7293 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7294 | struct sk_buff *msg; |
| 7295 | void *hdr; |
| 7296 | int err; |
| 7297 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7298 | wdev = dev->ieee80211_ptr; |
| 7299 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7300 | if (!rdev->ops->set_power_mgmt) |
| 7301 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7302 | |
| 7303 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7304 | if (!msg) |
| 7305 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7306 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7307 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7308 | NL80211_CMD_GET_POWER_SAVE); |
| 7309 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7310 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7311 | goto free_msg; |
| 7312 | } |
| 7313 | |
| 7314 | if (wdev->ps) |
| 7315 | ps_state = NL80211_PS_ENABLED; |
| 7316 | else |
| 7317 | ps_state = NL80211_PS_DISABLED; |
| 7318 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7319 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7320 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7321 | |
| 7322 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7323 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7324 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7325 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7326 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7327 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7328 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7329 | return err; |
| 7330 | } |
| 7331 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7332 | static struct nla_policy |
| 7333 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7334 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7335 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7336 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7337 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7338 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7339 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7340 | }; |
| 7341 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7342 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7343 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7344 | { |
| 7345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7346 | struct wireless_dev *wdev; |
| 7347 | struct net_device *dev = info->user_ptr[1]; |
| 7348 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7349 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7350 | return -EINVAL; |
| 7351 | |
| 7352 | wdev = dev->ieee80211_ptr; |
| 7353 | |
| 7354 | if (!rdev->ops->set_cqm_txe_config) |
| 7355 | return -EOPNOTSUPP; |
| 7356 | |
| 7357 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7358 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7359 | return -EOPNOTSUPP; |
| 7360 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7361 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7362 | } |
| 7363 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7364 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7365 | s32 threshold, u32 hysteresis) |
| 7366 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7368 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7369 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7370 | |
| 7371 | if (threshold > 0) |
| 7372 | return -EINVAL; |
| 7373 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7374 | wdev = dev->ieee80211_ptr; |
| 7375 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7376 | if (!rdev->ops->set_cqm_rssi_config) |
| 7377 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7378 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7379 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7380 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7381 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7382 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7383 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7384 | } |
| 7385 | |
| 7386 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7387 | { |
| 7388 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7389 | struct nlattr *cqm; |
| 7390 | int err; |
| 7391 | |
| 7392 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7393 | if (!cqm) { |
| 7394 | err = -EINVAL; |
| 7395 | goto out; |
| 7396 | } |
| 7397 | |
| 7398 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7399 | nl80211_attr_cqm_policy); |
| 7400 | if (err) |
| 7401 | goto out; |
| 7402 | |
| 7403 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7404 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7405 | s32 threshold; |
| 7406 | u32 hysteresis; |
| 7407 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7408 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7409 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7410 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7411 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7412 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7413 | u32 rate, pkts, intvl; |
| 7414 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7415 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7416 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7417 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7418 | } else |
| 7419 | err = -EINVAL; |
| 7420 | |
| 7421 | out: |
| 7422 | return err; |
| 7423 | } |
| 7424 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7425 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7426 | { |
| 7427 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7428 | struct net_device *dev = info->user_ptr[1]; |
| 7429 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7430 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7431 | int err; |
| 7432 | |
| 7433 | /* start with default */ |
| 7434 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7435 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7436 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7437 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7438 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7439 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7440 | if (err) |
| 7441 | return err; |
| 7442 | } |
| 7443 | |
| 7444 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7445 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7446 | return -EINVAL; |
| 7447 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7448 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7449 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7450 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7451 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7452 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7453 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7454 | return -EINVAL; |
| 7455 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7456 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7457 | setup.beacon_interval = |
| 7458 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7459 | if (setup.beacon_interval < 10 || |
| 7460 | setup.beacon_interval > 10000) |
| 7461 | return -EINVAL; |
| 7462 | } |
| 7463 | |
| 7464 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7465 | setup.dtim_period = |
| 7466 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7467 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7468 | return -EINVAL; |
| 7469 | } |
| 7470 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7471 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7472 | /* parse additional setup parameters if given */ |
| 7473 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7474 | if (err) |
| 7475 | return err; |
| 7476 | } |
| 7477 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7478 | if (setup.user_mpm) |
| 7479 | cfg.auto_open_plinks = false; |
| 7480 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7481 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7482 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7483 | if (err) |
| 7484 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7485 | } else { |
| 7486 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7487 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7488 | } |
| 7489 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7490 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7491 | } |
| 7492 | |
| 7493 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7494 | { |
| 7495 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7496 | struct net_device *dev = info->user_ptr[1]; |
| 7497 | |
| 7498 | return cfg80211_leave_mesh(rdev, dev); |
| 7499 | } |
| 7500 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7501 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7502 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7503 | struct cfg80211_registered_device *rdev) |
| 7504 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7505 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7506 | struct nlattr *nl_pats, *nl_pat; |
| 7507 | int i, pat_len; |
| 7508 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7509 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7510 | return 0; |
| 7511 | |
| 7512 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7513 | if (!nl_pats) |
| 7514 | return -ENOBUFS; |
| 7515 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7516 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7517 | nl_pat = nla_nest_start(msg, i + 1); |
| 7518 | if (!nl_pat) |
| 7519 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7520 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7521 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7522 | DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7523 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7524 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7525 | pat_len, wowlan->patterns[i].pattern) || |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7526 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7527 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7528 | return -ENOBUFS; |
| 7529 | nla_nest_end(msg, nl_pat); |
| 7530 | } |
| 7531 | nla_nest_end(msg, nl_pats); |
| 7532 | |
| 7533 | return 0; |
| 7534 | } |
| 7535 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7536 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7537 | struct cfg80211_wowlan_tcp *tcp) |
| 7538 | { |
| 7539 | struct nlattr *nl_tcp; |
| 7540 | |
| 7541 | if (!tcp) |
| 7542 | return 0; |
| 7543 | |
| 7544 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7545 | if (!nl_tcp) |
| 7546 | return -ENOBUFS; |
| 7547 | |
| 7548 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7549 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7550 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7551 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7552 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7553 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7554 | tcp->payload_len, tcp->payload) || |
| 7555 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7556 | tcp->data_interval) || |
| 7557 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7558 | tcp->wake_len, tcp->wake_data) || |
| 7559 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7560 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7561 | return -ENOBUFS; |
| 7562 | |
| 7563 | if (tcp->payload_seq.len && |
| 7564 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7565 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7566 | return -ENOBUFS; |
| 7567 | |
| 7568 | if (tcp->payload_tok.len && |
| 7569 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7570 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7571 | &tcp->payload_tok)) |
| 7572 | return -ENOBUFS; |
| 7573 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7574 | nla_nest_end(msg, nl_tcp); |
| 7575 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7576 | return 0; |
| 7577 | } |
| 7578 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7579 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7580 | { |
| 7581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7582 | struct sk_buff *msg; |
| 7583 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7584 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7585 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7586 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7587 | return -EOPNOTSUPP; |
| 7588 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7589 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7590 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7591 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7592 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7593 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7594 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7595 | } |
| 7596 | |
| 7597 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7598 | if (!msg) |
| 7599 | return -ENOMEM; |
| 7600 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7601 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7602 | NL80211_CMD_GET_WOWLAN); |
| 7603 | if (!hdr) |
| 7604 | goto nla_put_failure; |
| 7605 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7606 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7607 | struct nlattr *nl_wowlan; |
| 7608 | |
| 7609 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7610 | if (!nl_wowlan) |
| 7611 | goto nla_put_failure; |
| 7612 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7613 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7614 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7615 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7616 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7617 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7618 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7619 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7620 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7621 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7622 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7623 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7624 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7625 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7626 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7627 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7628 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7629 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7630 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7631 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7632 | if (nl80211_send_wowlan_tcp(msg, |
| 7633 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7634 | goto nla_put_failure; |
| 7635 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7636 | nla_nest_end(msg, nl_wowlan); |
| 7637 | } |
| 7638 | |
| 7639 | genlmsg_end(msg, hdr); |
| 7640 | return genlmsg_reply(msg, info); |
| 7641 | |
| 7642 | nla_put_failure: |
| 7643 | nlmsg_free(msg); |
| 7644 | return -ENOBUFS; |
| 7645 | } |
| 7646 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7647 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7648 | struct nlattr *attr, |
| 7649 | struct cfg80211_wowlan *trig) |
| 7650 | { |
| 7651 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7652 | struct cfg80211_wowlan_tcp *cfg; |
| 7653 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7654 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7655 | u32 size; |
| 7656 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7657 | int err, port; |
| 7658 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7659 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7660 | return -EINVAL; |
| 7661 | |
| 7662 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7663 | nla_data(attr), nla_len(attr), |
| 7664 | nl80211_wowlan_tcp_policy); |
| 7665 | if (err) |
| 7666 | return err; |
| 7667 | |
| 7668 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7669 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7670 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7671 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7672 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7673 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7674 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7675 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7676 | return -EINVAL; |
| 7677 | |
| 7678 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7679 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7680 | return -EINVAL; |
| 7681 | |
| 7682 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7683 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7684 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7685 | return -EINVAL; |
| 7686 | |
| 7687 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7688 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7689 | return -EINVAL; |
| 7690 | |
| 7691 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7692 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7693 | return -EINVAL; |
| 7694 | |
| 7695 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7696 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7697 | |
| 7698 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7699 | tokens_size = tokln - sizeof(*tok); |
| 7700 | |
| 7701 | if (!tok->len || tokens_size % tok->len) |
| 7702 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7703 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7704 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7705 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7706 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7707 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7708 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7709 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7710 | return -EINVAL; |
| 7711 | if (tok->offset + tok->len > data_size) |
| 7712 | return -EINVAL; |
| 7713 | } |
| 7714 | |
| 7715 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7716 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7717 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7718 | return -EINVAL; |
| 7719 | if (seq->len == 0 || seq->len > 4) |
| 7720 | return -EINVAL; |
| 7721 | if (seq->len + seq->offset > data_size) |
| 7722 | return -EINVAL; |
| 7723 | } |
| 7724 | |
| 7725 | size = sizeof(*cfg); |
| 7726 | size += data_size; |
| 7727 | size += wake_size + wake_mask_size; |
| 7728 | size += tokens_size; |
| 7729 | |
| 7730 | cfg = kzalloc(size, GFP_KERNEL); |
| 7731 | if (!cfg) |
| 7732 | return -ENOMEM; |
| 7733 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7734 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7735 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7736 | ETH_ALEN); |
| 7737 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7738 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7739 | else |
| 7740 | port = 0; |
| 7741 | #ifdef CONFIG_INET |
| 7742 | /* allocate a socket and port for it and use it */ |
| 7743 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7744 | IPPROTO_TCP, &cfg->sock, 1); |
| 7745 | if (err) { |
| 7746 | kfree(cfg); |
| 7747 | return err; |
| 7748 | } |
| 7749 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7750 | sock_release(cfg->sock); |
| 7751 | kfree(cfg); |
| 7752 | return -EADDRINUSE; |
| 7753 | } |
| 7754 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7755 | #else |
| 7756 | if (!port) { |
| 7757 | kfree(cfg); |
| 7758 | return -EINVAL; |
| 7759 | } |
| 7760 | cfg->src_port = port; |
| 7761 | #endif |
| 7762 | |
| 7763 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7764 | cfg->payload_len = data_size; |
| 7765 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7766 | memcpy((void *)cfg->payload, |
| 7767 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7768 | data_size); |
| 7769 | if (seq) |
| 7770 | cfg->payload_seq = *seq; |
| 7771 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7772 | cfg->wake_len = wake_size; |
| 7773 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7774 | memcpy((void *)cfg->wake_data, |
| 7775 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7776 | wake_size); |
| 7777 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7778 | data_size + wake_size; |
| 7779 | memcpy((void *)cfg->wake_mask, |
| 7780 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7781 | wake_mask_size); |
| 7782 | if (tok) { |
| 7783 | cfg->tokens_size = tokens_size; |
| 7784 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7785 | } |
| 7786 | |
| 7787 | trig->tcp = cfg; |
| 7788 | |
| 7789 | return 0; |
| 7790 | } |
| 7791 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7792 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7793 | { |
| 7794 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7795 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7796 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7797 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7798 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7799 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7800 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7801 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7802 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7803 | return -EOPNOTSUPP; |
| 7804 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7805 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7806 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7807 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7808 | goto set_wakeup; |
| 7809 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7810 | |
| 7811 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7812 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7813 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7814 | nl80211_wowlan_policy); |
| 7815 | if (err) |
| 7816 | return err; |
| 7817 | |
| 7818 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7819 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7820 | return -EINVAL; |
| 7821 | new_triggers.any = true; |
| 7822 | } |
| 7823 | |
| 7824 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7825 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7826 | return -EINVAL; |
| 7827 | new_triggers.disconnect = true; |
| 7828 | } |
| 7829 | |
| 7830 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7831 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7832 | return -EINVAL; |
| 7833 | new_triggers.magic_pkt = true; |
| 7834 | } |
| 7835 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7836 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7837 | return -EINVAL; |
| 7838 | |
| 7839 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7840 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7841 | return -EINVAL; |
| 7842 | new_triggers.gtk_rekey_failure = true; |
| 7843 | } |
| 7844 | |
| 7845 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7846 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7847 | return -EINVAL; |
| 7848 | new_triggers.eap_identity_req = true; |
| 7849 | } |
| 7850 | |
| 7851 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7852 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7853 | return -EINVAL; |
| 7854 | new_triggers.four_way_handshake = true; |
| 7855 | } |
| 7856 | |
| 7857 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7858 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7859 | return -EINVAL; |
| 7860 | new_triggers.rfkill_release = true; |
| 7861 | } |
| 7862 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7863 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7864 | struct nlattr *pat; |
| 7865 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7866 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7867 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7868 | |
| 7869 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7870 | rem) |
| 7871 | n_patterns++; |
| 7872 | if (n_patterns > wowlan->n_patterns) |
| 7873 | return -EINVAL; |
| 7874 | |
| 7875 | new_triggers.patterns = kcalloc(n_patterns, |
| 7876 | sizeof(new_triggers.patterns[0]), |
| 7877 | GFP_KERNEL); |
| 7878 | if (!new_triggers.patterns) |
| 7879 | return -ENOMEM; |
| 7880 | |
| 7881 | new_triggers.n_patterns = n_patterns; |
| 7882 | i = 0; |
| 7883 | |
| 7884 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7885 | rem) { |
| 7886 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7887 | nla_data(pat), nla_len(pat), NULL); |
| 7888 | err = -EINVAL; |
| 7889 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7890 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7891 | goto error; |
| 7892 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7893 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7894 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7895 | mask_len) |
| 7896 | goto error; |
| 7897 | if (pat_len > wowlan->pattern_max_len || |
| 7898 | pat_len < wowlan->pattern_min_len) |
| 7899 | goto error; |
| 7900 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7901 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7902 | pkt_offset = 0; |
| 7903 | else |
| 7904 | pkt_offset = nla_get_u32( |
| 7905 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7906 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7907 | goto error; |
| 7908 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7909 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7910 | new_triggers.patterns[i].mask = |
| 7911 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7912 | if (!new_triggers.patterns[i].mask) { |
| 7913 | err = -ENOMEM; |
| 7914 | goto error; |
| 7915 | } |
| 7916 | new_triggers.patterns[i].pattern = |
| 7917 | new_triggers.patterns[i].mask + mask_len; |
| 7918 | memcpy(new_triggers.patterns[i].mask, |
| 7919 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7920 | mask_len); |
| 7921 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7922 | memcpy(new_triggers.patterns[i].pattern, |
| 7923 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7924 | pat_len); |
| 7925 | i++; |
| 7926 | } |
| 7927 | } |
| 7928 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7929 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7930 | err = nl80211_parse_wowlan_tcp( |
| 7931 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7932 | &new_triggers); |
| 7933 | if (err) |
| 7934 | goto error; |
| 7935 | } |
| 7936 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7937 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7938 | if (!ntrig) { |
| 7939 | err = -ENOMEM; |
| 7940 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7941 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7942 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7943 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7944 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7945 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7946 | if (rdev->ops->set_wakeup && |
| 7947 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 7948 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7949 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7950 | return 0; |
| 7951 | error: |
| 7952 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7953 | kfree(new_triggers.patterns[i].mask); |
| 7954 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7955 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7956 | sock_release(new_triggers.tcp->sock); |
| 7957 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7958 | return err; |
| 7959 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7960 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7961 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7962 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7963 | { |
| 7964 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7965 | struct net_device *dev = info->user_ptr[1]; |
| 7966 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7967 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7968 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7969 | int err; |
| 7970 | |
| 7971 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7972 | return -EINVAL; |
| 7973 | |
| 7974 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7975 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7976 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7977 | nl80211_rekey_policy); |
| 7978 | if (err) |
| 7979 | return err; |
| 7980 | |
| 7981 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7982 | return -ERANGE; |
| 7983 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7984 | return -ERANGE; |
| 7985 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7986 | return -ERANGE; |
| 7987 | |
| 7988 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7989 | NL80211_KEK_LEN); |
| 7990 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7991 | NL80211_KCK_LEN); |
| 7992 | memcpy(rekey_data.replay_ctr, |
| 7993 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7994 | NL80211_REPLAY_CTR_LEN); |
| 7995 | |
| 7996 | wdev_lock(wdev); |
| 7997 | if (!wdev->current_bss) { |
| 7998 | err = -ENOTCONN; |
| 7999 | goto out; |
| 8000 | } |
| 8001 | |
| 8002 | if (!rdev->ops->set_rekey_data) { |
| 8003 | err = -EOPNOTSUPP; |
| 8004 | goto out; |
| 8005 | } |
| 8006 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8007 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8008 | out: |
| 8009 | wdev_unlock(wdev); |
| 8010 | return err; |
| 8011 | } |
| 8012 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8013 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8014 | struct genl_info *info) |
| 8015 | { |
| 8016 | struct net_device *dev = info->user_ptr[1]; |
| 8017 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8018 | |
| 8019 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8020 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8021 | return -EINVAL; |
| 8022 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8023 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8024 | return -EBUSY; |
| 8025 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8026 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8027 | return 0; |
| 8028 | } |
| 8029 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8030 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8031 | struct genl_info *info) |
| 8032 | { |
| 8033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8034 | struct net_device *dev = info->user_ptr[1]; |
| 8035 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8036 | struct sk_buff *msg; |
| 8037 | void *hdr; |
| 8038 | const u8 *addr; |
| 8039 | u64 cookie; |
| 8040 | int err; |
| 8041 | |
| 8042 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8043 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8044 | return -EOPNOTSUPP; |
| 8045 | |
| 8046 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8047 | return -EINVAL; |
| 8048 | |
| 8049 | if (!rdev->ops->probe_client) |
| 8050 | return -EOPNOTSUPP; |
| 8051 | |
| 8052 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8053 | if (!msg) |
| 8054 | return -ENOMEM; |
| 8055 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8056 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8057 | NL80211_CMD_PROBE_CLIENT); |
| 8058 | |
| 8059 | if (IS_ERR(hdr)) { |
| 8060 | err = PTR_ERR(hdr); |
| 8061 | goto free_msg; |
| 8062 | } |
| 8063 | |
| 8064 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8065 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8066 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8067 | if (err) |
| 8068 | goto free_msg; |
| 8069 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8070 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8071 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8072 | |
| 8073 | genlmsg_end(msg, hdr); |
| 8074 | |
| 8075 | return genlmsg_reply(msg, info); |
| 8076 | |
| 8077 | nla_put_failure: |
| 8078 | err = -ENOBUFS; |
| 8079 | free_msg: |
| 8080 | nlmsg_free(msg); |
| 8081 | return err; |
| 8082 | } |
| 8083 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8084 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8085 | { |
| 8086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8087 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8088 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8089 | |
| 8090 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8091 | return -EOPNOTSUPP; |
| 8092 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8093 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8094 | if (!nreg) |
| 8095 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8096 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8097 | /* First, check if already registered. */ |
| 8098 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8099 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8100 | if (reg->nlportid == info->snd_portid) { |
| 8101 | rv = -EALREADY; |
| 8102 | goto out_err; |
| 8103 | } |
| 8104 | } |
| 8105 | /* Add it to the list */ |
| 8106 | nreg->nlportid = info->snd_portid; |
| 8107 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8108 | |
| 8109 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8110 | |
| 8111 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8112 | out_err: |
| 8113 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8114 | kfree(nreg); |
| 8115 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8116 | } |
| 8117 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8118 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8119 | { |
| 8120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8121 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8122 | int err; |
| 8123 | |
| 8124 | if (!rdev->ops->start_p2p_device) |
| 8125 | return -EOPNOTSUPP; |
| 8126 | |
| 8127 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8128 | return -EOPNOTSUPP; |
| 8129 | |
| 8130 | if (wdev->p2p_started) |
| 8131 | return 0; |
| 8132 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8133 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8134 | if (err) |
| 8135 | return err; |
| 8136 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8137 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8138 | if (err) |
| 8139 | return err; |
| 8140 | |
| 8141 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8142 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8143 | |
| 8144 | return 0; |
| 8145 | } |
| 8146 | |
| 8147 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8148 | { |
| 8149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8150 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8151 | |
| 8152 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8153 | return -EOPNOTSUPP; |
| 8154 | |
| 8155 | if (!rdev->ops->stop_p2p_device) |
| 8156 | return -EOPNOTSUPP; |
| 8157 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8158 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8159 | |
| 8160 | return 0; |
| 8161 | } |
| 8162 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8163 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8164 | struct genl_info *info) |
| 8165 | { |
| 8166 | void *hdr; |
| 8167 | struct sk_buff *msg; |
| 8168 | |
| 8169 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8170 | if (!msg) |
| 8171 | return -ENOMEM; |
| 8172 | |
| 8173 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8174 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8175 | if (!hdr) |
| 8176 | goto nla_put_failure; |
| 8177 | |
| 8178 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8179 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8180 | goto nla_put_failure; |
| 8181 | |
| 8182 | genlmsg_end(msg, hdr); |
| 8183 | return genlmsg_reply(msg, info); |
| 8184 | |
| 8185 | nla_put_failure: |
| 8186 | kfree_skb(msg); |
| 8187 | return -ENOBUFS; |
| 8188 | } |
| 8189 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8190 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8191 | { |
| 8192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8193 | struct cfg80211_update_ft_ies_params ft_params; |
| 8194 | struct net_device *dev = info->user_ptr[1]; |
| 8195 | |
| 8196 | if (!rdev->ops->update_ft_ies) |
| 8197 | return -EOPNOTSUPP; |
| 8198 | |
| 8199 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8200 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8201 | return -EINVAL; |
| 8202 | |
| 8203 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8204 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8205 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8206 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8207 | |
| 8208 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8209 | } |
| 8210 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8211 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8212 | struct genl_info *info) |
| 8213 | { |
| 8214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8215 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8216 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8217 | u16 duration; |
| 8218 | int ret; |
| 8219 | |
| 8220 | if (!rdev->ops->crit_proto_start) |
| 8221 | return -EOPNOTSUPP; |
| 8222 | |
| 8223 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8224 | return -EINVAL; |
| 8225 | |
| 8226 | if (rdev->crit_proto_nlportid) |
| 8227 | return -EBUSY; |
| 8228 | |
| 8229 | /* determine protocol if provided */ |
| 8230 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8231 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8232 | |
| 8233 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8234 | return -EINVAL; |
| 8235 | |
| 8236 | /* timeout must be provided */ |
| 8237 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8238 | return -EINVAL; |
| 8239 | |
| 8240 | duration = |
| 8241 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8242 | |
| 8243 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8244 | return -ERANGE; |
| 8245 | |
| 8246 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8247 | if (!ret) |
| 8248 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8249 | |
| 8250 | return ret; |
| 8251 | } |
| 8252 | |
| 8253 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8254 | struct genl_info *info) |
| 8255 | { |
| 8256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8257 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8258 | |
| 8259 | if (!rdev->ops->crit_proto_stop) |
| 8260 | return -EOPNOTSUPP; |
| 8261 | |
| 8262 | if (rdev->crit_proto_nlportid) { |
| 8263 | rdev->crit_proto_nlportid = 0; |
| 8264 | rdev_crit_proto_stop(rdev, wdev); |
| 8265 | } |
| 8266 | return 0; |
| 8267 | } |
| 8268 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8269 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8270 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8271 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8272 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8273 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8274 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8275 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8276 | /* 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] | 8277 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8278 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8279 | |
| 8280 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8281 | struct genl_info *info) |
| 8282 | { |
| 8283 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8284 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8285 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8286 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8287 | |
| 8288 | if (rtnl) |
| 8289 | rtnl_lock(); |
| 8290 | |
| 8291 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8292 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8293 | if (IS_ERR(rdev)) { |
| 8294 | if (rtnl) |
| 8295 | rtnl_unlock(); |
| 8296 | return PTR_ERR(rdev); |
| 8297 | } |
| 8298 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8299 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8300 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8301 | ASSERT_RTNL(); |
| 8302 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8303 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8304 | info->attrs); |
| 8305 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8306 | if (rtnl) |
| 8307 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8308 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8309 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8310 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8311 | dev = wdev->netdev; |
| 8312 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8313 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8314 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8315 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8316 | if (rtnl) |
| 8317 | rtnl_unlock(); |
| 8318 | return -EINVAL; |
| 8319 | } |
| 8320 | |
| 8321 | info->user_ptr[1] = dev; |
| 8322 | } else { |
| 8323 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8324 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8325 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8326 | if (dev) { |
| 8327 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8328 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8329 | if (rtnl) |
| 8330 | rtnl_unlock(); |
| 8331 | return -ENETDOWN; |
| 8332 | } |
| 8333 | |
| 8334 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8335 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8336 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8337 | if (rtnl) |
| 8338 | rtnl_unlock(); |
| 8339 | return -ENETDOWN; |
| 8340 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8341 | } |
| 8342 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8343 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8344 | } |
| 8345 | |
| 8346 | return 0; |
| 8347 | } |
| 8348 | |
| 8349 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8350 | struct genl_info *info) |
| 8351 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8352 | if (info->user_ptr[1]) { |
| 8353 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8354 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8355 | |
| 8356 | if (wdev->netdev) |
| 8357 | dev_put(wdev->netdev); |
| 8358 | } else { |
| 8359 | dev_put(info->user_ptr[1]); |
| 8360 | } |
| 8361 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8362 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8363 | rtnl_unlock(); |
| 8364 | } |
| 8365 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8366 | static struct genl_ops nl80211_ops[] = { |
| 8367 | { |
| 8368 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8369 | .doit = nl80211_get_wiphy, |
| 8370 | .dumpit = nl80211_dump_wiphy, |
| 8371 | .policy = nl80211_policy, |
| 8372 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8373 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8374 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8375 | }, |
| 8376 | { |
| 8377 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8378 | .doit = nl80211_set_wiphy, |
| 8379 | .policy = nl80211_policy, |
| 8380 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8381 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8382 | }, |
| 8383 | { |
| 8384 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8385 | .doit = nl80211_get_interface, |
| 8386 | .dumpit = nl80211_dump_interface, |
| 8387 | .policy = nl80211_policy, |
| 8388 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8389 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8390 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8391 | }, |
| 8392 | { |
| 8393 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8394 | .doit = nl80211_set_interface, |
| 8395 | .policy = nl80211_policy, |
| 8396 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8397 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8398 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8399 | }, |
| 8400 | { |
| 8401 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8402 | .doit = nl80211_new_interface, |
| 8403 | .policy = nl80211_policy, |
| 8404 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8405 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8406 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8407 | }, |
| 8408 | { |
| 8409 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8410 | .doit = nl80211_del_interface, |
| 8411 | .policy = nl80211_policy, |
| 8412 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8413 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8414 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8415 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8416 | { |
| 8417 | .cmd = NL80211_CMD_GET_KEY, |
| 8418 | .doit = nl80211_get_key, |
| 8419 | .policy = nl80211_policy, |
| 8420 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8421 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8422 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8423 | }, |
| 8424 | { |
| 8425 | .cmd = NL80211_CMD_SET_KEY, |
| 8426 | .doit = nl80211_set_key, |
| 8427 | .policy = nl80211_policy, |
| 8428 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8429 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8430 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8431 | }, |
| 8432 | { |
| 8433 | .cmd = NL80211_CMD_NEW_KEY, |
| 8434 | .doit = nl80211_new_key, |
| 8435 | .policy = nl80211_policy, |
| 8436 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8437 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8438 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8439 | }, |
| 8440 | { |
| 8441 | .cmd = NL80211_CMD_DEL_KEY, |
| 8442 | .doit = nl80211_del_key, |
| 8443 | .policy = nl80211_policy, |
| 8444 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8445 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8446 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8447 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8448 | { |
| 8449 | .cmd = NL80211_CMD_SET_BEACON, |
| 8450 | .policy = nl80211_policy, |
| 8451 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8452 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8453 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8454 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8455 | }, |
| 8456 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8457 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8458 | .policy = nl80211_policy, |
| 8459 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8460 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8461 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8462 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8463 | }, |
| 8464 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8465 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8466 | .policy = nl80211_policy, |
| 8467 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8468 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8470 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8471 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8472 | { |
| 8473 | .cmd = NL80211_CMD_GET_STATION, |
| 8474 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8475 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8476 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8477 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8478 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8479 | }, |
| 8480 | { |
| 8481 | .cmd = NL80211_CMD_SET_STATION, |
| 8482 | .doit = nl80211_set_station, |
| 8483 | .policy = nl80211_policy, |
| 8484 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8485 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8486 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8487 | }, |
| 8488 | { |
| 8489 | .cmd = NL80211_CMD_NEW_STATION, |
| 8490 | .doit = nl80211_new_station, |
| 8491 | .policy = nl80211_policy, |
| 8492 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8493 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8494 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8495 | }, |
| 8496 | { |
| 8497 | .cmd = NL80211_CMD_DEL_STATION, |
| 8498 | .doit = nl80211_del_station, |
| 8499 | .policy = nl80211_policy, |
| 8500 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8501 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8502 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8503 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8504 | { |
| 8505 | .cmd = NL80211_CMD_GET_MPATH, |
| 8506 | .doit = nl80211_get_mpath, |
| 8507 | .dumpit = nl80211_dump_mpath, |
| 8508 | .policy = nl80211_policy, |
| 8509 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8510 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8511 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8512 | }, |
| 8513 | { |
| 8514 | .cmd = NL80211_CMD_SET_MPATH, |
| 8515 | .doit = nl80211_set_mpath, |
| 8516 | .policy = nl80211_policy, |
| 8517 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8518 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8519 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8520 | }, |
| 8521 | { |
| 8522 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8523 | .doit = nl80211_new_mpath, |
| 8524 | .policy = nl80211_policy, |
| 8525 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8526 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8527 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8528 | }, |
| 8529 | { |
| 8530 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8531 | .doit = nl80211_del_mpath, |
| 8532 | .policy = nl80211_policy, |
| 8533 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8534 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8535 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8536 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8537 | { |
| 8538 | .cmd = NL80211_CMD_SET_BSS, |
| 8539 | .doit = nl80211_set_bss, |
| 8540 | .policy = nl80211_policy, |
| 8541 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8542 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8543 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8544 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8545 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8546 | .cmd = NL80211_CMD_GET_REG, |
| 8547 | .doit = nl80211_get_reg, |
| 8548 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8549 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8550 | /* can be retrieved by unprivileged users */ |
| 8551 | }, |
| 8552 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8553 | .cmd = NL80211_CMD_SET_REG, |
| 8554 | .doit = nl80211_set_reg, |
| 8555 | .policy = nl80211_policy, |
| 8556 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8557 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8558 | }, |
| 8559 | { |
| 8560 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8561 | .doit = nl80211_req_set_reg, |
| 8562 | .policy = nl80211_policy, |
| 8563 | .flags = GENL_ADMIN_PERM, |
| 8564 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8565 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8566 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8567 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8568 | .policy = nl80211_policy, |
| 8569 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8570 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8571 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8572 | }, |
| 8573 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8574 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8575 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8576 | .policy = nl80211_policy, |
| 8577 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8578 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8579 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8580 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8581 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8582 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8583 | .doit = nl80211_trigger_scan, |
| 8584 | .policy = nl80211_policy, |
| 8585 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8586 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8587 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8588 | }, |
| 8589 | { |
| 8590 | .cmd = NL80211_CMD_GET_SCAN, |
| 8591 | .policy = nl80211_policy, |
| 8592 | .dumpit = nl80211_dump_scan, |
| 8593 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8594 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8595 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8596 | .doit = nl80211_start_sched_scan, |
| 8597 | .policy = nl80211_policy, |
| 8598 | .flags = GENL_ADMIN_PERM, |
| 8599 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8600 | NL80211_FLAG_NEED_RTNL, |
| 8601 | }, |
| 8602 | { |
| 8603 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8604 | .doit = nl80211_stop_sched_scan, |
| 8605 | .policy = nl80211_policy, |
| 8606 | .flags = GENL_ADMIN_PERM, |
| 8607 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8608 | NL80211_FLAG_NEED_RTNL, |
| 8609 | }, |
| 8610 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8611 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8612 | .doit = nl80211_authenticate, |
| 8613 | .policy = nl80211_policy, |
| 8614 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8615 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8616 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8617 | }, |
| 8618 | { |
| 8619 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8620 | .doit = nl80211_associate, |
| 8621 | .policy = nl80211_policy, |
| 8622 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8623 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8624 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8625 | }, |
| 8626 | { |
| 8627 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8628 | .doit = nl80211_deauthenticate, |
| 8629 | .policy = nl80211_policy, |
| 8630 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8631 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8632 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8633 | }, |
| 8634 | { |
| 8635 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8636 | .doit = nl80211_disassociate, |
| 8637 | .policy = nl80211_policy, |
| 8638 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8639 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8640 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8641 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8642 | { |
| 8643 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8644 | .doit = nl80211_join_ibss, |
| 8645 | .policy = nl80211_policy, |
| 8646 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8647 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8648 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8649 | }, |
| 8650 | { |
| 8651 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8652 | .doit = nl80211_leave_ibss, |
| 8653 | .policy = nl80211_policy, |
| 8654 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8655 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8656 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8657 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8658 | #ifdef CONFIG_NL80211_TESTMODE |
| 8659 | { |
| 8660 | .cmd = NL80211_CMD_TESTMODE, |
| 8661 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8662 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8663 | .policy = nl80211_policy, |
| 8664 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8665 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8666 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8667 | }, |
| 8668 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8669 | { |
| 8670 | .cmd = NL80211_CMD_CONNECT, |
| 8671 | .doit = nl80211_connect, |
| 8672 | .policy = nl80211_policy, |
| 8673 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8674 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8675 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8676 | }, |
| 8677 | { |
| 8678 | .cmd = NL80211_CMD_DISCONNECT, |
| 8679 | .doit = nl80211_disconnect, |
| 8680 | .policy = nl80211_policy, |
| 8681 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8682 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8683 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8684 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8685 | { |
| 8686 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8687 | .doit = nl80211_wiphy_netns, |
| 8688 | .policy = nl80211_policy, |
| 8689 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8690 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8691 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8692 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8693 | { |
| 8694 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8695 | .policy = nl80211_policy, |
| 8696 | .dumpit = nl80211_dump_survey, |
| 8697 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8698 | { |
| 8699 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8700 | .doit = nl80211_setdel_pmksa, |
| 8701 | .policy = nl80211_policy, |
| 8702 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8703 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8704 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8705 | }, |
| 8706 | { |
| 8707 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8708 | .doit = nl80211_setdel_pmksa, |
| 8709 | .policy = nl80211_policy, |
| 8710 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8711 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8712 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8713 | }, |
| 8714 | { |
| 8715 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8716 | .doit = nl80211_flush_pmksa, |
| 8717 | .policy = nl80211_policy, |
| 8718 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8719 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8720 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8721 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8722 | { |
| 8723 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8724 | .doit = nl80211_remain_on_channel, |
| 8725 | .policy = nl80211_policy, |
| 8726 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8727 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8728 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8729 | }, |
| 8730 | { |
| 8731 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8732 | .doit = nl80211_cancel_remain_on_channel, |
| 8733 | .policy = nl80211_policy, |
| 8734 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8735 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8736 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8737 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8738 | { |
| 8739 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8740 | .doit = nl80211_set_tx_bitrate_mask, |
| 8741 | .policy = nl80211_policy, |
| 8742 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8743 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8744 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8745 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8746 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8747 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8748 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8749 | .policy = nl80211_policy, |
| 8750 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8751 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8752 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8753 | }, |
| 8754 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8755 | .cmd = NL80211_CMD_FRAME, |
| 8756 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8757 | .policy = nl80211_policy, |
| 8758 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8759 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8760 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8761 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8762 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8763 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8764 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8765 | .policy = nl80211_policy, |
| 8766 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8767 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8768 | NL80211_FLAG_NEED_RTNL, |
| 8769 | }, |
| 8770 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8771 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8772 | .doit = nl80211_set_power_save, |
| 8773 | .policy = nl80211_policy, |
| 8774 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8775 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8776 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8777 | }, |
| 8778 | { |
| 8779 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8780 | .doit = nl80211_get_power_save, |
| 8781 | .policy = nl80211_policy, |
| 8782 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8783 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8784 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8785 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8786 | { |
| 8787 | .cmd = NL80211_CMD_SET_CQM, |
| 8788 | .doit = nl80211_set_cqm, |
| 8789 | .policy = nl80211_policy, |
| 8790 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8791 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8792 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8793 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8794 | { |
| 8795 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8796 | .doit = nl80211_set_channel, |
| 8797 | .policy = nl80211_policy, |
| 8798 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8799 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8800 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8801 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8802 | { |
| 8803 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8804 | .doit = nl80211_set_wds_peer, |
| 8805 | .policy = nl80211_policy, |
| 8806 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8807 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8808 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8809 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8810 | { |
| 8811 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8812 | .doit = nl80211_join_mesh, |
| 8813 | .policy = nl80211_policy, |
| 8814 | .flags = GENL_ADMIN_PERM, |
| 8815 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8816 | NL80211_FLAG_NEED_RTNL, |
| 8817 | }, |
| 8818 | { |
| 8819 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8820 | .doit = nl80211_leave_mesh, |
| 8821 | .policy = nl80211_policy, |
| 8822 | .flags = GENL_ADMIN_PERM, |
| 8823 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8824 | NL80211_FLAG_NEED_RTNL, |
| 8825 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8826 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8827 | { |
| 8828 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8829 | .doit = nl80211_get_wowlan, |
| 8830 | .policy = nl80211_policy, |
| 8831 | /* can be retrieved by unprivileged users */ |
| 8832 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8833 | NL80211_FLAG_NEED_RTNL, |
| 8834 | }, |
| 8835 | { |
| 8836 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8837 | .doit = nl80211_set_wowlan, |
| 8838 | .policy = nl80211_policy, |
| 8839 | .flags = GENL_ADMIN_PERM, |
| 8840 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8841 | NL80211_FLAG_NEED_RTNL, |
| 8842 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8843 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8844 | { |
| 8845 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8846 | .doit = nl80211_set_rekey_data, |
| 8847 | .policy = nl80211_policy, |
| 8848 | .flags = GENL_ADMIN_PERM, |
| 8849 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8850 | NL80211_FLAG_NEED_RTNL, |
| 8851 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8852 | { |
| 8853 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8854 | .doit = nl80211_tdls_mgmt, |
| 8855 | .policy = nl80211_policy, |
| 8856 | .flags = GENL_ADMIN_PERM, |
| 8857 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8858 | NL80211_FLAG_NEED_RTNL, |
| 8859 | }, |
| 8860 | { |
| 8861 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8862 | .doit = nl80211_tdls_oper, |
| 8863 | .policy = nl80211_policy, |
| 8864 | .flags = GENL_ADMIN_PERM, |
| 8865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8866 | NL80211_FLAG_NEED_RTNL, |
| 8867 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8868 | { |
| 8869 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8870 | .doit = nl80211_register_unexpected_frame, |
| 8871 | .policy = nl80211_policy, |
| 8872 | .flags = GENL_ADMIN_PERM, |
| 8873 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8874 | NL80211_FLAG_NEED_RTNL, |
| 8875 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8876 | { |
| 8877 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8878 | .doit = nl80211_probe_client, |
| 8879 | .policy = nl80211_policy, |
| 8880 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8881 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8882 | NL80211_FLAG_NEED_RTNL, |
| 8883 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8884 | { |
| 8885 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8886 | .doit = nl80211_register_beacons, |
| 8887 | .policy = nl80211_policy, |
| 8888 | .flags = GENL_ADMIN_PERM, |
| 8889 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8890 | NL80211_FLAG_NEED_RTNL, |
| 8891 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8892 | { |
| 8893 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8894 | .doit = nl80211_set_noack_map, |
| 8895 | .policy = nl80211_policy, |
| 8896 | .flags = GENL_ADMIN_PERM, |
| 8897 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8898 | NL80211_FLAG_NEED_RTNL, |
| 8899 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8900 | { |
| 8901 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8902 | .doit = nl80211_start_p2p_device, |
| 8903 | .policy = nl80211_policy, |
| 8904 | .flags = GENL_ADMIN_PERM, |
| 8905 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8906 | NL80211_FLAG_NEED_RTNL, |
| 8907 | }, |
| 8908 | { |
| 8909 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8910 | .doit = nl80211_stop_p2p_device, |
| 8911 | .policy = nl80211_policy, |
| 8912 | .flags = GENL_ADMIN_PERM, |
| 8913 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8914 | NL80211_FLAG_NEED_RTNL, |
| 8915 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8916 | { |
| 8917 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8918 | .doit = nl80211_set_mcast_rate, |
| 8919 | .policy = nl80211_policy, |
| 8920 | .flags = GENL_ADMIN_PERM, |
| 8921 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8922 | NL80211_FLAG_NEED_RTNL, |
| 8923 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8924 | { |
| 8925 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8926 | .doit = nl80211_set_mac_acl, |
| 8927 | .policy = nl80211_policy, |
| 8928 | .flags = GENL_ADMIN_PERM, |
| 8929 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8930 | NL80211_FLAG_NEED_RTNL, |
| 8931 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8932 | { |
| 8933 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8934 | .doit = nl80211_start_radar_detection, |
| 8935 | .policy = nl80211_policy, |
| 8936 | .flags = GENL_ADMIN_PERM, |
| 8937 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8938 | NL80211_FLAG_NEED_RTNL, |
| 8939 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8940 | { |
| 8941 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 8942 | .doit = nl80211_get_protocol_features, |
| 8943 | .policy = nl80211_policy, |
| 8944 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8945 | { |
| 8946 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 8947 | .doit = nl80211_update_ft_ies, |
| 8948 | .policy = nl80211_policy, |
| 8949 | .flags = GENL_ADMIN_PERM, |
| 8950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8951 | NL80211_FLAG_NEED_RTNL, |
| 8952 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8953 | { |
| 8954 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 8955 | .doit = nl80211_crit_protocol_start, |
| 8956 | .policy = nl80211_policy, |
| 8957 | .flags = GENL_ADMIN_PERM, |
| 8958 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8959 | NL80211_FLAG_NEED_RTNL, |
| 8960 | }, |
| 8961 | { |
| 8962 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 8963 | .doit = nl80211_crit_protocol_stop, |
| 8964 | .policy = nl80211_policy, |
| 8965 | .flags = GENL_ADMIN_PERM, |
| 8966 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8967 | NL80211_FLAG_NEED_RTNL, |
| 8968 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8969 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8970 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8971 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8972 | .name = "mlme", |
| 8973 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8974 | |
| 8975 | /* multicast groups */ |
| 8976 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8977 | .name = "config", |
| 8978 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8979 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8980 | .name = "scan", |
| 8981 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8982 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8983 | .name = "regulatory", |
| 8984 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8985 | |
| 8986 | /* notification functions */ |
| 8987 | |
| 8988 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8989 | { |
| 8990 | struct sk_buff *msg; |
| 8991 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8992 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8993 | if (!msg) |
| 8994 | return; |
| 8995 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8996 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
| 8997 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8998 | nlmsg_free(msg); |
| 8999 | return; |
| 9000 | } |
| 9001 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9002 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9003 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9004 | } |
| 9005 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9006 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9007 | struct cfg80211_registered_device *rdev) |
| 9008 | { |
| 9009 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9010 | struct nlattr *nest; |
| 9011 | int i; |
| 9012 | |
| 9013 | if (WARN_ON(!req)) |
| 9014 | return 0; |
| 9015 | |
| 9016 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9017 | if (!nest) |
| 9018 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9019 | for (i = 0; i < req->n_ssids; i++) { |
| 9020 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9021 | goto nla_put_failure; |
| 9022 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9023 | nla_nest_end(msg, nest); |
| 9024 | |
| 9025 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9026 | if (!nest) |
| 9027 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9028 | for (i = 0; i < req->n_channels; i++) { |
| 9029 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9030 | goto nla_put_failure; |
| 9031 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9032 | nla_nest_end(msg, nest); |
| 9033 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9034 | if (req->ie && |
| 9035 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9036 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9037 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9038 | if (req->flags) |
| 9039 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9040 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9041 | return 0; |
| 9042 | nla_put_failure: |
| 9043 | return -ENOBUFS; |
| 9044 | } |
| 9045 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9046 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9047 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9048 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9049 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9050 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9051 | { |
| 9052 | void *hdr; |
| 9053 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9054 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9055 | if (!hdr) |
| 9056 | return -1; |
| 9057 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9058 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9059 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9060 | wdev->netdev->ifindex)) || |
| 9061 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9062 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9063 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9064 | /* ignore errors and send incomplete event anyway */ |
| 9065 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9066 | |
| 9067 | return genlmsg_end(msg, hdr); |
| 9068 | |
| 9069 | nla_put_failure: |
| 9070 | genlmsg_cancel(msg, hdr); |
| 9071 | return -EMSGSIZE; |
| 9072 | } |
| 9073 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9074 | static int |
| 9075 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9076 | struct cfg80211_registered_device *rdev, |
| 9077 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9078 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9079 | { |
| 9080 | void *hdr; |
| 9081 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9082 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9083 | if (!hdr) |
| 9084 | return -1; |
| 9085 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9086 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9087 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9088 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9089 | |
| 9090 | return genlmsg_end(msg, hdr); |
| 9091 | |
| 9092 | nla_put_failure: |
| 9093 | genlmsg_cancel(msg, hdr); |
| 9094 | return -EMSGSIZE; |
| 9095 | } |
| 9096 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9097 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9098 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9099 | { |
| 9100 | struct sk_buff *msg; |
| 9101 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9103 | if (!msg) |
| 9104 | return; |
| 9105 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9106 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9107 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9108 | nlmsg_free(msg); |
| 9109 | return; |
| 9110 | } |
| 9111 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9112 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9113 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9114 | } |
| 9115 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9116 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9117 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9118 | { |
| 9119 | struct sk_buff *msg; |
| 9120 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9121 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9122 | if (!msg) |
| 9123 | return; |
| 9124 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9125 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9126 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9127 | nlmsg_free(msg); |
| 9128 | return; |
| 9129 | } |
| 9130 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9131 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9132 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9133 | } |
| 9134 | |
| 9135 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9136 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9137 | { |
| 9138 | struct sk_buff *msg; |
| 9139 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9140 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9141 | if (!msg) |
| 9142 | return; |
| 9143 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9144 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9145 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9146 | nlmsg_free(msg); |
| 9147 | return; |
| 9148 | } |
| 9149 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9150 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9151 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9152 | } |
| 9153 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9154 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9155 | struct net_device *netdev) |
| 9156 | { |
| 9157 | struct sk_buff *msg; |
| 9158 | |
| 9159 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9160 | if (!msg) |
| 9161 | return; |
| 9162 | |
| 9163 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9164 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9165 | nlmsg_free(msg); |
| 9166 | return; |
| 9167 | } |
| 9168 | |
| 9169 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9170 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9171 | } |
| 9172 | |
| 9173 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9174 | struct net_device *netdev, u32 cmd) |
| 9175 | { |
| 9176 | struct sk_buff *msg; |
| 9177 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9178 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9179 | if (!msg) |
| 9180 | return; |
| 9181 | |
| 9182 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9183 | nlmsg_free(msg); |
| 9184 | return; |
| 9185 | } |
| 9186 | |
| 9187 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9188 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9189 | } |
| 9190 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9191 | /* |
| 9192 | * This can happen on global regulatory changes or device specific settings |
| 9193 | * based on custom world regulatory domains. |
| 9194 | */ |
| 9195 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9196 | { |
| 9197 | struct sk_buff *msg; |
| 9198 | void *hdr; |
| 9199 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9200 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9201 | if (!msg) |
| 9202 | return; |
| 9203 | |
| 9204 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9205 | if (!hdr) { |
| 9206 | nlmsg_free(msg); |
| 9207 | return; |
| 9208 | } |
| 9209 | |
| 9210 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9211 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9212 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9213 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9214 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9215 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9216 | NL80211_REGDOM_TYPE_WORLD)) |
| 9217 | goto nla_put_failure; |
| 9218 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9219 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9220 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9221 | goto nla_put_failure; |
| 9222 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9223 | request->intersect) { |
| 9224 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9225 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9226 | goto nla_put_failure; |
| 9227 | } else { |
| 9228 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9229 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9230 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9231 | request->alpha2)) |
| 9232 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9233 | } |
| 9234 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9235 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9236 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9237 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9238 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9239 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9240 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9241 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9242 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9243 | GFP_ATOMIC); |
| 9244 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9245 | |
| 9246 | return; |
| 9247 | |
| 9248 | nla_put_failure: |
| 9249 | genlmsg_cancel(msg, hdr); |
| 9250 | nlmsg_free(msg); |
| 9251 | } |
| 9252 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9253 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9254 | struct net_device *netdev, |
| 9255 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9256 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9257 | { |
| 9258 | struct sk_buff *msg; |
| 9259 | void *hdr; |
| 9260 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9261 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9262 | if (!msg) |
| 9263 | return; |
| 9264 | |
| 9265 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9266 | if (!hdr) { |
| 9267 | nlmsg_free(msg); |
| 9268 | return; |
| 9269 | } |
| 9270 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9271 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9272 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9273 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9274 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9275 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9276 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9277 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9278 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9279 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9280 | return; |
| 9281 | |
| 9282 | nla_put_failure: |
| 9283 | genlmsg_cancel(msg, hdr); |
| 9284 | nlmsg_free(msg); |
| 9285 | } |
| 9286 | |
| 9287 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9288 | struct net_device *netdev, const u8 *buf, |
| 9289 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9290 | { |
| 9291 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9292 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9293 | } |
| 9294 | |
| 9295 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9296 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9297 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9298 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9299 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9300 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9301 | } |
| 9302 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9303 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9304 | struct net_device *netdev, const u8 *buf, |
| 9305 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9306 | { |
| 9307 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9308 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9309 | } |
| 9310 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9311 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9312 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9313 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9314 | { |
| 9315 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9316 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9317 | } |
| 9318 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9319 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9320 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9321 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9322 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9323 | struct wiphy *wiphy = wdev->wiphy; |
| 9324 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9325 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9326 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9327 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9328 | if (WARN_ON(len < 2)) |
| 9329 | return; |
| 9330 | |
| 9331 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9332 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9333 | else |
| 9334 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9335 | |
| 9336 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9337 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9338 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9339 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9340 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9341 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9342 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9343 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9344 | { |
| 9345 | struct sk_buff *msg; |
| 9346 | void *hdr; |
| 9347 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9348 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9349 | if (!msg) |
| 9350 | return; |
| 9351 | |
| 9352 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9353 | if (!hdr) { |
| 9354 | nlmsg_free(msg); |
| 9355 | return; |
| 9356 | } |
| 9357 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9358 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9359 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9360 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9361 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9362 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9363 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9364 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9365 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9366 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9367 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9368 | return; |
| 9369 | |
| 9370 | nla_put_failure: |
| 9371 | genlmsg_cancel(msg, hdr); |
| 9372 | nlmsg_free(msg); |
| 9373 | } |
| 9374 | |
| 9375 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9376 | struct net_device *netdev, const u8 *addr, |
| 9377 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9378 | { |
| 9379 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9380 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9381 | } |
| 9382 | |
| 9383 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9384 | struct net_device *netdev, const u8 *addr, |
| 9385 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9386 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9387 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9388 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9389 | } |
| 9390 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9391 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9392 | struct net_device *netdev, const u8 *bssid, |
| 9393 | const u8 *req_ie, size_t req_ie_len, |
| 9394 | const u8 *resp_ie, size_t resp_ie_len, |
| 9395 | u16 status, gfp_t gfp) |
| 9396 | { |
| 9397 | struct sk_buff *msg; |
| 9398 | void *hdr; |
| 9399 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9400 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9401 | if (!msg) |
| 9402 | return; |
| 9403 | |
| 9404 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9405 | if (!hdr) { |
| 9406 | nlmsg_free(msg); |
| 9407 | return; |
| 9408 | } |
| 9409 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9410 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9411 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9412 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9413 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9414 | (req_ie && |
| 9415 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9416 | (resp_ie && |
| 9417 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9418 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9419 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9420 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9421 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9422 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9423 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9424 | return; |
| 9425 | |
| 9426 | nla_put_failure: |
| 9427 | genlmsg_cancel(msg, hdr); |
| 9428 | nlmsg_free(msg); |
| 9429 | |
| 9430 | } |
| 9431 | |
| 9432 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9433 | struct net_device *netdev, const u8 *bssid, |
| 9434 | const u8 *req_ie, size_t req_ie_len, |
| 9435 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9436 | { |
| 9437 | struct sk_buff *msg; |
| 9438 | void *hdr; |
| 9439 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9440 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9441 | if (!msg) |
| 9442 | return; |
| 9443 | |
| 9444 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9445 | if (!hdr) { |
| 9446 | nlmsg_free(msg); |
| 9447 | return; |
| 9448 | } |
| 9449 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9450 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9451 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9452 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9453 | (req_ie && |
| 9454 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9455 | (resp_ie && |
| 9456 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9457 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9458 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9459 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9460 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9461 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9462 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9463 | return; |
| 9464 | |
| 9465 | nla_put_failure: |
| 9466 | genlmsg_cancel(msg, hdr); |
| 9467 | nlmsg_free(msg); |
| 9468 | |
| 9469 | } |
| 9470 | |
| 9471 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9472 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9473 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9474 | { |
| 9475 | struct sk_buff *msg; |
| 9476 | void *hdr; |
| 9477 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9479 | if (!msg) |
| 9480 | return; |
| 9481 | |
| 9482 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9483 | if (!hdr) { |
| 9484 | nlmsg_free(msg); |
| 9485 | return; |
| 9486 | } |
| 9487 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9488 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9489 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9490 | (from_ap && reason && |
| 9491 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9492 | (from_ap && |
| 9493 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9494 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9495 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9496 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9497 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9498 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9499 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9500 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9501 | return; |
| 9502 | |
| 9503 | nla_put_failure: |
| 9504 | genlmsg_cancel(msg, hdr); |
| 9505 | nlmsg_free(msg); |
| 9506 | |
| 9507 | } |
| 9508 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9509 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9510 | struct net_device *netdev, const u8 *bssid, |
| 9511 | gfp_t gfp) |
| 9512 | { |
| 9513 | struct sk_buff *msg; |
| 9514 | void *hdr; |
| 9515 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9516 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9517 | if (!msg) |
| 9518 | return; |
| 9519 | |
| 9520 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9521 | if (!hdr) { |
| 9522 | nlmsg_free(msg); |
| 9523 | return; |
| 9524 | } |
| 9525 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9526 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9527 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9528 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9529 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9530 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9531 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9532 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9533 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9534 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9535 | return; |
| 9536 | |
| 9537 | nla_put_failure: |
| 9538 | genlmsg_cancel(msg, hdr); |
| 9539 | nlmsg_free(msg); |
| 9540 | } |
| 9541 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9542 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 9543 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9544 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9545 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9546 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9547 | struct sk_buff *msg; |
| 9548 | void *hdr; |
| 9549 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9550 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 9551 | return; |
| 9552 | |
| 9553 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 9554 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9555 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9556 | if (!msg) |
| 9557 | return; |
| 9558 | |
| 9559 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9560 | if (!hdr) { |
| 9561 | nlmsg_free(msg); |
| 9562 | return; |
| 9563 | } |
| 9564 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9565 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9566 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9567 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9568 | (ie_len && ie && |
| 9569 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9570 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9571 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9572 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9573 | |
| 9574 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9575 | nl80211_mlme_mcgrp.id, gfp); |
| 9576 | return; |
| 9577 | |
| 9578 | nla_put_failure: |
| 9579 | genlmsg_cancel(msg, hdr); |
| 9580 | nlmsg_free(msg); |
| 9581 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9582 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9583 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9584 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9585 | struct net_device *netdev, const u8 *addr, |
| 9586 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9587 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9588 | { |
| 9589 | struct sk_buff *msg; |
| 9590 | void *hdr; |
| 9591 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9593 | if (!msg) |
| 9594 | return; |
| 9595 | |
| 9596 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9597 | if (!hdr) { |
| 9598 | nlmsg_free(msg); |
| 9599 | return; |
| 9600 | } |
| 9601 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9602 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9603 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9604 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9605 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9606 | (key_id != -1 && |
| 9607 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9608 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9609 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9610 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9611 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9612 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9613 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9614 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9615 | return; |
| 9616 | |
| 9617 | nla_put_failure: |
| 9618 | genlmsg_cancel(msg, hdr); |
| 9619 | nlmsg_free(msg); |
| 9620 | } |
| 9621 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9622 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9623 | struct ieee80211_channel *channel_before, |
| 9624 | struct ieee80211_channel *channel_after) |
| 9625 | { |
| 9626 | struct sk_buff *msg; |
| 9627 | void *hdr; |
| 9628 | struct nlattr *nl_freq; |
| 9629 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9630 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9631 | if (!msg) |
| 9632 | return; |
| 9633 | |
| 9634 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9635 | if (!hdr) { |
| 9636 | nlmsg_free(msg); |
| 9637 | return; |
| 9638 | } |
| 9639 | |
| 9640 | /* |
| 9641 | * Since we are applying the beacon hint to a wiphy we know its |
| 9642 | * wiphy_idx is valid |
| 9643 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9644 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9645 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9646 | |
| 9647 | /* Before */ |
| 9648 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9649 | if (!nl_freq) |
| 9650 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9651 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9652 | goto nla_put_failure; |
| 9653 | nla_nest_end(msg, nl_freq); |
| 9654 | |
| 9655 | /* After */ |
| 9656 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9657 | if (!nl_freq) |
| 9658 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9659 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9660 | goto nla_put_failure; |
| 9661 | nla_nest_end(msg, nl_freq); |
| 9662 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9663 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9664 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9665 | rcu_read_lock(); |
| 9666 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9667 | GFP_ATOMIC); |
| 9668 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9669 | |
| 9670 | return; |
| 9671 | |
| 9672 | nla_put_failure: |
| 9673 | genlmsg_cancel(msg, hdr); |
| 9674 | nlmsg_free(msg); |
| 9675 | } |
| 9676 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9677 | static void nl80211_send_remain_on_chan_event( |
| 9678 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9679 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9680 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9681 | unsigned int duration, gfp_t gfp) |
| 9682 | { |
| 9683 | struct sk_buff *msg; |
| 9684 | void *hdr; |
| 9685 | |
| 9686 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9687 | if (!msg) |
| 9688 | return; |
| 9689 | |
| 9690 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9691 | if (!hdr) { |
| 9692 | nlmsg_free(msg); |
| 9693 | return; |
| 9694 | } |
| 9695 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9696 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9697 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9698 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9699 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9700 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9701 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9702 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9703 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9704 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9705 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9706 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9707 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9708 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9709 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9710 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9711 | |
| 9712 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9713 | nl80211_mlme_mcgrp.id, gfp); |
| 9714 | return; |
| 9715 | |
| 9716 | nla_put_failure: |
| 9717 | genlmsg_cancel(msg, hdr); |
| 9718 | nlmsg_free(msg); |
| 9719 | } |
| 9720 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9721 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 9722 | struct ieee80211_channel *chan, |
| 9723 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9724 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9725 | struct wiphy *wiphy = wdev->wiphy; |
| 9726 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9727 | |
| 9728 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9729 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9730 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9731 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9732 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9733 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9734 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9735 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 9736 | struct ieee80211_channel *chan, |
| 9737 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9738 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9739 | struct wiphy *wiphy = wdev->wiphy; |
| 9740 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9741 | |
| 9742 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9743 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9744 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9745 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9746 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9747 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9748 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 9749 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9750 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9751 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9752 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9753 | struct sk_buff *msg; |
| 9754 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9755 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 9756 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9757 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9758 | if (!msg) |
| 9759 | return; |
| 9760 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9761 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9762 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9763 | nlmsg_free(msg); |
| 9764 | return; |
| 9765 | } |
| 9766 | |
| 9767 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9768 | nl80211_mlme_mcgrp.id, gfp); |
| 9769 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9770 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9771 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9772 | 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] | 9773 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9774 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9775 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9776 | struct sk_buff *msg; |
| 9777 | void *hdr; |
| 9778 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9779 | trace_cfg80211_del_sta(dev, mac_addr); |
| 9780 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9781 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9782 | if (!msg) |
| 9783 | return; |
| 9784 | |
| 9785 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9786 | if (!hdr) { |
| 9787 | nlmsg_free(msg); |
| 9788 | return; |
| 9789 | } |
| 9790 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9791 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9792 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9793 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9794 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9795 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9796 | |
| 9797 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9798 | nl80211_mlme_mcgrp.id, gfp); |
| 9799 | return; |
| 9800 | |
| 9801 | nla_put_failure: |
| 9802 | genlmsg_cancel(msg, hdr); |
| 9803 | nlmsg_free(msg); |
| 9804 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9805 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9806 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9807 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 9808 | enum nl80211_connect_failed_reason reason, |
| 9809 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9810 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9811 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9812 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9813 | struct sk_buff *msg; |
| 9814 | void *hdr; |
| 9815 | |
| 9816 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9817 | if (!msg) |
| 9818 | return; |
| 9819 | |
| 9820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9821 | if (!hdr) { |
| 9822 | nlmsg_free(msg); |
| 9823 | return; |
| 9824 | } |
| 9825 | |
| 9826 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9827 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9828 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9829 | goto nla_put_failure; |
| 9830 | |
| 9831 | genlmsg_end(msg, hdr); |
| 9832 | |
| 9833 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9834 | nl80211_mlme_mcgrp.id, gfp); |
| 9835 | return; |
| 9836 | |
| 9837 | nla_put_failure: |
| 9838 | genlmsg_cancel(msg, hdr); |
| 9839 | nlmsg_free(msg); |
| 9840 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9841 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9842 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9843 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9844 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9845 | { |
| 9846 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9847 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9848 | struct sk_buff *msg; |
| 9849 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9850 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9851 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9852 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9853 | return false; |
| 9854 | |
| 9855 | msg = nlmsg_new(100, gfp); |
| 9856 | if (!msg) |
| 9857 | return true; |
| 9858 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9859 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9860 | if (!hdr) { |
| 9861 | nlmsg_free(msg); |
| 9862 | return true; |
| 9863 | } |
| 9864 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9865 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9866 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9867 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9868 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9869 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 9870 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9871 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9872 | return true; |
| 9873 | |
| 9874 | nla_put_failure: |
| 9875 | genlmsg_cancel(msg, hdr); |
| 9876 | nlmsg_free(msg); |
| 9877 | return true; |
| 9878 | } |
| 9879 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9880 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 9881 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9882 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9883 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9884 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9885 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9886 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 9887 | |
| 9888 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9889 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 9890 | trace_cfg80211_return_bool(false); |
| 9891 | return false; |
| 9892 | } |
| 9893 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9894 | addr, gfp); |
| 9895 | trace_cfg80211_return_bool(ret); |
| 9896 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9897 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9898 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 9899 | |
| 9900 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 9901 | const u8 *addr, gfp_t gfp) |
| 9902 | { |
| 9903 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9904 | bool ret; |
| 9905 | |
| 9906 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 9907 | |
| 9908 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9909 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 9910 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 9911 | trace_cfg80211_return_bool(false); |
| 9912 | return false; |
| 9913 | } |
| 9914 | ret = __nl80211_unexpected_frame(dev, |
| 9915 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9916 | addr, gfp); |
| 9917 | trace_cfg80211_return_bool(ret); |
| 9918 | return ret; |
| 9919 | } |
| 9920 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9921 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9922 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9923 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9924 | int freq, int sig_dbm, |
| 9925 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9926 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9927 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9928 | struct sk_buff *msg; |
| 9929 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9930 | |
| 9931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9932 | if (!msg) |
| 9933 | return -ENOMEM; |
| 9934 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9935 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9936 | if (!hdr) { |
| 9937 | nlmsg_free(msg); |
| 9938 | return -ENOMEM; |
| 9939 | } |
| 9940 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9941 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9942 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9943 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 9944 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9945 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9946 | (sig_dbm && |
| 9947 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9948 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9949 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9950 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9951 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9952 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9953 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9954 | |
| 9955 | nla_put_failure: |
| 9956 | genlmsg_cancel(msg, hdr); |
| 9957 | nlmsg_free(msg); |
| 9958 | return -ENOBUFS; |
| 9959 | } |
| 9960 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9961 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 9962 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9963 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9964 | struct wiphy *wiphy = wdev->wiphy; |
| 9965 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9966 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9967 | struct sk_buff *msg; |
| 9968 | void *hdr; |
| 9969 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9970 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 9971 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9972 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9973 | if (!msg) |
| 9974 | return; |
| 9975 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9976 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9977 | if (!hdr) { |
| 9978 | nlmsg_free(msg); |
| 9979 | return; |
| 9980 | } |
| 9981 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9982 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9983 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9984 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 9985 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9986 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9987 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9988 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9989 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9990 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9991 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9992 | |
| 9993 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9994 | return; |
| 9995 | |
| 9996 | nla_put_failure: |
| 9997 | genlmsg_cancel(msg, hdr); |
| 9998 | nlmsg_free(msg); |
| 9999 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10000 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10001 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10002 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10003 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10004 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10005 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10006 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10007 | struct wiphy *wiphy = wdev->wiphy; |
| 10008 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10009 | struct sk_buff *msg; |
| 10010 | struct nlattr *pinfoattr; |
| 10011 | void *hdr; |
| 10012 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10013 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10014 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10015 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10016 | if (!msg) |
| 10017 | return; |
| 10018 | |
| 10019 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10020 | if (!hdr) { |
| 10021 | nlmsg_free(msg); |
| 10022 | return; |
| 10023 | } |
| 10024 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10025 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10026 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10027 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10028 | |
| 10029 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10030 | if (!pinfoattr) |
| 10031 | goto nla_put_failure; |
| 10032 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10033 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10034 | rssi_event)) |
| 10035 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10036 | |
| 10037 | nla_nest_end(msg, pinfoattr); |
| 10038 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10039 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10040 | |
| 10041 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10042 | nl80211_mlme_mcgrp.id, gfp); |
| 10043 | return; |
| 10044 | |
| 10045 | nla_put_failure: |
| 10046 | genlmsg_cancel(msg, hdr); |
| 10047 | nlmsg_free(msg); |
| 10048 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10049 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10050 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10051 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10052 | struct net_device *netdev, const u8 *bssid, |
| 10053 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10054 | { |
| 10055 | struct sk_buff *msg; |
| 10056 | struct nlattr *rekey_attr; |
| 10057 | void *hdr; |
| 10058 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10059 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10060 | if (!msg) |
| 10061 | return; |
| 10062 | |
| 10063 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10064 | if (!hdr) { |
| 10065 | nlmsg_free(msg); |
| 10066 | return; |
| 10067 | } |
| 10068 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10069 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10070 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10071 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10072 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10073 | |
| 10074 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10075 | if (!rekey_attr) |
| 10076 | goto nla_put_failure; |
| 10077 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10078 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10079 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10080 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10081 | |
| 10082 | nla_nest_end(msg, rekey_attr); |
| 10083 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10084 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10085 | |
| 10086 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10087 | nl80211_mlme_mcgrp.id, gfp); |
| 10088 | return; |
| 10089 | |
| 10090 | nla_put_failure: |
| 10091 | genlmsg_cancel(msg, hdr); |
| 10092 | nlmsg_free(msg); |
| 10093 | } |
| 10094 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10095 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10096 | const u8 *replay_ctr, gfp_t gfp) |
| 10097 | { |
| 10098 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10099 | struct wiphy *wiphy = wdev->wiphy; |
| 10100 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10101 | |
| 10102 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10103 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10104 | } |
| 10105 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10106 | |
| 10107 | static void |
| 10108 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10109 | struct net_device *netdev, int index, |
| 10110 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10111 | { |
| 10112 | struct sk_buff *msg; |
| 10113 | struct nlattr *attr; |
| 10114 | void *hdr; |
| 10115 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10116 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10117 | if (!msg) |
| 10118 | return; |
| 10119 | |
| 10120 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10121 | if (!hdr) { |
| 10122 | nlmsg_free(msg); |
| 10123 | return; |
| 10124 | } |
| 10125 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10126 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10127 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10128 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10129 | |
| 10130 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10131 | if (!attr) |
| 10132 | goto nla_put_failure; |
| 10133 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10134 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10135 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10136 | (preauth && |
| 10137 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10138 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10139 | |
| 10140 | nla_nest_end(msg, attr); |
| 10141 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10142 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10143 | |
| 10144 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10145 | nl80211_mlme_mcgrp.id, gfp); |
| 10146 | return; |
| 10147 | |
| 10148 | nla_put_failure: |
| 10149 | genlmsg_cancel(msg, hdr); |
| 10150 | nlmsg_free(msg); |
| 10151 | } |
| 10152 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10153 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10154 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10155 | { |
| 10156 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10157 | struct wiphy *wiphy = wdev->wiphy; |
| 10158 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10159 | |
| 10160 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10161 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10162 | } |
| 10163 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10164 | |
| 10165 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10166 | struct net_device *netdev, |
| 10167 | struct cfg80211_chan_def *chandef, |
| 10168 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10169 | { |
| 10170 | struct sk_buff *msg; |
| 10171 | void *hdr; |
| 10172 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10173 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10174 | if (!msg) |
| 10175 | return; |
| 10176 | |
| 10177 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10178 | if (!hdr) { |
| 10179 | nlmsg_free(msg); |
| 10180 | return; |
| 10181 | } |
| 10182 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10183 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10184 | goto nla_put_failure; |
| 10185 | |
| 10186 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10187 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10188 | |
| 10189 | genlmsg_end(msg, hdr); |
| 10190 | |
| 10191 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10192 | nl80211_mlme_mcgrp.id, gfp); |
| 10193 | return; |
| 10194 | |
| 10195 | nla_put_failure: |
| 10196 | genlmsg_cancel(msg, hdr); |
| 10197 | nlmsg_free(msg); |
| 10198 | } |
| 10199 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10200 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10201 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10202 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10203 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10204 | struct wiphy *wiphy = wdev->wiphy; |
| 10205 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10206 | |
| 10207 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10208 | |
| 10209 | wdev_lock(wdev); |
| 10210 | |
| 10211 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10212 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10213 | goto out; |
| 10214 | |
| 10215 | wdev->channel = chandef->chan; |
| 10216 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10217 | out: |
| 10218 | wdev_unlock(wdev); |
| 10219 | return; |
| 10220 | } |
| 10221 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10222 | |
| 10223 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10224 | const u8 *peer, u32 num_packets, |
| 10225 | u32 rate, u32 intvl, gfp_t gfp) |
| 10226 | { |
| 10227 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10228 | struct wiphy *wiphy = wdev->wiphy; |
| 10229 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10230 | struct sk_buff *msg; |
| 10231 | struct nlattr *pinfoattr; |
| 10232 | void *hdr; |
| 10233 | |
| 10234 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10235 | if (!msg) |
| 10236 | return; |
| 10237 | |
| 10238 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10239 | if (!hdr) { |
| 10240 | nlmsg_free(msg); |
| 10241 | return; |
| 10242 | } |
| 10243 | |
| 10244 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10245 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10246 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10247 | goto nla_put_failure; |
| 10248 | |
| 10249 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10250 | if (!pinfoattr) |
| 10251 | goto nla_put_failure; |
| 10252 | |
| 10253 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10254 | goto nla_put_failure; |
| 10255 | |
| 10256 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10257 | goto nla_put_failure; |
| 10258 | |
| 10259 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10260 | goto nla_put_failure; |
| 10261 | |
| 10262 | nla_nest_end(msg, pinfoattr); |
| 10263 | |
| 10264 | genlmsg_end(msg, hdr); |
| 10265 | |
| 10266 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10267 | nl80211_mlme_mcgrp.id, gfp); |
| 10268 | return; |
| 10269 | |
| 10270 | nla_put_failure: |
| 10271 | genlmsg_cancel(msg, hdr); |
| 10272 | nlmsg_free(msg); |
| 10273 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10274 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10275 | |
| 10276 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10277 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10278 | struct cfg80211_chan_def *chandef, |
| 10279 | enum nl80211_radar_event event, |
| 10280 | struct net_device *netdev, gfp_t gfp) |
| 10281 | { |
| 10282 | struct sk_buff *msg; |
| 10283 | void *hdr; |
| 10284 | |
| 10285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10286 | if (!msg) |
| 10287 | return; |
| 10288 | |
| 10289 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10290 | if (!hdr) { |
| 10291 | nlmsg_free(msg); |
| 10292 | return; |
| 10293 | } |
| 10294 | |
| 10295 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10296 | goto nla_put_failure; |
| 10297 | |
| 10298 | /* NOP and radar events don't need a netdev parameter */ |
| 10299 | if (netdev) { |
| 10300 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10301 | |
| 10302 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10303 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10304 | goto nla_put_failure; |
| 10305 | } |
| 10306 | |
| 10307 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10308 | goto nla_put_failure; |
| 10309 | |
| 10310 | if (nl80211_send_chandef(msg, chandef)) |
| 10311 | goto nla_put_failure; |
| 10312 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10313 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10314 | |
| 10315 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10316 | nl80211_mlme_mcgrp.id, gfp); |
| 10317 | return; |
| 10318 | |
| 10319 | nla_put_failure: |
| 10320 | genlmsg_cancel(msg, hdr); |
| 10321 | nlmsg_free(msg); |
| 10322 | } |
| 10323 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10324 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10325 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10326 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10327 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10328 | struct wiphy *wiphy = wdev->wiphy; |
| 10329 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10330 | struct sk_buff *msg; |
| 10331 | struct nlattr *pinfoattr; |
| 10332 | void *hdr; |
| 10333 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10334 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10335 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10336 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10337 | if (!msg) |
| 10338 | return; |
| 10339 | |
| 10340 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10341 | if (!hdr) { |
| 10342 | nlmsg_free(msg); |
| 10343 | return; |
| 10344 | } |
| 10345 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10346 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10347 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10348 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10349 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10350 | |
| 10351 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10352 | if (!pinfoattr) |
| 10353 | goto nla_put_failure; |
| 10354 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10355 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10356 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10357 | |
| 10358 | nla_nest_end(msg, pinfoattr); |
| 10359 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10360 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10361 | |
| 10362 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10363 | nl80211_mlme_mcgrp.id, gfp); |
| 10364 | return; |
| 10365 | |
| 10366 | nla_put_failure: |
| 10367 | genlmsg_cancel(msg, hdr); |
| 10368 | nlmsg_free(msg); |
| 10369 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10370 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10371 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10372 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10373 | u64 cookie, bool acked, gfp_t gfp) |
| 10374 | { |
| 10375 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10376 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10377 | struct sk_buff *msg; |
| 10378 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10379 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10380 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10381 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10383 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10384 | if (!msg) |
| 10385 | return; |
| 10386 | |
| 10387 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10388 | if (!hdr) { |
| 10389 | nlmsg_free(msg); |
| 10390 | return; |
| 10391 | } |
| 10392 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10393 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10394 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10395 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10396 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10397 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10398 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10399 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10400 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10401 | |
| 10402 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10403 | nl80211_mlme_mcgrp.id, gfp); |
| 10404 | return; |
| 10405 | |
| 10406 | nla_put_failure: |
| 10407 | genlmsg_cancel(msg, hdr); |
| 10408 | nlmsg_free(msg); |
| 10409 | } |
| 10410 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10411 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10412 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10413 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10414 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10415 | { |
| 10416 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10417 | struct sk_buff *msg; |
| 10418 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10419 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10420 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10421 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10422 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10423 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10424 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10425 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10426 | if (!msg) { |
| 10427 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10428 | return; |
| 10429 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10430 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10431 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10432 | if (!hdr) |
| 10433 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10434 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10435 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10436 | (freq && |
| 10437 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10438 | (sig_dbm && |
| 10439 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10440 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10441 | goto nla_put_failure; |
| 10442 | |
| 10443 | genlmsg_end(msg, hdr); |
| 10444 | |
| 10445 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10446 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10447 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10448 | return; |
| 10449 | |
| 10450 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10451 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10452 | if (hdr) |
| 10453 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10454 | nlmsg_free(msg); |
| 10455 | } |
| 10456 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10457 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10458 | #ifdef CONFIG_PM |
| 10459 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10460 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10461 | gfp_t gfp) |
| 10462 | { |
| 10463 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10464 | struct sk_buff *msg; |
| 10465 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10466 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10467 | |
| 10468 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10469 | |
| 10470 | if (wakeup) |
| 10471 | size += wakeup->packet_present_len; |
| 10472 | |
| 10473 | msg = nlmsg_new(size, gfp); |
| 10474 | if (!msg) |
| 10475 | return; |
| 10476 | |
| 10477 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 10478 | if (!hdr) |
| 10479 | goto free_msg; |
| 10480 | |
| 10481 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10482 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10483 | goto free_msg; |
| 10484 | |
| 10485 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10486 | wdev->netdev->ifindex)) |
| 10487 | goto free_msg; |
| 10488 | |
| 10489 | if (wakeup) { |
| 10490 | struct nlattr *reasons; |
| 10491 | |
| 10492 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10493 | |
| 10494 | if (wakeup->disconnect && |
| 10495 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 10496 | goto free_msg; |
| 10497 | if (wakeup->magic_pkt && |
| 10498 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 10499 | goto free_msg; |
| 10500 | if (wakeup->gtk_rekey_failure && |
| 10501 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 10502 | goto free_msg; |
| 10503 | if (wakeup->eap_identity_req && |
| 10504 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 10505 | goto free_msg; |
| 10506 | if (wakeup->four_way_handshake && |
| 10507 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 10508 | goto free_msg; |
| 10509 | if (wakeup->rfkill_release && |
| 10510 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 10511 | goto free_msg; |
| 10512 | |
| 10513 | if (wakeup->pattern_idx >= 0 && |
| 10514 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 10515 | wakeup->pattern_idx)) |
| 10516 | goto free_msg; |
| 10517 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10518 | if (wakeup->tcp_match) |
| 10519 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 10520 | |
| 10521 | if (wakeup->tcp_connlost) |
| 10522 | nla_put_flag(msg, |
| 10523 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 10524 | |
| 10525 | if (wakeup->tcp_nomoretokens) |
| 10526 | nla_put_flag(msg, |
| 10527 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 10528 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10529 | if (wakeup->packet) { |
| 10530 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 10531 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 10532 | |
| 10533 | if (!wakeup->packet_80211) { |
| 10534 | pkt_attr = |
| 10535 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 10536 | len_attr = |
| 10537 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 10538 | } |
| 10539 | |
| 10540 | if (wakeup->packet_len && |
| 10541 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 10542 | goto free_msg; |
| 10543 | |
| 10544 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 10545 | wakeup->packet)) |
| 10546 | goto free_msg; |
| 10547 | } |
| 10548 | |
| 10549 | nla_nest_end(msg, reasons); |
| 10550 | } |
| 10551 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10552 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10553 | |
| 10554 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10555 | nl80211_mlme_mcgrp.id, gfp); |
| 10556 | return; |
| 10557 | |
| 10558 | free_msg: |
| 10559 | nlmsg_free(msg); |
| 10560 | } |
| 10561 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 10562 | #endif |
| 10563 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10564 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10565 | enum nl80211_tdls_operation oper, |
| 10566 | u16 reason_code, gfp_t gfp) |
| 10567 | { |
| 10568 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10569 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10570 | struct sk_buff *msg; |
| 10571 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10572 | |
| 10573 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10574 | reason_code); |
| 10575 | |
| 10576 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10577 | if (!msg) |
| 10578 | return; |
| 10579 | |
| 10580 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10581 | if (!hdr) { |
| 10582 | nlmsg_free(msg); |
| 10583 | return; |
| 10584 | } |
| 10585 | |
| 10586 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10587 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10588 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10589 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10590 | (reason_code > 0 && |
| 10591 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10592 | goto nla_put_failure; |
| 10593 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10594 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10595 | |
| 10596 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10597 | nl80211_mlme_mcgrp.id, gfp); |
| 10598 | return; |
| 10599 | |
| 10600 | nla_put_failure: |
| 10601 | genlmsg_cancel(msg, hdr); |
| 10602 | nlmsg_free(msg); |
| 10603 | } |
| 10604 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10605 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10606 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10607 | unsigned long state, |
| 10608 | void *_notify) |
| 10609 | { |
| 10610 | struct netlink_notify *notify = _notify; |
| 10611 | struct cfg80211_registered_device *rdev; |
| 10612 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10613 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10614 | |
| 10615 | if (state != NETLINK_URELEASE) |
| 10616 | return NOTIFY_DONE; |
| 10617 | |
| 10618 | rcu_read_lock(); |
| 10619 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10620 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10621 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10622 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10623 | |
| 10624 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10625 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10626 | list) { |
| 10627 | if (reg->nlportid == notify->portid) { |
| 10628 | list_del(®->list); |
| 10629 | kfree(reg); |
| 10630 | break; |
| 10631 | } |
| 10632 | } |
| 10633 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10634 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10635 | |
| 10636 | rcu_read_unlock(); |
| 10637 | |
| 10638 | return NOTIFY_DONE; |
| 10639 | } |
| 10640 | |
| 10641 | static struct notifier_block nl80211_netlink_notifier = { |
| 10642 | .notifier_call = nl80211_netlink_notify, |
| 10643 | }; |
| 10644 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10645 | void cfg80211_ft_event(struct net_device *netdev, |
| 10646 | struct cfg80211_ft_event_params *ft_event) |
| 10647 | { |
| 10648 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 10649 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10650 | struct sk_buff *msg; |
| 10651 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10652 | |
| 10653 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 10654 | |
| 10655 | if (!ft_event->target_ap) |
| 10656 | return; |
| 10657 | |
| 10658 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10659 | if (!msg) |
| 10660 | return; |
| 10661 | |
| 10662 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 10663 | if (!hdr) { |
| 10664 | nlmsg_free(msg); |
| 10665 | return; |
| 10666 | } |
| 10667 | |
| 10668 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 10669 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 10670 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 10671 | if (ft_event->ies) |
| 10672 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 10673 | if (ft_event->ric_ies) |
| 10674 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 10675 | ft_event->ric_ies); |
| 10676 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10677 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10678 | |
| 10679 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10680 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 10681 | } |
| 10682 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 10683 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10684 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 10685 | { |
| 10686 | struct cfg80211_registered_device *rdev; |
| 10687 | struct sk_buff *msg; |
| 10688 | void *hdr; |
| 10689 | u32 nlportid; |
| 10690 | |
| 10691 | rdev = wiphy_to_dev(wdev->wiphy); |
| 10692 | if (!rdev->crit_proto_nlportid) |
| 10693 | return; |
| 10694 | |
| 10695 | nlportid = rdev->crit_proto_nlportid; |
| 10696 | rdev->crit_proto_nlportid = 0; |
| 10697 | |
| 10698 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10699 | if (!msg) |
| 10700 | return; |
| 10701 | |
| 10702 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 10703 | if (!hdr) |
| 10704 | goto nla_put_failure; |
| 10705 | |
| 10706 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10707 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10708 | goto nla_put_failure; |
| 10709 | |
| 10710 | genlmsg_end(msg, hdr); |
| 10711 | |
| 10712 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 10713 | return; |
| 10714 | |
| 10715 | nla_put_failure: |
| 10716 | if (hdr) |
| 10717 | genlmsg_cancel(msg, hdr); |
| 10718 | nlmsg_free(msg); |
| 10719 | |
| 10720 | } |
| 10721 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 10722 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10723 | /* initialisation/exit functions */ |
| 10724 | |
| 10725 | int nl80211_init(void) |
| 10726 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10727 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10728 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10729 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10730 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10731 | if (err) |
| 10732 | return err; |
| 10733 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10734 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10735 | if (err) |
| 10736 | goto err_out; |
| 10737 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10738 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10739 | if (err) |
| 10740 | goto err_out; |
| 10741 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10742 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10743 | if (err) |
| 10744 | goto err_out; |
| 10745 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10746 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10747 | if (err) |
| 10748 | goto err_out; |
| 10749 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10750 | #ifdef CONFIG_NL80211_TESTMODE |
| 10751 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10752 | if (err) |
| 10753 | goto err_out; |
| 10754 | #endif |
| 10755 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10756 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10757 | if (err) |
| 10758 | goto err_out; |
| 10759 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10760 | return 0; |
| 10761 | err_out: |
| 10762 | genl_unregister_family(&nl80211_fam); |
| 10763 | return err; |
| 10764 | } |
| 10765 | |
| 10766 | void nl80211_exit(void) |
| 10767 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10768 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10769 | genl_unregister_family(&nl80211_fam); |
| 10770 | } |