Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 62 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 94 | |
| 95 | if (result) |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | if (result) |
| 100 | return result; |
| 101 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 104 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 108 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 109 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 110 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 113 | !attrs[NL80211_ATTR_IFINDEX] && |
| 114 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 115 | return ERR_PTR(-EINVAL); |
| 116 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 121 | if (attrs[NL80211_ATTR_WDEV]) { |
| 122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 123 | struct wireless_dev *wdev; |
| 124 | bool found = false; |
| 125 | |
| 126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 127 | if (tmp) { |
| 128 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 129 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 130 | if (wdev->identifier != (u32)wdev_id) |
| 131 | continue; |
| 132 | found = true; |
| 133 | break; |
| 134 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | |
| 136 | if (!found) |
| 137 | tmp = NULL; |
| 138 | |
| 139 | if (rdev && tmp != rdev) |
| 140 | return ERR_PTR(-EINVAL); |
| 141 | rdev = tmp; |
| 142 | } |
| 143 | } |
| 144 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 145 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 146 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 147 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 148 | if (netdev) { |
| 149 | if (netdev->ieee80211_ptr) |
| 150 | tmp = wiphy_to_dev( |
| 151 | netdev->ieee80211_ptr->wiphy); |
| 152 | else |
| 153 | tmp = NULL; |
| 154 | |
| 155 | dev_put(netdev); |
| 156 | |
| 157 | /* not wireless device -- return error */ |
| 158 | if (!tmp) |
| 159 | return ERR_PTR(-EINVAL); |
| 160 | |
| 161 | /* mismatch -- return error */ |
| 162 | if (rdev && tmp != rdev) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 166 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 169 | if (!rdev) |
| 170 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (netns != wiphy_net(&rdev->wiphy)) |
| 173 | return ERR_PTR(-ENODEV); |
| 174 | |
| 175 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
| 179 | * This function returns a pointer to the driver |
| 180 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | * |
| 182 | * The result of this can be a PTR_ERR and hence must |
| 183 | * be checked with IS_ERR() for errors. |
| 184 | */ |
| 185 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 186 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 188 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 191 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 192 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 193 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 194 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 195 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 196 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 197 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 198 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 199 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 200 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 201 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 202 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 203 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 204 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 205 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 206 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 207 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 208 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 209 | |
| 210 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 211 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 212 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 213 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 214 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 215 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 216 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 218 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 219 | .len = WLAN_MAX_KEY_LEN }, |
| 220 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 221 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 225 | |
| 226 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 228 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 229 | .len = IEEE80211_MAX_DATA_LEN }, |
| 230 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 231 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 232 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 233 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 234 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 235 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 236 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 239 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 240 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 241 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 242 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 243 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 244 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 245 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 246 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 247 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 248 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 249 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 250 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 251 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 252 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 253 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 256 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 258 | |
| 259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 264 | |
| 265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 266 | .len = IEEE80211_MAX_SSID_LEN }, |
| 267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 272 | [NL80211_ATTR_STA_FLAGS2] = { |
| 273 | .len = sizeof(struct nl80211_sta_flag_update), |
| 274 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 284 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_DATA_LEN }, |
| 290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 327 | .len = NL80211_HT_CAPABILITY_LEN |
| 328 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 347 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 350 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 352 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 353 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 354 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
| 355 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 }, |
| 356 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 357 | }; |
| 358 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 359 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 360 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 361 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 362 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 363 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 364 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 365 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 366 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 367 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 368 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 369 | }; |
| 370 | |
| 371 | /* policy for the key default flags */ |
| 372 | static const struct nla_policy |
| 373 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 374 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 375 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 376 | }; |
| 377 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 378 | /* policy for WoWLAN attributes */ |
| 379 | static const struct nla_policy |
| 380 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 381 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 382 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 383 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 384 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 385 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 386 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 387 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 388 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 389 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 390 | }; |
| 391 | |
| 392 | static const struct nla_policy |
| 393 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 394 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 395 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 396 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 397 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 398 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 399 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 400 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 401 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 402 | }, |
| 403 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 404 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 405 | }, |
| 406 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 407 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 408 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 409 | }; |
| 410 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 411 | /* policy for coalesce rule attributes */ |
| 412 | static const struct nla_policy |
| 413 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 414 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 415 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 416 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 417 | }; |
| 418 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 419 | /* policy for GTK rekey offload attributes */ |
| 420 | static const struct nla_policy |
| 421 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 422 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 423 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 424 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 425 | }; |
| 426 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 427 | static const struct nla_policy |
| 428 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 429 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 430 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 431 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 432 | }; |
| 433 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 434 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 435 | struct netlink_callback *cb, |
| 436 | struct cfg80211_registered_device **rdev, |
| 437 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 438 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 439 | int err; |
| 440 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 441 | rtnl_lock(); |
| 442 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 443 | if (!cb->args[0]) { |
| 444 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 445 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 446 | nl80211_policy); |
| 447 | if (err) |
| 448 | goto out_unlock; |
| 449 | |
| 450 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 451 | nl80211_fam.attrbuf); |
| 452 | if (IS_ERR(*wdev)) { |
| 453 | err = PTR_ERR(*wdev); |
| 454 | goto out_unlock; |
| 455 | } |
| 456 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
| 457 | cb->args[0] = (*rdev)->wiphy_idx; |
| 458 | cb->args[1] = (*wdev)->identifier; |
| 459 | } else { |
| 460 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); |
| 461 | struct wireless_dev *tmp; |
| 462 | |
| 463 | if (!wiphy) { |
| 464 | err = -ENODEV; |
| 465 | goto out_unlock; |
| 466 | } |
| 467 | *rdev = wiphy_to_dev(wiphy); |
| 468 | *wdev = NULL; |
| 469 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 470 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 471 | if (tmp->identifier == cb->args[1]) { |
| 472 | *wdev = tmp; |
| 473 | break; |
| 474 | } |
| 475 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 476 | |
| 477 | if (!*wdev) { |
| 478 | err = -ENODEV; |
| 479 | goto out_unlock; |
| 480 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 483 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 484 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 485 | rtnl_unlock(); |
| 486 | return err; |
| 487 | } |
| 488 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 489 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 490 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 491 | rtnl_unlock(); |
| 492 | } |
| 493 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 494 | /* IE validation */ |
| 495 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 496 | { |
| 497 | const u8 *pos; |
| 498 | int len; |
| 499 | |
| 500 | if (!attr) |
| 501 | return true; |
| 502 | |
| 503 | pos = nla_data(attr); |
| 504 | len = nla_len(attr); |
| 505 | |
| 506 | while (len) { |
| 507 | u8 elemlen; |
| 508 | |
| 509 | if (len < 2) |
| 510 | return false; |
| 511 | len -= 2; |
| 512 | |
| 513 | elemlen = pos[1]; |
| 514 | if (elemlen > len) |
| 515 | return false; |
| 516 | |
| 517 | len -= elemlen; |
| 518 | pos += 2 + elemlen; |
| 519 | } |
| 520 | |
| 521 | return true; |
| 522 | } |
| 523 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 524 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 525 | 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] | 526 | int flags, u8 cmd) |
| 527 | { |
| 528 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 529 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 530 | } |
| 531 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 532 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 533 | struct ieee80211_channel *chan, |
| 534 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 535 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 536 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 537 | chan->center_freq)) |
| 538 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 539 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 540 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 541 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 542 | goto nla_put_failure; |
| 543 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 544 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 545 | goto nla_put_failure; |
| 546 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 547 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 548 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 549 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 550 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 551 | goto nla_put_failure; |
| 552 | if (large) { |
| 553 | u32 time; |
| 554 | |
| 555 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 556 | |
| 557 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 558 | chan->dfs_state)) |
| 559 | goto nla_put_failure; |
| 560 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 561 | time)) |
| 562 | goto nla_put_failure; |
| 563 | } |
| 564 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 565 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 566 | if (large) { |
| 567 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 568 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 569 | goto nla_put_failure; |
| 570 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 571 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 572 | goto nla_put_failure; |
| 573 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 574 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 575 | goto nla_put_failure; |
| 576 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 577 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 578 | goto nla_put_failure; |
| 579 | } |
| 580 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 581 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 582 | DBM_TO_MBM(chan->max_power))) |
| 583 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 584 | |
| 585 | return 0; |
| 586 | |
| 587 | nla_put_failure: |
| 588 | return -ENOBUFS; |
| 589 | } |
| 590 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 591 | /* netlink command implementations */ |
| 592 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 593 | struct key_parse { |
| 594 | struct key_params p; |
| 595 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 596 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 597 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 598 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 599 | }; |
| 600 | |
| 601 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 602 | { |
| 603 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 604 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 605 | nl80211_key_policy); |
| 606 | if (err) |
| 607 | return err; |
| 608 | |
| 609 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 610 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 611 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 612 | if (k->def) { |
| 613 | k->def_uni = true; |
| 614 | k->def_multi = true; |
| 615 | } |
| 616 | if (k->defmgmt) |
| 617 | k->def_multi = true; |
| 618 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 619 | if (tb[NL80211_KEY_IDX]) |
| 620 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 621 | |
| 622 | if (tb[NL80211_KEY_DATA]) { |
| 623 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 624 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 625 | } |
| 626 | |
| 627 | if (tb[NL80211_KEY_SEQ]) { |
| 628 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 629 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 630 | } |
| 631 | |
| 632 | if (tb[NL80211_KEY_CIPHER]) |
| 633 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 634 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 635 | if (tb[NL80211_KEY_TYPE]) { |
| 636 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 637 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 638 | return -EINVAL; |
| 639 | } |
| 640 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 641 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 642 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 643 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 644 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 645 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 646 | if (err) |
| 647 | return err; |
| 648 | |
| 649 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 650 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 651 | } |
| 652 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 657 | { |
| 658 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 659 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 660 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 661 | } |
| 662 | |
| 663 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 664 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 665 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 666 | } |
| 667 | |
| 668 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 669 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 670 | |
| 671 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 672 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 673 | |
| 674 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 675 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 676 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 677 | if (k->def) { |
| 678 | k->def_uni = true; |
| 679 | k->def_multi = true; |
| 680 | } |
| 681 | if (k->defmgmt) |
| 682 | k->def_multi = true; |
| 683 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 684 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 685 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 686 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 687 | return -EINVAL; |
| 688 | } |
| 689 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 690 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 691 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 692 | int err = nla_parse_nested( |
| 693 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 694 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 695 | nl80211_key_default_policy); |
| 696 | if (err) |
| 697 | return err; |
| 698 | |
| 699 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 700 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 701 | } |
| 702 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 707 | { |
| 708 | int err; |
| 709 | |
| 710 | memset(k, 0, sizeof(*k)); |
| 711 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 712 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 713 | |
| 714 | if (info->attrs[NL80211_ATTR_KEY]) |
| 715 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 716 | else |
| 717 | err = nl80211_parse_key_old(info, k); |
| 718 | |
| 719 | if (err) |
| 720 | return err; |
| 721 | |
| 722 | if (k->def && k->defmgmt) |
| 723 | return -EINVAL; |
| 724 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 725 | if (k->defmgmt) { |
| 726 | if (k->def_uni || !k->def_multi) |
| 727 | return -EINVAL; |
| 728 | } |
| 729 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 730 | if (k->idx != -1) { |
| 731 | if (k->defmgmt) { |
| 732 | if (k->idx < 4 || k->idx > 5) |
| 733 | return -EINVAL; |
| 734 | } else if (k->def) { |
| 735 | if (k->idx < 0 || k->idx > 3) |
| 736 | return -EINVAL; |
| 737 | } else { |
| 738 | if (k->idx < 0 || k->idx > 5) |
| 739 | return -EINVAL; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 746 | static struct cfg80211_cached_keys * |
| 747 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 748 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 749 | { |
| 750 | struct key_parse parse; |
| 751 | struct nlattr *key; |
| 752 | struct cfg80211_cached_keys *result; |
| 753 | int rem, err, def = 0; |
| 754 | |
| 755 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 756 | if (!result) |
| 757 | return ERR_PTR(-ENOMEM); |
| 758 | |
| 759 | result->def = -1; |
| 760 | result->defmgmt = -1; |
| 761 | |
| 762 | nla_for_each_nested(key, keys, rem) { |
| 763 | memset(&parse, 0, sizeof(parse)); |
| 764 | parse.idx = -1; |
| 765 | |
| 766 | err = nl80211_parse_key_new(key, &parse); |
| 767 | if (err) |
| 768 | goto error; |
| 769 | err = -EINVAL; |
| 770 | if (!parse.p.key) |
| 771 | goto error; |
| 772 | if (parse.idx < 0 || parse.idx > 4) |
| 773 | goto error; |
| 774 | if (parse.def) { |
| 775 | if (def) |
| 776 | goto error; |
| 777 | def = 1; |
| 778 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 779 | if (!parse.def_uni || !parse.def_multi) |
| 780 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 781 | } else if (parse.defmgmt) |
| 782 | goto error; |
| 783 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 784 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 785 | if (err) |
| 786 | goto error; |
| 787 | result->params[parse.idx].cipher = parse.p.cipher; |
| 788 | result->params[parse.idx].key_len = parse.p.key_len; |
| 789 | result->params[parse.idx].key = result->data[parse.idx]; |
| 790 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 791 | |
| 792 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 793 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 794 | if (no_ht) |
| 795 | *no_ht = true; |
| 796 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | return result; |
| 800 | error: |
| 801 | kfree(result); |
| 802 | return ERR_PTR(err); |
| 803 | } |
| 804 | |
| 805 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 806 | { |
| 807 | ASSERT_WDEV_LOCK(wdev); |
| 808 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 809 | switch (wdev->iftype) { |
| 810 | case NL80211_IFTYPE_AP: |
| 811 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 812 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 813 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 814 | break; |
| 815 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 816 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 817 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 818 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 819 | return -ENOLINK; |
| 820 | break; |
| 821 | default: |
| 822 | return -EINVAL; |
| 823 | } |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 828 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 829 | { |
| 830 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 831 | int i; |
| 832 | |
| 833 | if (!nl_modes) |
| 834 | goto nla_put_failure; |
| 835 | |
| 836 | i = 0; |
| 837 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 838 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 839 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 840 | ifmodes >>= 1; |
| 841 | i++; |
| 842 | } |
| 843 | |
| 844 | nla_nest_end(msg, nl_modes); |
| 845 | return 0; |
| 846 | |
| 847 | nla_put_failure: |
| 848 | return -ENOBUFS; |
| 849 | } |
| 850 | |
| 851 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 852 | struct sk_buff *msg, |
| 853 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 854 | { |
| 855 | struct nlattr *nl_combis; |
| 856 | int i, j; |
| 857 | |
| 858 | nl_combis = nla_nest_start(msg, |
| 859 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 860 | if (!nl_combis) |
| 861 | goto nla_put_failure; |
| 862 | |
| 863 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 864 | const struct ieee80211_iface_combination *c; |
| 865 | struct nlattr *nl_combi, *nl_limits; |
| 866 | |
| 867 | c = &wiphy->iface_combinations[i]; |
| 868 | |
| 869 | nl_combi = nla_nest_start(msg, i + 1); |
| 870 | if (!nl_combi) |
| 871 | goto nla_put_failure; |
| 872 | |
| 873 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 874 | if (!nl_limits) |
| 875 | goto nla_put_failure; |
| 876 | |
| 877 | for (j = 0; j < c->n_limits; j++) { |
| 878 | struct nlattr *nl_limit; |
| 879 | |
| 880 | nl_limit = nla_nest_start(msg, j + 1); |
| 881 | if (!nl_limit) |
| 882 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 883 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 884 | c->limits[j].max)) |
| 885 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 886 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 887 | c->limits[j].types)) |
| 888 | goto nla_put_failure; |
| 889 | nla_nest_end(msg, nl_limit); |
| 890 | } |
| 891 | |
| 892 | nla_nest_end(msg, nl_limits); |
| 893 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 894 | if (c->beacon_int_infra_match && |
| 895 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 896 | goto nla_put_failure; |
| 897 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 898 | c->num_different_channels) || |
| 899 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 900 | c->max_interfaces)) |
| 901 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 902 | if (large && |
| 903 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 904 | c->radar_detect_widths)) |
| 905 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 906 | |
| 907 | nla_nest_end(msg, nl_combi); |
| 908 | } |
| 909 | |
| 910 | nla_nest_end(msg, nl_combis); |
| 911 | |
| 912 | return 0; |
| 913 | nla_put_failure: |
| 914 | return -ENOBUFS; |
| 915 | } |
| 916 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 917 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 918 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 919 | struct sk_buff *msg) |
| 920 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 921 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 922 | struct nlattr *nl_tcp; |
| 923 | |
| 924 | if (!tcp) |
| 925 | return 0; |
| 926 | |
| 927 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 928 | if (!nl_tcp) |
| 929 | return -ENOBUFS; |
| 930 | |
| 931 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 932 | tcp->data_payload_max)) |
| 933 | return -ENOBUFS; |
| 934 | |
| 935 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 936 | tcp->data_payload_max)) |
| 937 | return -ENOBUFS; |
| 938 | |
| 939 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 940 | return -ENOBUFS; |
| 941 | |
| 942 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 943 | sizeof(*tcp->tok), tcp->tok)) |
| 944 | return -ENOBUFS; |
| 945 | |
| 946 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 947 | tcp->data_interval_max)) |
| 948 | return -ENOBUFS; |
| 949 | |
| 950 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 951 | tcp->wake_payload_max)) |
| 952 | return -ENOBUFS; |
| 953 | |
| 954 | nla_nest_end(msg, nl_tcp); |
| 955 | return 0; |
| 956 | } |
| 957 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 958 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 959 | struct cfg80211_registered_device *dev, |
| 960 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 961 | { |
| 962 | struct nlattr *nl_wowlan; |
| 963 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 964 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 965 | return 0; |
| 966 | |
| 967 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 968 | if (!nl_wowlan) |
| 969 | return -ENOBUFS; |
| 970 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 971 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 972 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 973 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 974 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 975 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 976 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 977 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 978 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 979 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 980 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 981 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 982 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 983 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 984 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 985 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 986 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 987 | return -ENOBUFS; |
| 988 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 989 | if (dev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 990 | struct nl80211_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 991 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 992 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 993 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 994 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 995 | }; |
| 996 | |
| 997 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 998 | sizeof(pat), &pat)) |
| 999 | return -ENOBUFS; |
| 1000 | } |
| 1001 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1002 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 1003 | return -ENOBUFS; |
| 1004 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1005 | nla_nest_end(msg, nl_wowlan); |
| 1006 | |
| 1007 | return 0; |
| 1008 | } |
| 1009 | #endif |
| 1010 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1011 | static int nl80211_send_coalesce(struct sk_buff *msg, |
| 1012 | struct cfg80211_registered_device *dev) |
| 1013 | { |
| 1014 | struct nl80211_coalesce_rule_support rule; |
| 1015 | |
| 1016 | if (!dev->wiphy.coalesce) |
| 1017 | return 0; |
| 1018 | |
| 1019 | rule.max_rules = dev->wiphy.coalesce->n_rules; |
| 1020 | rule.max_delay = dev->wiphy.coalesce->max_delay; |
| 1021 | rule.pat.max_patterns = dev->wiphy.coalesce->n_patterns; |
| 1022 | rule.pat.min_pattern_len = dev->wiphy.coalesce->pattern_min_len; |
| 1023 | rule.pat.max_pattern_len = dev->wiphy.coalesce->pattern_max_len; |
| 1024 | rule.pat.max_pkt_offset = dev->wiphy.coalesce->max_pkt_offset; |
| 1025 | |
| 1026 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1027 | return -ENOBUFS; |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1032 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1033 | struct ieee80211_supported_band *sband) |
| 1034 | { |
| 1035 | struct nlattr *nl_rates, *nl_rate; |
| 1036 | struct ieee80211_rate *rate; |
| 1037 | int i; |
| 1038 | |
| 1039 | /* add HT info */ |
| 1040 | if (sband->ht_cap.ht_supported && |
| 1041 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1042 | sizeof(sband->ht_cap.mcs), |
| 1043 | &sband->ht_cap.mcs) || |
| 1044 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1045 | sband->ht_cap.cap) || |
| 1046 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1047 | sband->ht_cap.ampdu_factor) || |
| 1048 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1049 | sband->ht_cap.ampdu_density))) |
| 1050 | return -ENOBUFS; |
| 1051 | |
| 1052 | /* add VHT info */ |
| 1053 | if (sband->vht_cap.vht_supported && |
| 1054 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1055 | sizeof(sband->vht_cap.vht_mcs), |
| 1056 | &sband->vht_cap.vht_mcs) || |
| 1057 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1058 | sband->vht_cap.cap))) |
| 1059 | return -ENOBUFS; |
| 1060 | |
| 1061 | /* add bitrates */ |
| 1062 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1063 | if (!nl_rates) |
| 1064 | return -ENOBUFS; |
| 1065 | |
| 1066 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1067 | nl_rate = nla_nest_start(msg, i); |
| 1068 | if (!nl_rate) |
| 1069 | return -ENOBUFS; |
| 1070 | |
| 1071 | rate = &sband->bitrates[i]; |
| 1072 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1073 | rate->bitrate)) |
| 1074 | return -ENOBUFS; |
| 1075 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1076 | nla_put_flag(msg, |
| 1077 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1078 | return -ENOBUFS; |
| 1079 | |
| 1080 | nla_nest_end(msg, nl_rate); |
| 1081 | } |
| 1082 | |
| 1083 | nla_nest_end(msg, nl_rates); |
| 1084 | |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
| 1088 | static int |
| 1089 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1090 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1091 | { |
| 1092 | u16 stypes; |
| 1093 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1094 | enum nl80211_iftype ift; |
| 1095 | int i; |
| 1096 | |
| 1097 | if (!mgmt_stypes) |
| 1098 | return 0; |
| 1099 | |
| 1100 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1101 | if (!nl_ifs) |
| 1102 | return -ENOBUFS; |
| 1103 | |
| 1104 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1105 | nl_ftypes = nla_nest_start(msg, ift); |
| 1106 | if (!nl_ftypes) |
| 1107 | return -ENOBUFS; |
| 1108 | i = 0; |
| 1109 | stypes = mgmt_stypes[ift].tx; |
| 1110 | while (stypes) { |
| 1111 | if ((stypes & 1) && |
| 1112 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1113 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1114 | return -ENOBUFS; |
| 1115 | stypes >>= 1; |
| 1116 | i++; |
| 1117 | } |
| 1118 | nla_nest_end(msg, nl_ftypes); |
| 1119 | } |
| 1120 | |
| 1121 | nla_nest_end(msg, nl_ifs); |
| 1122 | |
| 1123 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1124 | if (!nl_ifs) |
| 1125 | return -ENOBUFS; |
| 1126 | |
| 1127 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1128 | nl_ftypes = nla_nest_start(msg, ift); |
| 1129 | if (!nl_ftypes) |
| 1130 | return -ENOBUFS; |
| 1131 | i = 0; |
| 1132 | stypes = mgmt_stypes[ift].rx; |
| 1133 | while (stypes) { |
| 1134 | if ((stypes & 1) && |
| 1135 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1136 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1137 | return -ENOBUFS; |
| 1138 | stypes >>= 1; |
| 1139 | i++; |
| 1140 | } |
| 1141 | nla_nest_end(msg, nl_ftypes); |
| 1142 | } |
| 1143 | nla_nest_end(msg, nl_ifs); |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1148 | struct nl80211_dump_wiphy_state { |
| 1149 | s64 filter_wiphy; |
| 1150 | long start; |
| 1151 | long split_start, band_start, chan_start; |
| 1152 | bool split; |
| 1153 | }; |
| 1154 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1155 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1156 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1157 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1158 | { |
| 1159 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1160 | struct nlattr *nl_bands, *nl_band; |
| 1161 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1162 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1163 | enum ieee80211_band band; |
| 1164 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1165 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1166 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1167 | dev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1168 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1169 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1170 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1171 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1172 | return -ENOBUFS; |
| 1173 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1174 | if (WARN_ON(!state)) |
| 1175 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1176 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1178 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1179 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1180 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1181 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1182 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1183 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1184 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1185 | case 0: |
| 1186 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1187 | dev->wiphy.retry_short) || |
| 1188 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1189 | dev->wiphy.retry_long) || |
| 1190 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1191 | dev->wiphy.frag_threshold) || |
| 1192 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1193 | dev->wiphy.rts_threshold) || |
| 1194 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1195 | dev->wiphy.coverage_class) || |
| 1196 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1197 | dev->wiphy.max_scan_ssids) || |
| 1198 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1199 | dev->wiphy.max_sched_scan_ssids) || |
| 1200 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1201 | dev->wiphy.max_scan_ie_len) || |
| 1202 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1203 | dev->wiphy.max_sched_scan_ie_len) || |
| 1204 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1205 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1206 | goto nla_put_failure; |
| 1207 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1208 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1209 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1210 | goto nla_put_failure; |
| 1211 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1212 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1213 | goto nla_put_failure; |
| 1214 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1215 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1216 | goto nla_put_failure; |
| 1217 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1218 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1219 | goto nla_put_failure; |
| 1220 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1221 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1222 | goto nla_put_failure; |
| 1223 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1224 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1225 | goto nla_put_failure; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1226 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1227 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1228 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1229 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1230 | state->split_start++; |
| 1231 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1232 | break; |
| 1233 | case 1: |
| 1234 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1235 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1236 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1237 | goto nla_put_failure; |
| 1238 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1239 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1240 | dev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1241 | goto nla_put_failure; |
| 1242 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1243 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 1244 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1245 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1246 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1247 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1248 | dev->wiphy.available_antennas_tx) || |
| 1249 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1250 | dev->wiphy.available_antennas_rx)) |
| 1251 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1252 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1253 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1254 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1255 | dev->wiphy.probe_resp_offload)) |
| 1256 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1257 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1258 | if ((dev->wiphy.available_antennas_tx || |
| 1259 | dev->wiphy.available_antennas_rx) && |
| 1260 | dev->ops->get_antenna) { |
| 1261 | u32 tx_ant = 0, rx_ant = 0; |
| 1262 | int res; |
| 1263 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1264 | if (!res) { |
| 1265 | if (nla_put_u32(msg, |
| 1266 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1267 | tx_ant) || |
| 1268 | nla_put_u32(msg, |
| 1269 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1270 | rx_ant)) |
| 1271 | goto nla_put_failure; |
| 1272 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1275 | state->split_start++; |
| 1276 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1277 | break; |
| 1278 | case 2: |
| 1279 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1280 | dev->wiphy.interface_modes)) |
| 1281 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1282 | state->split_start++; |
| 1283 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1284 | break; |
| 1285 | case 3: |
| 1286 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1287 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1288 | goto nla_put_failure; |
| 1289 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1290 | for (band = state->band_start; |
| 1291 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | struct ieee80211_supported_band *sband; |
| 1293 | |
| 1294 | sband = dev->wiphy.bands[band]; |
| 1295 | |
| 1296 | if (!sband) |
| 1297 | continue; |
| 1298 | |
| 1299 | nl_band = nla_nest_start(msg, band); |
| 1300 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1301 | goto nla_put_failure; |
| 1302 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1303 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | case 0: |
| 1305 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1306 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1307 | state->chan_start++; |
| 1308 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1309 | break; |
| 1310 | default: |
| 1311 | /* add frequencies */ |
| 1312 | nl_freqs = nla_nest_start( |
| 1313 | msg, NL80211_BAND_ATTR_FREQS); |
| 1314 | if (!nl_freqs) |
| 1315 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1316 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1317 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | i < sband->n_channels; |
| 1319 | i++) { |
| 1320 | nl_freq = nla_nest_start(msg, i); |
| 1321 | if (!nl_freq) |
| 1322 | goto nla_put_failure; |
| 1323 | |
| 1324 | chan = &sband->channels[i]; |
| 1325 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1326 | if (nl80211_msg_put_channel( |
| 1327 | msg, chan, |
| 1328 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | goto nla_put_failure; |
| 1330 | |
| 1331 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1332 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1333 | break; |
| 1334 | } |
| 1335 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1336 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1337 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1338 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1339 | nla_nest_end(msg, nl_freqs); |
| 1340 | } |
| 1341 | |
| 1342 | nla_nest_end(msg, nl_band); |
| 1343 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1344 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1346 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1347 | band--; |
| 1348 | break; |
| 1349 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1350 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1352 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1353 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1354 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1356 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1357 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1358 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1359 | if (state->band_start == 0 && state->chan_start == 0) |
| 1360 | state->split_start++; |
| 1361 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1362 | break; |
| 1363 | case 4: |
| 1364 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1365 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1366 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | |
| 1368 | i = 0; |
| 1369 | #define CMD(op, n) \ |
| 1370 | do { \ |
| 1371 | if (dev->ops->op) { \ |
| 1372 | i++; \ |
| 1373 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1374 | goto nla_put_failure; \ |
| 1375 | } \ |
| 1376 | } while (0) |
| 1377 | |
| 1378 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1379 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1380 | CMD(add_key, NEW_KEY); |
| 1381 | CMD(start_ap, START_AP); |
| 1382 | CMD(add_station, NEW_STATION); |
| 1383 | CMD(add_mpath, NEW_MPATH); |
| 1384 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1385 | CMD(change_bss, SET_BSS); |
| 1386 | CMD(auth, AUTHENTICATE); |
| 1387 | CMD(assoc, ASSOCIATE); |
| 1388 | CMD(deauth, DEAUTHENTICATE); |
| 1389 | CMD(disassoc, DISASSOCIATE); |
| 1390 | CMD(join_ibss, JOIN_IBSS); |
| 1391 | CMD(join_mesh, JOIN_MESH); |
| 1392 | CMD(set_pmksa, SET_PMKSA); |
| 1393 | CMD(del_pmksa, DEL_PMKSA); |
| 1394 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1395 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1396 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1397 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1398 | CMD(mgmt_tx, FRAME); |
| 1399 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1400 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1401 | i++; |
| 1402 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1403 | goto nla_put_failure; |
| 1404 | } |
| 1405 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1406 | dev->ops->join_mesh) { |
| 1407 | i++; |
| 1408 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1409 | goto nla_put_failure; |
| 1410 | } |
| 1411 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1412 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1413 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1414 | CMD(tdls_oper, TDLS_OPER); |
| 1415 | } |
| 1416 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1417 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1418 | CMD(probe_client, PROBE_CLIENT); |
| 1419 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1420 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1421 | i++; |
| 1422 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1423 | goto nla_put_failure; |
| 1424 | } |
| 1425 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1426 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1427 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1428 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1429 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1430 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
| 1431 | CMD(channel_switch, CHANNEL_SWITCH); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1432 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1433 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1434 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1435 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1436 | #endif |
| 1437 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1438 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1439 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1440 | if (dev->ops->connect || dev->ops->auth) { |
| 1441 | i++; |
| 1442 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1443 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1444 | } |
| 1445 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1447 | i++; |
| 1448 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1449 | goto nla_put_failure; |
| 1450 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1451 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1452 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1453 | state->split_start++; |
| 1454 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1455 | break; |
| 1456 | case 5: |
| 1457 | if (dev->ops->remain_on_channel && |
| 1458 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1459 | nla_put_u32(msg, |
| 1460 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1461 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1462 | goto nla_put_failure; |
| 1463 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1464 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1465 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1466 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1467 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1468 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1469 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1470 | state->split_start++; |
| 1471 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1472 | break; |
| 1473 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1474 | #ifdef CONFIG_PM |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1475 | if (nl80211_send_wowlan(msg, dev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1477 | state->split_start++; |
| 1478 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1479 | break; |
| 1480 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1481 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | #endif |
| 1483 | case 7: |
| 1484 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1485 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1486 | goto nla_put_failure; |
| 1487 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1488 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, |
| 1489 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1490 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1491 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1492 | state->split_start++; |
| 1493 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1494 | break; |
| 1495 | case 8: |
| 1496 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1497 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1498 | dev->wiphy.ap_sme_capa)) |
| 1499 | goto nla_put_failure; |
| 1500 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1501 | features = dev->wiphy.features; |
| 1502 | /* |
| 1503 | * We can only add the per-channel limit information if the |
| 1504 | * dump is split, otherwise it makes it too big. Therefore |
| 1505 | * only advertise it in that case. |
| 1506 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1507 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1508 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1509 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1510 | goto nla_put_failure; |
| 1511 | |
| 1512 | if (dev->wiphy.ht_capa_mod_mask && |
| 1513 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1514 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1515 | dev->wiphy.ht_capa_mod_mask)) |
| 1516 | goto nla_put_failure; |
| 1517 | |
| 1518 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1519 | dev->wiphy.max_acl_mac_addrs && |
| 1520 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1521 | dev->wiphy.max_acl_mac_addrs)) |
| 1522 | goto nla_put_failure; |
| 1523 | |
| 1524 | /* |
| 1525 | * Any information below this point is only available to |
| 1526 | * applications that can deal with it being split. This |
| 1527 | * helps ensure that newly added capabilities don't break |
| 1528 | * older tools by overrunning their buffers. |
| 1529 | * |
| 1530 | * We still increment split_start so that in the split |
| 1531 | * case we'll continue with more data in the next round, |
| 1532 | * but break unconditionally so unsplit data stops here. |
| 1533 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1534 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | break; |
| 1536 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1537 | if (dev->wiphy.extended_capabilities && |
| 1538 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1539 | dev->wiphy.extended_capabilities_len, |
| 1540 | dev->wiphy.extended_capabilities) || |
| 1541 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1542 | dev->wiphy.extended_capabilities_len, |
| 1543 | dev->wiphy.extended_capabilities_mask))) |
| 1544 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1545 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1546 | if (dev->wiphy.vht_capa_mod_mask && |
| 1547 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1548 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1549 | dev->wiphy.vht_capa_mod_mask)) |
| 1550 | goto nla_put_failure; |
| 1551 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1552 | state->split_start++; |
| 1553 | break; |
| 1554 | case 10: |
| 1555 | if (nl80211_send_coalesce(msg, dev)) |
| 1556 | goto nla_put_failure; |
| 1557 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1558 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1559 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1560 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1561 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1562 | return genlmsg_end(msg, hdr); |
| 1563 | |
| 1564 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1565 | genlmsg_cancel(msg, hdr); |
| 1566 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1567 | } |
| 1568 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1569 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1570 | struct netlink_callback *cb, |
| 1571 | struct nl80211_dump_wiphy_state *state) |
| 1572 | { |
| 1573 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1574 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1575 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1576 | /* ignore parse errors for backward compatibility */ |
| 1577 | if (ret) |
| 1578 | return 0; |
| 1579 | |
| 1580 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1581 | if (tb[NL80211_ATTR_WIPHY]) |
| 1582 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1583 | if (tb[NL80211_ATTR_WDEV]) |
| 1584 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1585 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1586 | struct net_device *netdev; |
| 1587 | struct cfg80211_registered_device *rdev; |
| 1588 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1589 | |
| 1590 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
| 1591 | if (!netdev) |
| 1592 | return -ENODEV; |
| 1593 | if (netdev->ieee80211_ptr) { |
| 1594 | rdev = wiphy_to_dev( |
| 1595 | netdev->ieee80211_ptr->wiphy); |
| 1596 | state->filter_wiphy = rdev->wiphy_idx; |
| 1597 | } |
| 1598 | dev_put(netdev); |
| 1599 | } |
| 1600 | |
| 1601 | return 0; |
| 1602 | } |
| 1603 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1604 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1605 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1606 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1607 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1608 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1609 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1610 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1611 | if (!state) { |
| 1612 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1613 | if (!state) { |
| 1614 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1615 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1616 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1617 | state->filter_wiphy = -1; |
| 1618 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1619 | if (ret) { |
| 1620 | kfree(state); |
| 1621 | rtnl_unlock(); |
| 1622 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1623 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1624 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1625 | } |
| 1626 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1627 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1628 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1629 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1630 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1631 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1632 | if (state->filter_wiphy != -1 && |
| 1633 | state->filter_wiphy != dev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1634 | continue; |
| 1635 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1636 | do { |
| 1637 | ret = nl80211_send_wiphy(dev, skb, |
| 1638 | NETLINK_CB(cb->skb).portid, |
| 1639 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1640 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1641 | if (ret < 0) { |
| 1642 | /* |
| 1643 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1644 | * or EMSGSIZE returned), this SKB is still |
| 1645 | * empty (so it's not too big because another |
| 1646 | * wiphy dataset is already in the skb) and |
| 1647 | * we've not tried to adjust the dump allocation |
| 1648 | * yet ... then adjust the alloc size to be |
| 1649 | * bigger, and return 1 but with the empty skb. |
| 1650 | * This results in an empty message being RX'ed |
| 1651 | * in userspace, but that is ignored. |
| 1652 | * |
| 1653 | * We can then retry with the larger buffer. |
| 1654 | */ |
| 1655 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1656 | !skb->len && |
| 1657 | cb->min_dump_alloc < 4096) { |
| 1658 | cb->min_dump_alloc = 4096; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1659 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1660 | return 1; |
| 1661 | } |
| 1662 | idx--; |
| 1663 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1664 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1665 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1666 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1667 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1668 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1669 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1670 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1671 | |
| 1672 | return skb->len; |
| 1673 | } |
| 1674 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1675 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1676 | { |
| 1677 | kfree((void *)cb->args[0]); |
| 1678 | return 0; |
| 1679 | } |
| 1680 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1681 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1682 | { |
| 1683 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1684 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1685 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1686 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1687 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1688 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1689 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1690 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1691 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1692 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1693 | nlmsg_free(msg); |
| 1694 | return -ENOBUFS; |
| 1695 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1696 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1697 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1700 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1701 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1702 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1703 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1704 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1705 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1706 | }; |
| 1707 | |
| 1708 | static int parse_txq_params(struct nlattr *tb[], |
| 1709 | struct ieee80211_txq_params *txq_params) |
| 1710 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1711 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1712 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1713 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1714 | return -EINVAL; |
| 1715 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1716 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1717 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1718 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1719 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1720 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1721 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1722 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1723 | return -EINVAL; |
| 1724 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1725 | return 0; |
| 1726 | } |
| 1727 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1728 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1729 | { |
| 1730 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1731 | * You can only set the channel explicitly for WDS interfaces, |
| 1732 | * all others have their channel managed via their respective |
| 1733 | * "establish a connection" command (connect, join, ...) |
| 1734 | * |
| 1735 | * For AP/GO and mesh mode, the channel can be set with the |
| 1736 | * channel userspace API, but is only stored and passed to the |
| 1737 | * low-level driver when the AP starts or the mesh is joined. |
| 1738 | * This is for backward compatibility, userspace can also give |
| 1739 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1740 | * |
| 1741 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1742 | * whatever else is going on, so they have their own special |
| 1743 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1744 | */ |
| 1745 | return !wdev || |
| 1746 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1747 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1748 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1749 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1752 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1753 | struct genl_info *info, |
| 1754 | struct cfg80211_chan_def *chandef) |
| 1755 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1756 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1757 | |
| 1758 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1759 | return -EINVAL; |
| 1760 | |
| 1761 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1762 | |
| 1763 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1764 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1765 | chandef->center_freq1 = control_freq; |
| 1766 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1767 | |
| 1768 | /* Primary channel not allowed */ |
| 1769 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1770 | return -EINVAL; |
| 1771 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1772 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1773 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1774 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1775 | chantype = nla_get_u32( |
| 1776 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1777 | |
| 1778 | switch (chantype) { |
| 1779 | case NL80211_CHAN_NO_HT: |
| 1780 | case NL80211_CHAN_HT20: |
| 1781 | case NL80211_CHAN_HT40PLUS: |
| 1782 | case NL80211_CHAN_HT40MINUS: |
| 1783 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1784 | chantype); |
| 1785 | break; |
| 1786 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1787 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1788 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1789 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1790 | chandef->width = |
| 1791 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1792 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1793 | chandef->center_freq1 = |
| 1794 | nla_get_u32( |
| 1795 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1796 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1797 | chandef->center_freq2 = |
| 1798 | nla_get_u32( |
| 1799 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1800 | } |
| 1801 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1802 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1803 | return -EINVAL; |
| 1804 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1805 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1806 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1807 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1808 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1809 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1810 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1811 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1812 | return -EINVAL; |
| 1813 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1814 | return 0; |
| 1815 | } |
| 1816 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1817 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1818 | struct wireless_dev *wdev, |
| 1819 | struct genl_info *info) |
| 1820 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1821 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1822 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1823 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1824 | |
| 1825 | if (wdev) |
| 1826 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1827 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1828 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1829 | return -EOPNOTSUPP; |
| 1830 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1831 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1832 | if (result) |
| 1833 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1834 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1835 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1836 | case NL80211_IFTYPE_AP: |
| 1837 | case NL80211_IFTYPE_P2P_GO: |
| 1838 | if (wdev->beacon_interval) { |
| 1839 | result = -EBUSY; |
| 1840 | break; |
| 1841 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1842 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1843 | result = -EINVAL; |
| 1844 | break; |
| 1845 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1846 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1847 | result = 0; |
| 1848 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1849 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1850 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1851 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1852 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1853 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1854 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1855 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1856 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1857 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1858 | |
| 1859 | return result; |
| 1860 | } |
| 1861 | |
| 1862 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1863 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1865 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1866 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1867 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1870 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1871 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1872 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1873 | struct net_device *dev = info->user_ptr[1]; |
| 1874 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1875 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1876 | |
| 1877 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1878 | return -EINVAL; |
| 1879 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1880 | if (netif_running(dev)) |
| 1881 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1882 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1883 | if (!rdev->ops->set_wds_peer) |
| 1884 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1885 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1886 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1887 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1888 | |
| 1889 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1890 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1894 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1895 | { |
| 1896 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1897 | struct net_device *netdev = NULL; |
| 1898 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1899 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1900 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1901 | u32 changed; |
| 1902 | u8 retry_short = 0, retry_long = 0; |
| 1903 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1904 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1905 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1906 | ASSERT_RTNL(); |
| 1907 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1908 | /* |
| 1909 | * Try to find the wiphy and netdev. Normally this |
| 1910 | * function shouldn't need the netdev, but this is |
| 1911 | * done for backward compatibility -- previously |
| 1912 | * setting the channel was done per wiphy, but now |
| 1913 | * it is per netdev. Previous userland like hostapd |
| 1914 | * also passed a netdev to set_wiphy, so that it is |
| 1915 | * possible to let that go to the right netdev! |
| 1916 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1917 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1918 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1919 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1920 | |
| 1921 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1922 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1923 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1924 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1925 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1926 | } |
| 1927 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1928 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1929 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1930 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1931 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1932 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1933 | wdev = NULL; |
| 1934 | netdev = NULL; |
| 1935 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1936 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1937 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1938 | |
| 1939 | /* |
| 1940 | * end workaround code, by now the rdev is available |
| 1941 | * and locked, and wdev may or may not be NULL. |
| 1942 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1943 | |
| 1944 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1945 | result = cfg80211_dev_rename( |
| 1946 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1947 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1948 | if (result) |
| 1949 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1950 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1951 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1952 | struct ieee80211_txq_params txq_params; |
| 1953 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1954 | |
| 1955 | if (!rdev->ops->set_txq_params) { |
| 1956 | result = -EOPNOTSUPP; |
| 1957 | goto bad_res; |
| 1958 | } |
| 1959 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1960 | if (!netdev) { |
| 1961 | result = -EINVAL; |
| 1962 | goto bad_res; |
| 1963 | } |
| 1964 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1965 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1966 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1967 | result = -EINVAL; |
| 1968 | goto bad_res; |
| 1969 | } |
| 1970 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1971 | if (!netif_running(netdev)) { |
| 1972 | result = -ENETDOWN; |
| 1973 | goto bad_res; |
| 1974 | } |
| 1975 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1976 | nla_for_each_nested(nl_txq_params, |
| 1977 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1978 | rem_txq_params) { |
| 1979 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1980 | nla_data(nl_txq_params), |
| 1981 | nla_len(nl_txq_params), |
| 1982 | txq_params_policy); |
| 1983 | result = parse_txq_params(tb, &txq_params); |
| 1984 | if (result) |
| 1985 | goto bad_res; |
| 1986 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1987 | result = rdev_set_txq_params(rdev, netdev, |
| 1988 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1989 | if (result) |
| 1990 | goto bad_res; |
| 1991 | } |
| 1992 | } |
| 1993 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1994 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1995 | result = __nl80211_set_channel(rdev, |
| 1996 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1997 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1998 | if (result) |
| 1999 | goto bad_res; |
| 2000 | } |
| 2001 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2002 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2003 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2004 | enum nl80211_tx_power_setting type; |
| 2005 | int idx, mbm = 0; |
| 2006 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2007 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2008 | txp_wdev = NULL; |
| 2009 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2010 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 2011 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2012 | goto bad_res; |
| 2013 | } |
| 2014 | |
| 2015 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2016 | type = nla_get_u32(info->attrs[idx]); |
| 2017 | |
| 2018 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 2019 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 2020 | result = -EINVAL; |
| 2021 | goto bad_res; |
| 2022 | } |
| 2023 | |
| 2024 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2025 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2026 | mbm = nla_get_u32(info->attrs[idx]); |
| 2027 | } |
| 2028 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2029 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2030 | if (result) |
| 2031 | goto bad_res; |
| 2032 | } |
| 2033 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2034 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2035 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2036 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2037 | if ((!rdev->wiphy.available_antennas_tx && |
| 2038 | !rdev->wiphy.available_antennas_rx) || |
| 2039 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2040 | result = -EOPNOTSUPP; |
| 2041 | goto bad_res; |
| 2042 | } |
| 2043 | |
| 2044 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2045 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2046 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2047 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2048 | * available antenna masks, except for the "all" mask */ |
| 2049 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 2050 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2051 | result = -EINVAL; |
| 2052 | goto bad_res; |
| 2053 | } |
| 2054 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2055 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2056 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2057 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2058 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2059 | if (result) |
| 2060 | goto bad_res; |
| 2061 | } |
| 2062 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2063 | changed = 0; |
| 2064 | |
| 2065 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2066 | retry_short = nla_get_u8( |
| 2067 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 2068 | if (retry_short == 0) { |
| 2069 | result = -EINVAL; |
| 2070 | goto bad_res; |
| 2071 | } |
| 2072 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2073 | } |
| 2074 | |
| 2075 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2076 | retry_long = nla_get_u8( |
| 2077 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2078 | if (retry_long == 0) { |
| 2079 | result = -EINVAL; |
| 2080 | goto bad_res; |
| 2081 | } |
| 2082 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2083 | } |
| 2084 | |
| 2085 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2086 | frag_threshold = nla_get_u32( |
| 2087 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2088 | if (frag_threshold < 256) { |
| 2089 | result = -EINVAL; |
| 2090 | goto bad_res; |
| 2091 | } |
| 2092 | if (frag_threshold != (u32) -1) { |
| 2093 | /* |
| 2094 | * Fragments (apart from the last one) are required to |
| 2095 | * have even length. Make the fragmentation code |
| 2096 | * simpler by stripping LSB should someone try to use |
| 2097 | * odd threshold value. |
| 2098 | */ |
| 2099 | frag_threshold &= ~0x1; |
| 2100 | } |
| 2101 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2102 | } |
| 2103 | |
| 2104 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2105 | rts_threshold = nla_get_u32( |
| 2106 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2107 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2108 | } |
| 2109 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2110 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2111 | coverage_class = nla_get_u8( |
| 2112 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2113 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2114 | } |
| 2115 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2116 | if (changed) { |
| 2117 | u8 old_retry_short, old_retry_long; |
| 2118 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2119 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2120 | |
| 2121 | if (!rdev->ops->set_wiphy_params) { |
| 2122 | result = -EOPNOTSUPP; |
| 2123 | goto bad_res; |
| 2124 | } |
| 2125 | |
| 2126 | old_retry_short = rdev->wiphy.retry_short; |
| 2127 | old_retry_long = rdev->wiphy.retry_long; |
| 2128 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2129 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2130 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2131 | |
| 2132 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2133 | rdev->wiphy.retry_short = retry_short; |
| 2134 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2135 | rdev->wiphy.retry_long = retry_long; |
| 2136 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2137 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2138 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2139 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2140 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2141 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2142 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2143 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2144 | if (result) { |
| 2145 | rdev->wiphy.retry_short = old_retry_short; |
| 2146 | rdev->wiphy.retry_long = old_retry_long; |
| 2147 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2148 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2149 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2150 | } |
| 2151 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2152 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2153 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2154 | if (netdev) |
| 2155 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2156 | return result; |
| 2157 | } |
| 2158 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2159 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2160 | { |
| 2161 | return (u64)wdev->identifier | |
| 2162 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2163 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2164 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2165 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2166 | struct cfg80211_chan_def *chandef) |
| 2167 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2168 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2169 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2170 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2171 | chandef->chan->center_freq)) |
| 2172 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2173 | switch (chandef->width) { |
| 2174 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2175 | case NL80211_CHAN_WIDTH_20: |
| 2176 | case NL80211_CHAN_WIDTH_40: |
| 2177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2178 | cfg80211_get_chandef_type(chandef))) |
| 2179 | return -ENOBUFS; |
| 2180 | break; |
| 2181 | default: |
| 2182 | break; |
| 2183 | } |
| 2184 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2185 | return -ENOBUFS; |
| 2186 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2187 | return -ENOBUFS; |
| 2188 | if (chandef->center_freq2 && |
| 2189 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2190 | return -ENOBUFS; |
| 2191 | return 0; |
| 2192 | } |
| 2193 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2194 | 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] | 2195 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2196 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2197 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2198 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2199 | void *hdr; |
| 2200 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2201 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2202 | if (!hdr) |
| 2203 | return -1; |
| 2204 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2205 | if (dev && |
| 2206 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2207 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2208 | goto nla_put_failure; |
| 2209 | |
| 2210 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2211 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2212 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2213 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2214 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2215 | rdev->devlist_generation ^ |
| 2216 | (cfg80211_rdev_list_generation << 2))) |
| 2217 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2218 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2219 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2220 | int ret; |
| 2221 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2222 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2223 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2224 | if (ret == 0) { |
| 2225 | if (nl80211_send_chandef(msg, &chandef)) |
| 2226 | goto nla_put_failure; |
| 2227 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2228 | } |
| 2229 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2230 | if (wdev->ssid_len) { |
| 2231 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2232 | goto nla_put_failure; |
| 2233 | } |
| 2234 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2235 | return genlmsg_end(msg, hdr); |
| 2236 | |
| 2237 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2238 | genlmsg_cancel(msg, hdr); |
| 2239 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2243 | { |
| 2244 | int wp_idx = 0; |
| 2245 | int if_idx = 0; |
| 2246 | int wp_start = cb->args[0]; |
| 2247 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2248 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2249 | struct wireless_dev *wdev; |
| 2250 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2251 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2252 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2253 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2254 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2255 | if (wp_idx < wp_start) { |
| 2256 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2257 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2258 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2259 | if_idx = 0; |
| 2260 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2261 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2262 | if (if_idx < if_start) { |
| 2263 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2264 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2265 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2266 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2267 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2268 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2269 | goto out; |
| 2270 | } |
| 2271 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2272 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2273 | |
| 2274 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2275 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2276 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2277 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2278 | |
| 2279 | cb->args[0] = wp_idx; |
| 2280 | cb->args[1] = if_idx; |
| 2281 | |
| 2282 | return skb->len; |
| 2283 | } |
| 2284 | |
| 2285 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2286 | { |
| 2287 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2288 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2289 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2290 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2291 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2292 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2293 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2294 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2295 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2296 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2297 | nlmsg_free(msg); |
| 2298 | return -ENOBUFS; |
| 2299 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2300 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2301 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2302 | } |
| 2303 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2304 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2305 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2306 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2307 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2308 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2309 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2310 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2311 | }; |
| 2312 | |
| 2313 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2314 | { |
| 2315 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2316 | int flag; |
| 2317 | |
| 2318 | *mntrflags = 0; |
| 2319 | |
| 2320 | if (!nla) |
| 2321 | return -EINVAL; |
| 2322 | |
| 2323 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2324 | nla, mntr_flags_policy)) |
| 2325 | return -EINVAL; |
| 2326 | |
| 2327 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2328 | if (flags[flag]) |
| 2329 | *mntrflags |= (1<<flag); |
| 2330 | |
| 2331 | return 0; |
| 2332 | } |
| 2333 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2334 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2335 | struct net_device *netdev, u8 use_4addr, |
| 2336 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2337 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2338 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2339 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2340 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2341 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2342 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2343 | |
| 2344 | switch (iftype) { |
| 2345 | case NL80211_IFTYPE_AP_VLAN: |
| 2346 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2347 | return 0; |
| 2348 | break; |
| 2349 | case NL80211_IFTYPE_STATION: |
| 2350 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2351 | return 0; |
| 2352 | break; |
| 2353 | default: |
| 2354 | break; |
| 2355 | } |
| 2356 | |
| 2357 | return -EOPNOTSUPP; |
| 2358 | } |
| 2359 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2360 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2361 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2363 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2364 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2365 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2366 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2367 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2368 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2369 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2370 | memset(¶ms, 0, sizeof(params)); |
| 2371 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2372 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2373 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2374 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2375 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2376 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2377 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2378 | if (ntype > NL80211_IFTYPE_MAX) |
| 2379 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2380 | } |
| 2381 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2382 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2383 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2384 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2385 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2386 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2387 | if (netif_running(dev)) |
| 2388 | return -EBUSY; |
| 2389 | |
| 2390 | wdev_lock(wdev); |
| 2391 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2392 | IEEE80211_MAX_MESH_ID_LEN); |
| 2393 | wdev->mesh_id_up_len = |
| 2394 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2395 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2396 | wdev->mesh_id_up_len); |
| 2397 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2398 | } |
| 2399 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2400 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2401 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2402 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2403 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2404 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2405 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2406 | } else { |
| 2407 | params.use_4addr = -1; |
| 2408 | } |
| 2409 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2410 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2411 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2412 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2413 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2414 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2415 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2416 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2417 | |
| 2418 | flags = &_flags; |
| 2419 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2420 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2421 | |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2422 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2423 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2424 | return -EOPNOTSUPP; |
| 2425 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2426 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2427 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2428 | else |
| 2429 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2430 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2431 | if (!err && params.use_4addr != -1) |
| 2432 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2433 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2434 | return err; |
| 2435 | } |
| 2436 | |
| 2437 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2438 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2440 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2441 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2442 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2443 | int err; |
| 2444 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2445 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2446 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2447 | memset(¶ms, 0, sizeof(params)); |
| 2448 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2449 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2450 | return -EINVAL; |
| 2451 | |
| 2452 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2453 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2454 | if (type > NL80211_IFTYPE_MAX) |
| 2455 | return -EINVAL; |
| 2456 | } |
| 2457 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2458 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2459 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2460 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2461 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2462 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2463 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2464 | ETH_ALEN); |
| 2465 | if (!is_valid_ether_addr(params.macaddr)) |
| 2466 | return -EADDRNOTAVAIL; |
| 2467 | } |
| 2468 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2469 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2470 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2471 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2472 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2473 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2474 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2475 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2476 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2477 | if (!msg) |
| 2478 | return -ENOMEM; |
| 2479 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2480 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2481 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2482 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2483 | |
| 2484 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2485 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2486 | return -EOPNOTSUPP; |
| 2487 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2488 | wdev = rdev_add_virtual_intf(rdev, |
| 2489 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2490 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2491 | if (IS_ERR(wdev)) { |
| 2492 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2493 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2494 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2495 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2496 | switch (type) { |
| 2497 | case NL80211_IFTYPE_MESH_POINT: |
| 2498 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2499 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2500 | wdev_lock(wdev); |
| 2501 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2502 | IEEE80211_MAX_MESH_ID_LEN); |
| 2503 | wdev->mesh_id_up_len = |
| 2504 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2505 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2506 | wdev->mesh_id_up_len); |
| 2507 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2508 | break; |
| 2509 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2510 | /* |
| 2511 | * P2P Device doesn't have a netdev, so doesn't go |
| 2512 | * through the netdev notifier and must be added here |
| 2513 | */ |
| 2514 | mutex_init(&wdev->mtx); |
| 2515 | INIT_LIST_HEAD(&wdev->event_list); |
| 2516 | spin_lock_init(&wdev->event_lock); |
| 2517 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2518 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2519 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2520 | wdev->identifier = ++rdev->wdev_id; |
| 2521 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2522 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2523 | break; |
| 2524 | default: |
| 2525 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2526 | } |
| 2527 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2528 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2529 | rdev, wdev) < 0) { |
| 2530 | nlmsg_free(msg); |
| 2531 | return -ENOBUFS; |
| 2532 | } |
| 2533 | |
| 2534 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2538 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2540 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2541 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2542 | if (!rdev->ops->del_virtual_intf) |
| 2543 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2544 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2545 | /* |
| 2546 | * If we remove a wireless device without a netdev then clear |
| 2547 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2548 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2549 | * since the wdev has been freed, unlike with a netdev where |
| 2550 | * we need the dev_put() for the netdev to really be freed. |
| 2551 | */ |
| 2552 | if (!wdev->netdev) |
| 2553 | info->user_ptr[1] = NULL; |
| 2554 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2555 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2556 | } |
| 2557 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2558 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2559 | { |
| 2560 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2561 | struct net_device *dev = info->user_ptr[1]; |
| 2562 | u16 noack_map; |
| 2563 | |
| 2564 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2565 | return -EINVAL; |
| 2566 | |
| 2567 | if (!rdev->ops->set_noack_map) |
| 2568 | return -EOPNOTSUPP; |
| 2569 | |
| 2570 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2571 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2572 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2573 | } |
| 2574 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2575 | struct get_key_cookie { |
| 2576 | struct sk_buff *msg; |
| 2577 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2578 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2579 | }; |
| 2580 | |
| 2581 | static void get_key_callback(void *c, struct key_params *params) |
| 2582 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2583 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2584 | struct get_key_cookie *cookie = c; |
| 2585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2586 | if ((params->key && |
| 2587 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2588 | params->key_len, params->key)) || |
| 2589 | (params->seq && |
| 2590 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2591 | params->seq_len, params->seq)) || |
| 2592 | (params->cipher && |
| 2593 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2594 | params->cipher))) |
| 2595 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2596 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2597 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2598 | if (!key) |
| 2599 | goto nla_put_failure; |
| 2600 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2601 | if ((params->key && |
| 2602 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2603 | params->key_len, params->key)) || |
| 2604 | (params->seq && |
| 2605 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2606 | params->seq_len, params->seq)) || |
| 2607 | (params->cipher && |
| 2608 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2609 | params->cipher))) |
| 2610 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2611 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2612 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2613 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2614 | |
| 2615 | nla_nest_end(cookie->msg, key); |
| 2616 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2617 | return; |
| 2618 | nla_put_failure: |
| 2619 | cookie->error = 1; |
| 2620 | } |
| 2621 | |
| 2622 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2623 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2625 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2626 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2627 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2628 | const u8 *mac_addr = NULL; |
| 2629 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2630 | struct get_key_cookie cookie = { |
| 2631 | .error = 0, |
| 2632 | }; |
| 2633 | void *hdr; |
| 2634 | struct sk_buff *msg; |
| 2635 | |
| 2636 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2637 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2638 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2639 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2640 | return -EINVAL; |
| 2641 | |
| 2642 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2643 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2644 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2645 | pairwise = !!mac_addr; |
| 2646 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2647 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2648 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2649 | return -EINVAL; |
| 2650 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2651 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2652 | return -EINVAL; |
| 2653 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2654 | } |
| 2655 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2656 | if (!rdev->ops->get_key) |
| 2657 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2658 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2659 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2660 | if (!msg) |
| 2661 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2662 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2663 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2664 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2665 | if (IS_ERR(hdr)) |
| 2666 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2667 | |
| 2668 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2669 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2670 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2671 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2672 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2673 | goto nla_put_failure; |
| 2674 | if (mac_addr && |
| 2675 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2676 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2677 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2678 | if (pairwise && mac_addr && |
| 2679 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2680 | return -ENOENT; |
| 2681 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2682 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2683 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2684 | |
| 2685 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2686 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2687 | |
| 2688 | if (cookie.error) |
| 2689 | goto nla_put_failure; |
| 2690 | |
| 2691 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2692 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2693 | |
| 2694 | nla_put_failure: |
| 2695 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2696 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2697 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2698 | return err; |
| 2699 | } |
| 2700 | |
| 2701 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2702 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2704 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2705 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2706 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2707 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2708 | err = nl80211_parse_key(info, &key); |
| 2709 | if (err) |
| 2710 | return err; |
| 2711 | |
| 2712 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2713 | return -EINVAL; |
| 2714 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2715 | /* only support setting default key */ |
| 2716 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2717 | return -EINVAL; |
| 2718 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2719 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2720 | |
| 2721 | if (key.def) { |
| 2722 | if (!rdev->ops->set_default_key) { |
| 2723 | err = -EOPNOTSUPP; |
| 2724 | goto out; |
| 2725 | } |
| 2726 | |
| 2727 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2728 | if (err) |
| 2729 | goto out; |
| 2730 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2731 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2732 | key.def_uni, key.def_multi); |
| 2733 | |
| 2734 | if (err) |
| 2735 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2736 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2737 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2738 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2739 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2740 | } else { |
| 2741 | if (key.def_uni || !key.def_multi) { |
| 2742 | err = -EINVAL; |
| 2743 | goto out; |
| 2744 | } |
| 2745 | |
| 2746 | if (!rdev->ops->set_default_mgmt_key) { |
| 2747 | err = -EOPNOTSUPP; |
| 2748 | goto out; |
| 2749 | } |
| 2750 | |
| 2751 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2752 | if (err) |
| 2753 | goto out; |
| 2754 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2755 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2756 | if (err) |
| 2757 | goto out; |
| 2758 | |
| 2759 | #ifdef CONFIG_CFG80211_WEXT |
| 2760 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2761 | #endif |
| 2762 | } |
| 2763 | |
| 2764 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2765 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2766 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2767 | return err; |
| 2768 | } |
| 2769 | |
| 2770 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2771 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2773 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2774 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2775 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2776 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2777 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2778 | err = nl80211_parse_key(info, &key); |
| 2779 | if (err) |
| 2780 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2781 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2782 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2783 | return -EINVAL; |
| 2784 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2785 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2786 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2787 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2788 | if (key.type == -1) { |
| 2789 | if (mac_addr) |
| 2790 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2791 | else |
| 2792 | key.type = NL80211_KEYTYPE_GROUP; |
| 2793 | } |
| 2794 | |
| 2795 | /* for now */ |
| 2796 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2797 | key.type != NL80211_KEYTYPE_GROUP) |
| 2798 | return -EINVAL; |
| 2799 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2800 | if (!rdev->ops->add_key) |
| 2801 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2802 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2803 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2804 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2805 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2806 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2807 | |
| 2808 | wdev_lock(dev->ieee80211_ptr); |
| 2809 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2810 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2811 | err = rdev_add_key(rdev, dev, key.idx, |
| 2812 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2813 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2814 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2815 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2816 | return err; |
| 2817 | } |
| 2818 | |
| 2819 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2820 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2821 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2822 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2823 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2824 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2825 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2827 | err = nl80211_parse_key(info, &key); |
| 2828 | if (err) |
| 2829 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2830 | |
| 2831 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2832 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2833 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2834 | if (key.type == -1) { |
| 2835 | if (mac_addr) |
| 2836 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2837 | else |
| 2838 | key.type = NL80211_KEYTYPE_GROUP; |
| 2839 | } |
| 2840 | |
| 2841 | /* for now */ |
| 2842 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2843 | key.type != NL80211_KEYTYPE_GROUP) |
| 2844 | return -EINVAL; |
| 2845 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2846 | if (!rdev->ops->del_key) |
| 2847 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2848 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2849 | wdev_lock(dev->ieee80211_ptr); |
| 2850 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2851 | |
| 2852 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2853 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2854 | err = -ENOENT; |
| 2855 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2856 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2857 | err = rdev_del_key(rdev, dev, key.idx, |
| 2858 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2859 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2860 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2861 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2862 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2863 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2864 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2865 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2866 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2867 | } |
| 2868 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2869 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2870 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2871 | return err; |
| 2872 | } |
| 2873 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2874 | /* This function returns an error or the number of nested attributes */ |
| 2875 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2876 | { |
| 2877 | struct nlattr *attr; |
| 2878 | int n_entries = 0, tmp; |
| 2879 | |
| 2880 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2881 | if (nla_len(attr) != ETH_ALEN) |
| 2882 | return -EINVAL; |
| 2883 | |
| 2884 | n_entries++; |
| 2885 | } |
| 2886 | |
| 2887 | return n_entries; |
| 2888 | } |
| 2889 | |
| 2890 | /* |
| 2891 | * This function parses ACL information and allocates memory for ACL data. |
| 2892 | * On successful return, the calling function is responsible to free the |
| 2893 | * ACL buffer returned by this function. |
| 2894 | */ |
| 2895 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2896 | struct genl_info *info) |
| 2897 | { |
| 2898 | enum nl80211_acl_policy acl_policy; |
| 2899 | struct nlattr *attr; |
| 2900 | struct cfg80211_acl_data *acl; |
| 2901 | int i = 0, n_entries, tmp; |
| 2902 | |
| 2903 | if (!wiphy->max_acl_mac_addrs) |
| 2904 | return ERR_PTR(-EOPNOTSUPP); |
| 2905 | |
| 2906 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2907 | return ERR_PTR(-EINVAL); |
| 2908 | |
| 2909 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2910 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2911 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2912 | return ERR_PTR(-EINVAL); |
| 2913 | |
| 2914 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2915 | return ERR_PTR(-EINVAL); |
| 2916 | |
| 2917 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2918 | if (n_entries < 0) |
| 2919 | return ERR_PTR(n_entries); |
| 2920 | |
| 2921 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2922 | return ERR_PTR(-ENOTSUPP); |
| 2923 | |
| 2924 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2925 | GFP_KERNEL); |
| 2926 | if (!acl) |
| 2927 | return ERR_PTR(-ENOMEM); |
| 2928 | |
| 2929 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2930 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2931 | i++; |
| 2932 | } |
| 2933 | |
| 2934 | acl->n_acl_entries = n_entries; |
| 2935 | acl->acl_policy = acl_policy; |
| 2936 | |
| 2937 | return acl; |
| 2938 | } |
| 2939 | |
| 2940 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2941 | { |
| 2942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2943 | struct net_device *dev = info->user_ptr[1]; |
| 2944 | struct cfg80211_acl_data *acl; |
| 2945 | int err; |
| 2946 | |
| 2947 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2948 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2949 | return -EOPNOTSUPP; |
| 2950 | |
| 2951 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2952 | return -EINVAL; |
| 2953 | |
| 2954 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2955 | if (IS_ERR(acl)) |
| 2956 | return PTR_ERR(acl); |
| 2957 | |
| 2958 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2959 | |
| 2960 | kfree(acl); |
| 2961 | |
| 2962 | return err; |
| 2963 | } |
| 2964 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2965 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2966 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2967 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2968 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2969 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2970 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2971 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2972 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2973 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2974 | return -EINVAL; |
| 2975 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2976 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2977 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2978 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2979 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2980 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2981 | if (!bcn->head_len) |
| 2982 | return -EINVAL; |
| 2983 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2984 | } |
| 2985 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2986 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2987 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2988 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2989 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2990 | } |
| 2991 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2992 | if (!haveinfo) |
| 2993 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2994 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2995 | if (attrs[NL80211_ATTR_IE]) { |
| 2996 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 2997 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2998 | } |
| 2999 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3000 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3001 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3002 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3003 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3004 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3005 | } |
| 3006 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3007 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3008 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3009 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3010 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3011 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3012 | } |
| 3013 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3014 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3015 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3016 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3017 | } |
| 3018 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3019 | return 0; |
| 3020 | } |
| 3021 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3022 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3023 | struct cfg80211_ap_settings *params) |
| 3024 | { |
| 3025 | struct wireless_dev *wdev; |
| 3026 | bool ret = false; |
| 3027 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3028 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3029 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3030 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3031 | continue; |
| 3032 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3033 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3034 | continue; |
| 3035 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3036 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3037 | ret = true; |
| 3038 | break; |
| 3039 | } |
| 3040 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3041 | return ret; |
| 3042 | } |
| 3043 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3044 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3045 | enum nl80211_auth_type auth_type, |
| 3046 | enum nl80211_commands cmd) |
| 3047 | { |
| 3048 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3049 | return false; |
| 3050 | |
| 3051 | switch (cmd) { |
| 3052 | case NL80211_CMD_AUTHENTICATE: |
| 3053 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3054 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3055 | return false; |
| 3056 | return true; |
| 3057 | case NL80211_CMD_CONNECT: |
| 3058 | case NL80211_CMD_START_AP: |
| 3059 | /* SAE not supported yet */ |
| 3060 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3061 | return false; |
| 3062 | return true; |
| 3063 | default: |
| 3064 | return false; |
| 3065 | } |
| 3066 | } |
| 3067 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3068 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3069 | { |
| 3070 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3071 | struct net_device *dev = info->user_ptr[1]; |
| 3072 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3073 | struct cfg80211_ap_settings params; |
| 3074 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3075 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3076 | |
| 3077 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3078 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3079 | return -EOPNOTSUPP; |
| 3080 | |
| 3081 | if (!rdev->ops->start_ap) |
| 3082 | return -EOPNOTSUPP; |
| 3083 | |
| 3084 | if (wdev->beacon_interval) |
| 3085 | return -EALREADY; |
| 3086 | |
| 3087 | memset(¶ms, 0, sizeof(params)); |
| 3088 | |
| 3089 | /* these are required for START_AP */ |
| 3090 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3091 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3092 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3093 | return -EINVAL; |
| 3094 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3095 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3096 | if (err) |
| 3097 | return err; |
| 3098 | |
| 3099 | params.beacon_interval = |
| 3100 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3101 | params.dtim_period = |
| 3102 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3103 | |
| 3104 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3105 | if (err) |
| 3106 | return err; |
| 3107 | |
| 3108 | /* |
| 3109 | * In theory, some of these attributes should be required here |
| 3110 | * but since they were not used when the command was originally |
| 3111 | * added, keep them optional for old user space programs to let |
| 3112 | * them continue to work with drivers that do not need the |
| 3113 | * additional information -- drivers must check! |
| 3114 | */ |
| 3115 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3116 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3117 | params.ssid_len = |
| 3118 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3119 | if (params.ssid_len == 0 || |
| 3120 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3121 | return -EINVAL; |
| 3122 | } |
| 3123 | |
| 3124 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3125 | params.hidden_ssid = nla_get_u32( |
| 3126 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3127 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3128 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3129 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3130 | return -EINVAL; |
| 3131 | } |
| 3132 | |
| 3133 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3134 | |
| 3135 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3136 | params.auth_type = nla_get_u32( |
| 3137 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3138 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3139 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3140 | return -EINVAL; |
| 3141 | } else |
| 3142 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3143 | |
| 3144 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3145 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3146 | if (err) |
| 3147 | return err; |
| 3148 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3149 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3150 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3151 | return -EOPNOTSUPP; |
| 3152 | params.inactivity_timeout = nla_get_u16( |
| 3153 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3154 | } |
| 3155 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3156 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3157 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3158 | return -EINVAL; |
| 3159 | params.p2p_ctwindow = |
| 3160 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3161 | if (params.p2p_ctwindow > 127) |
| 3162 | return -EINVAL; |
| 3163 | if (params.p2p_ctwindow != 0 && |
| 3164 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3165 | return -EINVAL; |
| 3166 | } |
| 3167 | |
| 3168 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3169 | u8 tmp; |
| 3170 | |
| 3171 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3172 | return -EINVAL; |
| 3173 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3174 | if (tmp > 1) |
| 3175 | return -EINVAL; |
| 3176 | params.p2p_opp_ps = tmp; |
| 3177 | if (params.p2p_opp_ps != 0 && |
| 3178 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3179 | return -EINVAL; |
| 3180 | } |
| 3181 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3182 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3183 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3184 | if (err) |
| 3185 | return err; |
| 3186 | } else if (wdev->preset_chandef.chan) { |
| 3187 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3188 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3189 | return -EINVAL; |
| 3190 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3191 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3192 | return -EINVAL; |
| 3193 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3194 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3195 | if (err < 0) |
| 3196 | return err; |
| 3197 | if (err) { |
| 3198 | radar_detect_width = BIT(params.chandef.width); |
| 3199 | params.radar_required = true; |
| 3200 | } |
| 3201 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3202 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3203 | params.chandef.chan, |
| 3204 | CHAN_MODE_SHARED, |
| 3205 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3206 | if (err) |
| 3207 | return err; |
| 3208 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3209 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3210 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3211 | if (IS_ERR(params.acl)) |
| 3212 | return PTR_ERR(params.acl); |
| 3213 | } |
| 3214 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3215 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3216 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3217 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3218 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3219 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3220 | wdev->ssid_len = params.ssid_len; |
| 3221 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3222 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3223 | |
| 3224 | kfree(params.acl); |
| 3225 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3226 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3227 | } |
| 3228 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3229 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3230 | { |
| 3231 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3232 | struct net_device *dev = info->user_ptr[1]; |
| 3233 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3234 | struct cfg80211_beacon_data params; |
| 3235 | int err; |
| 3236 | |
| 3237 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3238 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3239 | return -EOPNOTSUPP; |
| 3240 | |
| 3241 | if (!rdev->ops->change_beacon) |
| 3242 | return -EOPNOTSUPP; |
| 3243 | |
| 3244 | if (!wdev->beacon_interval) |
| 3245 | return -EINVAL; |
| 3246 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3247 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3248 | if (err) |
| 3249 | return err; |
| 3250 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3251 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | 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] | 3255 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3257 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3258 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3259 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3260 | } |
| 3261 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3262 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3263 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3264 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3265 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3266 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3267 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3268 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3269 | }; |
| 3270 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3271 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3272 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3273 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3274 | { |
| 3275 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3276 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3277 | int flag; |
| 3278 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3279 | /* |
| 3280 | * Try parsing the new attribute first so userspace |
| 3281 | * can specify both for older kernels. |
| 3282 | */ |
| 3283 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3284 | if (nla) { |
| 3285 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3286 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3287 | sta_flags = nla_data(nla); |
| 3288 | params->sta_flags_mask = sta_flags->mask; |
| 3289 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3290 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3291 | if ((params->sta_flags_mask | |
| 3292 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3293 | return -EINVAL; |
| 3294 | return 0; |
| 3295 | } |
| 3296 | |
| 3297 | /* if present, parse the old attribute */ |
| 3298 | |
| 3299 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3300 | if (!nla) |
| 3301 | return 0; |
| 3302 | |
| 3303 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3304 | nla, sta_flags_policy)) |
| 3305 | return -EINVAL; |
| 3306 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3307 | /* |
| 3308 | * Only allow certain flags for interface types so that |
| 3309 | * other attributes are silently ignored. Remember that |
| 3310 | * this is backward compatibility code with old userspace |
| 3311 | * and shouldn't be hit in other cases anyway. |
| 3312 | */ |
| 3313 | switch (iftype) { |
| 3314 | case NL80211_IFTYPE_AP: |
| 3315 | case NL80211_IFTYPE_AP_VLAN: |
| 3316 | case NL80211_IFTYPE_P2P_GO: |
| 3317 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3318 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3319 | BIT(NL80211_STA_FLAG_WME) | |
| 3320 | BIT(NL80211_STA_FLAG_MFP); |
| 3321 | break; |
| 3322 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3323 | case NL80211_IFTYPE_STATION: |
| 3324 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3325 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3326 | break; |
| 3327 | case NL80211_IFTYPE_MESH_POINT: |
| 3328 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3329 | BIT(NL80211_STA_FLAG_MFP) | |
| 3330 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3331 | default: |
| 3332 | return -EINVAL; |
| 3333 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3334 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3335 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3336 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3337 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3338 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3339 | /* no longer support new API additions in old API */ |
| 3340 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3341 | return -EINVAL; |
| 3342 | } |
| 3343 | } |
| 3344 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3345 | return 0; |
| 3346 | } |
| 3347 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3348 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3349 | int attr) |
| 3350 | { |
| 3351 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3352 | u32 bitrate; |
| 3353 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3354 | |
| 3355 | rate = nla_nest_start(msg, attr); |
| 3356 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3357 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3358 | |
| 3359 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3360 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3361 | /* report 16-bit bitrate only if we can */ |
| 3362 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3363 | if (bitrate > 0 && |
| 3364 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3365 | return false; |
| 3366 | if (bitrate_compat > 0 && |
| 3367 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3368 | return false; |
| 3369 | |
| 3370 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3371 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3372 | return false; |
| 3373 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3374 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3375 | return false; |
| 3376 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3377 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3378 | return false; |
| 3379 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3380 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3381 | return false; |
| 3382 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3383 | return false; |
| 3384 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3385 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3386 | return false; |
| 3387 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3388 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3389 | return false; |
| 3390 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3391 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3392 | return false; |
| 3393 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3394 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3395 | return false; |
| 3396 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3397 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3398 | return false; |
| 3399 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3400 | |
| 3401 | nla_nest_end(msg, rate); |
| 3402 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3403 | } |
| 3404 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3405 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3406 | int id) |
| 3407 | { |
| 3408 | void *attr; |
| 3409 | int i = 0; |
| 3410 | |
| 3411 | if (!mask) |
| 3412 | return true; |
| 3413 | |
| 3414 | attr = nla_nest_start(msg, id); |
| 3415 | if (!attr) |
| 3416 | return false; |
| 3417 | |
| 3418 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3419 | if (!(mask & BIT(i))) |
| 3420 | continue; |
| 3421 | |
| 3422 | if (nla_put_u8(msg, i, signal[i])) |
| 3423 | return false; |
| 3424 | } |
| 3425 | |
| 3426 | nla_nest_end(msg, attr); |
| 3427 | |
| 3428 | return true; |
| 3429 | } |
| 3430 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3431 | 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] | 3432 | int flags, |
| 3433 | struct cfg80211_registered_device *rdev, |
| 3434 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3435 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3436 | { |
| 3437 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3438 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3439 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3440 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3441 | if (!hdr) |
| 3442 | return -1; |
| 3443 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3444 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3445 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3446 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3447 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3448 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3449 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3450 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3451 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3452 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3453 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3454 | sinfo->connected_time)) |
| 3455 | goto nla_put_failure; |
| 3456 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3457 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3458 | sinfo->inactive_time)) |
| 3459 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3460 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3461 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3462 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3463 | (u32)sinfo->rx_bytes)) |
| 3464 | goto nla_put_failure; |
| 3465 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3466 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3467 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3468 | (u32)sinfo->tx_bytes)) |
| 3469 | goto nla_put_failure; |
| 3470 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3471 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3472 | sinfo->rx_bytes)) |
| 3473 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3474 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3475 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3476 | sinfo->tx_bytes)) |
| 3477 | goto nla_put_failure; |
| 3478 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3479 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3480 | goto nla_put_failure; |
| 3481 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3482 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3483 | goto nla_put_failure; |
| 3484 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3485 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3486 | sinfo->plink_state)) |
| 3487 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3488 | switch (rdev->wiphy.signal_type) { |
| 3489 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3490 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3491 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3492 | sinfo->signal)) |
| 3493 | goto nla_put_failure; |
| 3494 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3495 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3496 | sinfo->signal_avg)) |
| 3497 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3498 | break; |
| 3499 | default: |
| 3500 | break; |
| 3501 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3502 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3503 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3504 | sinfo->chain_signal, |
| 3505 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3506 | goto nla_put_failure; |
| 3507 | } |
| 3508 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3509 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3510 | sinfo->chain_signal_avg, |
| 3511 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3512 | goto nla_put_failure; |
| 3513 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3514 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3515 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3516 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3517 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3518 | } |
| 3519 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3520 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3521 | NL80211_STA_INFO_RX_BITRATE)) |
| 3522 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3523 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3524 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3525 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3526 | sinfo->rx_packets)) |
| 3527 | goto nla_put_failure; |
| 3528 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3529 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3530 | sinfo->tx_packets)) |
| 3531 | goto nla_put_failure; |
| 3532 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3533 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3534 | sinfo->tx_retries)) |
| 3535 | goto nla_put_failure; |
| 3536 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3537 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3538 | sinfo->tx_failed)) |
| 3539 | goto nla_put_failure; |
| 3540 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3541 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3542 | sinfo->beacon_loss_count)) |
| 3543 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3544 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3545 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3546 | sinfo->local_pm)) |
| 3547 | goto nla_put_failure; |
| 3548 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3549 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3550 | sinfo->peer_pm)) |
| 3551 | goto nla_put_failure; |
| 3552 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3553 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3554 | sinfo->nonpeer_pm)) |
| 3555 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3556 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3557 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3558 | if (!bss_param) |
| 3559 | goto nla_put_failure; |
| 3560 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3561 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3562 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3563 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3564 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3565 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3566 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3567 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3568 | sinfo->bss_param.dtim_period) || |
| 3569 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3570 | sinfo->bss_param.beacon_interval)) |
| 3571 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3572 | |
| 3573 | nla_nest_end(msg, bss_param); |
| 3574 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3575 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3576 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3577 | sizeof(struct nl80211_sta_flag_update), |
| 3578 | &sinfo->sta_flags)) |
| 3579 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3580 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3581 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3582 | sinfo->t_offset)) |
| 3583 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3584 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3586 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3587 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3588 | sinfo->assoc_req_ies)) |
| 3589 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3590 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3591 | return genlmsg_end(msg, hdr); |
| 3592 | |
| 3593 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3594 | genlmsg_cancel(msg, hdr); |
| 3595 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3596 | } |
| 3597 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3598 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3599 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3600 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3601 | struct station_info sinfo; |
| 3602 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3603 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3604 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3605 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3606 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3607 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3608 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3609 | if (err) |
| 3610 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3611 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3612 | if (!wdev->netdev) { |
| 3613 | err = -EINVAL; |
| 3614 | goto out_err; |
| 3615 | } |
| 3616 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3617 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3618 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3619 | goto out_err; |
| 3620 | } |
| 3621 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3622 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3623 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3624 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3625 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3626 | if (err == -ENOENT) |
| 3627 | break; |
| 3628 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3629 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3630 | |
| 3631 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3632 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3633 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3634 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3635 | &sinfo) < 0) |
| 3636 | goto out; |
| 3637 | |
| 3638 | sta_idx++; |
| 3639 | } |
| 3640 | |
| 3641 | |
| 3642 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3643 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3644 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3645 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3646 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3647 | |
| 3648 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3649 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3650 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3651 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3652 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3654 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3655 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3656 | struct sk_buff *msg; |
| 3657 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3658 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3659 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3660 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3661 | |
| 3662 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3663 | return -EINVAL; |
| 3664 | |
| 3665 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3666 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3667 | if (!rdev->ops->get_station) |
| 3668 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3669 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3670 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3671 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3672 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3673 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3674 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3675 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3676 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3677 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3678 | 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] | 3679 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3680 | nlmsg_free(msg); |
| 3681 | return -ENOBUFS; |
| 3682 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3683 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3684 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3685 | } |
| 3686 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3687 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3688 | struct station_parameters *params, |
| 3689 | enum cfg80211_station_type statype) |
| 3690 | { |
| 3691 | if (params->listen_interval != -1) |
| 3692 | return -EINVAL; |
| 3693 | if (params->aid) |
| 3694 | return -EINVAL; |
| 3695 | |
| 3696 | /* When you run into this, adjust the code below for the new flag */ |
| 3697 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3698 | |
| 3699 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3700 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3701 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3702 | /* |
| 3703 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3704 | * code doesn't have the bug of including TDLS in the |
| 3705 | * mask everywhere. |
| 3706 | */ |
| 3707 | if (params->sta_flags_mask & |
| 3708 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3709 | BIT(NL80211_STA_FLAG_MFP) | |
| 3710 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3711 | return -EINVAL; |
| 3712 | break; |
| 3713 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3714 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3715 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3716 | return -EINVAL; |
| 3717 | /* ignore since it can't change */ |
| 3718 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3719 | break; |
| 3720 | default: |
| 3721 | /* disallow mesh-specific things */ |
| 3722 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3723 | return -EINVAL; |
| 3724 | if (params->local_pm) |
| 3725 | return -EINVAL; |
| 3726 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3727 | return -EINVAL; |
| 3728 | } |
| 3729 | |
| 3730 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3731 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3732 | /* TDLS can't be set, ... */ |
| 3733 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3734 | return -EINVAL; |
| 3735 | /* |
| 3736 | * ... but don't bother the driver with it. This works around |
| 3737 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3738 | * TLDS_PEER flag in the mask even for AP mode. |
| 3739 | */ |
| 3740 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3741 | } |
| 3742 | |
| 3743 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3744 | /* reject other things that can't change */ |
| 3745 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3746 | return -EINVAL; |
| 3747 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3748 | return -EINVAL; |
| 3749 | if (params->supported_rates) |
| 3750 | return -EINVAL; |
| 3751 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3752 | return -EINVAL; |
| 3753 | } |
| 3754 | |
| 3755 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3756 | if (params->vlan) |
| 3757 | return -EINVAL; |
| 3758 | } |
| 3759 | |
| 3760 | switch (statype) { |
| 3761 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3762 | /* Use this only for authorizing/unauthorizing a station */ |
| 3763 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3764 | return -EOPNOTSUPP; |
| 3765 | break; |
| 3766 | case CFG80211_STA_AP_CLIENT: |
| 3767 | /* accept only the listed bits */ |
| 3768 | if (params->sta_flags_mask & |
| 3769 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3770 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3771 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3772 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3773 | BIT(NL80211_STA_FLAG_WME) | |
| 3774 | BIT(NL80211_STA_FLAG_MFP))) |
| 3775 | return -EINVAL; |
| 3776 | |
| 3777 | /* but authenticated/associated only if driver handles it */ |
| 3778 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3779 | params->sta_flags_mask & |
| 3780 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3781 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3782 | return -EINVAL; |
| 3783 | break; |
| 3784 | case CFG80211_STA_IBSS: |
| 3785 | case CFG80211_STA_AP_STA: |
| 3786 | /* reject any changes other than AUTHORIZED */ |
| 3787 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3788 | return -EINVAL; |
| 3789 | break; |
| 3790 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3791 | /* reject any changes other than AUTHORIZED or WME */ |
| 3792 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3793 | BIT(NL80211_STA_FLAG_WME))) |
| 3794 | return -EINVAL; |
| 3795 | /* force (at least) rates when authorizing */ |
| 3796 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3797 | !params->supported_rates) |
| 3798 | return -EINVAL; |
| 3799 | break; |
| 3800 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3801 | /* reject any changes */ |
| 3802 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3803 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3804 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3805 | return -EINVAL; |
| 3806 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3807 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3808 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3809 | return -EINVAL; |
| 3810 | break; |
| 3811 | } |
| 3812 | |
| 3813 | return 0; |
| 3814 | } |
| 3815 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3816 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3817 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3818 | * 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] | 3819 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3820 | static struct net_device *get_vlan(struct genl_info *info, |
| 3821 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3822 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3823 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3824 | struct net_device *v; |
| 3825 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3826 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3827 | if (!vlanattr) |
| 3828 | return NULL; |
| 3829 | |
| 3830 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3831 | if (!v) |
| 3832 | return ERR_PTR(-ENODEV); |
| 3833 | |
| 3834 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3835 | ret = -EINVAL; |
| 3836 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3837 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3838 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3839 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3840 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3841 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3842 | ret = -EINVAL; |
| 3843 | goto error; |
| 3844 | } |
| 3845 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3846 | if (!netif_running(v)) { |
| 3847 | ret = -ENETDOWN; |
| 3848 | goto error; |
| 3849 | } |
| 3850 | |
| 3851 | return v; |
| 3852 | error: |
| 3853 | dev_put(v); |
| 3854 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3855 | } |
| 3856 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3857 | static struct nla_policy |
| 3858 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3859 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3860 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3861 | }; |
| 3862 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3863 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3864 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3865 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3866 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3867 | struct nlattr *nla; |
| 3868 | int err; |
| 3869 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3870 | /* parse WME attributes if present */ |
| 3871 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3872 | return 0; |
| 3873 | |
| 3874 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3875 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3876 | nl80211_sta_wme_policy); |
| 3877 | if (err) |
| 3878 | return err; |
| 3879 | |
| 3880 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3881 | params->uapsd_queues = nla_get_u8( |
| 3882 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3883 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3884 | return -EINVAL; |
| 3885 | |
| 3886 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3887 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3888 | |
| 3889 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3890 | return -EINVAL; |
| 3891 | |
| 3892 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3893 | |
| 3894 | return 0; |
| 3895 | } |
| 3896 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3897 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3898 | struct station_parameters *params) |
| 3899 | { |
| 3900 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3901 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3902 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3903 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3904 | params->ht_capa = |
| 3905 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3906 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3907 | params->vht_capa = |
| 3908 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3909 | |
| 3910 | return nl80211_parse_sta_wme(info, params); |
| 3911 | } |
| 3912 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3913 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3914 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3916 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3917 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3918 | u8 *mac_addr; |
| 3919 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3920 | |
| 3921 | memset(¶ms, 0, sizeof(params)); |
| 3922 | |
| 3923 | params.listen_interval = -1; |
| 3924 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3925 | if (!rdev->ops->change_station) |
| 3926 | return -EOPNOTSUPP; |
| 3927 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3928 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3929 | return -EINVAL; |
| 3930 | |
| 3931 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3932 | return -EINVAL; |
| 3933 | |
| 3934 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3935 | |
| 3936 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3937 | params.supported_rates = |
| 3938 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3939 | params.supported_rates_len = |
| 3940 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3941 | } |
| 3942 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3943 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3944 | params.capability = |
| 3945 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3946 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3947 | } |
| 3948 | |
| 3949 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3950 | params.ext_capab = |
| 3951 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3952 | params.ext_capab_len = |
| 3953 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3954 | } |
| 3955 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3956 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3957 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3958 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3959 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3960 | return -EINVAL; |
| 3961 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3962 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3963 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3964 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3965 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3966 | return -EINVAL; |
| 3967 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3968 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3969 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3970 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3971 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3972 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3973 | return -EINVAL; |
| 3974 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3975 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3976 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3977 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3978 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3979 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3980 | |
| 3981 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3982 | pm > NL80211_MESH_POWER_MAX) |
| 3983 | return -EINVAL; |
| 3984 | |
| 3985 | params.local_pm = pm; |
| 3986 | } |
| 3987 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3988 | /* Include parameters for TDLS peer (will check later) */ |
| 3989 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3990 | if (err) |
| 3991 | return err; |
| 3992 | |
| 3993 | params.vlan = get_vlan(info, rdev); |
| 3994 | if (IS_ERR(params.vlan)) |
| 3995 | return PTR_ERR(params.vlan); |
| 3996 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3997 | switch (dev->ieee80211_ptr->iftype) { |
| 3998 | case NL80211_IFTYPE_AP: |
| 3999 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4000 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4001 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4002 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4003 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4004 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4005 | break; |
| 4006 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4007 | err = -EOPNOTSUPP; |
| 4008 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4009 | } |
| 4010 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4011 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4012 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4013 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4014 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4015 | if (params.vlan) |
| 4016 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4017 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4018 | return err; |
| 4019 | } |
| 4020 | |
| 4021 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4022 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4023 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4024 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4025 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4026 | struct station_parameters params; |
| 4027 | u8 *mac_addr = NULL; |
| 4028 | |
| 4029 | memset(¶ms, 0, sizeof(params)); |
| 4030 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4031 | if (!rdev->ops->add_station) |
| 4032 | return -EOPNOTSUPP; |
| 4033 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4034 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4035 | return -EINVAL; |
| 4036 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4037 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4038 | return -EINVAL; |
| 4039 | |
| 4040 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4041 | return -EINVAL; |
| 4042 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4043 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4044 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4045 | return -EINVAL; |
| 4046 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4047 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4048 | params.supported_rates = |
| 4049 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4050 | params.supported_rates_len = |
| 4051 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4052 | params.listen_interval = |
| 4053 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4054 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4055 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4056 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4057 | else |
| 4058 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4059 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4060 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4061 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4062 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4063 | params.capability = |
| 4064 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4065 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4066 | } |
| 4067 | |
| 4068 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4069 | params.ext_capab = |
| 4070 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4071 | params.ext_capab_len = |
| 4072 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4073 | } |
| 4074 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4075 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4076 | params.ht_capa = |
| 4077 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4078 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4079 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4080 | params.vht_capa = |
| 4081 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4082 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4083 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4084 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4085 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4086 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4087 | return -EINVAL; |
| 4088 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4089 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4090 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4091 | if (err) |
| 4092 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4093 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4094 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4095 | return -EINVAL; |
| 4096 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4097 | /* When you run into this, adjust the code below for the new flag */ |
| 4098 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4099 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4100 | switch (dev->ieee80211_ptr->iftype) { |
| 4101 | case NL80211_IFTYPE_AP: |
| 4102 | case NL80211_IFTYPE_AP_VLAN: |
| 4103 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4104 | /* ignore WME attributes if iface/sta is not capable */ |
| 4105 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4106 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4107 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4108 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4109 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4110 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4111 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4112 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4113 | /* but don't bother the driver with it */ |
| 4114 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4115 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4116 | /* allow authenticated/associated only if driver handles it */ |
| 4117 | if (!(rdev->wiphy.features & |
| 4118 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4119 | params.sta_flags_mask & |
| 4120 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4121 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4122 | return -EINVAL; |
| 4123 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4124 | /* must be last in here for error handling */ |
| 4125 | params.vlan = get_vlan(info, rdev); |
| 4126 | if (IS_ERR(params.vlan)) |
| 4127 | return PTR_ERR(params.vlan); |
| 4128 | break; |
| 4129 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4130 | /* ignore uAPSD data */ |
| 4131 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4132 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4133 | /* associated is disallowed */ |
| 4134 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4135 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4136 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4137 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4138 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4139 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4140 | break; |
| 4141 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4142 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4143 | /* ignore uAPSD data */ |
| 4144 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4145 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4146 | /* these are disallowed */ |
| 4147 | if (params.sta_flags_mask & |
| 4148 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4149 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4150 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4151 | /* Only TDLS peers can be added */ |
| 4152 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4153 | return -EINVAL; |
| 4154 | /* Can only add if TDLS ... */ |
| 4155 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4156 | return -EOPNOTSUPP; |
| 4157 | /* ... with external setup is supported */ |
| 4158 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4159 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4160 | /* |
| 4161 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4162 | * as authorized, but it shouldn't yet be. |
| 4163 | */ |
| 4164 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4165 | break; |
| 4166 | default: |
| 4167 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4168 | } |
| 4169 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4170 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4171 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4172 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4173 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4174 | if (params.vlan) |
| 4175 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4176 | return err; |
| 4177 | } |
| 4178 | |
| 4179 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4180 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4182 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4183 | u8 *mac_addr = NULL; |
| 4184 | |
| 4185 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4186 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4187 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4188 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4189 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4190 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4191 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4192 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4193 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4194 | if (!rdev->ops->del_station) |
| 4195 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4196 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4197 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4198 | } |
| 4199 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4200 | 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] | 4201 | int flags, struct net_device *dev, |
| 4202 | u8 *dst, u8 *next_hop, |
| 4203 | struct mpath_info *pinfo) |
| 4204 | { |
| 4205 | void *hdr; |
| 4206 | struct nlattr *pinfoattr; |
| 4207 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4208 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4209 | if (!hdr) |
| 4210 | return -1; |
| 4211 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4212 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4213 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4214 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4215 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4216 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4217 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4218 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4219 | if (!pinfoattr) |
| 4220 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4221 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4222 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4223 | pinfo->frame_qlen)) |
| 4224 | goto nla_put_failure; |
| 4225 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4226 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4227 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4228 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4229 | pinfo->metric)) || |
| 4230 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4231 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4232 | pinfo->exptime)) || |
| 4233 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4234 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4235 | pinfo->flags)) || |
| 4236 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4237 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4238 | pinfo->discovery_timeout)) || |
| 4239 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4240 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4241 | pinfo->discovery_retries))) |
| 4242 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4243 | |
| 4244 | nla_nest_end(msg, pinfoattr); |
| 4245 | |
| 4246 | return genlmsg_end(msg, hdr); |
| 4247 | |
| 4248 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4249 | genlmsg_cancel(msg, hdr); |
| 4250 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4254 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4255 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4256 | struct mpath_info pinfo; |
| 4257 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4258 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4259 | u8 dst[ETH_ALEN]; |
| 4260 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4261 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4262 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4263 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4264 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4265 | if (err) |
| 4266 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4267 | |
| 4268 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4269 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4270 | goto out_err; |
| 4271 | } |
| 4272 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4273 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4274 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4275 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4276 | } |
| 4277 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4278 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4279 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4280 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4281 | if (err == -ENOENT) |
| 4282 | break; |
| 4283 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4284 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4285 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4286 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4287 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4288 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4289 | &pinfo) < 0) |
| 4290 | goto out; |
| 4291 | |
| 4292 | path_idx++; |
| 4293 | } |
| 4294 | |
| 4295 | |
| 4296 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4297 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4298 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4299 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4300 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4301 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4305 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4307 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4308 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4309 | struct mpath_info pinfo; |
| 4310 | struct sk_buff *msg; |
| 4311 | u8 *dst = NULL; |
| 4312 | u8 next_hop[ETH_ALEN]; |
| 4313 | |
| 4314 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4315 | |
| 4316 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4317 | return -EINVAL; |
| 4318 | |
| 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->get_mpath) |
| 4322 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4323 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4324 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4325 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4326 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4327 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4328 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4329 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4330 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4331 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4332 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4333 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4334 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4335 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4336 | dev, dst, next_hop, &pinfo) < 0) { |
| 4337 | nlmsg_free(msg); |
| 4338 | return -ENOBUFS; |
| 4339 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4340 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4341 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4345 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4346 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4347 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4348 | u8 *dst = NULL; |
| 4349 | u8 *next_hop = NULL; |
| 4350 | |
| 4351 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4352 | return -EINVAL; |
| 4353 | |
| 4354 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4355 | return -EINVAL; |
| 4356 | |
| 4357 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4358 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4359 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4360 | if (!rdev->ops->change_mpath) |
| 4361 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4362 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4363 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4364 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4365 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4366 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4367 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4368 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4369 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4370 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4371 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4372 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4373 | u8 *dst = NULL; |
| 4374 | u8 *next_hop = NULL; |
| 4375 | |
| 4376 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4377 | return -EINVAL; |
| 4378 | |
| 4379 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4380 | return -EINVAL; |
| 4381 | |
| 4382 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4383 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4384 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4385 | if (!rdev->ops->add_mpath) |
| 4386 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4387 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4388 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4389 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4390 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4391 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4392 | } |
| 4393 | |
| 4394 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4395 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4397 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4398 | u8 *dst = NULL; |
| 4399 | |
| 4400 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4401 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4402 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4403 | if (!rdev->ops->del_mpath) |
| 4404 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4405 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4406 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4407 | } |
| 4408 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4409 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4410 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4412 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4413 | struct bss_parameters params; |
| 4414 | |
| 4415 | memset(¶ms, 0, sizeof(params)); |
| 4416 | /* default to not changing parameters */ |
| 4417 | params.use_cts_prot = -1; |
| 4418 | params.use_short_preamble = -1; |
| 4419 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4420 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4421 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4422 | params.p2p_ctwindow = -1; |
| 4423 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4424 | |
| 4425 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4426 | params.use_cts_prot = |
| 4427 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4428 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4429 | params.use_short_preamble = |
| 4430 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4431 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4432 | params.use_short_slot_time = |
| 4433 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4434 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4435 | params.basic_rates = |
| 4436 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4437 | params.basic_rates_len = |
| 4438 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4439 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4440 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4441 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4442 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4443 | params.ht_opmode = |
| 4444 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4445 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4446 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4447 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4448 | return -EINVAL; |
| 4449 | params.p2p_ctwindow = |
| 4450 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4451 | if (params.p2p_ctwindow < 0) |
| 4452 | return -EINVAL; |
| 4453 | if (params.p2p_ctwindow != 0 && |
| 4454 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4455 | return -EINVAL; |
| 4456 | } |
| 4457 | |
| 4458 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4459 | u8 tmp; |
| 4460 | |
| 4461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4462 | return -EINVAL; |
| 4463 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4464 | if (tmp > 1) |
| 4465 | return -EINVAL; |
| 4466 | params.p2p_opp_ps = tmp; |
| 4467 | if (params.p2p_opp_ps && |
| 4468 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4469 | return -EINVAL; |
| 4470 | } |
| 4471 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4472 | if (!rdev->ops->change_bss) |
| 4473 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4474 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4475 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4476 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4477 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4478 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4479 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4480 | } |
| 4481 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4482 | 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] | 4483 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4484 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4485 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4486 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4487 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4488 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4489 | }; |
| 4490 | |
| 4491 | static int parse_reg_rule(struct nlattr *tb[], |
| 4492 | struct ieee80211_reg_rule *reg_rule) |
| 4493 | { |
| 4494 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4495 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4496 | |
| 4497 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4498 | return -EINVAL; |
| 4499 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4500 | return -EINVAL; |
| 4501 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4502 | return -EINVAL; |
| 4503 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4504 | return -EINVAL; |
| 4505 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4506 | return -EINVAL; |
| 4507 | |
| 4508 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4509 | |
| 4510 | freq_range->start_freq_khz = |
| 4511 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4512 | freq_range->end_freq_khz = |
| 4513 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4514 | freq_range->max_bandwidth_khz = |
| 4515 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4516 | |
| 4517 | power_rule->max_eirp = |
| 4518 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4519 | |
| 4520 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4521 | power_rule->max_antenna_gain = |
| 4522 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4523 | |
| 4524 | return 0; |
| 4525 | } |
| 4526 | |
| 4527 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4528 | { |
| 4529 | int r; |
| 4530 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4531 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4532 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4533 | /* |
| 4534 | * You should only get this when cfg80211 hasn't yet initialized |
| 4535 | * completely when built-in to the kernel right between the time |
| 4536 | * window between nl80211_init() and regulatory_init(), if that is |
| 4537 | * even possible. |
| 4538 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4539 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4540 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4541 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4542 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4543 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4544 | |
| 4545 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4546 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4547 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4548 | user_reg_hint_type = |
| 4549 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4550 | else |
| 4551 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4552 | |
| 4553 | switch (user_reg_hint_type) { |
| 4554 | case NL80211_USER_REG_HINT_USER: |
| 4555 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4556 | break; |
| 4557 | default: |
| 4558 | return -EINVAL; |
| 4559 | } |
| 4560 | |
| 4561 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4562 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4563 | return r; |
| 4564 | } |
| 4565 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4566 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4567 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4568 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4570 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4571 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4572 | struct mesh_config cur_params; |
| 4573 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4574 | void *hdr; |
| 4575 | struct nlattr *pinfoattr; |
| 4576 | struct sk_buff *msg; |
| 4577 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4578 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4579 | return -EOPNOTSUPP; |
| 4580 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4581 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4582 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4583 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4584 | wdev_lock(wdev); |
| 4585 | /* If not connected, get default parameters */ |
| 4586 | if (!wdev->mesh_id_len) |
| 4587 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4588 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4589 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4590 | wdev_unlock(wdev); |
| 4591 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4592 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4593 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4594 | |
| 4595 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4596 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4597 | if (!msg) |
| 4598 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4599 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4600 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4601 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4602 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4603 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4604 | if (!pinfoattr) |
| 4605 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4606 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4607 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4608 | cur_params.dot11MeshRetryTimeout) || |
| 4609 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4610 | cur_params.dot11MeshConfirmTimeout) || |
| 4611 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4612 | cur_params.dot11MeshHoldingTimeout) || |
| 4613 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4614 | cur_params.dot11MeshMaxPeerLinks) || |
| 4615 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4616 | cur_params.dot11MeshMaxRetries) || |
| 4617 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4618 | cur_params.dot11MeshTTL) || |
| 4619 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4620 | cur_params.element_ttl) || |
| 4621 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4622 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4623 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4624 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4625 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4626 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4627 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4628 | cur_params.path_refresh_time) || |
| 4629 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4630 | cur_params.min_discovery_timeout) || |
| 4631 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4632 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4633 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4634 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4635 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4636 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4637 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4638 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4639 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4640 | cur_params.dot11MeshHWMPRootMode) || |
| 4641 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4642 | cur_params.dot11MeshHWMPRannInterval) || |
| 4643 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4644 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4645 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4646 | cur_params.dot11MeshForwarding) || |
| 4647 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4648 | cur_params.rssi_threshold) || |
| 4649 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4650 | cur_params.ht_opmode) || |
| 4651 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4652 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4653 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4654 | cur_params.dot11MeshHWMProotInterval) || |
| 4655 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4656 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4657 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4658 | cur_params.power_mode) || |
| 4659 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4660 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4661 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4662 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4663 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4664 | nla_nest_end(msg, pinfoattr); |
| 4665 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4666 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4667 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4668 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4669 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4670 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4671 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4672 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4673 | } |
| 4674 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4675 | 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] | 4676 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4677 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4678 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4679 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4680 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4681 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4682 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4683 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4684 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4685 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4686 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4687 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4688 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4689 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4690 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4691 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4692 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4693 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4694 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4695 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4696 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4697 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4698 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4699 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4700 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4701 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4702 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4703 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4704 | }; |
| 4705 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4706 | static const struct nla_policy |
| 4707 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4708 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4709 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4710 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4711 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4712 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4713 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4714 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4715 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4716 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4717 | }; |
| 4718 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4719 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4720 | struct mesh_config *cfg, |
| 4721 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4722 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4723 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4724 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4725 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4726 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4727 | do { \ |
| 4728 | if (tb[attr]) { \ |
| 4729 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4730 | return -EINVAL; \ |
| 4731 | cfg->param = fn(tb[attr]); \ |
| 4732 | mask |= (1 << (attr - 1)); \ |
| 4733 | } \ |
| 4734 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4735 | |
| 4736 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4737 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4738 | return -EINVAL; |
| 4739 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4740 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4741 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4742 | return -EINVAL; |
| 4743 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4744 | /* This makes sure that there aren't more than 32 mesh config |
| 4745 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4746 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4747 | |
| 4748 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4749 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4750 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4751 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4752 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4753 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4754 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4755 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4756 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4757 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4758 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4759 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4760 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4761 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4762 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4763 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4764 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4765 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4766 | 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] | 4767 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4768 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4769 | 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] | 4770 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4771 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4772 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4773 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4774 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4775 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4776 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4777 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4778 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4779 | 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] | 4780 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4781 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4782 | 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] | 4783 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4784 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4785 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4786 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4787 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4788 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4789 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4790 | 1, 65535, mask, |
| 4791 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4792 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4793 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4794 | 1, 65535, mask, |
| 4795 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4796 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4797 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4798 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4799 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4800 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4801 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4802 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4803 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4804 | nla_get_u8); |
| 4805 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4806 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4807 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4808 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4809 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4810 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4811 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4812 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4813 | mask, NL80211_MESHCONF_FORWARDING, |
| 4814 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4815 | 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] | 4816 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4817 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4818 | 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] | 4819 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4820 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4822 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4823 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4824 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4825 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4826 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4827 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4828 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4829 | dot11MeshHWMPconfirmationInterval, |
| 4830 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4831 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4832 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4833 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4834 | NL80211_MESH_POWER_ACTIVE, |
| 4835 | NL80211_MESH_POWER_MAX, |
| 4836 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4837 | nla_get_u32); |
| 4838 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4839 | 0, 65535, mask, |
| 4840 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4841 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4842 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4843 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4844 | if (mask_out) |
| 4845 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4846 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4847 | return 0; |
| 4848 | |
| 4849 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4850 | } |
| 4851 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4852 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4853 | struct mesh_setup *setup) |
| 4854 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4856 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4857 | |
| 4858 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4859 | return -EINVAL; |
| 4860 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4861 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4862 | nl80211_mesh_setup_params_policy)) |
| 4863 | return -EINVAL; |
| 4864 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4865 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4866 | setup->sync_method = |
| 4867 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4868 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4869 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4870 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4871 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4872 | setup->path_sel_proto = |
| 4873 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4874 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4875 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4876 | |
| 4877 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4878 | setup->path_metric = |
| 4879 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4880 | IEEE80211_PATH_METRIC_VENDOR : |
| 4881 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4882 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4883 | |
| 4884 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4885 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4886 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4887 | if (!is_valid_ie_attr(ieattr)) |
| 4888 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4889 | setup->ie = nla_data(ieattr); |
| 4890 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4891 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4892 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4893 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4894 | return -EINVAL; |
| 4895 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4896 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4897 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4898 | if (setup->is_secure) |
| 4899 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4900 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4901 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4902 | if (!setup->user_mpm) |
| 4903 | return -EINVAL; |
| 4904 | setup->auth_id = |
| 4905 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4906 | } |
| 4907 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4908 | return 0; |
| 4909 | } |
| 4910 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4911 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4912 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4913 | { |
| 4914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4915 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4916 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4917 | struct mesh_config cfg; |
| 4918 | u32 mask; |
| 4919 | int err; |
| 4920 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4921 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4922 | return -EOPNOTSUPP; |
| 4923 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4924 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4925 | return -EOPNOTSUPP; |
| 4926 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4927 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4928 | if (err) |
| 4929 | return err; |
| 4930 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4931 | wdev_lock(wdev); |
| 4932 | if (!wdev->mesh_id_len) |
| 4933 | err = -ENOLINK; |
| 4934 | |
| 4935 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4936 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4937 | |
| 4938 | wdev_unlock(wdev); |
| 4939 | |
| 4940 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4941 | } |
| 4942 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4943 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4944 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4945 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4946 | struct sk_buff *msg; |
| 4947 | void *hdr = NULL; |
| 4948 | struct nlattr *nl_reg_rules; |
| 4949 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4950 | |
| 4951 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4952 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4953 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4954 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4955 | if (!msg) |
| 4956 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4957 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4958 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4959 | NL80211_CMD_GET_REG); |
| 4960 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4961 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4962 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4963 | if (reg_last_request_cell_base() && |
| 4964 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4965 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4966 | goto nla_put_failure; |
| 4967 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4968 | rcu_read_lock(); |
| 4969 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4970 | |
| 4971 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4972 | (regdom->dfs_region && |
| 4973 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4974 | goto nla_put_failure_rcu; |
| 4975 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4976 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4977 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4978 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4979 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4980 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4981 | struct nlattr *nl_reg_rule; |
| 4982 | const struct ieee80211_reg_rule *reg_rule; |
| 4983 | const struct ieee80211_freq_range *freq_range; |
| 4984 | const struct ieee80211_power_rule *power_rule; |
| 4985 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4986 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4987 | freq_range = ®_rule->freq_range; |
| 4988 | power_rule = ®_rule->power_rule; |
| 4989 | |
| 4990 | nl_reg_rule = nla_nest_start(msg, i); |
| 4991 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4992 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4993 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4994 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4995 | reg_rule->flags) || |
| 4996 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4997 | freq_range->start_freq_khz) || |
| 4998 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4999 | freq_range->end_freq_khz) || |
| 5000 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 5001 | freq_range->max_bandwidth_khz) || |
| 5002 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5003 | power_rule->max_antenna_gain) || |
| 5004 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 5005 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5006 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5007 | |
| 5008 | nla_nest_end(msg, nl_reg_rule); |
| 5009 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5010 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5011 | |
| 5012 | nla_nest_end(msg, nl_reg_rules); |
| 5013 | |
| 5014 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5015 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5016 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5017 | nla_put_failure_rcu: |
| 5018 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5019 | nla_put_failure: |
| 5020 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5021 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5022 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5023 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5024 | } |
| 5025 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5026 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5027 | { |
| 5028 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5029 | struct nlattr *nl_reg_rule; |
| 5030 | char *alpha2 = NULL; |
| 5031 | int rem_reg_rules = 0, r = 0; |
| 5032 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5033 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5034 | struct ieee80211_regdomain *rd = NULL; |
| 5035 | |
| 5036 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5037 | return -EINVAL; |
| 5038 | |
| 5039 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5040 | return -EINVAL; |
| 5041 | |
| 5042 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5043 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5044 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5045 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5046 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5047 | 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] | 5048 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5049 | num_rules++; |
| 5050 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5051 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5054 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5055 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5056 | |
| 5057 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5058 | if (!rd) |
| 5059 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5060 | |
| 5061 | rd->n_reg_rules = num_rules; |
| 5062 | rd->alpha2[0] = alpha2[0]; |
| 5063 | rd->alpha2[1] = alpha2[1]; |
| 5064 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5065 | /* |
| 5066 | * Disable DFS master mode if the DFS region was |
| 5067 | * not supported or known on this kernel. |
| 5068 | */ |
| 5069 | if (reg_supported_dfs_region(dfs_region)) |
| 5070 | rd->dfs_region = dfs_region; |
| 5071 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5072 | 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] | 5073 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5074 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5075 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5076 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5077 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5078 | if (r) |
| 5079 | goto bad_reg; |
| 5080 | |
| 5081 | rule_idx++; |
| 5082 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5083 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5084 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5085 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5086 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5087 | } |
| 5088 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5089 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5090 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5091 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5092 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5093 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5094 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5095 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5096 | } |
| 5097 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5098 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5099 | { |
| 5100 | struct nlattr *attr1, *attr2; |
| 5101 | int n_channels = 0, tmp1, tmp2; |
| 5102 | |
| 5103 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5104 | n_channels++; |
| 5105 | /* |
| 5106 | * Some hardware has a limited channel list for |
| 5107 | * scanning, and it is pretty much nonsensical |
| 5108 | * to scan for a channel twice, so disallow that |
| 5109 | * and don't require drivers to check that the |
| 5110 | * channel list they get isn't longer than what |
| 5111 | * they can scan, as long as they can scan all |
| 5112 | * the channels they registered at once. |
| 5113 | */ |
| 5114 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5115 | if (attr1 != attr2 && |
| 5116 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5117 | return 0; |
| 5118 | } |
| 5119 | |
| 5120 | return n_channels; |
| 5121 | } |
| 5122 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5123 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5124 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5126 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5127 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5128 | struct nlattr *attr; |
| 5129 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5130 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5131 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5132 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5133 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5134 | return -EINVAL; |
| 5135 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5136 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5137 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5138 | if (!rdev->ops->scan) |
| 5139 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5140 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5141 | if (rdev->scan_req) { |
| 5142 | err = -EBUSY; |
| 5143 | goto unlock; |
| 5144 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5145 | |
| 5146 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5147 | n_channels = validate_scan_freqs( |
| 5148 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5149 | if (!n_channels) { |
| 5150 | err = -EINVAL; |
| 5151 | goto unlock; |
| 5152 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5153 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5154 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5155 | n_channels = 0; |
| 5156 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5157 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5158 | if (wiphy->bands[band]) |
| 5159 | n_channels += wiphy->bands[band]->n_channels; |
| 5160 | } |
| 5161 | |
| 5162 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5163 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5164 | n_ssids++; |
| 5165 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5166 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5167 | err = -EINVAL; |
| 5168 | goto unlock; |
| 5169 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5170 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5171 | if (info->attrs[NL80211_ATTR_IE]) |
| 5172 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5173 | else |
| 5174 | ie_len = 0; |
| 5175 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5176 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5177 | err = -EINVAL; |
| 5178 | goto unlock; |
| 5179 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5180 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5181 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5182 | + sizeof(*request->ssids) * n_ssids |
| 5183 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5184 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5185 | if (!request) { |
| 5186 | err = -ENOMEM; |
| 5187 | goto unlock; |
| 5188 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5189 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5190 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5191 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5192 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5193 | if (ie_len) { |
| 5194 | if (request->ssids) |
| 5195 | request->ie = (void *)(request->ssids + n_ssids); |
| 5196 | else |
| 5197 | request->ie = (void *)(request->channels + n_channels); |
| 5198 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5199 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5200 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5201 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5202 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5203 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5204 | struct ieee80211_channel *chan; |
| 5205 | |
| 5206 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5207 | |
| 5208 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5209 | err = -EINVAL; |
| 5210 | goto out_free; |
| 5211 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5212 | |
| 5213 | /* ignore disabled channels */ |
| 5214 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5215 | continue; |
| 5216 | |
| 5217 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5218 | i++; |
| 5219 | } |
| 5220 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5221 | enum ieee80211_band band; |
| 5222 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5223 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5224 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5225 | int j; |
| 5226 | if (!wiphy->bands[band]) |
| 5227 | continue; |
| 5228 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5229 | struct ieee80211_channel *chan; |
| 5230 | |
| 5231 | chan = &wiphy->bands[band]->channels[j]; |
| 5232 | |
| 5233 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5234 | continue; |
| 5235 | |
| 5236 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5237 | i++; |
| 5238 | } |
| 5239 | } |
| 5240 | } |
| 5241 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5242 | if (!i) { |
| 5243 | err = -EINVAL; |
| 5244 | goto out_free; |
| 5245 | } |
| 5246 | |
| 5247 | request->n_channels = i; |
| 5248 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5249 | i = 0; |
| 5250 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5251 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5252 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5253 | err = -EINVAL; |
| 5254 | goto out_free; |
| 5255 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5256 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5257 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5258 | i++; |
| 5259 | } |
| 5260 | } |
| 5261 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5262 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5263 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5264 | memcpy((void *)request->ie, |
| 5265 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5266 | request->ie_len); |
| 5267 | } |
| 5268 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5269 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5270 | if (wiphy->bands[i]) |
| 5271 | request->rates[i] = |
| 5272 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5273 | |
| 5274 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5275 | nla_for_each_nested(attr, |
| 5276 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5277 | tmp) { |
| 5278 | enum ieee80211_band band = nla_type(attr); |
| 5279 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5280 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5281 | err = -EINVAL; |
| 5282 | goto out_free; |
| 5283 | } |
| 5284 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5285 | nla_data(attr), |
| 5286 | nla_len(attr), |
| 5287 | &request->rates[band]); |
| 5288 | if (err) |
| 5289 | goto out_free; |
| 5290 | } |
| 5291 | } |
| 5292 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5293 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5294 | request->flags = nla_get_u32( |
| 5295 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5296 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5297 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5298 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5299 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5300 | err = -EOPNOTSUPP; |
| 5301 | goto out_free; |
| 5302 | } |
| 5303 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5304 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5305 | request->no_cck = |
| 5306 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5307 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5308 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5309 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5310 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5311 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5312 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5313 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5314 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5315 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5316 | nl80211_send_scan_start(rdev, wdev); |
| 5317 | if (wdev->netdev) |
| 5318 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5319 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5320 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5321 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5322 | kfree(request); |
| 5323 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5324 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5325 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5326 | return err; |
| 5327 | } |
| 5328 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5329 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5330 | struct genl_info *info) |
| 5331 | { |
| 5332 | struct cfg80211_sched_scan_request *request; |
| 5333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5334 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5335 | struct nlattr *attr; |
| 5336 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5337 | 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] | 5338 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5339 | enum ieee80211_band band; |
| 5340 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5341 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5342 | |
| 5343 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5344 | !rdev->ops->sched_scan_start) |
| 5345 | return -EOPNOTSUPP; |
| 5346 | |
| 5347 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5348 | return -EINVAL; |
| 5349 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5350 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5351 | return -EINVAL; |
| 5352 | |
| 5353 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5354 | if (interval == 0) |
| 5355 | return -EINVAL; |
| 5356 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5357 | wiphy = &rdev->wiphy; |
| 5358 | |
| 5359 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5360 | n_channels = validate_scan_freqs( |
| 5361 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5362 | if (!n_channels) |
| 5363 | return -EINVAL; |
| 5364 | } else { |
| 5365 | n_channels = 0; |
| 5366 | |
| 5367 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5368 | if (wiphy->bands[band]) |
| 5369 | n_channels += wiphy->bands[band]->n_channels; |
| 5370 | } |
| 5371 | |
| 5372 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5373 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5374 | tmp) |
| 5375 | n_ssids++; |
| 5376 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5377 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5378 | return -EINVAL; |
| 5379 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5380 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5381 | nla_for_each_nested(attr, |
| 5382 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5383 | tmp) |
| 5384 | n_match_sets++; |
| 5385 | |
| 5386 | if (n_match_sets > wiphy->max_match_sets) |
| 5387 | return -EINVAL; |
| 5388 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5389 | if (info->attrs[NL80211_ATTR_IE]) |
| 5390 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5391 | else |
| 5392 | ie_len = 0; |
| 5393 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5394 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5395 | return -EINVAL; |
| 5396 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5397 | if (rdev->sched_scan_req) { |
| 5398 | err = -EINPROGRESS; |
| 5399 | goto out; |
| 5400 | } |
| 5401 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5402 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5403 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5404 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5405 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5406 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5407 | if (!request) { |
| 5408 | err = -ENOMEM; |
| 5409 | goto out; |
| 5410 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5411 | |
| 5412 | if (n_ssids) |
| 5413 | request->ssids = (void *)&request->channels[n_channels]; |
| 5414 | request->n_ssids = n_ssids; |
| 5415 | if (ie_len) { |
| 5416 | if (request->ssids) |
| 5417 | request->ie = (void *)(request->ssids + n_ssids); |
| 5418 | else |
| 5419 | request->ie = (void *)(request->channels + n_channels); |
| 5420 | } |
| 5421 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5422 | if (n_match_sets) { |
| 5423 | if (request->ie) |
| 5424 | request->match_sets = (void *)(request->ie + ie_len); |
| 5425 | else if (request->ssids) |
| 5426 | request->match_sets = |
| 5427 | (void *)(request->ssids + n_ssids); |
| 5428 | else |
| 5429 | request->match_sets = |
| 5430 | (void *)(request->channels + n_channels); |
| 5431 | } |
| 5432 | request->n_match_sets = n_match_sets; |
| 5433 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5434 | i = 0; |
| 5435 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5436 | /* user specified, bail out if channel not found */ |
| 5437 | nla_for_each_nested(attr, |
| 5438 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5439 | tmp) { |
| 5440 | struct ieee80211_channel *chan; |
| 5441 | |
| 5442 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5443 | |
| 5444 | if (!chan) { |
| 5445 | err = -EINVAL; |
| 5446 | goto out_free; |
| 5447 | } |
| 5448 | |
| 5449 | /* ignore disabled channels */ |
| 5450 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5451 | continue; |
| 5452 | |
| 5453 | request->channels[i] = chan; |
| 5454 | i++; |
| 5455 | } |
| 5456 | } else { |
| 5457 | /* all channels */ |
| 5458 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5459 | int j; |
| 5460 | if (!wiphy->bands[band]) |
| 5461 | continue; |
| 5462 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5463 | struct ieee80211_channel *chan; |
| 5464 | |
| 5465 | chan = &wiphy->bands[band]->channels[j]; |
| 5466 | |
| 5467 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5468 | continue; |
| 5469 | |
| 5470 | request->channels[i] = chan; |
| 5471 | i++; |
| 5472 | } |
| 5473 | } |
| 5474 | } |
| 5475 | |
| 5476 | if (!i) { |
| 5477 | err = -EINVAL; |
| 5478 | goto out_free; |
| 5479 | } |
| 5480 | |
| 5481 | request->n_channels = i; |
| 5482 | |
| 5483 | i = 0; |
| 5484 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5485 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5486 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5487 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5488 | err = -EINVAL; |
| 5489 | goto out_free; |
| 5490 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5491 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5492 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5493 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5494 | i++; |
| 5495 | } |
| 5496 | } |
| 5497 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5498 | i = 0; |
| 5499 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5500 | nla_for_each_nested(attr, |
| 5501 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5502 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5503 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5504 | |
| 5505 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5506 | nla_data(attr), nla_len(attr), |
| 5507 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5508 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5509 | if (ssid) { |
| 5510 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5511 | err = -EINVAL; |
| 5512 | goto out_free; |
| 5513 | } |
| 5514 | memcpy(request->match_sets[i].ssid.ssid, |
| 5515 | nla_data(ssid), nla_len(ssid)); |
| 5516 | request->match_sets[i].ssid.ssid_len = |
| 5517 | nla_len(ssid); |
| 5518 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5519 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5520 | if (rssi) |
| 5521 | request->rssi_thold = nla_get_u32(rssi); |
| 5522 | else |
| 5523 | request->rssi_thold = |
| 5524 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5525 | i++; |
| 5526 | } |
| 5527 | } |
| 5528 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5529 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5530 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5531 | memcpy((void *)request->ie, |
| 5532 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5533 | request->ie_len); |
| 5534 | } |
| 5535 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5536 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5537 | request->flags = nla_get_u32( |
| 5538 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5539 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5540 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5541 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5542 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5543 | err = -EOPNOTSUPP; |
| 5544 | goto out_free; |
| 5545 | } |
| 5546 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5547 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5548 | request->dev = dev; |
| 5549 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5550 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5551 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5552 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5553 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5554 | if (!err) { |
| 5555 | rdev->sched_scan_req = request; |
| 5556 | nl80211_send_sched_scan(rdev, dev, |
| 5557 | NL80211_CMD_START_SCHED_SCAN); |
| 5558 | goto out; |
| 5559 | } |
| 5560 | |
| 5561 | out_free: |
| 5562 | kfree(request); |
| 5563 | out: |
| 5564 | return err; |
| 5565 | } |
| 5566 | |
| 5567 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5568 | struct genl_info *info) |
| 5569 | { |
| 5570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5571 | |
| 5572 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5573 | !rdev->ops->sched_scan_stop) |
| 5574 | return -EOPNOTSUPP; |
| 5575 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5576 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5577 | } |
| 5578 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5579 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5580 | struct genl_info *info) |
| 5581 | { |
| 5582 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5583 | struct net_device *dev = info->user_ptr[1]; |
| 5584 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5585 | struct cfg80211_chan_def chandef; |
| 5586 | int err; |
| 5587 | |
| 5588 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5589 | if (err) |
| 5590 | return err; |
| 5591 | |
| 5592 | if (wdev->cac_started) |
| 5593 | return -EBUSY; |
| 5594 | |
| 5595 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5596 | if (err < 0) |
| 5597 | return err; |
| 5598 | |
| 5599 | if (err == 0) |
| 5600 | return -EINVAL; |
| 5601 | |
| 5602 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5603 | return -EINVAL; |
| 5604 | |
| 5605 | if (!rdev->ops->start_radar_detection) |
| 5606 | return -EOPNOTSUPP; |
| 5607 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5608 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5609 | chandef.chan, CHAN_MODE_SHARED, |
| 5610 | BIT(chandef.width)); |
| 5611 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5612 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5613 | |
| 5614 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5615 | if (!err) { |
| 5616 | wdev->channel = chandef.chan; |
| 5617 | wdev->cac_started = true; |
| 5618 | wdev->cac_start_time = jiffies; |
| 5619 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5620 | return err; |
| 5621 | } |
| 5622 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5623 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5624 | { |
| 5625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5626 | struct net_device *dev = info->user_ptr[1]; |
| 5627 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5628 | struct cfg80211_csa_settings params; |
| 5629 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5630 | * function is called under RTNL lock, so this should not be a problem. |
| 5631 | */ |
| 5632 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5633 | u8 radar_detect_width = 0; |
| 5634 | int err; |
| 5635 | |
| 5636 | if (!rdev->ops->channel_switch || |
| 5637 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5638 | return -EOPNOTSUPP; |
| 5639 | |
| 5640 | /* may add IBSS support later */ |
| 5641 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5642 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5643 | return -EOPNOTSUPP; |
| 5644 | |
| 5645 | memset(¶ms, 0, sizeof(params)); |
| 5646 | |
| 5647 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5648 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5649 | return -EINVAL; |
| 5650 | |
| 5651 | /* only important for AP, IBSS and mesh create IEs internally */ |
| 5652 | if (!info->attrs[NL80211_ATTR_CSA_IES]) |
| 5653 | return -EINVAL; |
| 5654 | |
| 5655 | /* useless if AP is not running */ |
| 5656 | if (!wdev->beacon_interval) |
| 5657 | return -EINVAL; |
| 5658 | |
| 5659 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5660 | |
| 5661 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5662 | if (err) |
| 5663 | return err; |
| 5664 | |
| 5665 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5666 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5667 | nl80211_policy); |
| 5668 | if (err) |
| 5669 | return err; |
| 5670 | |
| 5671 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5672 | if (err) |
| 5673 | return err; |
| 5674 | |
| 5675 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5676 | return -EINVAL; |
| 5677 | |
| 5678 | params.counter_offset_beacon = |
| 5679 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5680 | if (params.counter_offset_beacon >= params.beacon_csa.tail_len) |
| 5681 | return -EINVAL; |
| 5682 | |
| 5683 | /* sanity check - counters should be the same */ |
| 5684 | if (params.beacon_csa.tail[params.counter_offset_beacon] != |
| 5685 | params.count) |
| 5686 | return -EINVAL; |
| 5687 | |
| 5688 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
| 5689 | params.counter_offset_presp = |
| 5690 | nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5691 | if (params.counter_offset_presp >= |
| 5692 | params.beacon_csa.probe_resp_len) |
| 5693 | return -EINVAL; |
| 5694 | |
| 5695 | if (params.beacon_csa.probe_resp[params.counter_offset_presp] != |
| 5696 | params.count) |
| 5697 | return -EINVAL; |
| 5698 | } |
| 5699 | |
| 5700 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5701 | if (err) |
| 5702 | return err; |
| 5703 | |
| 5704 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
| 5705 | return -EINVAL; |
| 5706 | |
| 5707 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 5708 | if (err < 0) { |
| 5709 | return err; |
| 5710 | } else if (err) { |
| 5711 | radar_detect_width = BIT(params.chandef.width); |
| 5712 | params.radar_required = true; |
| 5713 | } |
| 5714 | |
| 5715 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5716 | params.chandef.chan, |
| 5717 | CHAN_MODE_SHARED, |
| 5718 | radar_detect_width); |
| 5719 | if (err) |
| 5720 | return err; |
| 5721 | |
| 5722 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 5723 | params.block_tx = true; |
| 5724 | |
| 5725 | return rdev_channel_switch(rdev, dev, ¶ms); |
| 5726 | } |
| 5727 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5728 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5729 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5730 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5731 | struct wireless_dev *wdev, |
| 5732 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5733 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5734 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5735 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5736 | void *hdr; |
| 5737 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5738 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5739 | |
| 5740 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5741 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5742 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5743 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5744 | if (!hdr) |
| 5745 | return -1; |
| 5746 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5747 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5748 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5749 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5750 | goto nla_put_failure; |
| 5751 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5752 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5753 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5754 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5755 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5756 | |
| 5757 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5758 | if (!bss) |
| 5759 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5760 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5761 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5762 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5763 | |
| 5764 | rcu_read_lock(); |
| 5765 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5766 | if (ies) { |
| 5767 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5768 | goto fail_unlock_rcu; |
| 5769 | tsf = true; |
| 5770 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5771 | ies->len, ies->data)) |
| 5772 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5773 | } |
| 5774 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5775 | if (ies) { |
| 5776 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5777 | goto fail_unlock_rcu; |
| 5778 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5779 | ies->len, ies->data)) |
| 5780 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5781 | } |
| 5782 | rcu_read_unlock(); |
| 5783 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5784 | if (res->beacon_interval && |
| 5785 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5786 | goto nla_put_failure; |
| 5787 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5788 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 5789 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5790 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5791 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5792 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5793 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5794 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5795 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5796 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5797 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5798 | break; |
| 5799 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5800 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5801 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5802 | break; |
| 5803 | default: |
| 5804 | break; |
| 5805 | } |
| 5806 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5807 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5808 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5809 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5810 | if (intbss == wdev->current_bss && |
| 5811 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5812 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5813 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5814 | break; |
| 5815 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5816 | if (intbss == wdev->current_bss && |
| 5817 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5818 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5819 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5820 | break; |
| 5821 | default: |
| 5822 | break; |
| 5823 | } |
| 5824 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5825 | nla_nest_end(msg, bss); |
| 5826 | |
| 5827 | return genlmsg_end(msg, hdr); |
| 5828 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5829 | fail_unlock_rcu: |
| 5830 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5831 | nla_put_failure: |
| 5832 | genlmsg_cancel(msg, hdr); |
| 5833 | return -EMSGSIZE; |
| 5834 | } |
| 5835 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5836 | 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] | 5837 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5838 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5839 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5840 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5841 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5842 | int err; |
| 5843 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5844 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5845 | if (err) |
| 5846 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5847 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5848 | wdev_lock(wdev); |
| 5849 | spin_lock_bh(&rdev->bss_lock); |
| 5850 | cfg80211_bss_expire(rdev); |
| 5851 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5852 | cb->seq = rdev->bss_generation; |
| 5853 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5854 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5855 | if (++idx <= start) |
| 5856 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5857 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5858 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5859 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5860 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5861 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5862 | } |
| 5863 | } |
| 5864 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5865 | spin_unlock_bh(&rdev->bss_lock); |
| 5866 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5867 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5868 | cb->args[2] = idx; |
| 5869 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5870 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5871 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5872 | } |
| 5873 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5874 | 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] | 5875 | int flags, struct net_device *dev, |
| 5876 | struct survey_info *survey) |
| 5877 | { |
| 5878 | void *hdr; |
| 5879 | struct nlattr *infoattr; |
| 5880 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5881 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5882 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5883 | if (!hdr) |
| 5884 | return -ENOMEM; |
| 5885 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5886 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5887 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5888 | |
| 5889 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5890 | if (!infoattr) |
| 5891 | goto nla_put_failure; |
| 5892 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5893 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5894 | survey->channel->center_freq)) |
| 5895 | goto nla_put_failure; |
| 5896 | |
| 5897 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5898 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5899 | goto nla_put_failure; |
| 5900 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5901 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5902 | goto nla_put_failure; |
| 5903 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5904 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5905 | survey->channel_time)) |
| 5906 | goto nla_put_failure; |
| 5907 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5908 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5909 | survey->channel_time_busy)) |
| 5910 | goto nla_put_failure; |
| 5911 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5912 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5913 | survey->channel_time_ext_busy)) |
| 5914 | goto nla_put_failure; |
| 5915 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5916 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5917 | survey->channel_time_rx)) |
| 5918 | goto nla_put_failure; |
| 5919 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5920 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5921 | survey->channel_time_tx)) |
| 5922 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5923 | |
| 5924 | nla_nest_end(msg, infoattr); |
| 5925 | |
| 5926 | return genlmsg_end(msg, hdr); |
| 5927 | |
| 5928 | nla_put_failure: |
| 5929 | genlmsg_cancel(msg, hdr); |
| 5930 | return -EMSGSIZE; |
| 5931 | } |
| 5932 | |
| 5933 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5934 | struct netlink_callback *cb) |
| 5935 | { |
| 5936 | struct survey_info survey; |
| 5937 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5938 | struct wireless_dev *wdev; |
| 5939 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5940 | int res; |
| 5941 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5942 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5943 | if (res) |
| 5944 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5945 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5946 | if (!wdev->netdev) { |
| 5947 | res = -EINVAL; |
| 5948 | goto out_err; |
| 5949 | } |
| 5950 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5951 | if (!dev->ops->dump_survey) { |
| 5952 | res = -EOPNOTSUPP; |
| 5953 | goto out_err; |
| 5954 | } |
| 5955 | |
| 5956 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5957 | struct ieee80211_channel *chan; |
| 5958 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5959 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5960 | if (res == -ENOENT) |
| 5961 | break; |
| 5962 | if (res) |
| 5963 | goto out_err; |
| 5964 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5965 | /* Survey without a channel doesn't make sense */ |
| 5966 | if (!survey.channel) { |
| 5967 | res = -EINVAL; |
| 5968 | goto out; |
| 5969 | } |
| 5970 | |
| 5971 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5972 | survey.channel->center_freq); |
| 5973 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5974 | survey_idx++; |
| 5975 | continue; |
| 5976 | } |
| 5977 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5978 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5979 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5980 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5981 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5982 | goto out; |
| 5983 | survey_idx++; |
| 5984 | } |
| 5985 | |
| 5986 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5987 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5988 | res = skb->len; |
| 5989 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5990 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5991 | return res; |
| 5992 | } |
| 5993 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5994 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5995 | { |
| 5996 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5997 | NL80211_WPA_VERSION_2)); |
| 5998 | } |
| 5999 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6000 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6001 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6003 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6004 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6005 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6006 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6007 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6008 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6009 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6010 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6011 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6012 | return -EINVAL; |
| 6013 | |
| 6014 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6015 | return -EINVAL; |
| 6016 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6017 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6018 | return -EINVAL; |
| 6019 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6020 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6021 | return -EINVAL; |
| 6022 | |
| 6023 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6024 | return -EINVAL; |
| 6025 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6026 | err = nl80211_parse_key(info, &key); |
| 6027 | if (err) |
| 6028 | return err; |
| 6029 | |
| 6030 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6031 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6032 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6033 | if (!key.p.key || !key.p.key_len) |
| 6034 | return -EINVAL; |
| 6035 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6036 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6037 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6038 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6039 | return -EINVAL; |
| 6040 | if (key.idx > 4) |
| 6041 | return -EINVAL; |
| 6042 | } else { |
| 6043 | key.p.key_len = 0; |
| 6044 | key.p.key = NULL; |
| 6045 | } |
| 6046 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6047 | if (key.idx >= 0) { |
| 6048 | int i; |
| 6049 | bool ok = false; |
| 6050 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6051 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6052 | ok = true; |
| 6053 | break; |
| 6054 | } |
| 6055 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6056 | if (!ok) |
| 6057 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6058 | } |
| 6059 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6060 | if (!rdev->ops->auth) |
| 6061 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6062 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6063 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6064 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6065 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6066 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6067 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6068 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6069 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6070 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6071 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6072 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6073 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6074 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6075 | |
| 6076 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6077 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6078 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6079 | } |
| 6080 | |
| 6081 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6082 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6083 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6084 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6085 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6086 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6087 | return -EINVAL; |
| 6088 | |
| 6089 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6090 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6091 | return -EINVAL; |
| 6092 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6093 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6094 | /* need to include at least Auth Transaction and Status Code */ |
| 6095 | if (sae_data_len < 4) |
| 6096 | return -EINVAL; |
| 6097 | } |
| 6098 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6099 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6100 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6101 | /* |
| 6102 | * Since we no longer track auth state, ignore |
| 6103 | * requests to only change local state. |
| 6104 | */ |
| 6105 | if (local_state_change) |
| 6106 | return 0; |
| 6107 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6108 | wdev_lock(dev->ieee80211_ptr); |
| 6109 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6110 | ssid, ssid_len, ie, ie_len, |
| 6111 | key.p.key, key.p.key_len, key.idx, |
| 6112 | sae_data, sae_data_len); |
| 6113 | wdev_unlock(dev->ieee80211_ptr); |
| 6114 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6115 | } |
| 6116 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6117 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6118 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6119 | struct cfg80211_crypto_settings *settings, |
| 6120 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6121 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6122 | memset(settings, 0, sizeof(*settings)); |
| 6123 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6124 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6125 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6126 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6127 | u16 proto; |
| 6128 | proto = nla_get_u16( |
| 6129 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6130 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6131 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6132 | proto != ETH_P_PAE) |
| 6133 | return -EINVAL; |
| 6134 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6135 | settings->control_port_no_encrypt = true; |
| 6136 | } else |
| 6137 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6138 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6139 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6140 | void *data; |
| 6141 | int len, i; |
| 6142 | |
| 6143 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6144 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6145 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6146 | |
| 6147 | if (len % sizeof(u32)) |
| 6148 | return -EINVAL; |
| 6149 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6150 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6151 | return -EINVAL; |
| 6152 | |
| 6153 | memcpy(settings->ciphers_pairwise, data, len); |
| 6154 | |
| 6155 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6156 | if (!cfg80211_supported_cipher_suite( |
| 6157 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6158 | settings->ciphers_pairwise[i])) |
| 6159 | return -EINVAL; |
| 6160 | } |
| 6161 | |
| 6162 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6163 | settings->cipher_group = |
| 6164 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6165 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6166 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6167 | return -EINVAL; |
| 6168 | } |
| 6169 | |
| 6170 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6171 | settings->wpa_versions = |
| 6172 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6173 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6174 | return -EINVAL; |
| 6175 | } |
| 6176 | |
| 6177 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6178 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6179 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6180 | |
| 6181 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6182 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6183 | settings->n_akm_suites = len / sizeof(u32); |
| 6184 | |
| 6185 | if (len % sizeof(u32)) |
| 6186 | return -EINVAL; |
| 6187 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6188 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6189 | return -EINVAL; |
| 6190 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6191 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6192 | } |
| 6193 | |
| 6194 | return 0; |
| 6195 | } |
| 6196 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6197 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6198 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6200 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6201 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6202 | struct cfg80211_assoc_request req = {}; |
| 6203 | const u8 *bssid, *ssid; |
| 6204 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6205 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6206 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6207 | return -EINVAL; |
| 6208 | |
| 6209 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6210 | !info->attrs[NL80211_ATTR_SSID] || |
| 6211 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6212 | return -EINVAL; |
| 6213 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6214 | if (!rdev->ops->assoc) |
| 6215 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6216 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6217 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6218 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6219 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6220 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6221 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6222 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6223 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6224 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6225 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6226 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6227 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6228 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6229 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6230 | |
| 6231 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6232 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6233 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6234 | } |
| 6235 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6236 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6237 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6238 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6239 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6240 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6241 | else if (mfp != NL80211_MFP_NO) |
| 6242 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6243 | } |
| 6244 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6245 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6246 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6247 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6248 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6249 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6250 | |
| 6251 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6252 | memcpy(&req.ht_capa_mask, |
| 6253 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6254 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6255 | |
| 6256 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6257 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6258 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6259 | memcpy(&req.ht_capa, |
| 6260 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6261 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6262 | } |
| 6263 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6264 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6265 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6266 | |
| 6267 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6268 | memcpy(&req.vht_capa_mask, |
| 6269 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6270 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6271 | |
| 6272 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6273 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6274 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6275 | memcpy(&req.vht_capa, |
| 6276 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6277 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6278 | } |
| 6279 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6280 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6281 | if (!err) { |
| 6282 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6283 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6284 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6285 | wdev_unlock(dev->ieee80211_ptr); |
| 6286 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6287 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6288 | return err; |
| 6289 | } |
| 6290 | |
| 6291 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6292 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6294 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6295 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6296 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6297 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6298 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6299 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6300 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6301 | return -EINVAL; |
| 6302 | |
| 6303 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6304 | return -EINVAL; |
| 6305 | |
| 6306 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6307 | return -EINVAL; |
| 6308 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6309 | if (!rdev->ops->deauth) |
| 6310 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6311 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6312 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6313 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6314 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6315 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6316 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6317 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6318 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6319 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6320 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6321 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6322 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6323 | |
| 6324 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6325 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6326 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6327 | } |
| 6328 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6329 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6330 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6331 | wdev_lock(dev->ieee80211_ptr); |
| 6332 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6333 | local_state_change); |
| 6334 | wdev_unlock(dev->ieee80211_ptr); |
| 6335 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6339 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6340 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6341 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6342 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6343 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6344 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6345 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6346 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6347 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6348 | return -EINVAL; |
| 6349 | |
| 6350 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6351 | return -EINVAL; |
| 6352 | |
| 6353 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6354 | return -EINVAL; |
| 6355 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6356 | if (!rdev->ops->disassoc) |
| 6357 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6358 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6359 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6360 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6361 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6362 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6363 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6364 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6365 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6366 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6367 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6368 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6369 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6370 | |
| 6371 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6372 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6373 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6374 | } |
| 6375 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6376 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6377 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6378 | wdev_lock(dev->ieee80211_ptr); |
| 6379 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6380 | local_state_change); |
| 6381 | wdev_unlock(dev->ieee80211_ptr); |
| 6382 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6383 | } |
| 6384 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6385 | static bool |
| 6386 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6387 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6388 | int rateval) |
| 6389 | { |
| 6390 | struct wiphy *wiphy = &rdev->wiphy; |
| 6391 | bool found = false; |
| 6392 | int band, i; |
| 6393 | |
| 6394 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6395 | struct ieee80211_supported_band *sband; |
| 6396 | |
| 6397 | sband = wiphy->bands[band]; |
| 6398 | if (!sband) |
| 6399 | continue; |
| 6400 | |
| 6401 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6402 | if (sband->bitrates[i].bitrate == rateval) { |
| 6403 | mcast_rate[band] = i + 1; |
| 6404 | found = true; |
| 6405 | break; |
| 6406 | } |
| 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | return found; |
| 6411 | } |
| 6412 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6413 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6414 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6416 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6417 | struct cfg80211_ibss_params ibss; |
| 6418 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6419 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6420 | int err; |
| 6421 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6422 | memset(&ibss, 0, sizeof(ibss)); |
| 6423 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6424 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6425 | return -EINVAL; |
| 6426 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6427 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6428 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6429 | return -EINVAL; |
| 6430 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6431 | ibss.beacon_interval = 100; |
| 6432 | |
| 6433 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6434 | ibss.beacon_interval = |
| 6435 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6436 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6437 | return -EINVAL; |
| 6438 | } |
| 6439 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6440 | if (!rdev->ops->join_ibss) |
| 6441 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6442 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6443 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6444 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6445 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6446 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6447 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6448 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6449 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6450 | |
| 6451 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6452 | return -EINVAL; |
| 6453 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6454 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6455 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6456 | |
| 6457 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6458 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6459 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6460 | } |
| 6461 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6462 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6463 | if (err) |
| 6464 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6465 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6466 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6467 | return -EINVAL; |
| 6468 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6469 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6470 | case NL80211_CHAN_WIDTH_5: |
| 6471 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6472 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6473 | break; |
| 6474 | case NL80211_CHAN_WIDTH_20: |
| 6475 | case NL80211_CHAN_WIDTH_40: |
| 6476 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6477 | break; |
| 6478 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6479 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6480 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6481 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6482 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6483 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6484 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6485 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6486 | u8 *rates = |
| 6487 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6488 | int n_rates = |
| 6489 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6490 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6491 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6492 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6493 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6494 | &ibss.basic_rates); |
| 6495 | if (err) |
| 6496 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6497 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6498 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6499 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6500 | memcpy(&ibss.ht_capa_mask, |
| 6501 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6502 | sizeof(ibss.ht_capa_mask)); |
| 6503 | |
| 6504 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6505 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6506 | return -EINVAL; |
| 6507 | memcpy(&ibss.ht_capa, |
| 6508 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6509 | sizeof(ibss.ht_capa)); |
| 6510 | } |
| 6511 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6512 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6513 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6514 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6515 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6516 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6517 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6518 | bool no_ht = false; |
| 6519 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6520 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6521 | info->attrs[NL80211_ATTR_KEYS], |
| 6522 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6523 | if (IS_ERR(connkeys)) |
| 6524 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6525 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6526 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6527 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6528 | kfree(connkeys); |
| 6529 | return -EINVAL; |
| 6530 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6531 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6532 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6533 | ibss.control_port = |
| 6534 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6536 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6537 | if (err) |
| 6538 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6539 | return err; |
| 6540 | } |
| 6541 | |
| 6542 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6543 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6545 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6546 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6547 | if (!rdev->ops->leave_ibss) |
| 6548 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6549 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6550 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6551 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6552 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6553 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6554 | } |
| 6555 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6556 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6557 | { |
| 6558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6559 | struct net_device *dev = info->user_ptr[1]; |
| 6560 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6561 | u32 nla_rate; |
| 6562 | int err; |
| 6563 | |
| 6564 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6565 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6566 | return -EOPNOTSUPP; |
| 6567 | |
| 6568 | if (!rdev->ops->set_mcast_rate) |
| 6569 | return -EOPNOTSUPP; |
| 6570 | |
| 6571 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6572 | |
| 6573 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6574 | return -EINVAL; |
| 6575 | |
| 6576 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6577 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6578 | return -EINVAL; |
| 6579 | |
| 6580 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6581 | |
| 6582 | return err; |
| 6583 | } |
| 6584 | |
| 6585 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6586 | #ifdef CONFIG_NL80211_TESTMODE |
| 6587 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6588 | .name = "testmode", |
| 6589 | }; |
| 6590 | |
| 6591 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6592 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6593 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6594 | struct wireless_dev *wdev = |
| 6595 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6596 | int err; |
| 6597 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6598 | if (!rdev->ops->testmode_cmd) |
| 6599 | return -EOPNOTSUPP; |
| 6600 | |
| 6601 | if (IS_ERR(wdev)) { |
| 6602 | err = PTR_ERR(wdev); |
| 6603 | if (err != -EINVAL) |
| 6604 | return err; |
| 6605 | wdev = NULL; |
| 6606 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 6607 | return -EINVAL; |
| 6608 | } |
| 6609 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6610 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6611 | return -EINVAL; |
| 6612 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6613 | rdev->testmode_info = info; |
| 6614 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6615 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6616 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 6617 | rdev->testmode_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6618 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6619 | return err; |
| 6620 | } |
| 6621 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6622 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6623 | struct netlink_callback *cb) |
| 6624 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6625 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6626 | int err; |
| 6627 | long phy_idx; |
| 6628 | void *data = NULL; |
| 6629 | int data_len = 0; |
| 6630 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6631 | rtnl_lock(); |
| 6632 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6633 | if (cb->args[0]) { |
| 6634 | /* |
| 6635 | * 0 is a valid index, but not valid for args[0], |
| 6636 | * so we need to offset by 1. |
| 6637 | */ |
| 6638 | phy_idx = cb->args[0] - 1; |
| 6639 | } else { |
| 6640 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6641 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6642 | nl80211_policy); |
| 6643 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6644 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6645 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6646 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6647 | nl80211_fam.attrbuf); |
| 6648 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6649 | err = PTR_ERR(rdev); |
| 6650 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6651 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6652 | phy_idx = rdev->wiphy_idx; |
| 6653 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6654 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6655 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6656 | cb->args[1] = |
| 6657 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6658 | } |
| 6659 | |
| 6660 | if (cb->args[1]) { |
| 6661 | data = nla_data((void *)cb->args[1]); |
| 6662 | data_len = nla_len((void *)cb->args[1]); |
| 6663 | } |
| 6664 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6665 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6666 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6667 | err = -ENOENT; |
| 6668 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6669 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6670 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6671 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6672 | err = -EOPNOTSUPP; |
| 6673 | goto out_err; |
| 6674 | } |
| 6675 | |
| 6676 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6677 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6678 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6679 | NL80211_CMD_TESTMODE); |
| 6680 | struct nlattr *tmdata; |
| 6681 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6682 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6683 | genlmsg_cancel(skb, hdr); |
| 6684 | break; |
| 6685 | } |
| 6686 | |
| 6687 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6688 | if (!tmdata) { |
| 6689 | genlmsg_cancel(skb, hdr); |
| 6690 | break; |
| 6691 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6692 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6693 | nla_nest_end(skb, tmdata); |
| 6694 | |
| 6695 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6696 | genlmsg_cancel(skb, hdr); |
| 6697 | break; |
| 6698 | } else if (err) { |
| 6699 | genlmsg_cancel(skb, hdr); |
| 6700 | goto out_err; |
| 6701 | } |
| 6702 | |
| 6703 | genlmsg_end(skb, hdr); |
| 6704 | } |
| 6705 | |
| 6706 | err = skb->len; |
| 6707 | /* see above */ |
| 6708 | cb->args[0] = phy_idx + 1; |
| 6709 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6710 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6711 | return err; |
| 6712 | } |
| 6713 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6714 | static struct sk_buff * |
| 6715 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6716 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6717 | { |
| 6718 | struct sk_buff *skb; |
| 6719 | void *hdr; |
| 6720 | struct nlattr *data; |
| 6721 | |
| 6722 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6723 | if (!skb) |
| 6724 | return NULL; |
| 6725 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6726 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6727 | if (!hdr) { |
| 6728 | kfree_skb(skb); |
| 6729 | return NULL; |
| 6730 | } |
| 6731 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6732 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6733 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6734 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6735 | |
| 6736 | ((void **)skb->cb)[0] = rdev; |
| 6737 | ((void **)skb->cb)[1] = hdr; |
| 6738 | ((void **)skb->cb)[2] = data; |
| 6739 | |
| 6740 | return skb; |
| 6741 | |
| 6742 | nla_put_failure: |
| 6743 | kfree_skb(skb); |
| 6744 | return NULL; |
| 6745 | } |
| 6746 | |
| 6747 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6748 | int approxlen) |
| 6749 | { |
| 6750 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6751 | |
| 6752 | if (WARN_ON(!rdev->testmode_info)) |
| 6753 | return NULL; |
| 6754 | |
| 6755 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6756 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6757 | rdev->testmode_info->snd_seq, |
| 6758 | GFP_KERNEL); |
| 6759 | } |
| 6760 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6761 | |
| 6762 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6763 | { |
| 6764 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6765 | void *hdr = ((void **)skb->cb)[1]; |
| 6766 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6767 | |
| 6768 | if (WARN_ON(!rdev->testmode_info)) { |
| 6769 | kfree_skb(skb); |
| 6770 | return -EINVAL; |
| 6771 | } |
| 6772 | |
| 6773 | nla_nest_end(skb, data); |
| 6774 | genlmsg_end(skb, hdr); |
| 6775 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6776 | } |
| 6777 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6778 | |
| 6779 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6780 | int approxlen, gfp_t gfp) |
| 6781 | { |
| 6782 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6783 | |
| 6784 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6785 | } |
| 6786 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6787 | |
| 6788 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6789 | { |
| 6790 | void *hdr = ((void **)skb->cb)[1]; |
| 6791 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6792 | |
| 6793 | nla_nest_end(skb, data); |
| 6794 | genlmsg_end(skb, hdr); |
| 6795 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6796 | } |
| 6797 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6798 | #endif |
| 6799 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6800 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6801 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6802 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6803 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6804 | struct cfg80211_connect_params connect; |
| 6805 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6806 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6807 | int err; |
| 6808 | |
| 6809 | memset(&connect, 0, sizeof(connect)); |
| 6810 | |
| 6811 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6812 | return -EINVAL; |
| 6813 | |
| 6814 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6815 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6816 | return -EINVAL; |
| 6817 | |
| 6818 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6819 | connect.auth_type = |
| 6820 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6821 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6822 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6823 | return -EINVAL; |
| 6824 | } else |
| 6825 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6826 | |
| 6827 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6828 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6829 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6830 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6831 | if (err) |
| 6832 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6833 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6834 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6835 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6836 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6837 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6838 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6839 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6840 | connect.bg_scan_period = -1; |
| 6841 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6842 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6843 | connect.bg_scan_period = |
| 6844 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6845 | } |
| 6846 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6847 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6848 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6849 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6850 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6851 | |
| 6852 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6853 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6854 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6855 | } |
| 6856 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6857 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6858 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6859 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6860 | connect.mfp != NL80211_MFP_NO) |
| 6861 | return -EINVAL; |
| 6862 | } else { |
| 6863 | connect.mfp = NL80211_MFP_NO; |
| 6864 | } |
| 6865 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6866 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6867 | connect.channel = |
| 6868 | ieee80211_get_channel(wiphy, |
| 6869 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6870 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6871 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6872 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6873 | } |
| 6874 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6875 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6876 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6877 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6878 | if (IS_ERR(connkeys)) |
| 6879 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6880 | } |
| 6881 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6882 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6883 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6884 | |
| 6885 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6886 | memcpy(&connect.ht_capa_mask, |
| 6887 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6888 | sizeof(connect.ht_capa_mask)); |
| 6889 | |
| 6890 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6891 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6892 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6893 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6894 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6895 | memcpy(&connect.ht_capa, |
| 6896 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6897 | sizeof(connect.ht_capa)); |
| 6898 | } |
| 6899 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6900 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6901 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6902 | |
| 6903 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6904 | memcpy(&connect.vht_capa_mask, |
| 6905 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6906 | sizeof(connect.vht_capa_mask)); |
| 6907 | |
| 6908 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6909 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6910 | kfree(connkeys); |
| 6911 | return -EINVAL; |
| 6912 | } |
| 6913 | memcpy(&connect.vht_capa, |
| 6914 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6915 | sizeof(connect.vht_capa)); |
| 6916 | } |
| 6917 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6918 | wdev_lock(dev->ieee80211_ptr); |
| 6919 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6920 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6921 | if (err) |
| 6922 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6923 | return err; |
| 6924 | } |
| 6925 | |
| 6926 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6927 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6929 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6930 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6931 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6932 | |
| 6933 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6934 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6935 | else |
| 6936 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6937 | |
| 6938 | if (reason == 0) |
| 6939 | return -EINVAL; |
| 6940 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6941 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6942 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6943 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6944 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6945 | wdev_lock(dev->ieee80211_ptr); |
| 6946 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 6947 | wdev_unlock(dev->ieee80211_ptr); |
| 6948 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6949 | } |
| 6950 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6951 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6952 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6954 | struct net *net; |
| 6955 | int err; |
| 6956 | u32 pid; |
| 6957 | |
| 6958 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6959 | return -EINVAL; |
| 6960 | |
| 6961 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6962 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6963 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6964 | if (IS_ERR(net)) |
| 6965 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6966 | |
| 6967 | err = 0; |
| 6968 | |
| 6969 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6970 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6971 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6972 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6973 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6974 | return err; |
| 6975 | } |
| 6976 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6977 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6978 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6979 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6980 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6981 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6982 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6983 | struct cfg80211_pmksa pmksa; |
| 6984 | |
| 6985 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6986 | |
| 6987 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6988 | return -EINVAL; |
| 6989 | |
| 6990 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6991 | return -EINVAL; |
| 6992 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6993 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6994 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6995 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6996 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6997 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6998 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6999 | |
| 7000 | switch (info->genlhdr->cmd) { |
| 7001 | case NL80211_CMD_SET_PMKSA: |
| 7002 | rdev_ops = rdev->ops->set_pmksa; |
| 7003 | break; |
| 7004 | case NL80211_CMD_DEL_PMKSA: |
| 7005 | rdev_ops = rdev->ops->del_pmksa; |
| 7006 | break; |
| 7007 | default: |
| 7008 | WARN_ON(1); |
| 7009 | break; |
| 7010 | } |
| 7011 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7012 | if (!rdev_ops) |
| 7013 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7014 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7015 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7016 | } |
| 7017 | |
| 7018 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7019 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7020 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7021 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7022 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7023 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7024 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7025 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7026 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7027 | if (!rdev->ops->flush_pmksa) |
| 7028 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7029 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7030 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7031 | } |
| 7032 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7033 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7034 | { |
| 7035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7036 | struct net_device *dev = info->user_ptr[1]; |
| 7037 | u8 action_code, dialog_token; |
| 7038 | u16 status_code; |
| 7039 | u8 *peer; |
| 7040 | |
| 7041 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7042 | !rdev->ops->tdls_mgmt) |
| 7043 | return -EOPNOTSUPP; |
| 7044 | |
| 7045 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7046 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7047 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7048 | !info->attrs[NL80211_ATTR_IE] || |
| 7049 | !info->attrs[NL80211_ATTR_MAC]) |
| 7050 | return -EINVAL; |
| 7051 | |
| 7052 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7053 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7054 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7055 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 7056 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7057 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 7058 | dialog_token, status_code, |
| 7059 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7060 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7061 | } |
| 7062 | |
| 7063 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7064 | { |
| 7065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7066 | struct net_device *dev = info->user_ptr[1]; |
| 7067 | enum nl80211_tdls_operation operation; |
| 7068 | u8 *peer; |
| 7069 | |
| 7070 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7071 | !rdev->ops->tdls_oper) |
| 7072 | return -EOPNOTSUPP; |
| 7073 | |
| 7074 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7075 | !info->attrs[NL80211_ATTR_MAC]) |
| 7076 | return -EINVAL; |
| 7077 | |
| 7078 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7079 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7080 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7081 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7082 | } |
| 7083 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7084 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7085 | struct genl_info *info) |
| 7086 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7088 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7089 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7090 | struct sk_buff *msg; |
| 7091 | void *hdr; |
| 7092 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7093 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7094 | int err; |
| 7095 | |
| 7096 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7097 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7098 | return -EINVAL; |
| 7099 | |
| 7100 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7101 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7102 | if (!rdev->ops->remain_on_channel || |
| 7103 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7104 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7105 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7106 | /* |
| 7107 | * We should be on that channel for at least a minimum amount of |
| 7108 | * time (10ms) but no longer than the driver supports. |
| 7109 | */ |
| 7110 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7111 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7112 | return -EINVAL; |
| 7113 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7114 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7115 | if (err) |
| 7116 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7117 | |
| 7118 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7119 | if (!msg) |
| 7120 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7121 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7122 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7123 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 7124 | |
| 7125 | if (IS_ERR(hdr)) { |
| 7126 | err = PTR_ERR(hdr); |
| 7127 | goto free_msg; |
| 7128 | } |
| 7129 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7130 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7131 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7132 | |
| 7133 | if (err) |
| 7134 | goto free_msg; |
| 7135 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7136 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7137 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7138 | |
| 7139 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7140 | |
| 7141 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7142 | |
| 7143 | nla_put_failure: |
| 7144 | err = -ENOBUFS; |
| 7145 | free_msg: |
| 7146 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7147 | return err; |
| 7148 | } |
| 7149 | |
| 7150 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7151 | struct genl_info *info) |
| 7152 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7153 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7154 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7155 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7156 | |
| 7157 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7158 | return -EINVAL; |
| 7159 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7160 | if (!rdev->ops->cancel_remain_on_channel) |
| 7161 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7162 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7163 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7164 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7165 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7166 | } |
| 7167 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7168 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7169 | u8 *rates, u8 rates_len) |
| 7170 | { |
| 7171 | u8 i; |
| 7172 | u32 mask = 0; |
| 7173 | |
| 7174 | for (i = 0; i < rates_len; i++) { |
| 7175 | int rate = (rates[i] & 0x7f) * 5; |
| 7176 | int ridx; |
| 7177 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7178 | struct ieee80211_rate *srate = |
| 7179 | &sband->bitrates[ridx]; |
| 7180 | if (rate == srate->bitrate) { |
| 7181 | mask |= 1 << ridx; |
| 7182 | break; |
| 7183 | } |
| 7184 | } |
| 7185 | if (ridx == sband->n_bitrates) |
| 7186 | return 0; /* rate not found */ |
| 7187 | } |
| 7188 | |
| 7189 | return mask; |
| 7190 | } |
| 7191 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7192 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7193 | u8 *rates, u8 rates_len, |
| 7194 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7195 | { |
| 7196 | u8 i; |
| 7197 | |
| 7198 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7199 | |
| 7200 | for (i = 0; i < rates_len; i++) { |
| 7201 | int ridx, rbit; |
| 7202 | |
| 7203 | ridx = rates[i] / 8; |
| 7204 | rbit = BIT(rates[i] % 8); |
| 7205 | |
| 7206 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7207 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7208 | return false; |
| 7209 | |
| 7210 | /* check availability */ |
| 7211 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7212 | mcs[ridx] |= rbit; |
| 7213 | else |
| 7214 | return false; |
| 7215 | } |
| 7216 | |
| 7217 | return true; |
| 7218 | } |
| 7219 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7220 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7221 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7222 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7223 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7224 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7225 | }; |
| 7226 | |
| 7227 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7228 | struct genl_info *info) |
| 7229 | { |
| 7230 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7231 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7232 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7233 | int rem, i; |
| 7234 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7235 | struct nlattr *tx_rates; |
| 7236 | struct ieee80211_supported_band *sband; |
| 7237 | |
| 7238 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7239 | return -EINVAL; |
| 7240 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7241 | if (!rdev->ops->set_bitrate_mask) |
| 7242 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7243 | |
| 7244 | memset(&mask, 0, sizeof(mask)); |
| 7245 | /* Default to all rates enabled */ |
| 7246 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7247 | sband = rdev->wiphy.bands[i]; |
| 7248 | mask.control[i].legacy = |
| 7249 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7250 | if (sband) |
| 7251 | memcpy(mask.control[i].mcs, |
| 7252 | sband->ht_cap.mcs.rx_mask, |
| 7253 | sizeof(mask.control[i].mcs)); |
| 7254 | else |
| 7255 | memset(mask.control[i].mcs, 0, |
| 7256 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7257 | } |
| 7258 | |
| 7259 | /* |
| 7260 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7261 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7262 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7263 | 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] | 7264 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7265 | { |
| 7266 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7267 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7268 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7269 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7270 | if (sband == NULL) |
| 7271 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7272 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7273 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7274 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7275 | mask.control[band].legacy = rateset_to_mask( |
| 7276 | sband, |
| 7277 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7278 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7279 | if ((mask.control[band].legacy == 0) && |
| 7280 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7281 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7282 | } |
| 7283 | if (tb[NL80211_TXRATE_MCS]) { |
| 7284 | if (!ht_rateset_to_mask( |
| 7285 | sband, |
| 7286 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7287 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7288 | mask.control[band].mcs)) |
| 7289 | return -EINVAL; |
| 7290 | } |
| 7291 | |
| 7292 | if (mask.control[band].legacy == 0) { |
| 7293 | /* don't allow empty legacy rates if HT |
| 7294 | * is not even supported. */ |
| 7295 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7296 | return -EINVAL; |
| 7297 | |
| 7298 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7299 | if (mask.control[band].mcs[i]) |
| 7300 | break; |
| 7301 | |
| 7302 | /* legacy and mcs rates may not be both empty */ |
| 7303 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7304 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7305 | } |
| 7306 | } |
| 7307 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7308 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7309 | } |
| 7310 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7311 | 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] | 7312 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7314 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7315 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7316 | |
| 7317 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7318 | return -EINVAL; |
| 7319 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7320 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7321 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7322 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7323 | switch (wdev->iftype) { |
| 7324 | case NL80211_IFTYPE_STATION: |
| 7325 | case NL80211_IFTYPE_ADHOC: |
| 7326 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7327 | case NL80211_IFTYPE_AP: |
| 7328 | case NL80211_IFTYPE_AP_VLAN: |
| 7329 | case NL80211_IFTYPE_MESH_POINT: |
| 7330 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7331 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7332 | break; |
| 7333 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7334 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7335 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7336 | |
| 7337 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7338 | if (!rdev->ops->mgmt_tx) |
| 7339 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7340 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7341 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7342 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7343 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7344 | } |
| 7345 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7346 | 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] | 7347 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7348 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7349 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7350 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7351 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7352 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7353 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7354 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7355 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7356 | bool offchan, no_cck, dont_wait_for_ack; |
| 7357 | |
| 7358 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7359 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7360 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7361 | return -EINVAL; |
| 7362 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7363 | if (!rdev->ops->mgmt_tx) |
| 7364 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7365 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7366 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7367 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7368 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7369 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7370 | case NL80211_IFTYPE_STATION: |
| 7371 | case NL80211_IFTYPE_ADHOC: |
| 7372 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7373 | case NL80211_IFTYPE_AP: |
| 7374 | case NL80211_IFTYPE_AP_VLAN: |
| 7375 | case NL80211_IFTYPE_MESH_POINT: |
| 7376 | case NL80211_IFTYPE_P2P_GO: |
| 7377 | break; |
| 7378 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7379 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7380 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7381 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7382 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7383 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7384 | return -EINVAL; |
| 7385 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7386 | |
| 7387 | /* |
| 7388 | * We should wait on the channel for at least a minimum amount |
| 7389 | * of time (10ms) but no longer than the driver supports. |
| 7390 | */ |
| 7391 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7392 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7393 | return -EINVAL; |
| 7394 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7395 | } |
| 7396 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7397 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7398 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7399 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7400 | return -EINVAL; |
| 7401 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7402 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7403 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7404 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7405 | * the driver. The latter will use the current one |
| 7406 | */ |
| 7407 | chandef.chan = NULL; |
| 7408 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7409 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7410 | if (err) |
| 7411 | return err; |
| 7412 | } |
| 7413 | |
| 7414 | if (!chandef.chan && offchan) |
| 7415 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7416 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7417 | if (!dont_wait_for_ack) { |
| 7418 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7419 | if (!msg) |
| 7420 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7421 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7422 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7423 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7424 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7425 | if (IS_ERR(hdr)) { |
| 7426 | err = PTR_ERR(hdr); |
| 7427 | goto free_msg; |
| 7428 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7429 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7430 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7431 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7432 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7433 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7434 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7435 | if (err) |
| 7436 | goto free_msg; |
| 7437 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7438 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7439 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7440 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7441 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7442 | genlmsg_end(msg, hdr); |
| 7443 | return genlmsg_reply(msg, info); |
| 7444 | } |
| 7445 | |
| 7446 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7447 | |
| 7448 | nla_put_failure: |
| 7449 | err = -ENOBUFS; |
| 7450 | free_msg: |
| 7451 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7452 | return err; |
| 7453 | } |
| 7454 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7455 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7456 | { |
| 7457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7458 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7459 | u64 cookie; |
| 7460 | |
| 7461 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7462 | return -EINVAL; |
| 7463 | |
| 7464 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7465 | return -EOPNOTSUPP; |
| 7466 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7467 | switch (wdev->iftype) { |
| 7468 | case NL80211_IFTYPE_STATION: |
| 7469 | case NL80211_IFTYPE_ADHOC: |
| 7470 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7471 | case NL80211_IFTYPE_AP: |
| 7472 | case NL80211_IFTYPE_AP_VLAN: |
| 7473 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7474 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7475 | break; |
| 7476 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7477 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7478 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7479 | |
| 7480 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7481 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7482 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7483 | } |
| 7484 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7485 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7486 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7488 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7489 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7490 | u8 ps_state; |
| 7491 | bool state; |
| 7492 | int err; |
| 7493 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7494 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7495 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7496 | |
| 7497 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7498 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7499 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7500 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7501 | |
| 7502 | wdev = dev->ieee80211_ptr; |
| 7503 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7504 | if (!rdev->ops->set_power_mgmt) |
| 7505 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7506 | |
| 7507 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7508 | |
| 7509 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7510 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7511 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7512 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7513 | if (!err) |
| 7514 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7515 | return err; |
| 7516 | } |
| 7517 | |
| 7518 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7519 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7521 | enum nl80211_ps_state ps_state; |
| 7522 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7523 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7524 | struct sk_buff *msg; |
| 7525 | void *hdr; |
| 7526 | int err; |
| 7527 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7528 | wdev = dev->ieee80211_ptr; |
| 7529 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7530 | if (!rdev->ops->set_power_mgmt) |
| 7531 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7532 | |
| 7533 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7534 | if (!msg) |
| 7535 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7536 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7537 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7538 | NL80211_CMD_GET_POWER_SAVE); |
| 7539 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7540 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7541 | goto free_msg; |
| 7542 | } |
| 7543 | |
| 7544 | if (wdev->ps) |
| 7545 | ps_state = NL80211_PS_ENABLED; |
| 7546 | else |
| 7547 | ps_state = NL80211_PS_DISABLED; |
| 7548 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7549 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7550 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7551 | |
| 7552 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7553 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7554 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7555 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7556 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7557 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7558 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7559 | return err; |
| 7560 | } |
| 7561 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7562 | static struct nla_policy |
| 7563 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7564 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7565 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7566 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7567 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7568 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7569 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7570 | }; |
| 7571 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7572 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7573 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7574 | { |
| 7575 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7576 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7577 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7578 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7579 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7580 | return -EINVAL; |
| 7581 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7582 | if (!rdev->ops->set_cqm_txe_config) |
| 7583 | return -EOPNOTSUPP; |
| 7584 | |
| 7585 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7586 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7587 | return -EOPNOTSUPP; |
| 7588 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7589 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7590 | } |
| 7591 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7592 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7593 | s32 threshold, u32 hysteresis) |
| 7594 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7595 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7596 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7597 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7598 | |
| 7599 | if (threshold > 0) |
| 7600 | return -EINVAL; |
| 7601 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7602 | /* disabling - hysteresis should also be zero then */ |
| 7603 | if (threshold == 0) |
| 7604 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7605 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7606 | if (!rdev->ops->set_cqm_rssi_config) |
| 7607 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7608 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7609 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7610 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7611 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7612 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7613 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7614 | } |
| 7615 | |
| 7616 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7617 | { |
| 7618 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7619 | struct nlattr *cqm; |
| 7620 | int err; |
| 7621 | |
| 7622 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7623 | if (!cqm) |
| 7624 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7625 | |
| 7626 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7627 | nl80211_attr_cqm_policy); |
| 7628 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7629 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7630 | |
| 7631 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7632 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7633 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7634 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7635 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 7636 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 7637 | } |
| 7638 | |
| 7639 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7640 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7641 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7642 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7643 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7644 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7645 | |
| 7646 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 7647 | } |
| 7648 | |
| 7649 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7650 | } |
| 7651 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7652 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7653 | { |
| 7654 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7655 | struct net_device *dev = info->user_ptr[1]; |
| 7656 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7657 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7658 | int err; |
| 7659 | |
| 7660 | /* start with default */ |
| 7661 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7662 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7663 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7664 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7665 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7666 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7667 | if (err) |
| 7668 | return err; |
| 7669 | } |
| 7670 | |
| 7671 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7672 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7673 | return -EINVAL; |
| 7674 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7675 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7676 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7677 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7678 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7679 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7680 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7681 | return -EINVAL; |
| 7682 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7683 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7684 | setup.beacon_interval = |
| 7685 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7686 | if (setup.beacon_interval < 10 || |
| 7687 | setup.beacon_interval > 10000) |
| 7688 | return -EINVAL; |
| 7689 | } |
| 7690 | |
| 7691 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7692 | setup.dtim_period = |
| 7693 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7694 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7695 | return -EINVAL; |
| 7696 | } |
| 7697 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7698 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7699 | /* parse additional setup parameters if given */ |
| 7700 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7701 | if (err) |
| 7702 | return err; |
| 7703 | } |
| 7704 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7705 | if (setup.user_mpm) |
| 7706 | cfg.auto_open_plinks = false; |
| 7707 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7708 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7709 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7710 | if (err) |
| 7711 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7712 | } else { |
| 7713 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7714 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7715 | } |
| 7716 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7717 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7718 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7719 | int n_rates = |
| 7720 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7721 | struct ieee80211_supported_band *sband; |
| 7722 | |
| 7723 | if (!setup.chandef.chan) |
| 7724 | return -EINVAL; |
| 7725 | |
| 7726 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7727 | |
| 7728 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7729 | &setup.basic_rates); |
| 7730 | if (err) |
| 7731 | return err; |
| 7732 | } |
| 7733 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7734 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7735 | } |
| 7736 | |
| 7737 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7738 | { |
| 7739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7740 | struct net_device *dev = info->user_ptr[1]; |
| 7741 | |
| 7742 | return cfg80211_leave_mesh(rdev, dev); |
| 7743 | } |
| 7744 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7745 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7746 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7747 | struct cfg80211_registered_device *rdev) |
| 7748 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7749 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7750 | struct nlattr *nl_pats, *nl_pat; |
| 7751 | int i, pat_len; |
| 7752 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7753 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7754 | return 0; |
| 7755 | |
| 7756 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7757 | if (!nl_pats) |
| 7758 | return -ENOBUFS; |
| 7759 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7760 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7761 | nl_pat = nla_nest_start(msg, i + 1); |
| 7762 | if (!nl_pat) |
| 7763 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7764 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7765 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7766 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 7767 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 7768 | wowlan->patterns[i].pattern) || |
| 7769 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7770 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7771 | return -ENOBUFS; |
| 7772 | nla_nest_end(msg, nl_pat); |
| 7773 | } |
| 7774 | nla_nest_end(msg, nl_pats); |
| 7775 | |
| 7776 | return 0; |
| 7777 | } |
| 7778 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7779 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7780 | struct cfg80211_wowlan_tcp *tcp) |
| 7781 | { |
| 7782 | struct nlattr *nl_tcp; |
| 7783 | |
| 7784 | if (!tcp) |
| 7785 | return 0; |
| 7786 | |
| 7787 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7788 | if (!nl_tcp) |
| 7789 | return -ENOBUFS; |
| 7790 | |
| 7791 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7792 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7793 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7794 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7795 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7796 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7797 | tcp->payload_len, tcp->payload) || |
| 7798 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7799 | tcp->data_interval) || |
| 7800 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7801 | tcp->wake_len, tcp->wake_data) || |
| 7802 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7803 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7804 | return -ENOBUFS; |
| 7805 | |
| 7806 | if (tcp->payload_seq.len && |
| 7807 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7808 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7809 | return -ENOBUFS; |
| 7810 | |
| 7811 | if (tcp->payload_tok.len && |
| 7812 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7813 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7814 | &tcp->payload_tok)) |
| 7815 | return -ENOBUFS; |
| 7816 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7817 | nla_nest_end(msg, nl_tcp); |
| 7818 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7819 | return 0; |
| 7820 | } |
| 7821 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7822 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7823 | { |
| 7824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7825 | struct sk_buff *msg; |
| 7826 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7827 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7828 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7829 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7830 | return -EOPNOTSUPP; |
| 7831 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7832 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7833 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7834 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7835 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7836 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7837 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7838 | } |
| 7839 | |
| 7840 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7841 | if (!msg) |
| 7842 | return -ENOMEM; |
| 7843 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7844 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7845 | NL80211_CMD_GET_WOWLAN); |
| 7846 | if (!hdr) |
| 7847 | goto nla_put_failure; |
| 7848 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7849 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7850 | struct nlattr *nl_wowlan; |
| 7851 | |
| 7852 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7853 | if (!nl_wowlan) |
| 7854 | goto nla_put_failure; |
| 7855 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7856 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7857 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7858 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7859 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7860 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7861 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7862 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7863 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7864 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7865 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7866 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7867 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7868 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7869 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7870 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7871 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7872 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7873 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7874 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7875 | if (nl80211_send_wowlan_tcp(msg, |
| 7876 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7877 | goto nla_put_failure; |
| 7878 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7879 | nla_nest_end(msg, nl_wowlan); |
| 7880 | } |
| 7881 | |
| 7882 | genlmsg_end(msg, hdr); |
| 7883 | return genlmsg_reply(msg, info); |
| 7884 | |
| 7885 | nla_put_failure: |
| 7886 | nlmsg_free(msg); |
| 7887 | return -ENOBUFS; |
| 7888 | } |
| 7889 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7890 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7891 | struct nlattr *attr, |
| 7892 | struct cfg80211_wowlan *trig) |
| 7893 | { |
| 7894 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7895 | struct cfg80211_wowlan_tcp *cfg; |
| 7896 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7897 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7898 | u32 size; |
| 7899 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7900 | int err, port; |
| 7901 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7902 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7903 | return -EINVAL; |
| 7904 | |
| 7905 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7906 | nla_data(attr), nla_len(attr), |
| 7907 | nl80211_wowlan_tcp_policy); |
| 7908 | if (err) |
| 7909 | return err; |
| 7910 | |
| 7911 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7912 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7913 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7914 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7915 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7916 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7917 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7918 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7919 | return -EINVAL; |
| 7920 | |
| 7921 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7922 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7923 | return -EINVAL; |
| 7924 | |
| 7925 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7926 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7927 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7928 | return -EINVAL; |
| 7929 | |
| 7930 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7931 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7932 | return -EINVAL; |
| 7933 | |
| 7934 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7935 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7936 | return -EINVAL; |
| 7937 | |
| 7938 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7939 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7940 | |
| 7941 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7942 | tokens_size = tokln - sizeof(*tok); |
| 7943 | |
| 7944 | if (!tok->len || tokens_size % tok->len) |
| 7945 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7946 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7947 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7948 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7949 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7950 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7951 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7952 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7953 | return -EINVAL; |
| 7954 | if (tok->offset + tok->len > data_size) |
| 7955 | return -EINVAL; |
| 7956 | } |
| 7957 | |
| 7958 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7959 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7960 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7961 | return -EINVAL; |
| 7962 | if (seq->len == 0 || seq->len > 4) |
| 7963 | return -EINVAL; |
| 7964 | if (seq->len + seq->offset > data_size) |
| 7965 | return -EINVAL; |
| 7966 | } |
| 7967 | |
| 7968 | size = sizeof(*cfg); |
| 7969 | size += data_size; |
| 7970 | size += wake_size + wake_mask_size; |
| 7971 | size += tokens_size; |
| 7972 | |
| 7973 | cfg = kzalloc(size, GFP_KERNEL); |
| 7974 | if (!cfg) |
| 7975 | return -ENOMEM; |
| 7976 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7977 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7978 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7979 | ETH_ALEN); |
| 7980 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7981 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7982 | else |
| 7983 | port = 0; |
| 7984 | #ifdef CONFIG_INET |
| 7985 | /* allocate a socket and port for it and use it */ |
| 7986 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7987 | IPPROTO_TCP, &cfg->sock, 1); |
| 7988 | if (err) { |
| 7989 | kfree(cfg); |
| 7990 | return err; |
| 7991 | } |
| 7992 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7993 | sock_release(cfg->sock); |
| 7994 | kfree(cfg); |
| 7995 | return -EADDRINUSE; |
| 7996 | } |
| 7997 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7998 | #else |
| 7999 | if (!port) { |
| 8000 | kfree(cfg); |
| 8001 | return -EINVAL; |
| 8002 | } |
| 8003 | cfg->src_port = port; |
| 8004 | #endif |
| 8005 | |
| 8006 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8007 | cfg->payload_len = data_size; |
| 8008 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8009 | memcpy((void *)cfg->payload, |
| 8010 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8011 | data_size); |
| 8012 | if (seq) |
| 8013 | cfg->payload_seq = *seq; |
| 8014 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8015 | cfg->wake_len = wake_size; |
| 8016 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8017 | memcpy((void *)cfg->wake_data, |
| 8018 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8019 | wake_size); |
| 8020 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8021 | data_size + wake_size; |
| 8022 | memcpy((void *)cfg->wake_mask, |
| 8023 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8024 | wake_mask_size); |
| 8025 | if (tok) { |
| 8026 | cfg->tokens_size = tokens_size; |
| 8027 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8028 | } |
| 8029 | |
| 8030 | trig->tcp = cfg; |
| 8031 | |
| 8032 | return 0; |
| 8033 | } |
| 8034 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8035 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8036 | { |
| 8037 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8038 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8039 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8040 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8041 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8042 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8043 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8044 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8045 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8046 | return -EOPNOTSUPP; |
| 8047 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8048 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8049 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8050 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8051 | goto set_wakeup; |
| 8052 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8053 | |
| 8054 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8055 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8056 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8057 | nl80211_wowlan_policy); |
| 8058 | if (err) |
| 8059 | return err; |
| 8060 | |
| 8061 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8062 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8063 | return -EINVAL; |
| 8064 | new_triggers.any = true; |
| 8065 | } |
| 8066 | |
| 8067 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8068 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8069 | return -EINVAL; |
| 8070 | new_triggers.disconnect = true; |
| 8071 | } |
| 8072 | |
| 8073 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8074 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8075 | return -EINVAL; |
| 8076 | new_triggers.magic_pkt = true; |
| 8077 | } |
| 8078 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8079 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8080 | return -EINVAL; |
| 8081 | |
| 8082 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8083 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8084 | return -EINVAL; |
| 8085 | new_triggers.gtk_rekey_failure = true; |
| 8086 | } |
| 8087 | |
| 8088 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8089 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8090 | return -EINVAL; |
| 8091 | new_triggers.eap_identity_req = true; |
| 8092 | } |
| 8093 | |
| 8094 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8095 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8096 | return -EINVAL; |
| 8097 | new_triggers.four_way_handshake = true; |
| 8098 | } |
| 8099 | |
| 8100 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8101 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8102 | return -EINVAL; |
| 8103 | new_triggers.rfkill_release = true; |
| 8104 | } |
| 8105 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8106 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8107 | struct nlattr *pat; |
| 8108 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8109 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8110 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8111 | |
| 8112 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8113 | rem) |
| 8114 | n_patterns++; |
| 8115 | if (n_patterns > wowlan->n_patterns) |
| 8116 | return -EINVAL; |
| 8117 | |
| 8118 | new_triggers.patterns = kcalloc(n_patterns, |
| 8119 | sizeof(new_triggers.patterns[0]), |
| 8120 | GFP_KERNEL); |
| 8121 | if (!new_triggers.patterns) |
| 8122 | return -ENOMEM; |
| 8123 | |
| 8124 | new_triggers.n_patterns = n_patterns; |
| 8125 | i = 0; |
| 8126 | |
| 8127 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8128 | rem) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8129 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8130 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8131 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8132 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8133 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8134 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8135 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8136 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8137 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8138 | goto error; |
| 8139 | if (pat_len > wowlan->pattern_max_len || |
| 8140 | pat_len < wowlan->pattern_min_len) |
| 8141 | goto error; |
| 8142 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8143 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8144 | pkt_offset = 0; |
| 8145 | else |
| 8146 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8147 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8148 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8149 | goto error; |
| 8150 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8151 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8152 | new_triggers.patterns[i].mask = |
| 8153 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8154 | if (!new_triggers.patterns[i].mask) { |
| 8155 | err = -ENOMEM; |
| 8156 | goto error; |
| 8157 | } |
| 8158 | new_triggers.patterns[i].pattern = |
| 8159 | new_triggers.patterns[i].mask + mask_len; |
| 8160 | memcpy(new_triggers.patterns[i].mask, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8161 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8162 | mask_len); |
| 8163 | new_triggers.patterns[i].pattern_len = pat_len; |
| 8164 | memcpy(new_triggers.patterns[i].pattern, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8165 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8166 | pat_len); |
| 8167 | i++; |
| 8168 | } |
| 8169 | } |
| 8170 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8171 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8172 | err = nl80211_parse_wowlan_tcp( |
| 8173 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8174 | &new_triggers); |
| 8175 | if (err) |
| 8176 | goto error; |
| 8177 | } |
| 8178 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8179 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8180 | if (!ntrig) { |
| 8181 | err = -ENOMEM; |
| 8182 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8183 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8184 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8185 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8186 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8187 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8188 | if (rdev->ops->set_wakeup && |
| 8189 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8190 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8191 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8192 | return 0; |
| 8193 | error: |
| 8194 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8195 | kfree(new_triggers.patterns[i].mask); |
| 8196 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8197 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8198 | sock_release(new_triggers.tcp->sock); |
| 8199 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8200 | return err; |
| 8201 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8202 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8203 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8204 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8205 | struct cfg80211_registered_device *rdev) |
| 8206 | { |
| 8207 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8208 | int i, j, pat_len; |
| 8209 | struct cfg80211_coalesce_rules *rule; |
| 8210 | |
| 8211 | if (!rdev->coalesce->n_rules) |
| 8212 | return 0; |
| 8213 | |
| 8214 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8215 | if (!nl_rules) |
| 8216 | return -ENOBUFS; |
| 8217 | |
| 8218 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8219 | nl_rule = nla_nest_start(msg, i + 1); |
| 8220 | if (!nl_rule) |
| 8221 | return -ENOBUFS; |
| 8222 | |
| 8223 | rule = &rdev->coalesce->rules[i]; |
| 8224 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8225 | rule->delay)) |
| 8226 | return -ENOBUFS; |
| 8227 | |
| 8228 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8229 | rule->condition)) |
| 8230 | return -ENOBUFS; |
| 8231 | |
| 8232 | nl_pats = nla_nest_start(msg, |
| 8233 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8234 | if (!nl_pats) |
| 8235 | return -ENOBUFS; |
| 8236 | |
| 8237 | for (j = 0; j < rule->n_patterns; j++) { |
| 8238 | nl_pat = nla_nest_start(msg, j + 1); |
| 8239 | if (!nl_pat) |
| 8240 | return -ENOBUFS; |
| 8241 | pat_len = rule->patterns[j].pattern_len; |
| 8242 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8243 | DIV_ROUND_UP(pat_len, 8), |
| 8244 | rule->patterns[j].mask) || |
| 8245 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8246 | rule->patterns[j].pattern) || |
| 8247 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8248 | rule->patterns[j].pkt_offset)) |
| 8249 | return -ENOBUFS; |
| 8250 | nla_nest_end(msg, nl_pat); |
| 8251 | } |
| 8252 | nla_nest_end(msg, nl_pats); |
| 8253 | nla_nest_end(msg, nl_rule); |
| 8254 | } |
| 8255 | nla_nest_end(msg, nl_rules); |
| 8256 | |
| 8257 | return 0; |
| 8258 | } |
| 8259 | |
| 8260 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8261 | { |
| 8262 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8263 | struct sk_buff *msg; |
| 8264 | void *hdr; |
| 8265 | |
| 8266 | if (!rdev->wiphy.coalesce) |
| 8267 | return -EOPNOTSUPP; |
| 8268 | |
| 8269 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8270 | if (!msg) |
| 8271 | return -ENOMEM; |
| 8272 | |
| 8273 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8274 | NL80211_CMD_GET_COALESCE); |
| 8275 | if (!hdr) |
| 8276 | goto nla_put_failure; |
| 8277 | |
| 8278 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8279 | goto nla_put_failure; |
| 8280 | |
| 8281 | genlmsg_end(msg, hdr); |
| 8282 | return genlmsg_reply(msg, info); |
| 8283 | |
| 8284 | nla_put_failure: |
| 8285 | nlmsg_free(msg); |
| 8286 | return -ENOBUFS; |
| 8287 | } |
| 8288 | |
| 8289 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8290 | { |
| 8291 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8292 | int i, j; |
| 8293 | struct cfg80211_coalesce_rules *rule; |
| 8294 | |
| 8295 | if (!coalesce) |
| 8296 | return; |
| 8297 | |
| 8298 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8299 | rule = &coalesce->rules[i]; |
| 8300 | for (j = 0; j < rule->n_patterns; j++) |
| 8301 | kfree(rule->patterns[j].mask); |
| 8302 | kfree(rule->patterns); |
| 8303 | } |
| 8304 | kfree(coalesce->rules); |
| 8305 | kfree(coalesce); |
| 8306 | rdev->coalesce = NULL; |
| 8307 | } |
| 8308 | |
| 8309 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8310 | struct nlattr *rule, |
| 8311 | struct cfg80211_coalesce_rules *new_rule) |
| 8312 | { |
| 8313 | int err, i; |
| 8314 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8315 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8316 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8317 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8318 | |
| 8319 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8320 | nla_len(rule), nl80211_coalesce_policy); |
| 8321 | if (err) |
| 8322 | return err; |
| 8323 | |
| 8324 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8325 | new_rule->delay = |
| 8326 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8327 | if (new_rule->delay > coalesce->max_delay) |
| 8328 | return -EINVAL; |
| 8329 | |
| 8330 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8331 | new_rule->condition = |
| 8332 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8333 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8334 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8335 | return -EINVAL; |
| 8336 | |
| 8337 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8338 | return -EINVAL; |
| 8339 | |
| 8340 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8341 | rem) |
| 8342 | n_patterns++; |
| 8343 | if (n_patterns > coalesce->n_patterns) |
| 8344 | return -EINVAL; |
| 8345 | |
| 8346 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8347 | GFP_KERNEL); |
| 8348 | if (!new_rule->patterns) |
| 8349 | return -ENOMEM; |
| 8350 | |
| 8351 | new_rule->n_patterns = n_patterns; |
| 8352 | i = 0; |
| 8353 | |
| 8354 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8355 | rem) { |
| 8356 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8357 | nla_len(pat), NULL); |
| 8358 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8359 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8360 | return -EINVAL; |
| 8361 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8362 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8363 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8364 | return -EINVAL; |
| 8365 | if (pat_len > coalesce->pattern_max_len || |
| 8366 | pat_len < coalesce->pattern_min_len) |
| 8367 | return -EINVAL; |
| 8368 | |
| 8369 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8370 | pkt_offset = 0; |
| 8371 | else |
| 8372 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8373 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8374 | return -EINVAL; |
| 8375 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8376 | |
| 8377 | new_rule->patterns[i].mask = |
| 8378 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8379 | if (!new_rule->patterns[i].mask) |
| 8380 | return -ENOMEM; |
| 8381 | new_rule->patterns[i].pattern = |
| 8382 | new_rule->patterns[i].mask + mask_len; |
| 8383 | memcpy(new_rule->patterns[i].mask, |
| 8384 | nla_data(pat_tb[NL80211_PKTPAT_MASK]), mask_len); |
| 8385 | new_rule->patterns[i].pattern_len = pat_len; |
| 8386 | memcpy(new_rule->patterns[i].pattern, |
| 8387 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), pat_len); |
| 8388 | i++; |
| 8389 | } |
| 8390 | |
| 8391 | return 0; |
| 8392 | } |
| 8393 | |
| 8394 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8395 | { |
| 8396 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8397 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8398 | struct cfg80211_coalesce new_coalesce = {}; |
| 8399 | struct cfg80211_coalesce *n_coalesce; |
| 8400 | int err, rem_rule, n_rules = 0, i, j; |
| 8401 | struct nlattr *rule; |
| 8402 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8403 | |
| 8404 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8405 | return -EOPNOTSUPP; |
| 8406 | |
| 8407 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8408 | cfg80211_rdev_free_coalesce(rdev); |
| 8409 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8410 | return 0; |
| 8411 | } |
| 8412 | |
| 8413 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8414 | rem_rule) |
| 8415 | n_rules++; |
| 8416 | if (n_rules > coalesce->n_rules) |
| 8417 | return -EINVAL; |
| 8418 | |
| 8419 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8420 | GFP_KERNEL); |
| 8421 | if (!new_coalesce.rules) |
| 8422 | return -ENOMEM; |
| 8423 | |
| 8424 | new_coalesce.n_rules = n_rules; |
| 8425 | i = 0; |
| 8426 | |
| 8427 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8428 | rem_rule) { |
| 8429 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8430 | &new_coalesce.rules[i]); |
| 8431 | if (err) |
| 8432 | goto error; |
| 8433 | |
| 8434 | i++; |
| 8435 | } |
| 8436 | |
| 8437 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8438 | if (err) |
| 8439 | goto error; |
| 8440 | |
| 8441 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8442 | if (!n_coalesce) { |
| 8443 | err = -ENOMEM; |
| 8444 | goto error; |
| 8445 | } |
| 8446 | cfg80211_rdev_free_coalesce(rdev); |
| 8447 | rdev->coalesce = n_coalesce; |
| 8448 | |
| 8449 | return 0; |
| 8450 | error: |
| 8451 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8452 | tmp_rule = &new_coalesce.rules[i]; |
| 8453 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8454 | kfree(tmp_rule->patterns[j].mask); |
| 8455 | kfree(tmp_rule->patterns); |
| 8456 | } |
| 8457 | kfree(new_coalesce.rules); |
| 8458 | |
| 8459 | return err; |
| 8460 | } |
| 8461 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8462 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8463 | { |
| 8464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8465 | struct net_device *dev = info->user_ptr[1]; |
| 8466 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8467 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8468 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8469 | int err; |
| 8470 | |
| 8471 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8472 | return -EINVAL; |
| 8473 | |
| 8474 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8475 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8476 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8477 | nl80211_rekey_policy); |
| 8478 | if (err) |
| 8479 | return err; |
| 8480 | |
| 8481 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8482 | return -ERANGE; |
| 8483 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8484 | return -ERANGE; |
| 8485 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8486 | return -ERANGE; |
| 8487 | |
| 8488 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8489 | NL80211_KEK_LEN); |
| 8490 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8491 | NL80211_KCK_LEN); |
| 8492 | memcpy(rekey_data.replay_ctr, |
| 8493 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8494 | NL80211_REPLAY_CTR_LEN); |
| 8495 | |
| 8496 | wdev_lock(wdev); |
| 8497 | if (!wdev->current_bss) { |
| 8498 | err = -ENOTCONN; |
| 8499 | goto out; |
| 8500 | } |
| 8501 | |
| 8502 | if (!rdev->ops->set_rekey_data) { |
| 8503 | err = -EOPNOTSUPP; |
| 8504 | goto out; |
| 8505 | } |
| 8506 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8507 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8508 | out: |
| 8509 | wdev_unlock(wdev); |
| 8510 | return err; |
| 8511 | } |
| 8512 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8513 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8514 | struct genl_info *info) |
| 8515 | { |
| 8516 | struct net_device *dev = info->user_ptr[1]; |
| 8517 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8518 | |
| 8519 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8520 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8521 | return -EINVAL; |
| 8522 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8523 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8524 | return -EBUSY; |
| 8525 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8526 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8527 | return 0; |
| 8528 | } |
| 8529 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8530 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8531 | struct genl_info *info) |
| 8532 | { |
| 8533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8534 | struct net_device *dev = info->user_ptr[1]; |
| 8535 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8536 | struct sk_buff *msg; |
| 8537 | void *hdr; |
| 8538 | const u8 *addr; |
| 8539 | u64 cookie; |
| 8540 | int err; |
| 8541 | |
| 8542 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8543 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8544 | return -EOPNOTSUPP; |
| 8545 | |
| 8546 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8547 | return -EINVAL; |
| 8548 | |
| 8549 | if (!rdev->ops->probe_client) |
| 8550 | return -EOPNOTSUPP; |
| 8551 | |
| 8552 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8553 | if (!msg) |
| 8554 | return -ENOMEM; |
| 8555 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8556 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8557 | NL80211_CMD_PROBE_CLIENT); |
| 8558 | |
| 8559 | if (IS_ERR(hdr)) { |
| 8560 | err = PTR_ERR(hdr); |
| 8561 | goto free_msg; |
| 8562 | } |
| 8563 | |
| 8564 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8565 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8566 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8567 | if (err) |
| 8568 | goto free_msg; |
| 8569 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8570 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8571 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8572 | |
| 8573 | genlmsg_end(msg, hdr); |
| 8574 | |
| 8575 | return genlmsg_reply(msg, info); |
| 8576 | |
| 8577 | nla_put_failure: |
| 8578 | err = -ENOBUFS; |
| 8579 | free_msg: |
| 8580 | nlmsg_free(msg); |
| 8581 | return err; |
| 8582 | } |
| 8583 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8584 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8585 | { |
| 8586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8587 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8588 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8589 | |
| 8590 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8591 | return -EOPNOTSUPP; |
| 8592 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8593 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8594 | if (!nreg) |
| 8595 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8596 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8597 | /* First, check if already registered. */ |
| 8598 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8599 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8600 | if (reg->nlportid == info->snd_portid) { |
| 8601 | rv = -EALREADY; |
| 8602 | goto out_err; |
| 8603 | } |
| 8604 | } |
| 8605 | /* Add it to the list */ |
| 8606 | nreg->nlportid = info->snd_portid; |
| 8607 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8608 | |
| 8609 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8610 | |
| 8611 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8612 | out_err: |
| 8613 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8614 | kfree(nreg); |
| 8615 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8616 | } |
| 8617 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8618 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8619 | { |
| 8620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8621 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8622 | int err; |
| 8623 | |
| 8624 | if (!rdev->ops->start_p2p_device) |
| 8625 | return -EOPNOTSUPP; |
| 8626 | |
| 8627 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8628 | return -EOPNOTSUPP; |
| 8629 | |
| 8630 | if (wdev->p2p_started) |
| 8631 | return 0; |
| 8632 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8633 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8634 | if (err) |
| 8635 | return err; |
| 8636 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8637 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8638 | if (err) |
| 8639 | return err; |
| 8640 | |
| 8641 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8642 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8643 | |
| 8644 | return 0; |
| 8645 | } |
| 8646 | |
| 8647 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8648 | { |
| 8649 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8650 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8651 | |
| 8652 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8653 | return -EOPNOTSUPP; |
| 8654 | |
| 8655 | if (!rdev->ops->stop_p2p_device) |
| 8656 | return -EOPNOTSUPP; |
| 8657 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8658 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8659 | |
| 8660 | return 0; |
| 8661 | } |
| 8662 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8663 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8664 | struct genl_info *info) |
| 8665 | { |
| 8666 | void *hdr; |
| 8667 | struct sk_buff *msg; |
| 8668 | |
| 8669 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8670 | if (!msg) |
| 8671 | return -ENOMEM; |
| 8672 | |
| 8673 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8674 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8675 | if (!hdr) |
| 8676 | goto nla_put_failure; |
| 8677 | |
| 8678 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8679 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8680 | goto nla_put_failure; |
| 8681 | |
| 8682 | genlmsg_end(msg, hdr); |
| 8683 | return genlmsg_reply(msg, info); |
| 8684 | |
| 8685 | nla_put_failure: |
| 8686 | kfree_skb(msg); |
| 8687 | return -ENOBUFS; |
| 8688 | } |
| 8689 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8690 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8691 | { |
| 8692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8693 | struct cfg80211_update_ft_ies_params ft_params; |
| 8694 | struct net_device *dev = info->user_ptr[1]; |
| 8695 | |
| 8696 | if (!rdev->ops->update_ft_ies) |
| 8697 | return -EOPNOTSUPP; |
| 8698 | |
| 8699 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8700 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8701 | return -EINVAL; |
| 8702 | |
| 8703 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8704 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8705 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8706 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8707 | |
| 8708 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8709 | } |
| 8710 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8711 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8712 | struct genl_info *info) |
| 8713 | { |
| 8714 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8715 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8716 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8717 | u16 duration; |
| 8718 | int ret; |
| 8719 | |
| 8720 | if (!rdev->ops->crit_proto_start) |
| 8721 | return -EOPNOTSUPP; |
| 8722 | |
| 8723 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8724 | return -EINVAL; |
| 8725 | |
| 8726 | if (rdev->crit_proto_nlportid) |
| 8727 | return -EBUSY; |
| 8728 | |
| 8729 | /* determine protocol if provided */ |
| 8730 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8731 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8732 | |
| 8733 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8734 | return -EINVAL; |
| 8735 | |
| 8736 | /* timeout must be provided */ |
| 8737 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8738 | return -EINVAL; |
| 8739 | |
| 8740 | duration = |
| 8741 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8742 | |
| 8743 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8744 | return -ERANGE; |
| 8745 | |
| 8746 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8747 | if (!ret) |
| 8748 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8749 | |
| 8750 | return ret; |
| 8751 | } |
| 8752 | |
| 8753 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8754 | struct genl_info *info) |
| 8755 | { |
| 8756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8757 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8758 | |
| 8759 | if (!rdev->ops->crit_proto_stop) |
| 8760 | return -EOPNOTSUPP; |
| 8761 | |
| 8762 | if (rdev->crit_proto_nlportid) { |
| 8763 | rdev->crit_proto_nlportid = 0; |
| 8764 | rdev_crit_proto_stop(rdev, wdev); |
| 8765 | } |
| 8766 | return 0; |
| 8767 | } |
| 8768 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8769 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8770 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8771 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8772 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8773 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8774 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8775 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8776 | /* 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] | 8777 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8778 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8779 | |
| 8780 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8781 | struct genl_info *info) |
| 8782 | { |
| 8783 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8784 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8785 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8786 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8787 | |
| 8788 | if (rtnl) |
| 8789 | rtnl_lock(); |
| 8790 | |
| 8791 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8792 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8793 | if (IS_ERR(rdev)) { |
| 8794 | if (rtnl) |
| 8795 | rtnl_unlock(); |
| 8796 | return PTR_ERR(rdev); |
| 8797 | } |
| 8798 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8799 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8800 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8801 | ASSERT_RTNL(); |
| 8802 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8803 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8804 | info->attrs); |
| 8805 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8806 | if (rtnl) |
| 8807 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8808 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8809 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8810 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8811 | dev = wdev->netdev; |
| 8812 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8813 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8814 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8815 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8816 | if (rtnl) |
| 8817 | rtnl_unlock(); |
| 8818 | return -EINVAL; |
| 8819 | } |
| 8820 | |
| 8821 | info->user_ptr[1] = dev; |
| 8822 | } else { |
| 8823 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8824 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8825 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8826 | if (dev) { |
| 8827 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8828 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8829 | if (rtnl) |
| 8830 | rtnl_unlock(); |
| 8831 | return -ENETDOWN; |
| 8832 | } |
| 8833 | |
| 8834 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8835 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8836 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8837 | if (rtnl) |
| 8838 | rtnl_unlock(); |
| 8839 | return -ENETDOWN; |
| 8840 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8841 | } |
| 8842 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8843 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8844 | } |
| 8845 | |
| 8846 | return 0; |
| 8847 | } |
| 8848 | |
| 8849 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8850 | struct genl_info *info) |
| 8851 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8852 | if (info->user_ptr[1]) { |
| 8853 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8854 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8855 | |
| 8856 | if (wdev->netdev) |
| 8857 | dev_put(wdev->netdev); |
| 8858 | } else { |
| 8859 | dev_put(info->user_ptr[1]); |
| 8860 | } |
| 8861 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8862 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8863 | rtnl_unlock(); |
| 8864 | } |
| 8865 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8866 | static struct genl_ops nl80211_ops[] = { |
| 8867 | { |
| 8868 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8869 | .doit = nl80211_get_wiphy, |
| 8870 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 8871 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8872 | .policy = nl80211_policy, |
| 8873 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8874 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8875 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8876 | }, |
| 8877 | { |
| 8878 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8879 | .doit = nl80211_set_wiphy, |
| 8880 | .policy = nl80211_policy, |
| 8881 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8882 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8883 | }, |
| 8884 | { |
| 8885 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8886 | .doit = nl80211_get_interface, |
| 8887 | .dumpit = nl80211_dump_interface, |
| 8888 | .policy = nl80211_policy, |
| 8889 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8890 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8891 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8892 | }, |
| 8893 | { |
| 8894 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8895 | .doit = nl80211_set_interface, |
| 8896 | .policy = nl80211_policy, |
| 8897 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8898 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8899 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8900 | }, |
| 8901 | { |
| 8902 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8903 | .doit = nl80211_new_interface, |
| 8904 | .policy = nl80211_policy, |
| 8905 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8906 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8907 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8908 | }, |
| 8909 | { |
| 8910 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8911 | .doit = nl80211_del_interface, |
| 8912 | .policy = nl80211_policy, |
| 8913 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8914 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8915 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8916 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8917 | { |
| 8918 | .cmd = NL80211_CMD_GET_KEY, |
| 8919 | .doit = nl80211_get_key, |
| 8920 | .policy = nl80211_policy, |
| 8921 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8922 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8923 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8924 | }, |
| 8925 | { |
| 8926 | .cmd = NL80211_CMD_SET_KEY, |
| 8927 | .doit = nl80211_set_key, |
| 8928 | .policy = nl80211_policy, |
| 8929 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8930 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8931 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8932 | }, |
| 8933 | { |
| 8934 | .cmd = NL80211_CMD_NEW_KEY, |
| 8935 | .doit = nl80211_new_key, |
| 8936 | .policy = nl80211_policy, |
| 8937 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8938 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8939 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8940 | }, |
| 8941 | { |
| 8942 | .cmd = NL80211_CMD_DEL_KEY, |
| 8943 | .doit = nl80211_del_key, |
| 8944 | .policy = nl80211_policy, |
| 8945 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8947 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8948 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8949 | { |
| 8950 | .cmd = NL80211_CMD_SET_BEACON, |
| 8951 | .policy = nl80211_policy, |
| 8952 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8953 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8954 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8955 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8956 | }, |
| 8957 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8958 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8959 | .policy = nl80211_policy, |
| 8960 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8961 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8962 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8963 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8964 | }, |
| 8965 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8966 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8967 | .policy = nl80211_policy, |
| 8968 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8969 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8970 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8971 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8972 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8973 | { |
| 8974 | .cmd = NL80211_CMD_GET_STATION, |
| 8975 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8976 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8977 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8978 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8979 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8980 | }, |
| 8981 | { |
| 8982 | .cmd = NL80211_CMD_SET_STATION, |
| 8983 | .doit = nl80211_set_station, |
| 8984 | .policy = nl80211_policy, |
| 8985 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8986 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8987 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8988 | }, |
| 8989 | { |
| 8990 | .cmd = NL80211_CMD_NEW_STATION, |
| 8991 | .doit = nl80211_new_station, |
| 8992 | .policy = nl80211_policy, |
| 8993 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8994 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8995 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8996 | }, |
| 8997 | { |
| 8998 | .cmd = NL80211_CMD_DEL_STATION, |
| 8999 | .doit = nl80211_del_station, |
| 9000 | .policy = nl80211_policy, |
| 9001 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9002 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9003 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9004 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9005 | { |
| 9006 | .cmd = NL80211_CMD_GET_MPATH, |
| 9007 | .doit = nl80211_get_mpath, |
| 9008 | .dumpit = nl80211_dump_mpath, |
| 9009 | .policy = nl80211_policy, |
| 9010 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9012 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9013 | }, |
| 9014 | { |
| 9015 | .cmd = NL80211_CMD_SET_MPATH, |
| 9016 | .doit = nl80211_set_mpath, |
| 9017 | .policy = nl80211_policy, |
| 9018 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9020 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9021 | }, |
| 9022 | { |
| 9023 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9024 | .doit = nl80211_new_mpath, |
| 9025 | .policy = nl80211_policy, |
| 9026 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9028 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9029 | }, |
| 9030 | { |
| 9031 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9032 | .doit = nl80211_del_mpath, |
| 9033 | .policy = nl80211_policy, |
| 9034 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9036 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9037 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9038 | { |
| 9039 | .cmd = NL80211_CMD_SET_BSS, |
| 9040 | .doit = nl80211_set_bss, |
| 9041 | .policy = nl80211_policy, |
| 9042 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9043 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9044 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9045 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9046 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9047 | .cmd = NL80211_CMD_GET_REG, |
| 9048 | .doit = nl80211_get_reg, |
| 9049 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9050 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9051 | /* can be retrieved by unprivileged users */ |
| 9052 | }, |
| 9053 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9054 | .cmd = NL80211_CMD_SET_REG, |
| 9055 | .doit = nl80211_set_reg, |
| 9056 | .policy = nl80211_policy, |
| 9057 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9058 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9059 | }, |
| 9060 | { |
| 9061 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9062 | .doit = nl80211_req_set_reg, |
| 9063 | .policy = nl80211_policy, |
| 9064 | .flags = GENL_ADMIN_PERM, |
| 9065 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9066 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9067 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9068 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9069 | .policy = nl80211_policy, |
| 9070 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9071 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9072 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9073 | }, |
| 9074 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9075 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9076 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9077 | .policy = nl80211_policy, |
| 9078 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9079 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9080 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9081 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9082 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9083 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9084 | .doit = nl80211_trigger_scan, |
| 9085 | .policy = nl80211_policy, |
| 9086 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9087 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9088 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9089 | }, |
| 9090 | { |
| 9091 | .cmd = NL80211_CMD_GET_SCAN, |
| 9092 | .policy = nl80211_policy, |
| 9093 | .dumpit = nl80211_dump_scan, |
| 9094 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9095 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9096 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9097 | .doit = nl80211_start_sched_scan, |
| 9098 | .policy = nl80211_policy, |
| 9099 | .flags = GENL_ADMIN_PERM, |
| 9100 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9101 | NL80211_FLAG_NEED_RTNL, |
| 9102 | }, |
| 9103 | { |
| 9104 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9105 | .doit = nl80211_stop_sched_scan, |
| 9106 | .policy = nl80211_policy, |
| 9107 | .flags = GENL_ADMIN_PERM, |
| 9108 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9109 | NL80211_FLAG_NEED_RTNL, |
| 9110 | }, |
| 9111 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9112 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9113 | .doit = nl80211_authenticate, |
| 9114 | .policy = nl80211_policy, |
| 9115 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9116 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9117 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9118 | }, |
| 9119 | { |
| 9120 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9121 | .doit = nl80211_associate, |
| 9122 | .policy = nl80211_policy, |
| 9123 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9124 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9125 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9126 | }, |
| 9127 | { |
| 9128 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9129 | .doit = nl80211_deauthenticate, |
| 9130 | .policy = nl80211_policy, |
| 9131 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9132 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9133 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9134 | }, |
| 9135 | { |
| 9136 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9137 | .doit = nl80211_disassociate, |
| 9138 | .policy = nl80211_policy, |
| 9139 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9140 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9141 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9142 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9143 | { |
| 9144 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9145 | .doit = nl80211_join_ibss, |
| 9146 | .policy = nl80211_policy, |
| 9147 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9148 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9149 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9150 | }, |
| 9151 | { |
| 9152 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9153 | .doit = nl80211_leave_ibss, |
| 9154 | .policy = nl80211_policy, |
| 9155 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9156 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9157 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9158 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9159 | #ifdef CONFIG_NL80211_TESTMODE |
| 9160 | { |
| 9161 | .cmd = NL80211_CMD_TESTMODE, |
| 9162 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9163 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9164 | .policy = nl80211_policy, |
| 9165 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9166 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9167 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9168 | }, |
| 9169 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9170 | { |
| 9171 | .cmd = NL80211_CMD_CONNECT, |
| 9172 | .doit = nl80211_connect, |
| 9173 | .policy = nl80211_policy, |
| 9174 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9175 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9176 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9177 | }, |
| 9178 | { |
| 9179 | .cmd = NL80211_CMD_DISCONNECT, |
| 9180 | .doit = nl80211_disconnect, |
| 9181 | .policy = nl80211_policy, |
| 9182 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9183 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9184 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9185 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9186 | { |
| 9187 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9188 | .doit = nl80211_wiphy_netns, |
| 9189 | .policy = nl80211_policy, |
| 9190 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9191 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9192 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9193 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9194 | { |
| 9195 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9196 | .policy = nl80211_policy, |
| 9197 | .dumpit = nl80211_dump_survey, |
| 9198 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9199 | { |
| 9200 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9201 | .doit = nl80211_setdel_pmksa, |
| 9202 | .policy = nl80211_policy, |
| 9203 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9204 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9205 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9206 | }, |
| 9207 | { |
| 9208 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9209 | .doit = nl80211_setdel_pmksa, |
| 9210 | .policy = nl80211_policy, |
| 9211 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9212 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9213 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9214 | }, |
| 9215 | { |
| 9216 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9217 | .doit = nl80211_flush_pmksa, |
| 9218 | .policy = nl80211_policy, |
| 9219 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9220 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9221 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9222 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9223 | { |
| 9224 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9225 | .doit = nl80211_remain_on_channel, |
| 9226 | .policy = nl80211_policy, |
| 9227 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9228 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9229 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9230 | }, |
| 9231 | { |
| 9232 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9233 | .doit = nl80211_cancel_remain_on_channel, |
| 9234 | .policy = nl80211_policy, |
| 9235 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9236 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9237 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9238 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9239 | { |
| 9240 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9241 | .doit = nl80211_set_tx_bitrate_mask, |
| 9242 | .policy = nl80211_policy, |
| 9243 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9244 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9245 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9246 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9247 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9248 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9249 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9250 | .policy = nl80211_policy, |
| 9251 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9252 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9253 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9254 | }, |
| 9255 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9256 | .cmd = NL80211_CMD_FRAME, |
| 9257 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9258 | .policy = nl80211_policy, |
| 9259 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9260 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9261 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9262 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9263 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9264 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9265 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9266 | .policy = nl80211_policy, |
| 9267 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9268 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9269 | NL80211_FLAG_NEED_RTNL, |
| 9270 | }, |
| 9271 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9272 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 9273 | .doit = nl80211_set_power_save, |
| 9274 | .policy = nl80211_policy, |
| 9275 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9276 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9277 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9278 | }, |
| 9279 | { |
| 9280 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 9281 | .doit = nl80211_get_power_save, |
| 9282 | .policy = nl80211_policy, |
| 9283 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9284 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9285 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9286 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9287 | { |
| 9288 | .cmd = NL80211_CMD_SET_CQM, |
| 9289 | .doit = nl80211_set_cqm, |
| 9290 | .policy = nl80211_policy, |
| 9291 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9292 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9293 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9294 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9295 | { |
| 9296 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 9297 | .doit = nl80211_set_channel, |
| 9298 | .policy = nl80211_policy, |
| 9299 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9300 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9301 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9302 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9303 | { |
| 9304 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 9305 | .doit = nl80211_set_wds_peer, |
| 9306 | .policy = nl80211_policy, |
| 9307 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 9308 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9309 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 9310 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9311 | { |
| 9312 | .cmd = NL80211_CMD_JOIN_MESH, |
| 9313 | .doit = nl80211_join_mesh, |
| 9314 | .policy = nl80211_policy, |
| 9315 | .flags = GENL_ADMIN_PERM, |
| 9316 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9317 | NL80211_FLAG_NEED_RTNL, |
| 9318 | }, |
| 9319 | { |
| 9320 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 9321 | .doit = nl80211_leave_mesh, |
| 9322 | .policy = nl80211_policy, |
| 9323 | .flags = GENL_ADMIN_PERM, |
| 9324 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9325 | NL80211_FLAG_NEED_RTNL, |
| 9326 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9327 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9328 | { |
| 9329 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 9330 | .doit = nl80211_get_wowlan, |
| 9331 | .policy = nl80211_policy, |
| 9332 | /* can be retrieved by unprivileged users */ |
| 9333 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9334 | NL80211_FLAG_NEED_RTNL, |
| 9335 | }, |
| 9336 | { |
| 9337 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 9338 | .doit = nl80211_set_wowlan, |
| 9339 | .policy = nl80211_policy, |
| 9340 | .flags = GENL_ADMIN_PERM, |
| 9341 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9342 | NL80211_FLAG_NEED_RTNL, |
| 9343 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9344 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9345 | { |
| 9346 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 9347 | .doit = nl80211_set_rekey_data, |
| 9348 | .policy = nl80211_policy, |
| 9349 | .flags = GENL_ADMIN_PERM, |
| 9350 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9351 | NL80211_FLAG_NEED_RTNL, |
| 9352 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9353 | { |
| 9354 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 9355 | .doit = nl80211_tdls_mgmt, |
| 9356 | .policy = nl80211_policy, |
| 9357 | .flags = GENL_ADMIN_PERM, |
| 9358 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9359 | NL80211_FLAG_NEED_RTNL, |
| 9360 | }, |
| 9361 | { |
| 9362 | .cmd = NL80211_CMD_TDLS_OPER, |
| 9363 | .doit = nl80211_tdls_oper, |
| 9364 | .policy = nl80211_policy, |
| 9365 | .flags = GENL_ADMIN_PERM, |
| 9366 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9367 | NL80211_FLAG_NEED_RTNL, |
| 9368 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9369 | { |
| 9370 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 9371 | .doit = nl80211_register_unexpected_frame, |
| 9372 | .policy = nl80211_policy, |
| 9373 | .flags = GENL_ADMIN_PERM, |
| 9374 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9375 | NL80211_FLAG_NEED_RTNL, |
| 9376 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9377 | { |
| 9378 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 9379 | .doit = nl80211_probe_client, |
| 9380 | .policy = nl80211_policy, |
| 9381 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9383 | NL80211_FLAG_NEED_RTNL, |
| 9384 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9385 | { |
| 9386 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 9387 | .doit = nl80211_register_beacons, |
| 9388 | .policy = nl80211_policy, |
| 9389 | .flags = GENL_ADMIN_PERM, |
| 9390 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9391 | NL80211_FLAG_NEED_RTNL, |
| 9392 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 9393 | { |
| 9394 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 9395 | .doit = nl80211_set_noack_map, |
| 9396 | .policy = nl80211_policy, |
| 9397 | .flags = GENL_ADMIN_PERM, |
| 9398 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9399 | NL80211_FLAG_NEED_RTNL, |
| 9400 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9401 | { |
| 9402 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 9403 | .doit = nl80211_start_p2p_device, |
| 9404 | .policy = nl80211_policy, |
| 9405 | .flags = GENL_ADMIN_PERM, |
| 9406 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9407 | NL80211_FLAG_NEED_RTNL, |
| 9408 | }, |
| 9409 | { |
| 9410 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 9411 | .doit = nl80211_stop_p2p_device, |
| 9412 | .policy = nl80211_policy, |
| 9413 | .flags = GENL_ADMIN_PERM, |
| 9414 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9415 | NL80211_FLAG_NEED_RTNL, |
| 9416 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9417 | { |
| 9418 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 9419 | .doit = nl80211_set_mcast_rate, |
| 9420 | .policy = nl80211_policy, |
| 9421 | .flags = GENL_ADMIN_PERM, |
| 9422 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9423 | NL80211_FLAG_NEED_RTNL, |
| 9424 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 9425 | { |
| 9426 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 9427 | .doit = nl80211_set_mac_acl, |
| 9428 | .policy = nl80211_policy, |
| 9429 | .flags = GENL_ADMIN_PERM, |
| 9430 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9431 | NL80211_FLAG_NEED_RTNL, |
| 9432 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9433 | { |
| 9434 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 9435 | .doit = nl80211_start_radar_detection, |
| 9436 | .policy = nl80211_policy, |
| 9437 | .flags = GENL_ADMIN_PERM, |
| 9438 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9439 | NL80211_FLAG_NEED_RTNL, |
| 9440 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9441 | { |
| 9442 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 9443 | .doit = nl80211_get_protocol_features, |
| 9444 | .policy = nl80211_policy, |
| 9445 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9446 | { |
| 9447 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 9448 | .doit = nl80211_update_ft_ies, |
| 9449 | .policy = nl80211_policy, |
| 9450 | .flags = GENL_ADMIN_PERM, |
| 9451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9452 | NL80211_FLAG_NEED_RTNL, |
| 9453 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9454 | { |
| 9455 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 9456 | .doit = nl80211_crit_protocol_start, |
| 9457 | .policy = nl80211_policy, |
| 9458 | .flags = GENL_ADMIN_PERM, |
| 9459 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9460 | NL80211_FLAG_NEED_RTNL, |
| 9461 | }, |
| 9462 | { |
| 9463 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9464 | .doit = nl80211_crit_protocol_stop, |
| 9465 | .policy = nl80211_policy, |
| 9466 | .flags = GENL_ADMIN_PERM, |
| 9467 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9468 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9469 | }, |
| 9470 | { |
| 9471 | .cmd = NL80211_CMD_GET_COALESCE, |
| 9472 | .doit = nl80211_get_coalesce, |
| 9473 | .policy = nl80211_policy, |
| 9474 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9475 | NL80211_FLAG_NEED_RTNL, |
| 9476 | }, |
| 9477 | { |
| 9478 | .cmd = NL80211_CMD_SET_COALESCE, |
| 9479 | .doit = nl80211_set_coalesce, |
| 9480 | .policy = nl80211_policy, |
| 9481 | .flags = GENL_ADMIN_PERM, |
| 9482 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9483 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9484 | }, |
| 9485 | { |
| 9486 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 9487 | .doit = nl80211_channel_switch, |
| 9488 | .policy = nl80211_policy, |
| 9489 | .flags = GENL_ADMIN_PERM, |
| 9490 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9491 | NL80211_FLAG_NEED_RTNL, |
| 9492 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9493 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9494 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9495 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9496 | .name = "mlme", |
| 9497 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9498 | |
| 9499 | /* multicast groups */ |
| 9500 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9501 | .name = "config", |
| 9502 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9503 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9504 | .name = "scan", |
| 9505 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9506 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9507 | .name = "regulatory", |
| 9508 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9509 | |
| 9510 | /* notification functions */ |
| 9511 | |
| 9512 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9513 | { |
| 9514 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9515 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9516 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9517 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9518 | if (!msg) |
| 9519 | return; |
| 9520 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9521 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9522 | nlmsg_free(msg); |
| 9523 | return; |
| 9524 | } |
| 9525 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9526 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9527 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9528 | } |
| 9529 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9530 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9531 | struct cfg80211_registered_device *rdev) |
| 9532 | { |
| 9533 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9534 | struct nlattr *nest; |
| 9535 | int i; |
| 9536 | |
| 9537 | if (WARN_ON(!req)) |
| 9538 | return 0; |
| 9539 | |
| 9540 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9541 | if (!nest) |
| 9542 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9543 | for (i = 0; i < req->n_ssids; i++) { |
| 9544 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9545 | goto nla_put_failure; |
| 9546 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9547 | nla_nest_end(msg, nest); |
| 9548 | |
| 9549 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9550 | if (!nest) |
| 9551 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9552 | for (i = 0; i < req->n_channels; i++) { |
| 9553 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9554 | goto nla_put_failure; |
| 9555 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9556 | nla_nest_end(msg, nest); |
| 9557 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9558 | if (req->ie && |
| 9559 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9560 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9561 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9562 | if (req->flags) |
| 9563 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9564 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9565 | return 0; |
| 9566 | nla_put_failure: |
| 9567 | return -ENOBUFS; |
| 9568 | } |
| 9569 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9570 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9571 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9572 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9573 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9574 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9575 | { |
| 9576 | void *hdr; |
| 9577 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9578 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9579 | if (!hdr) |
| 9580 | return -1; |
| 9581 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9582 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9583 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9584 | wdev->netdev->ifindex)) || |
| 9585 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9586 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9587 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9588 | /* ignore errors and send incomplete event anyway */ |
| 9589 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9590 | |
| 9591 | return genlmsg_end(msg, hdr); |
| 9592 | |
| 9593 | nla_put_failure: |
| 9594 | genlmsg_cancel(msg, hdr); |
| 9595 | return -EMSGSIZE; |
| 9596 | } |
| 9597 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9598 | static int |
| 9599 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9600 | struct cfg80211_registered_device *rdev, |
| 9601 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9602 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9603 | { |
| 9604 | void *hdr; |
| 9605 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9606 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9607 | if (!hdr) |
| 9608 | return -1; |
| 9609 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9610 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9611 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9612 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9613 | |
| 9614 | return genlmsg_end(msg, hdr); |
| 9615 | |
| 9616 | nla_put_failure: |
| 9617 | genlmsg_cancel(msg, hdr); |
| 9618 | return -EMSGSIZE; |
| 9619 | } |
| 9620 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9621 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9622 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9623 | { |
| 9624 | struct sk_buff *msg; |
| 9625 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9626 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9627 | if (!msg) |
| 9628 | return; |
| 9629 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9630 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9631 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9632 | nlmsg_free(msg); |
| 9633 | return; |
| 9634 | } |
| 9635 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9636 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9637 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9638 | } |
| 9639 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9640 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9641 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9642 | { |
| 9643 | struct sk_buff *msg; |
| 9644 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9645 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9646 | if (!msg) |
| 9647 | return; |
| 9648 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9649 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9650 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9651 | nlmsg_free(msg); |
| 9652 | return; |
| 9653 | } |
| 9654 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9655 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9656 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9657 | } |
| 9658 | |
| 9659 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9660 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9661 | { |
| 9662 | struct sk_buff *msg; |
| 9663 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9664 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9665 | if (!msg) |
| 9666 | return; |
| 9667 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9668 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9669 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9670 | nlmsg_free(msg); |
| 9671 | return; |
| 9672 | } |
| 9673 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9674 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9675 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9676 | } |
| 9677 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9678 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9679 | struct net_device *netdev) |
| 9680 | { |
| 9681 | struct sk_buff *msg; |
| 9682 | |
| 9683 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9684 | if (!msg) |
| 9685 | return; |
| 9686 | |
| 9687 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9688 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9689 | nlmsg_free(msg); |
| 9690 | return; |
| 9691 | } |
| 9692 | |
| 9693 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9694 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9695 | } |
| 9696 | |
| 9697 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9698 | struct net_device *netdev, u32 cmd) |
| 9699 | { |
| 9700 | struct sk_buff *msg; |
| 9701 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9702 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9703 | if (!msg) |
| 9704 | return; |
| 9705 | |
| 9706 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9707 | nlmsg_free(msg); |
| 9708 | return; |
| 9709 | } |
| 9710 | |
| 9711 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9712 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9713 | } |
| 9714 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9715 | /* |
| 9716 | * This can happen on global regulatory changes or device specific settings |
| 9717 | * based on custom world regulatory domains. |
| 9718 | */ |
| 9719 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9720 | { |
| 9721 | struct sk_buff *msg; |
| 9722 | void *hdr; |
| 9723 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9725 | if (!msg) |
| 9726 | return; |
| 9727 | |
| 9728 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9729 | if (!hdr) { |
| 9730 | nlmsg_free(msg); |
| 9731 | return; |
| 9732 | } |
| 9733 | |
| 9734 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9735 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9736 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9737 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9738 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9739 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9740 | NL80211_REGDOM_TYPE_WORLD)) |
| 9741 | goto nla_put_failure; |
| 9742 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9743 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9744 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9745 | goto nla_put_failure; |
| 9746 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9747 | request->intersect) { |
| 9748 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9749 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9750 | goto nla_put_failure; |
| 9751 | } else { |
| 9752 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9753 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9754 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9755 | request->alpha2)) |
| 9756 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9757 | } |
| 9758 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9759 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9760 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9761 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9762 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9763 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9764 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9765 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9766 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9767 | GFP_ATOMIC); |
| 9768 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9769 | |
| 9770 | return; |
| 9771 | |
| 9772 | nla_put_failure: |
| 9773 | genlmsg_cancel(msg, hdr); |
| 9774 | nlmsg_free(msg); |
| 9775 | } |
| 9776 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9777 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9778 | struct net_device *netdev, |
| 9779 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9780 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9781 | { |
| 9782 | struct sk_buff *msg; |
| 9783 | void *hdr; |
| 9784 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9785 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9786 | if (!msg) |
| 9787 | return; |
| 9788 | |
| 9789 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9790 | if (!hdr) { |
| 9791 | nlmsg_free(msg); |
| 9792 | return; |
| 9793 | } |
| 9794 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9795 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9796 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9797 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9798 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9799 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9800 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9801 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9802 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9803 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9804 | return; |
| 9805 | |
| 9806 | nla_put_failure: |
| 9807 | genlmsg_cancel(msg, hdr); |
| 9808 | nlmsg_free(msg); |
| 9809 | } |
| 9810 | |
| 9811 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9812 | struct net_device *netdev, const u8 *buf, |
| 9813 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9814 | { |
| 9815 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9816 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9817 | } |
| 9818 | |
| 9819 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9820 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9821 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9822 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9823 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9824 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9825 | } |
| 9826 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9827 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9828 | struct net_device *netdev, const u8 *buf, |
| 9829 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9830 | { |
| 9831 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9832 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9833 | } |
| 9834 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9835 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9836 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9837 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9838 | { |
| 9839 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9840 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9841 | } |
| 9842 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9843 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9844 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9845 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9846 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9847 | struct wiphy *wiphy = wdev->wiphy; |
| 9848 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9849 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9850 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9851 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9852 | if (WARN_ON(len < 2)) |
| 9853 | return; |
| 9854 | |
| 9855 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9856 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9857 | else |
| 9858 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9859 | |
| 9860 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9861 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9862 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9863 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9864 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9865 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9866 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9867 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9868 | { |
| 9869 | struct sk_buff *msg; |
| 9870 | void *hdr; |
| 9871 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9873 | if (!msg) |
| 9874 | return; |
| 9875 | |
| 9876 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9877 | if (!hdr) { |
| 9878 | nlmsg_free(msg); |
| 9879 | return; |
| 9880 | } |
| 9881 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9882 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9883 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9884 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9885 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9886 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9887 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9888 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9889 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9890 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9891 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9892 | return; |
| 9893 | |
| 9894 | nla_put_failure: |
| 9895 | genlmsg_cancel(msg, hdr); |
| 9896 | nlmsg_free(msg); |
| 9897 | } |
| 9898 | |
| 9899 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9900 | struct net_device *netdev, const u8 *addr, |
| 9901 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9902 | { |
| 9903 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9904 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9905 | } |
| 9906 | |
| 9907 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9908 | struct net_device *netdev, const u8 *addr, |
| 9909 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9910 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9911 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9912 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9913 | } |
| 9914 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9915 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9916 | struct net_device *netdev, const u8 *bssid, |
| 9917 | const u8 *req_ie, size_t req_ie_len, |
| 9918 | const u8 *resp_ie, size_t resp_ie_len, |
| 9919 | u16 status, gfp_t gfp) |
| 9920 | { |
| 9921 | struct sk_buff *msg; |
| 9922 | void *hdr; |
| 9923 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9924 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9925 | if (!msg) |
| 9926 | return; |
| 9927 | |
| 9928 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9929 | if (!hdr) { |
| 9930 | nlmsg_free(msg); |
| 9931 | return; |
| 9932 | } |
| 9933 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9934 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9935 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9936 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9937 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9938 | (req_ie && |
| 9939 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9940 | (resp_ie && |
| 9941 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9942 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9943 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9944 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9945 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9946 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9947 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9948 | return; |
| 9949 | |
| 9950 | nla_put_failure: |
| 9951 | genlmsg_cancel(msg, hdr); |
| 9952 | nlmsg_free(msg); |
| 9953 | |
| 9954 | } |
| 9955 | |
| 9956 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9957 | struct net_device *netdev, const u8 *bssid, |
| 9958 | const u8 *req_ie, size_t req_ie_len, |
| 9959 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9960 | { |
| 9961 | struct sk_buff *msg; |
| 9962 | void *hdr; |
| 9963 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9964 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9965 | if (!msg) |
| 9966 | return; |
| 9967 | |
| 9968 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9969 | if (!hdr) { |
| 9970 | nlmsg_free(msg); |
| 9971 | return; |
| 9972 | } |
| 9973 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9974 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9975 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9976 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9977 | (req_ie && |
| 9978 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9979 | (resp_ie && |
| 9980 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9981 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9982 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9983 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9984 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9985 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9986 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9987 | return; |
| 9988 | |
| 9989 | nla_put_failure: |
| 9990 | genlmsg_cancel(msg, hdr); |
| 9991 | nlmsg_free(msg); |
| 9992 | |
| 9993 | } |
| 9994 | |
| 9995 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9996 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9997 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9998 | { |
| 9999 | struct sk_buff *msg; |
| 10000 | void *hdr; |
| 10001 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10002 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10003 | if (!msg) |
| 10004 | return; |
| 10005 | |
| 10006 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10007 | if (!hdr) { |
| 10008 | nlmsg_free(msg); |
| 10009 | return; |
| 10010 | } |
| 10011 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10012 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10013 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10014 | (from_ap && reason && |
| 10015 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10016 | (from_ap && |
| 10017 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10018 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10019 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10020 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10021 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10022 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10023 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10024 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10025 | return; |
| 10026 | |
| 10027 | nla_put_failure: |
| 10028 | genlmsg_cancel(msg, hdr); |
| 10029 | nlmsg_free(msg); |
| 10030 | |
| 10031 | } |
| 10032 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10033 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10034 | struct net_device *netdev, const u8 *bssid, |
| 10035 | gfp_t gfp) |
| 10036 | { |
| 10037 | struct sk_buff *msg; |
| 10038 | void *hdr; |
| 10039 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10040 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10041 | if (!msg) |
| 10042 | return; |
| 10043 | |
| 10044 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10045 | if (!hdr) { |
| 10046 | nlmsg_free(msg); |
| 10047 | return; |
| 10048 | } |
| 10049 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10050 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10051 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10052 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10053 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10054 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10055 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10056 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10057 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10058 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10059 | return; |
| 10060 | |
| 10061 | nla_put_failure: |
| 10062 | genlmsg_cancel(msg, hdr); |
| 10063 | nlmsg_free(msg); |
| 10064 | } |
| 10065 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10066 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10067 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10068 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10069 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10070 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10071 | struct sk_buff *msg; |
| 10072 | void *hdr; |
| 10073 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10074 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10075 | return; |
| 10076 | |
| 10077 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10078 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10079 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10080 | if (!msg) |
| 10081 | return; |
| 10082 | |
| 10083 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10084 | if (!hdr) { |
| 10085 | nlmsg_free(msg); |
| 10086 | return; |
| 10087 | } |
| 10088 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10089 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10090 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10091 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10092 | (ie_len && ie && |
| 10093 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10094 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10095 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10096 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10097 | |
| 10098 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10099 | nl80211_mlme_mcgrp.id, gfp); |
| 10100 | return; |
| 10101 | |
| 10102 | nla_put_failure: |
| 10103 | genlmsg_cancel(msg, hdr); |
| 10104 | nlmsg_free(msg); |
| 10105 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10106 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10107 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10108 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10109 | struct net_device *netdev, const u8 *addr, |
| 10110 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10111 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10112 | { |
| 10113 | struct sk_buff *msg; |
| 10114 | void *hdr; |
| 10115 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10116 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10117 | if (!msg) |
| 10118 | return; |
| 10119 | |
| 10120 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 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 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10129 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10130 | (key_id != -1 && |
| 10131 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10132 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10133 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10134 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10135 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10136 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10137 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10138 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10139 | return; |
| 10140 | |
| 10141 | nla_put_failure: |
| 10142 | genlmsg_cancel(msg, hdr); |
| 10143 | nlmsg_free(msg); |
| 10144 | } |
| 10145 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10146 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10147 | struct ieee80211_channel *channel_before, |
| 10148 | struct ieee80211_channel *channel_after) |
| 10149 | { |
| 10150 | struct sk_buff *msg; |
| 10151 | void *hdr; |
| 10152 | struct nlattr *nl_freq; |
| 10153 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10154 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10155 | if (!msg) |
| 10156 | return; |
| 10157 | |
| 10158 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10159 | if (!hdr) { |
| 10160 | nlmsg_free(msg); |
| 10161 | return; |
| 10162 | } |
| 10163 | |
| 10164 | /* |
| 10165 | * Since we are applying the beacon hint to a wiphy we know its |
| 10166 | * wiphy_idx is valid |
| 10167 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10168 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10169 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10170 | |
| 10171 | /* Before */ |
| 10172 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10173 | if (!nl_freq) |
| 10174 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10175 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10176 | goto nla_put_failure; |
| 10177 | nla_nest_end(msg, nl_freq); |
| 10178 | |
| 10179 | /* After */ |
| 10180 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10181 | if (!nl_freq) |
| 10182 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10183 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10184 | goto nla_put_failure; |
| 10185 | nla_nest_end(msg, nl_freq); |
| 10186 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10187 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10188 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10189 | rcu_read_lock(); |
| 10190 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 10191 | GFP_ATOMIC); |
| 10192 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10193 | |
| 10194 | return; |
| 10195 | |
| 10196 | nla_put_failure: |
| 10197 | genlmsg_cancel(msg, hdr); |
| 10198 | nlmsg_free(msg); |
| 10199 | } |
| 10200 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10201 | static void nl80211_send_remain_on_chan_event( |
| 10202 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10203 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10204 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10205 | unsigned int duration, gfp_t gfp) |
| 10206 | { |
| 10207 | struct sk_buff *msg; |
| 10208 | void *hdr; |
| 10209 | |
| 10210 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10211 | if (!msg) |
| 10212 | return; |
| 10213 | |
| 10214 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10215 | if (!hdr) { |
| 10216 | nlmsg_free(msg); |
| 10217 | return; |
| 10218 | } |
| 10219 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10220 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10221 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10222 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10223 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10224 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10225 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10226 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10227 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10228 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10229 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10230 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10231 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10232 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10233 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10234 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10235 | |
| 10236 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10237 | nl80211_mlme_mcgrp.id, gfp); |
| 10238 | return; |
| 10239 | |
| 10240 | nla_put_failure: |
| 10241 | genlmsg_cancel(msg, hdr); |
| 10242 | nlmsg_free(msg); |
| 10243 | } |
| 10244 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10245 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 10246 | struct ieee80211_channel *chan, |
| 10247 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10248 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10249 | struct wiphy *wiphy = wdev->wiphy; |
| 10250 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10251 | |
| 10252 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10253 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10254 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10255 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10256 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10257 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10258 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10259 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 10260 | struct ieee80211_channel *chan, |
| 10261 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10262 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10263 | struct wiphy *wiphy = wdev->wiphy; |
| 10264 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10265 | |
| 10266 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10267 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10268 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10269 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10270 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10271 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10272 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 10273 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10274 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10275 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10276 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10277 | struct sk_buff *msg; |
| 10278 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10279 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 10280 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10281 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10282 | if (!msg) |
| 10283 | return; |
| 10284 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 10285 | if (nl80211_send_station(msg, 0, 0, 0, |
| 10286 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10287 | nlmsg_free(msg); |
| 10288 | return; |
| 10289 | } |
| 10290 | |
| 10291 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10292 | nl80211_mlme_mcgrp.id, gfp); |
| 10293 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10294 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 10295 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10296 | 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] | 10297 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10298 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10299 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10300 | struct sk_buff *msg; |
| 10301 | void *hdr; |
| 10302 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10303 | trace_cfg80211_del_sta(dev, mac_addr); |
| 10304 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10305 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10306 | if (!msg) |
| 10307 | return; |
| 10308 | |
| 10309 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 10310 | if (!hdr) { |
| 10311 | nlmsg_free(msg); |
| 10312 | return; |
| 10313 | } |
| 10314 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10315 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10316 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 10317 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10318 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10319 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10320 | |
| 10321 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10322 | nl80211_mlme_mcgrp.id, gfp); |
| 10323 | return; |
| 10324 | |
| 10325 | nla_put_failure: |
| 10326 | genlmsg_cancel(msg, hdr); |
| 10327 | nlmsg_free(msg); |
| 10328 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10329 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 10330 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10331 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 10332 | enum nl80211_connect_failed_reason reason, |
| 10333 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10334 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10335 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 10336 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10337 | struct sk_buff *msg; |
| 10338 | void *hdr; |
| 10339 | |
| 10340 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10341 | if (!msg) |
| 10342 | return; |
| 10343 | |
| 10344 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 10345 | if (!hdr) { |
| 10346 | nlmsg_free(msg); |
| 10347 | return; |
| 10348 | } |
| 10349 | |
| 10350 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10351 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 10352 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 10353 | goto nla_put_failure; |
| 10354 | |
| 10355 | genlmsg_end(msg, hdr); |
| 10356 | |
| 10357 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10358 | nl80211_mlme_mcgrp.id, gfp); |
| 10359 | return; |
| 10360 | |
| 10361 | nla_put_failure: |
| 10362 | genlmsg_cancel(msg, hdr); |
| 10363 | nlmsg_free(msg); |
| 10364 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10365 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 10366 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10367 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 10368 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10369 | { |
| 10370 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10371 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10372 | struct sk_buff *msg; |
| 10373 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10374 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10375 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10376 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10377 | return false; |
| 10378 | |
| 10379 | msg = nlmsg_new(100, gfp); |
| 10380 | if (!msg) |
| 10381 | return true; |
| 10382 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10383 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10384 | if (!hdr) { |
| 10385 | nlmsg_free(msg); |
| 10386 | return true; |
| 10387 | } |
| 10388 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10389 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10390 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10391 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10392 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10393 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10394 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10395 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10396 | return true; |
| 10397 | |
| 10398 | nla_put_failure: |
| 10399 | genlmsg_cancel(msg, hdr); |
| 10400 | nlmsg_free(msg); |
| 10401 | return true; |
| 10402 | } |
| 10403 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10404 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 10405 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10406 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10407 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10408 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10409 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10410 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 10411 | |
| 10412 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10413 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 10414 | trace_cfg80211_return_bool(false); |
| 10415 | return false; |
| 10416 | } |
| 10417 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 10418 | addr, gfp); |
| 10419 | trace_cfg80211_return_bool(ret); |
| 10420 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10421 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10422 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 10423 | |
| 10424 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 10425 | const u8 *addr, gfp_t gfp) |
| 10426 | { |
| 10427 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10428 | bool ret; |
| 10429 | |
| 10430 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 10431 | |
| 10432 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10433 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 10434 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 10435 | trace_cfg80211_return_bool(false); |
| 10436 | return false; |
| 10437 | } |
| 10438 | ret = __nl80211_unexpected_frame(dev, |
| 10439 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 10440 | addr, gfp); |
| 10441 | trace_cfg80211_return_bool(ret); |
| 10442 | return ret; |
| 10443 | } |
| 10444 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 10445 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10446 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10447 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 10448 | int freq, int sig_dbm, |
| 10449 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10450 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10451 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10452 | struct sk_buff *msg; |
| 10453 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10454 | |
| 10455 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10456 | if (!msg) |
| 10457 | return -ENOMEM; |
| 10458 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10459 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10460 | if (!hdr) { |
| 10461 | nlmsg_free(msg); |
| 10462 | return -ENOMEM; |
| 10463 | } |
| 10464 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10465 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10466 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10467 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10468 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10469 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 10470 | (sig_dbm && |
| 10471 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10472 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10473 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10474 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10475 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10476 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10477 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10478 | |
| 10479 | nla_put_failure: |
| 10480 | genlmsg_cancel(msg, hdr); |
| 10481 | nlmsg_free(msg); |
| 10482 | return -ENOBUFS; |
| 10483 | } |
| 10484 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10485 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10486 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10487 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10488 | struct wiphy *wiphy = wdev->wiphy; |
| 10489 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10490 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10491 | struct sk_buff *msg; |
| 10492 | void *hdr; |
| 10493 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10494 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10495 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10496 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10497 | if (!msg) |
| 10498 | return; |
| 10499 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10500 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10501 | if (!hdr) { |
| 10502 | nlmsg_free(msg); |
| 10503 | return; |
| 10504 | } |
| 10505 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10506 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10507 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10508 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10509 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10510 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10511 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10512 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10513 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10514 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10515 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10516 | |
| 10517 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 10518 | return; |
| 10519 | |
| 10520 | nla_put_failure: |
| 10521 | genlmsg_cancel(msg, hdr); |
| 10522 | nlmsg_free(msg); |
| 10523 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10524 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10525 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10526 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10527 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10528 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10529 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10530 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10531 | struct wiphy *wiphy = wdev->wiphy; |
| 10532 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10533 | struct sk_buff *msg; |
| 10534 | struct nlattr *pinfoattr; |
| 10535 | void *hdr; |
| 10536 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10537 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10538 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10539 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10540 | if (!msg) |
| 10541 | return; |
| 10542 | |
| 10543 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10544 | if (!hdr) { |
| 10545 | nlmsg_free(msg); |
| 10546 | return; |
| 10547 | } |
| 10548 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10549 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10550 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10551 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10552 | |
| 10553 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10554 | if (!pinfoattr) |
| 10555 | goto nla_put_failure; |
| 10556 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10557 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10558 | rssi_event)) |
| 10559 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10560 | |
| 10561 | nla_nest_end(msg, pinfoattr); |
| 10562 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10563 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10564 | |
| 10565 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10566 | nl80211_mlme_mcgrp.id, gfp); |
| 10567 | return; |
| 10568 | |
| 10569 | nla_put_failure: |
| 10570 | genlmsg_cancel(msg, hdr); |
| 10571 | nlmsg_free(msg); |
| 10572 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10573 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10574 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10575 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10576 | struct net_device *netdev, const u8 *bssid, |
| 10577 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10578 | { |
| 10579 | struct sk_buff *msg; |
| 10580 | struct nlattr *rekey_attr; |
| 10581 | void *hdr; |
| 10582 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10583 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10584 | if (!msg) |
| 10585 | return; |
| 10586 | |
| 10587 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10588 | if (!hdr) { |
| 10589 | nlmsg_free(msg); |
| 10590 | return; |
| 10591 | } |
| 10592 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10593 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10594 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10595 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10596 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10597 | |
| 10598 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10599 | if (!rekey_attr) |
| 10600 | goto nla_put_failure; |
| 10601 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10602 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10603 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10604 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10605 | |
| 10606 | nla_nest_end(msg, rekey_attr); |
| 10607 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10608 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10609 | |
| 10610 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10611 | nl80211_mlme_mcgrp.id, gfp); |
| 10612 | return; |
| 10613 | |
| 10614 | nla_put_failure: |
| 10615 | genlmsg_cancel(msg, hdr); |
| 10616 | nlmsg_free(msg); |
| 10617 | } |
| 10618 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10619 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10620 | const u8 *replay_ctr, gfp_t gfp) |
| 10621 | { |
| 10622 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10623 | struct wiphy *wiphy = wdev->wiphy; |
| 10624 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10625 | |
| 10626 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10627 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10628 | } |
| 10629 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10630 | |
| 10631 | static void |
| 10632 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10633 | struct net_device *netdev, int index, |
| 10634 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10635 | { |
| 10636 | struct sk_buff *msg; |
| 10637 | struct nlattr *attr; |
| 10638 | void *hdr; |
| 10639 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10640 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10641 | if (!msg) |
| 10642 | return; |
| 10643 | |
| 10644 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10645 | if (!hdr) { |
| 10646 | nlmsg_free(msg); |
| 10647 | return; |
| 10648 | } |
| 10649 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10650 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10651 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10652 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10653 | |
| 10654 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10655 | if (!attr) |
| 10656 | goto nla_put_failure; |
| 10657 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10658 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10659 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10660 | (preauth && |
| 10661 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10662 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10663 | |
| 10664 | nla_nest_end(msg, attr); |
| 10665 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10666 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10667 | |
| 10668 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10669 | nl80211_mlme_mcgrp.id, gfp); |
| 10670 | return; |
| 10671 | |
| 10672 | nla_put_failure: |
| 10673 | genlmsg_cancel(msg, hdr); |
| 10674 | nlmsg_free(msg); |
| 10675 | } |
| 10676 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10677 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10678 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10679 | { |
| 10680 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10681 | struct wiphy *wiphy = wdev->wiphy; |
| 10682 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10683 | |
| 10684 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10685 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10686 | } |
| 10687 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10688 | |
| 10689 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10690 | struct net_device *netdev, |
| 10691 | struct cfg80211_chan_def *chandef, |
| 10692 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10693 | { |
| 10694 | struct sk_buff *msg; |
| 10695 | void *hdr; |
| 10696 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10697 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10698 | if (!msg) |
| 10699 | return; |
| 10700 | |
| 10701 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10702 | if (!hdr) { |
| 10703 | nlmsg_free(msg); |
| 10704 | return; |
| 10705 | } |
| 10706 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10707 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10708 | goto nla_put_failure; |
| 10709 | |
| 10710 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10711 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10712 | |
| 10713 | genlmsg_end(msg, hdr); |
| 10714 | |
| 10715 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10716 | nl80211_mlme_mcgrp.id, gfp); |
| 10717 | return; |
| 10718 | |
| 10719 | nla_put_failure: |
| 10720 | genlmsg_cancel(msg, hdr); |
| 10721 | nlmsg_free(msg); |
| 10722 | } |
| 10723 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10724 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10725 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10726 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10727 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10728 | struct wiphy *wiphy = wdev->wiphy; |
| 10729 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10730 | |
| 10731 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10732 | |
| 10733 | wdev_lock(wdev); |
| 10734 | |
| 10735 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10736 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10737 | goto out; |
| 10738 | |
| 10739 | wdev->channel = chandef->chan; |
| 10740 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10741 | out: |
| 10742 | wdev_unlock(wdev); |
| 10743 | return; |
| 10744 | } |
| 10745 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10746 | |
| 10747 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10748 | const u8 *peer, u32 num_packets, |
| 10749 | u32 rate, u32 intvl, gfp_t gfp) |
| 10750 | { |
| 10751 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10752 | struct wiphy *wiphy = wdev->wiphy; |
| 10753 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10754 | struct sk_buff *msg; |
| 10755 | struct nlattr *pinfoattr; |
| 10756 | void *hdr; |
| 10757 | |
| 10758 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10759 | if (!msg) |
| 10760 | return; |
| 10761 | |
| 10762 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10763 | if (!hdr) { |
| 10764 | nlmsg_free(msg); |
| 10765 | return; |
| 10766 | } |
| 10767 | |
| 10768 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10769 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10770 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10771 | goto nla_put_failure; |
| 10772 | |
| 10773 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10774 | if (!pinfoattr) |
| 10775 | goto nla_put_failure; |
| 10776 | |
| 10777 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10778 | goto nla_put_failure; |
| 10779 | |
| 10780 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10781 | goto nla_put_failure; |
| 10782 | |
| 10783 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10784 | goto nla_put_failure; |
| 10785 | |
| 10786 | nla_nest_end(msg, pinfoattr); |
| 10787 | |
| 10788 | genlmsg_end(msg, hdr); |
| 10789 | |
| 10790 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10791 | nl80211_mlme_mcgrp.id, gfp); |
| 10792 | return; |
| 10793 | |
| 10794 | nla_put_failure: |
| 10795 | genlmsg_cancel(msg, hdr); |
| 10796 | nlmsg_free(msg); |
| 10797 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10798 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10799 | |
| 10800 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10801 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10802 | struct cfg80211_chan_def *chandef, |
| 10803 | enum nl80211_radar_event event, |
| 10804 | struct net_device *netdev, gfp_t gfp) |
| 10805 | { |
| 10806 | struct sk_buff *msg; |
| 10807 | void *hdr; |
| 10808 | |
| 10809 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10810 | if (!msg) |
| 10811 | return; |
| 10812 | |
| 10813 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10814 | if (!hdr) { |
| 10815 | nlmsg_free(msg); |
| 10816 | return; |
| 10817 | } |
| 10818 | |
| 10819 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10820 | goto nla_put_failure; |
| 10821 | |
| 10822 | /* NOP and radar events don't need a netdev parameter */ |
| 10823 | if (netdev) { |
| 10824 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10825 | |
| 10826 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10827 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10828 | goto nla_put_failure; |
| 10829 | } |
| 10830 | |
| 10831 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10832 | goto nla_put_failure; |
| 10833 | |
| 10834 | if (nl80211_send_chandef(msg, chandef)) |
| 10835 | goto nla_put_failure; |
| 10836 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10837 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10838 | |
| 10839 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10840 | nl80211_mlme_mcgrp.id, gfp); |
| 10841 | return; |
| 10842 | |
| 10843 | nla_put_failure: |
| 10844 | genlmsg_cancel(msg, hdr); |
| 10845 | nlmsg_free(msg); |
| 10846 | } |
| 10847 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10848 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10849 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10850 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10851 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10852 | struct wiphy *wiphy = wdev->wiphy; |
| 10853 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10854 | struct sk_buff *msg; |
| 10855 | struct nlattr *pinfoattr; |
| 10856 | void *hdr; |
| 10857 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10858 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10859 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10860 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10861 | if (!msg) |
| 10862 | return; |
| 10863 | |
| 10864 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10865 | if (!hdr) { |
| 10866 | nlmsg_free(msg); |
| 10867 | return; |
| 10868 | } |
| 10869 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10870 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10871 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10872 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10873 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10874 | |
| 10875 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10876 | if (!pinfoattr) |
| 10877 | goto nla_put_failure; |
| 10878 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10879 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10880 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10881 | |
| 10882 | nla_nest_end(msg, pinfoattr); |
| 10883 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10884 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10885 | |
| 10886 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10887 | nl80211_mlme_mcgrp.id, gfp); |
| 10888 | return; |
| 10889 | |
| 10890 | nla_put_failure: |
| 10891 | genlmsg_cancel(msg, hdr); |
| 10892 | nlmsg_free(msg); |
| 10893 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10894 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10895 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10896 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10897 | u64 cookie, bool acked, gfp_t gfp) |
| 10898 | { |
| 10899 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10900 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10901 | struct sk_buff *msg; |
| 10902 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10903 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10904 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10905 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10906 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10907 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10908 | if (!msg) |
| 10909 | return; |
| 10910 | |
| 10911 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10912 | if (!hdr) { |
| 10913 | nlmsg_free(msg); |
| 10914 | return; |
| 10915 | } |
| 10916 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10917 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10918 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10919 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10920 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10921 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10922 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10923 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10924 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10925 | |
| 10926 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10927 | nl80211_mlme_mcgrp.id, gfp); |
| 10928 | return; |
| 10929 | |
| 10930 | nla_put_failure: |
| 10931 | genlmsg_cancel(msg, hdr); |
| 10932 | nlmsg_free(msg); |
| 10933 | } |
| 10934 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10935 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10936 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10937 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10938 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10939 | { |
| 10940 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10941 | struct sk_buff *msg; |
| 10942 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10943 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10944 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10945 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10946 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10947 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10948 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10949 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10950 | if (!msg) { |
| 10951 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10952 | return; |
| 10953 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10954 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10955 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10956 | if (!hdr) |
| 10957 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10958 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10959 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10960 | (freq && |
| 10961 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10962 | (sig_dbm && |
| 10963 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10964 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10965 | goto nla_put_failure; |
| 10966 | |
| 10967 | genlmsg_end(msg, hdr); |
| 10968 | |
| 10969 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10970 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10971 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10972 | return; |
| 10973 | |
| 10974 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10975 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10976 | if (hdr) |
| 10977 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10978 | nlmsg_free(msg); |
| 10979 | } |
| 10980 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10981 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10982 | #ifdef CONFIG_PM |
| 10983 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10984 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10985 | gfp_t gfp) |
| 10986 | { |
| 10987 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10988 | struct sk_buff *msg; |
| 10989 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10990 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10991 | |
| 10992 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10993 | |
| 10994 | if (wakeup) |
| 10995 | size += wakeup->packet_present_len; |
| 10996 | |
| 10997 | msg = nlmsg_new(size, gfp); |
| 10998 | if (!msg) |
| 10999 | return; |
| 11000 | |
| 11001 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11002 | if (!hdr) |
| 11003 | goto free_msg; |
| 11004 | |
| 11005 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11006 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11007 | goto free_msg; |
| 11008 | |
| 11009 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11010 | wdev->netdev->ifindex)) |
| 11011 | goto free_msg; |
| 11012 | |
| 11013 | if (wakeup) { |
| 11014 | struct nlattr *reasons; |
| 11015 | |
| 11016 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 11017 | |
| 11018 | if (wakeup->disconnect && |
| 11019 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11020 | goto free_msg; |
| 11021 | if (wakeup->magic_pkt && |
| 11022 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11023 | goto free_msg; |
| 11024 | if (wakeup->gtk_rekey_failure && |
| 11025 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11026 | goto free_msg; |
| 11027 | if (wakeup->eap_identity_req && |
| 11028 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11029 | goto free_msg; |
| 11030 | if (wakeup->four_way_handshake && |
| 11031 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11032 | goto free_msg; |
| 11033 | if (wakeup->rfkill_release && |
| 11034 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11035 | goto free_msg; |
| 11036 | |
| 11037 | if (wakeup->pattern_idx >= 0 && |
| 11038 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11039 | wakeup->pattern_idx)) |
| 11040 | goto free_msg; |
| 11041 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11042 | if (wakeup->tcp_match) |
| 11043 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 11044 | |
| 11045 | if (wakeup->tcp_connlost) |
| 11046 | nla_put_flag(msg, |
| 11047 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 11048 | |
| 11049 | if (wakeup->tcp_nomoretokens) |
| 11050 | nla_put_flag(msg, |
| 11051 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 11052 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11053 | if (wakeup->packet) { |
| 11054 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11055 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11056 | |
| 11057 | if (!wakeup->packet_80211) { |
| 11058 | pkt_attr = |
| 11059 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11060 | len_attr = |
| 11061 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11062 | } |
| 11063 | |
| 11064 | if (wakeup->packet_len && |
| 11065 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11066 | goto free_msg; |
| 11067 | |
| 11068 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11069 | wakeup->packet)) |
| 11070 | goto free_msg; |
| 11071 | } |
| 11072 | |
| 11073 | nla_nest_end(msg, reasons); |
| 11074 | } |
| 11075 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11076 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11077 | |
| 11078 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11079 | nl80211_mlme_mcgrp.id, gfp); |
| 11080 | return; |
| 11081 | |
| 11082 | free_msg: |
| 11083 | nlmsg_free(msg); |
| 11084 | } |
| 11085 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11086 | #endif |
| 11087 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11088 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11089 | enum nl80211_tdls_operation oper, |
| 11090 | u16 reason_code, gfp_t gfp) |
| 11091 | { |
| 11092 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11093 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 11094 | struct sk_buff *msg; |
| 11095 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11096 | |
| 11097 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11098 | reason_code); |
| 11099 | |
| 11100 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11101 | if (!msg) |
| 11102 | return; |
| 11103 | |
| 11104 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11105 | if (!hdr) { |
| 11106 | nlmsg_free(msg); |
| 11107 | return; |
| 11108 | } |
| 11109 | |
| 11110 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11111 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11112 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11113 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11114 | (reason_code > 0 && |
| 11115 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11116 | goto nla_put_failure; |
| 11117 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11118 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11119 | |
| 11120 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11121 | nl80211_mlme_mcgrp.id, gfp); |
| 11122 | return; |
| 11123 | |
| 11124 | nla_put_failure: |
| 11125 | genlmsg_cancel(msg, hdr); |
| 11126 | nlmsg_free(msg); |
| 11127 | } |
| 11128 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11129 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11130 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11131 | unsigned long state, |
| 11132 | void *_notify) |
| 11133 | { |
| 11134 | struct netlink_notify *notify = _notify; |
| 11135 | struct cfg80211_registered_device *rdev; |
| 11136 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11137 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11138 | |
| 11139 | if (state != NETLINK_URELEASE) |
| 11140 | return NOTIFY_DONE; |
| 11141 | |
| 11142 | rcu_read_lock(); |
| 11143 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11144 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11145 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11146 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11147 | |
| 11148 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11149 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11150 | list) { |
| 11151 | if (reg->nlportid == notify->portid) { |
| 11152 | list_del(®->list); |
| 11153 | kfree(reg); |
| 11154 | break; |
| 11155 | } |
| 11156 | } |
| 11157 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11158 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11159 | |
| 11160 | rcu_read_unlock(); |
| 11161 | |
| 11162 | return NOTIFY_DONE; |
| 11163 | } |
| 11164 | |
| 11165 | static struct notifier_block nl80211_netlink_notifier = { |
| 11166 | .notifier_call = nl80211_netlink_notify, |
| 11167 | }; |
| 11168 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11169 | void cfg80211_ft_event(struct net_device *netdev, |
| 11170 | struct cfg80211_ft_event_params *ft_event) |
| 11171 | { |
| 11172 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 11173 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 11174 | struct sk_buff *msg; |
| 11175 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11176 | |
| 11177 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11178 | |
| 11179 | if (!ft_event->target_ap) |
| 11180 | return; |
| 11181 | |
| 11182 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11183 | if (!msg) |
| 11184 | return; |
| 11185 | |
| 11186 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 11187 | if (!hdr) { |
| 11188 | nlmsg_free(msg); |
| 11189 | return; |
| 11190 | } |
| 11191 | |
| 11192 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 11193 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 11194 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 11195 | if (ft_event->ies) |
| 11196 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 11197 | if (ft_event->ric_ies) |
| 11198 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11199 | ft_event->ric_ies); |
| 11200 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11201 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11202 | |
| 11203 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 11204 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 11205 | } |
| 11206 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11207 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11208 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 11209 | { |
| 11210 | struct cfg80211_registered_device *rdev; |
| 11211 | struct sk_buff *msg; |
| 11212 | void *hdr; |
| 11213 | u32 nlportid; |
| 11214 | |
| 11215 | rdev = wiphy_to_dev(wdev->wiphy); |
| 11216 | if (!rdev->crit_proto_nlportid) |
| 11217 | return; |
| 11218 | |
| 11219 | nlportid = rdev->crit_proto_nlportid; |
| 11220 | rdev->crit_proto_nlportid = 0; |
| 11221 | |
| 11222 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11223 | if (!msg) |
| 11224 | return; |
| 11225 | |
| 11226 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 11227 | if (!hdr) |
| 11228 | goto nla_put_failure; |
| 11229 | |
| 11230 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11231 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11232 | goto nla_put_failure; |
| 11233 | |
| 11234 | genlmsg_end(msg, hdr); |
| 11235 | |
| 11236 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 11237 | return; |
| 11238 | |
| 11239 | nla_put_failure: |
| 11240 | if (hdr) |
| 11241 | genlmsg_cancel(msg, hdr); |
| 11242 | nlmsg_free(msg); |
| 11243 | |
| 11244 | } |
| 11245 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 11246 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11247 | /* initialisation/exit functions */ |
| 11248 | |
| 11249 | int nl80211_init(void) |
| 11250 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11251 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11252 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 11253 | err = genl_register_family_with_ops(&nl80211_fam, |
| 11254 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11255 | if (err) |
| 11256 | return err; |
| 11257 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11258 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 11259 | if (err) |
| 11260 | goto err_out; |
| 11261 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11262 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 11263 | if (err) |
| 11264 | goto err_out; |
| 11265 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11266 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 11267 | if (err) |
| 11268 | goto err_out; |
| 11269 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11270 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 11271 | if (err) |
| 11272 | goto err_out; |
| 11273 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 11274 | #ifdef CONFIG_NL80211_TESTMODE |
| 11275 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 11276 | if (err) |
| 11277 | goto err_out; |
| 11278 | #endif |
| 11279 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11280 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 11281 | if (err) |
| 11282 | goto err_out; |
| 11283 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11284 | return 0; |
| 11285 | err_out: |
| 11286 | genl_unregister_family(&nl80211_fam); |
| 11287 | return err; |
| 11288 | } |
| 11289 | |
| 11290 | void nl80211_exit(void) |
| 11291 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11292 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11293 | genl_unregister_family(&nl80211_fam); |
| 11294 | } |