Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 22 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 23 | #include "core.h" |
| 24 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 25 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 26 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 27 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 28 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 29 | struct genl_info *info, |
| 30 | struct cfg80211_crypto_settings *settings, |
| 31 | int cipher_limit); |
| 32 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 33 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 34 | struct genl_info *info); |
| 35 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 36 | struct genl_info *info); |
| 37 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | /* the netlink family */ |
| 39 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 40 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 41 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 42 | .hdrsize = 0, /* no private header */ |
| 43 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 45 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 46 | .pre_doit = nl80211_pre_doit, |
| 47 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 50 | /* returns ERR_PTR values */ |
| 51 | static struct wireless_dev * |
| 52 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 54 | struct cfg80211_registered_device *rdev; |
| 55 | struct wireless_dev *result = NULL; |
| 56 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 57 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 58 | u64 wdev_id; |
| 59 | int wiphy_idx = -1; |
| 60 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 62 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 64 | if (!have_ifidx && !have_wdev_id) |
| 65 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 67 | if (have_ifidx) |
| 68 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 69 | if (have_wdev_id) { |
| 70 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 71 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 75 | struct wireless_dev *wdev; |
| 76 | |
| 77 | if (wiphy_net(&rdev->wiphy) != netns) |
| 78 | continue; |
| 79 | |
| 80 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 81 | continue; |
| 82 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 83 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 84 | if (have_ifidx && wdev->netdev && |
| 85 | wdev->netdev->ifindex == ifidx) { |
| 86 | result = wdev; |
| 87 | break; |
| 88 | } |
| 89 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 90 | result = wdev; |
| 91 | break; |
| 92 | } |
| 93 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 94 | |
| 95 | if (result) |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | if (result) |
| 100 | return result; |
| 101 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 104 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 105 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 106 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 107 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 108 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 109 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 110 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 112 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 113 | !attrs[NL80211_ATTR_IFINDEX] && |
| 114 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 115 | return ERR_PTR(-EINVAL); |
| 116 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 117 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 118 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 119 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 121 | if (attrs[NL80211_ATTR_WDEV]) { |
| 122 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 123 | struct wireless_dev *wdev; |
| 124 | bool found = false; |
| 125 | |
| 126 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 127 | if (tmp) { |
| 128 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 129 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 130 | if (wdev->identifier != (u32)wdev_id) |
| 131 | continue; |
| 132 | found = true; |
| 133 | break; |
| 134 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | |
| 136 | if (!found) |
| 137 | tmp = NULL; |
| 138 | |
| 139 | if (rdev && tmp != rdev) |
| 140 | return ERR_PTR(-EINVAL); |
| 141 | rdev = tmp; |
| 142 | } |
| 143 | } |
| 144 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 145 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 146 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 147 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 148 | if (netdev) { |
| 149 | if (netdev->ieee80211_ptr) |
| 150 | tmp = wiphy_to_dev( |
| 151 | netdev->ieee80211_ptr->wiphy); |
| 152 | else |
| 153 | tmp = NULL; |
| 154 | |
| 155 | dev_put(netdev); |
| 156 | |
| 157 | /* not wireless device -- return error */ |
| 158 | if (!tmp) |
| 159 | return ERR_PTR(-EINVAL); |
| 160 | |
| 161 | /* mismatch -- return error */ |
| 162 | if (rdev && tmp != rdev) |
| 163 | return ERR_PTR(-EINVAL); |
| 164 | |
| 165 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 166 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 169 | if (!rdev) |
| 170 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 171 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 172 | if (netns != wiphy_net(&rdev->wiphy)) |
| 173 | return ERR_PTR(-ENODEV); |
| 174 | |
| 175 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /* |
| 179 | * This function returns a pointer to the driver |
| 180 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | * |
| 182 | * The result of this can be a PTR_ERR and hence must |
| 183 | * be checked with IS_ERR() for errors. |
| 184 | */ |
| 185 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 186 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 188 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 191 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 192 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 193 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 194 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 195 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 196 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 197 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 198 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 199 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 200 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 201 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 202 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 203 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 204 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 205 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 206 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 207 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 208 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 209 | |
| 210 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 211 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 212 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 213 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 214 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 215 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 216 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 217 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 218 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 219 | .len = WLAN_MAX_KEY_LEN }, |
| 220 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 221 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 223 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 225 | |
| 226 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 228 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 229 | .len = IEEE80211_MAX_DATA_LEN }, |
| 230 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 231 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 232 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 233 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 234 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 235 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 236 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 237 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 238 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 239 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 240 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 241 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 242 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 243 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 244 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 245 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 246 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 247 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 248 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 249 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 250 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 251 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 252 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 253 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 254 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 255 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 256 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 257 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 258 | |
| 259 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 260 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 261 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 262 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 263 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 264 | |
| 265 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 266 | .len = IEEE80211_MAX_SSID_LEN }, |
| 267 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 268 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 269 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 271 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 272 | [NL80211_ATTR_STA_FLAGS2] = { |
| 273 | .len = sizeof(struct nl80211_sta_flag_update), |
| 274 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 275 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 276 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 277 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 278 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 279 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 280 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 281 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 282 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 284 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 285 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 286 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 287 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 288 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 289 | .len = IEEE80211_MAX_DATA_LEN }, |
| 290 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 291 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 294 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 295 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 296 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 297 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 298 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 299 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 300 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 301 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 302 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 304 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 305 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 306 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 307 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 308 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 309 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 312 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 313 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 315 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 317 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 318 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 319 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 320 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 322 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 324 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 325 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 326 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 327 | .len = NL80211_HT_CAPABILITY_LEN |
| 328 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 329 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 330 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 331 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 332 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 333 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 334 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 335 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 336 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 337 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 339 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 340 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 341 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 342 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 344 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 345 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 346 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 347 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 348 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 349 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 350 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 351 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 352 | }; |
| 353 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 354 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 355 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 356 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 357 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 358 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 359 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 360 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 361 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 362 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 363 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 364 | }; |
| 365 | |
| 366 | /* policy for the key default flags */ |
| 367 | static const struct nla_policy |
| 368 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 369 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 370 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 371 | }; |
| 372 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 373 | /* policy for WoWLAN attributes */ |
| 374 | static const struct nla_policy |
| 375 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 376 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 377 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 378 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 379 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 380 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 381 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 382 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 383 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 384 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 385 | }; |
| 386 | |
| 387 | static const struct nla_policy |
| 388 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 389 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 390 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 391 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 392 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 393 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 394 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 395 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 396 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 397 | }, |
| 398 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 399 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 400 | }, |
| 401 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 402 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 403 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 404 | }; |
| 405 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 406 | /* policy for GTK rekey offload attributes */ |
| 407 | static const struct nla_policy |
| 408 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 409 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 410 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 411 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 412 | }; |
| 413 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 414 | static const struct nla_policy |
| 415 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 416 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 417 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 418 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 419 | }; |
| 420 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 421 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 422 | struct netlink_callback *cb, |
| 423 | struct cfg80211_registered_device **rdev, |
| 424 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 425 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 426 | int err; |
| 427 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 428 | rtnl_lock(); |
| 429 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 430 | if (!cb->args[0]) { |
| 431 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 432 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 433 | nl80211_policy); |
| 434 | if (err) |
| 435 | goto out_unlock; |
| 436 | |
| 437 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 438 | nl80211_fam.attrbuf); |
| 439 | if (IS_ERR(*wdev)) { |
| 440 | err = PTR_ERR(*wdev); |
| 441 | goto out_unlock; |
| 442 | } |
| 443 | *rdev = wiphy_to_dev((*wdev)->wiphy); |
| 444 | cb->args[0] = (*rdev)->wiphy_idx; |
| 445 | cb->args[1] = (*wdev)->identifier; |
| 446 | } else { |
| 447 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]); |
| 448 | struct wireless_dev *tmp; |
| 449 | |
| 450 | if (!wiphy) { |
| 451 | err = -ENODEV; |
| 452 | goto out_unlock; |
| 453 | } |
| 454 | *rdev = wiphy_to_dev(wiphy); |
| 455 | *wdev = NULL; |
| 456 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 457 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 458 | if (tmp->identifier == cb->args[1]) { |
| 459 | *wdev = tmp; |
| 460 | break; |
| 461 | } |
| 462 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 463 | |
| 464 | if (!*wdev) { |
| 465 | err = -ENODEV; |
| 466 | goto out_unlock; |
| 467 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 468 | } |
| 469 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 470 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 471 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 472 | rtnl_unlock(); |
| 473 | return err; |
| 474 | } |
| 475 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 476 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 477 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 478 | rtnl_unlock(); |
| 479 | } |
| 480 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 481 | /* IE validation */ |
| 482 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 483 | { |
| 484 | const u8 *pos; |
| 485 | int len; |
| 486 | |
| 487 | if (!attr) |
| 488 | return true; |
| 489 | |
| 490 | pos = nla_data(attr); |
| 491 | len = nla_len(attr); |
| 492 | |
| 493 | while (len) { |
| 494 | u8 elemlen; |
| 495 | |
| 496 | if (len < 2) |
| 497 | return false; |
| 498 | len -= 2; |
| 499 | |
| 500 | elemlen = pos[1]; |
| 501 | if (elemlen > len) |
| 502 | return false; |
| 503 | |
| 504 | len -= elemlen; |
| 505 | pos += 2 + elemlen; |
| 506 | } |
| 507 | |
| 508 | return true; |
| 509 | } |
| 510 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 511 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 512 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 513 | int flags, u8 cmd) |
| 514 | { |
| 515 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 516 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 517 | } |
| 518 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 519 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 520 | struct ieee80211_channel *chan, |
| 521 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 522 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 523 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 524 | chan->center_freq)) |
| 525 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 526 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 527 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 528 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 529 | goto nla_put_failure; |
| 530 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 531 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 532 | goto nla_put_failure; |
| 533 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 534 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 535 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 536 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 537 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 538 | goto nla_put_failure; |
| 539 | if (large) { |
| 540 | u32 time; |
| 541 | |
| 542 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 543 | |
| 544 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 545 | chan->dfs_state)) |
| 546 | goto nla_put_failure; |
| 547 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 548 | time)) |
| 549 | goto nla_put_failure; |
| 550 | } |
| 551 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 552 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 553 | if (large) { |
| 554 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 555 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 556 | goto nla_put_failure; |
| 557 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 558 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 559 | goto nla_put_failure; |
| 560 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 561 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 562 | goto nla_put_failure; |
| 563 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 564 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 565 | goto nla_put_failure; |
| 566 | } |
| 567 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 568 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 569 | DBM_TO_MBM(chan->max_power))) |
| 570 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 571 | |
| 572 | return 0; |
| 573 | |
| 574 | nla_put_failure: |
| 575 | return -ENOBUFS; |
| 576 | } |
| 577 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 578 | /* netlink command implementations */ |
| 579 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 580 | struct key_parse { |
| 581 | struct key_params p; |
| 582 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 583 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 584 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 585 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 589 | { |
| 590 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 591 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 592 | nl80211_key_policy); |
| 593 | if (err) |
| 594 | return err; |
| 595 | |
| 596 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 597 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 598 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 599 | if (k->def) { |
| 600 | k->def_uni = true; |
| 601 | k->def_multi = true; |
| 602 | } |
| 603 | if (k->defmgmt) |
| 604 | k->def_multi = true; |
| 605 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 606 | if (tb[NL80211_KEY_IDX]) |
| 607 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 608 | |
| 609 | if (tb[NL80211_KEY_DATA]) { |
| 610 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 611 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 612 | } |
| 613 | |
| 614 | if (tb[NL80211_KEY_SEQ]) { |
| 615 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 616 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 617 | } |
| 618 | |
| 619 | if (tb[NL80211_KEY_CIPHER]) |
| 620 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 621 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 622 | if (tb[NL80211_KEY_TYPE]) { |
| 623 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 624 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 625 | return -EINVAL; |
| 626 | } |
| 627 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 628 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 629 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 630 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 631 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 632 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 633 | if (err) |
| 634 | return err; |
| 635 | |
| 636 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 637 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 638 | } |
| 639 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 644 | { |
| 645 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 646 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 647 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 648 | } |
| 649 | |
| 650 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 651 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 652 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 653 | } |
| 654 | |
| 655 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 656 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 657 | |
| 658 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 659 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 660 | |
| 661 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 662 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 663 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 664 | if (k->def) { |
| 665 | k->def_uni = true; |
| 666 | k->def_multi = true; |
| 667 | } |
| 668 | if (k->defmgmt) |
| 669 | k->def_multi = true; |
| 670 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 671 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 672 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 673 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 674 | return -EINVAL; |
| 675 | } |
| 676 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 677 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 678 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 679 | int err = nla_parse_nested( |
| 680 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 681 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 682 | nl80211_key_default_policy); |
| 683 | if (err) |
| 684 | return err; |
| 685 | |
| 686 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 687 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 688 | } |
| 689 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 694 | { |
| 695 | int err; |
| 696 | |
| 697 | memset(k, 0, sizeof(*k)); |
| 698 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 699 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 700 | |
| 701 | if (info->attrs[NL80211_ATTR_KEY]) |
| 702 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 703 | else |
| 704 | err = nl80211_parse_key_old(info, k); |
| 705 | |
| 706 | if (err) |
| 707 | return err; |
| 708 | |
| 709 | if (k->def && k->defmgmt) |
| 710 | return -EINVAL; |
| 711 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 712 | if (k->defmgmt) { |
| 713 | if (k->def_uni || !k->def_multi) |
| 714 | return -EINVAL; |
| 715 | } |
| 716 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 717 | if (k->idx != -1) { |
| 718 | if (k->defmgmt) { |
| 719 | if (k->idx < 4 || k->idx > 5) |
| 720 | return -EINVAL; |
| 721 | } else if (k->def) { |
| 722 | if (k->idx < 0 || k->idx > 3) |
| 723 | return -EINVAL; |
| 724 | } else { |
| 725 | if (k->idx < 0 || k->idx > 5) |
| 726 | return -EINVAL; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 733 | static struct cfg80211_cached_keys * |
| 734 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 735 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 736 | { |
| 737 | struct key_parse parse; |
| 738 | struct nlattr *key; |
| 739 | struct cfg80211_cached_keys *result; |
| 740 | int rem, err, def = 0; |
| 741 | |
| 742 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 743 | if (!result) |
| 744 | return ERR_PTR(-ENOMEM); |
| 745 | |
| 746 | result->def = -1; |
| 747 | result->defmgmt = -1; |
| 748 | |
| 749 | nla_for_each_nested(key, keys, rem) { |
| 750 | memset(&parse, 0, sizeof(parse)); |
| 751 | parse.idx = -1; |
| 752 | |
| 753 | err = nl80211_parse_key_new(key, &parse); |
| 754 | if (err) |
| 755 | goto error; |
| 756 | err = -EINVAL; |
| 757 | if (!parse.p.key) |
| 758 | goto error; |
| 759 | if (parse.idx < 0 || parse.idx > 4) |
| 760 | goto error; |
| 761 | if (parse.def) { |
| 762 | if (def) |
| 763 | goto error; |
| 764 | def = 1; |
| 765 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 766 | if (!parse.def_uni || !parse.def_multi) |
| 767 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 768 | } else if (parse.defmgmt) |
| 769 | goto error; |
| 770 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 771 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 772 | if (err) |
| 773 | goto error; |
| 774 | result->params[parse.idx].cipher = parse.p.cipher; |
| 775 | result->params[parse.idx].key_len = parse.p.key_len; |
| 776 | result->params[parse.idx].key = result->data[parse.idx]; |
| 777 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 778 | |
| 779 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 780 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 781 | if (no_ht) |
| 782 | *no_ht = true; |
| 783 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | return result; |
| 787 | error: |
| 788 | kfree(result); |
| 789 | return ERR_PTR(err); |
| 790 | } |
| 791 | |
| 792 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 793 | { |
| 794 | ASSERT_WDEV_LOCK(wdev); |
| 795 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 796 | switch (wdev->iftype) { |
| 797 | case NL80211_IFTYPE_AP: |
| 798 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 799 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 800 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 801 | break; |
| 802 | case NL80211_IFTYPE_ADHOC: |
| 803 | if (!wdev->current_bss) |
| 804 | return -ENOLINK; |
| 805 | break; |
| 806 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 807 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 808 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 809 | return -ENOLINK; |
| 810 | break; |
| 811 | default: |
| 812 | return -EINVAL; |
| 813 | } |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 818 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 819 | { |
| 820 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 821 | int i; |
| 822 | |
| 823 | if (!nl_modes) |
| 824 | goto nla_put_failure; |
| 825 | |
| 826 | i = 0; |
| 827 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 828 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 829 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 830 | ifmodes >>= 1; |
| 831 | i++; |
| 832 | } |
| 833 | |
| 834 | nla_nest_end(msg, nl_modes); |
| 835 | return 0; |
| 836 | |
| 837 | nla_put_failure: |
| 838 | return -ENOBUFS; |
| 839 | } |
| 840 | |
| 841 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 842 | struct sk_buff *msg, |
| 843 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 844 | { |
| 845 | struct nlattr *nl_combis; |
| 846 | int i, j; |
| 847 | |
| 848 | nl_combis = nla_nest_start(msg, |
| 849 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 850 | if (!nl_combis) |
| 851 | goto nla_put_failure; |
| 852 | |
| 853 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 854 | const struct ieee80211_iface_combination *c; |
| 855 | struct nlattr *nl_combi, *nl_limits; |
| 856 | |
| 857 | c = &wiphy->iface_combinations[i]; |
| 858 | |
| 859 | nl_combi = nla_nest_start(msg, i + 1); |
| 860 | if (!nl_combi) |
| 861 | goto nla_put_failure; |
| 862 | |
| 863 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 864 | if (!nl_limits) |
| 865 | goto nla_put_failure; |
| 866 | |
| 867 | for (j = 0; j < c->n_limits; j++) { |
| 868 | struct nlattr *nl_limit; |
| 869 | |
| 870 | nl_limit = nla_nest_start(msg, j + 1); |
| 871 | if (!nl_limit) |
| 872 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 873 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 874 | c->limits[j].max)) |
| 875 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 876 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 877 | c->limits[j].types)) |
| 878 | goto nla_put_failure; |
| 879 | nla_nest_end(msg, nl_limit); |
| 880 | } |
| 881 | |
| 882 | nla_nest_end(msg, nl_limits); |
| 883 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 884 | if (c->beacon_int_infra_match && |
| 885 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 886 | goto nla_put_failure; |
| 887 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 888 | c->num_different_channels) || |
| 889 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 890 | c->max_interfaces)) |
| 891 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 892 | if (large && |
| 893 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 894 | c->radar_detect_widths)) |
| 895 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 896 | |
| 897 | nla_nest_end(msg, nl_combi); |
| 898 | } |
| 899 | |
| 900 | nla_nest_end(msg, nl_combis); |
| 901 | |
| 902 | return 0; |
| 903 | nla_put_failure: |
| 904 | return -ENOBUFS; |
| 905 | } |
| 906 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 907 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 908 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 909 | struct sk_buff *msg) |
| 910 | { |
| 911 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; |
| 912 | struct nlattr *nl_tcp; |
| 913 | |
| 914 | if (!tcp) |
| 915 | return 0; |
| 916 | |
| 917 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 918 | if (!nl_tcp) |
| 919 | return -ENOBUFS; |
| 920 | |
| 921 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 922 | tcp->data_payload_max)) |
| 923 | return -ENOBUFS; |
| 924 | |
| 925 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 926 | tcp->data_payload_max)) |
| 927 | return -ENOBUFS; |
| 928 | |
| 929 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 930 | return -ENOBUFS; |
| 931 | |
| 932 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 933 | sizeof(*tcp->tok), tcp->tok)) |
| 934 | return -ENOBUFS; |
| 935 | |
| 936 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 937 | tcp->data_interval_max)) |
| 938 | return -ENOBUFS; |
| 939 | |
| 940 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 941 | tcp->wake_payload_max)) |
| 942 | return -ENOBUFS; |
| 943 | |
| 944 | nla_nest_end(msg, nl_tcp); |
| 945 | return 0; |
| 946 | } |
| 947 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 948 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 949 | struct cfg80211_registered_device *dev, |
| 950 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 951 | { |
| 952 | struct nlattr *nl_wowlan; |
| 953 | |
| 954 | if (!dev->wiphy.wowlan.flags && !dev->wiphy.wowlan.n_patterns) |
| 955 | return 0; |
| 956 | |
| 957 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 958 | if (!nl_wowlan) |
| 959 | return -ENOBUFS; |
| 960 | |
| 961 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 962 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 963 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 964 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 965 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 966 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 967 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 968 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 969 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 970 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 971 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 972 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 973 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 974 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 975 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 976 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 977 | return -ENOBUFS; |
| 978 | |
| 979 | if (dev->wiphy.wowlan.n_patterns) { |
| 980 | struct nl80211_wowlan_pattern_support pat = { |
| 981 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 982 | .min_pattern_len = dev->wiphy.wowlan.pattern_min_len, |
| 983 | .max_pattern_len = dev->wiphy.wowlan.pattern_max_len, |
| 984 | .max_pkt_offset = dev->wiphy.wowlan.max_pkt_offset, |
| 985 | }; |
| 986 | |
| 987 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 988 | sizeof(pat), &pat)) |
| 989 | return -ENOBUFS; |
| 990 | } |
| 991 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 992 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 993 | return -ENOBUFS; |
| 994 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 995 | nla_nest_end(msg, nl_wowlan); |
| 996 | |
| 997 | return 0; |
| 998 | } |
| 999 | #endif |
| 1000 | |
| 1001 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1002 | struct ieee80211_supported_band *sband) |
| 1003 | { |
| 1004 | struct nlattr *nl_rates, *nl_rate; |
| 1005 | struct ieee80211_rate *rate; |
| 1006 | int i; |
| 1007 | |
| 1008 | /* add HT info */ |
| 1009 | if (sband->ht_cap.ht_supported && |
| 1010 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1011 | sizeof(sband->ht_cap.mcs), |
| 1012 | &sband->ht_cap.mcs) || |
| 1013 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1014 | sband->ht_cap.cap) || |
| 1015 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1016 | sband->ht_cap.ampdu_factor) || |
| 1017 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1018 | sband->ht_cap.ampdu_density))) |
| 1019 | return -ENOBUFS; |
| 1020 | |
| 1021 | /* add VHT info */ |
| 1022 | if (sband->vht_cap.vht_supported && |
| 1023 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1024 | sizeof(sband->vht_cap.vht_mcs), |
| 1025 | &sband->vht_cap.vht_mcs) || |
| 1026 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1027 | sband->vht_cap.cap))) |
| 1028 | return -ENOBUFS; |
| 1029 | |
| 1030 | /* add bitrates */ |
| 1031 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1032 | if (!nl_rates) |
| 1033 | return -ENOBUFS; |
| 1034 | |
| 1035 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1036 | nl_rate = nla_nest_start(msg, i); |
| 1037 | if (!nl_rate) |
| 1038 | return -ENOBUFS; |
| 1039 | |
| 1040 | rate = &sband->bitrates[i]; |
| 1041 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1042 | rate->bitrate)) |
| 1043 | return -ENOBUFS; |
| 1044 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1045 | nla_put_flag(msg, |
| 1046 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1047 | return -ENOBUFS; |
| 1048 | |
| 1049 | nla_nest_end(msg, nl_rate); |
| 1050 | } |
| 1051 | |
| 1052 | nla_nest_end(msg, nl_rates); |
| 1053 | |
| 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | static int |
| 1058 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1059 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1060 | { |
| 1061 | u16 stypes; |
| 1062 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1063 | enum nl80211_iftype ift; |
| 1064 | int i; |
| 1065 | |
| 1066 | if (!mgmt_stypes) |
| 1067 | return 0; |
| 1068 | |
| 1069 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1070 | if (!nl_ifs) |
| 1071 | return -ENOBUFS; |
| 1072 | |
| 1073 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1074 | nl_ftypes = nla_nest_start(msg, ift); |
| 1075 | if (!nl_ftypes) |
| 1076 | return -ENOBUFS; |
| 1077 | i = 0; |
| 1078 | stypes = mgmt_stypes[ift].tx; |
| 1079 | while (stypes) { |
| 1080 | if ((stypes & 1) && |
| 1081 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1082 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1083 | return -ENOBUFS; |
| 1084 | stypes >>= 1; |
| 1085 | i++; |
| 1086 | } |
| 1087 | nla_nest_end(msg, nl_ftypes); |
| 1088 | } |
| 1089 | |
| 1090 | nla_nest_end(msg, nl_ifs); |
| 1091 | |
| 1092 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1093 | if (!nl_ifs) |
| 1094 | return -ENOBUFS; |
| 1095 | |
| 1096 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1097 | nl_ftypes = nla_nest_start(msg, ift); |
| 1098 | if (!nl_ftypes) |
| 1099 | return -ENOBUFS; |
| 1100 | i = 0; |
| 1101 | stypes = mgmt_stypes[ift].rx; |
| 1102 | while (stypes) { |
| 1103 | if ((stypes & 1) && |
| 1104 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1105 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1106 | return -ENOBUFS; |
| 1107 | stypes >>= 1; |
| 1108 | i++; |
| 1109 | } |
| 1110 | nla_nest_end(msg, nl_ftypes); |
| 1111 | } |
| 1112 | nla_nest_end(msg, nl_ifs); |
| 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1118 | struct sk_buff *msg, u32 portid, u32 seq, |
| 1119 | int flags, bool split, long *split_start, |
| 1120 | long *band_start, long *chan_start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1121 | { |
| 1122 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1123 | struct nlattr *nl_bands, *nl_band; |
| 1124 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1125 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1126 | enum ieee80211_band band; |
| 1127 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1128 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1129 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1130 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1131 | long start = 0, start_chan = 0, start_band = 0; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1132 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1133 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1134 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1135 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1136 | return -ENOBUFS; |
| 1137 | |
| 1138 | /* allow always using the variables */ |
| 1139 | if (!split) { |
| 1140 | split_start = &start; |
| 1141 | band_start = &start_band; |
| 1142 | chan_start = &start_chan; |
| 1143 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1144 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1145 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1146 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1147 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1148 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1149 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1150 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1151 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1152 | switch (*split_start) { |
| 1153 | case 0: |
| 1154 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1155 | dev->wiphy.retry_short) || |
| 1156 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1157 | dev->wiphy.retry_long) || |
| 1158 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1159 | dev->wiphy.frag_threshold) || |
| 1160 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1161 | dev->wiphy.rts_threshold) || |
| 1162 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1163 | dev->wiphy.coverage_class) || |
| 1164 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1165 | dev->wiphy.max_scan_ssids) || |
| 1166 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1167 | dev->wiphy.max_sched_scan_ssids) || |
| 1168 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1169 | dev->wiphy.max_scan_ie_len) || |
| 1170 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1171 | dev->wiphy.max_sched_scan_ie_len) || |
| 1172 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1173 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1174 | goto nla_put_failure; |
| 1175 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1176 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1177 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1178 | goto nla_put_failure; |
| 1179 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1180 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1181 | goto nla_put_failure; |
| 1182 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1183 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1184 | goto nla_put_failure; |
| 1185 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1186 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1187 | goto nla_put_failure; |
| 1188 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1189 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1190 | goto nla_put_failure; |
| 1191 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1192 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1193 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 1194 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1195 | (*split_start)++; |
| 1196 | if (split) |
| 1197 | break; |
| 1198 | case 1: |
| 1199 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 1200 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 1201 | dev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1202 | goto nla_put_failure; |
| 1203 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1204 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 1205 | dev->wiphy.max_num_pmkids)) |
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_CONTROL_PORT_PROTOCOL) && |
| 1209 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1210 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1211 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 1213 | dev->wiphy.available_antennas_tx) || |
| 1214 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 1215 | dev->wiphy.available_antennas_rx)) |
| 1216 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1217 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1218 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 1219 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 1220 | dev->wiphy.probe_resp_offload)) |
| 1221 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1222 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1223 | if ((dev->wiphy.available_antennas_tx || |
| 1224 | dev->wiphy.available_antennas_rx) && |
| 1225 | dev->ops->get_antenna) { |
| 1226 | u32 tx_ant = 0, rx_ant = 0; |
| 1227 | int res; |
| 1228 | res = rdev_get_antenna(dev, &tx_ant, &rx_ant); |
| 1229 | if (!res) { |
| 1230 | if (nla_put_u32(msg, |
| 1231 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1232 | tx_ant) || |
| 1233 | nla_put_u32(msg, |
| 1234 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1235 | rx_ant)) |
| 1236 | goto nla_put_failure; |
| 1237 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1238 | } |
| 1239 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1240 | (*split_start)++; |
| 1241 | if (split) |
| 1242 | break; |
| 1243 | case 2: |
| 1244 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 1245 | dev->wiphy.interface_modes)) |
| 1246 | goto nla_put_failure; |
| 1247 | (*split_start)++; |
| 1248 | if (split) |
| 1249 | break; |
| 1250 | case 3: |
| 1251 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1252 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1253 | goto nla_put_failure; |
| 1254 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1255 | for (band = *band_start; band < IEEE80211_NUM_BANDS; band++) { |
| 1256 | struct ieee80211_supported_band *sband; |
| 1257 | |
| 1258 | sband = dev->wiphy.bands[band]; |
| 1259 | |
| 1260 | if (!sband) |
| 1261 | continue; |
| 1262 | |
| 1263 | nl_band = nla_nest_start(msg, band); |
| 1264 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1265 | goto nla_put_failure; |
| 1266 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1267 | switch (*chan_start) { |
| 1268 | case 0: |
| 1269 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1270 | goto nla_put_failure; |
| 1271 | (*chan_start)++; |
| 1272 | if (split) |
| 1273 | break; |
| 1274 | default: |
| 1275 | /* add frequencies */ |
| 1276 | nl_freqs = nla_nest_start( |
| 1277 | msg, NL80211_BAND_ATTR_FREQS); |
| 1278 | if (!nl_freqs) |
| 1279 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1280 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1281 | for (i = *chan_start - 1; |
| 1282 | i < sband->n_channels; |
| 1283 | i++) { |
| 1284 | nl_freq = nla_nest_start(msg, i); |
| 1285 | if (!nl_freq) |
| 1286 | goto nla_put_failure; |
| 1287 | |
| 1288 | chan = &sband->channels[i]; |
| 1289 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1290 | if (nl80211_msg_put_channel(msg, chan, |
| 1291 | split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | goto nla_put_failure; |
| 1293 | |
| 1294 | nla_nest_end(msg, nl_freq); |
| 1295 | if (split) |
| 1296 | break; |
| 1297 | } |
| 1298 | if (i < sband->n_channels) |
| 1299 | *chan_start = i + 2; |
| 1300 | else |
| 1301 | *chan_start = 0; |
| 1302 | nla_nest_end(msg, nl_freqs); |
| 1303 | } |
| 1304 | |
| 1305 | nla_nest_end(msg, nl_band); |
| 1306 | |
| 1307 | if (split) { |
| 1308 | /* start again here */ |
| 1309 | if (*chan_start) |
| 1310 | band--; |
| 1311 | break; |
| 1312 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1313 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1314 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1315 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1316 | if (band < IEEE80211_NUM_BANDS) |
| 1317 | *band_start = band + 1; |
| 1318 | else |
| 1319 | *band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1320 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1321 | /* if bands & channels are done, continue outside */ |
| 1322 | if (*band_start == 0 && *chan_start == 0) |
| 1323 | (*split_start)++; |
| 1324 | if (split) |
| 1325 | break; |
| 1326 | case 4: |
| 1327 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1328 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1329 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | |
| 1331 | i = 0; |
| 1332 | #define CMD(op, n) \ |
| 1333 | do { \ |
| 1334 | if (dev->ops->op) { \ |
| 1335 | i++; \ |
| 1336 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1337 | goto nla_put_failure; \ |
| 1338 | } \ |
| 1339 | } while (0) |
| 1340 | |
| 1341 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1342 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1343 | CMD(add_key, NEW_KEY); |
| 1344 | CMD(start_ap, START_AP); |
| 1345 | CMD(add_station, NEW_STATION); |
| 1346 | CMD(add_mpath, NEW_MPATH); |
| 1347 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1348 | CMD(change_bss, SET_BSS); |
| 1349 | CMD(auth, AUTHENTICATE); |
| 1350 | CMD(assoc, ASSOCIATE); |
| 1351 | CMD(deauth, DEAUTHENTICATE); |
| 1352 | CMD(disassoc, DISASSOCIATE); |
| 1353 | CMD(join_ibss, JOIN_IBSS); |
| 1354 | CMD(join_mesh, JOIN_MESH); |
| 1355 | CMD(set_pmksa, SET_PMKSA); |
| 1356 | CMD(del_pmksa, DEL_PMKSA); |
| 1357 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1358 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1359 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1360 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1361 | CMD(mgmt_tx, FRAME); |
| 1362 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1363 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1364 | i++; |
| 1365 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1366 | goto nla_put_failure; |
| 1367 | } |
| 1368 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
| 1369 | dev->ops->join_mesh) { |
| 1370 | i++; |
| 1371 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1372 | goto nla_put_failure; |
| 1373 | } |
| 1374 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1375 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1376 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1377 | CMD(tdls_oper, TDLS_OPER); |
| 1378 | } |
| 1379 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1380 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1381 | CMD(probe_client, PROBE_CLIENT); |
| 1382 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1383 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1384 | i++; |
| 1385 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1386 | goto nla_put_failure; |
| 1387 | } |
| 1388 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1389 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1390 | if (split) { |
| 1391 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1392 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
| 1393 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1394 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1395 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1396 | CMD(testmode_cmd, TESTMODE); |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1397 | #endif |
| 1398 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1399 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1400 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1401 | if (dev->ops->connect || dev->ops->auth) { |
| 1402 | i++; |
| 1403 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1404 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1405 | } |
| 1406 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1407 | if (dev->ops->disconnect || dev->ops->deauth) { |
| 1408 | i++; |
| 1409 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1410 | goto nla_put_failure; |
| 1411 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1412 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1413 | nla_nest_end(msg, nl_cmds); |
| 1414 | (*split_start)++; |
| 1415 | if (split) |
| 1416 | break; |
| 1417 | case 5: |
| 1418 | if (dev->ops->remain_on_channel && |
| 1419 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1420 | nla_put_u32(msg, |
| 1421 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1422 | dev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1423 | goto nla_put_failure; |
| 1424 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1425 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1426 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1427 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1428 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1429 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1430 | goto nla_put_failure; |
| 1431 | (*split_start)++; |
| 1432 | if (split) |
| 1433 | break; |
| 1434 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1435 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1436 | if (nl80211_send_wowlan(msg, dev, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1437 | goto nla_put_failure; |
| 1438 | (*split_start)++; |
| 1439 | if (split) |
| 1440 | break; |
| 1441 | #else |
| 1442 | (*split_start)++; |
| 1443 | #endif |
| 1444 | case 7: |
| 1445 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1446 | dev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1447 | goto nla_put_failure; |
| 1448 | |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1449 | if (nl80211_put_iface_combinations(&dev->wiphy, msg, split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1450 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1451 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1452 | (*split_start)++; |
| 1453 | if (split) |
| 1454 | break; |
| 1455 | case 8: |
| 1456 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1457 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1458 | dev->wiphy.ap_sme_capa)) |
| 1459 | goto nla_put_failure; |
| 1460 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1461 | features = dev->wiphy.features; |
| 1462 | /* |
| 1463 | * We can only add the per-channel limit information if the |
| 1464 | * dump is split, otherwise it makes it too big. Therefore |
| 1465 | * only advertise it in that case. |
| 1466 | */ |
| 1467 | if (split) |
| 1468 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1469 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | goto nla_put_failure; |
| 1471 | |
| 1472 | if (dev->wiphy.ht_capa_mod_mask && |
| 1473 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1474 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1475 | dev->wiphy.ht_capa_mod_mask)) |
| 1476 | goto nla_put_failure; |
| 1477 | |
| 1478 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1479 | dev->wiphy.max_acl_mac_addrs && |
| 1480 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
| 1481 | dev->wiphy.max_acl_mac_addrs)) |
| 1482 | goto nla_put_failure; |
| 1483 | |
| 1484 | /* |
| 1485 | * Any information below this point is only available to |
| 1486 | * applications that can deal with it being split. This |
| 1487 | * helps ensure that newly added capabilities don't break |
| 1488 | * older tools by overrunning their buffers. |
| 1489 | * |
| 1490 | * We still increment split_start so that in the split |
| 1491 | * case we'll continue with more data in the next round, |
| 1492 | * but break unconditionally so unsplit data stops here. |
| 1493 | */ |
| 1494 | (*split_start)++; |
| 1495 | break; |
| 1496 | case 9: |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1497 | if (dev->wiphy.extended_capabilities && |
| 1498 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1499 | dev->wiphy.extended_capabilities_len, |
| 1500 | dev->wiphy.extended_capabilities) || |
| 1501 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1502 | dev->wiphy.extended_capabilities_len, |
| 1503 | dev->wiphy.extended_capabilities_mask))) |
| 1504 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1505 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1506 | if (dev->wiphy.vht_capa_mod_mask && |
| 1507 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
| 1508 | sizeof(*dev->wiphy.vht_capa_mod_mask), |
| 1509 | dev->wiphy.vht_capa_mod_mask)) |
| 1510 | goto nla_put_failure; |
| 1511 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | /* done */ |
| 1513 | *split_start = 0; |
| 1514 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1515 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1516 | return genlmsg_end(msg, hdr); |
| 1517 | |
| 1518 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1519 | genlmsg_cancel(msg, hdr); |
| 1520 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1524 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1525 | int idx = 0, ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1526 | int start = cb->args[0]; |
| 1527 | struct cfg80211_registered_device *dev; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1528 | s64 filter_wiphy = -1; |
| 1529 | bool split = false; |
| 1530 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1531 | int res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1532 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1533 | rtnl_lock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1534 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1535 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1536 | if (res == 0) { |
| 1537 | split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1538 | if (tb[NL80211_ATTR_WIPHY]) |
| 1539 | filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1540 | if (tb[NL80211_ATTR_WDEV]) |
| 1541 | filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1542 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1543 | struct net_device *netdev; |
| 1544 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1545 | |
| 1546 | netdev = dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1547 | if (!netdev) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1548 | return -ENODEV; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | if (netdev->ieee80211_ptr) { |
| 1550 | dev = wiphy_to_dev( |
| 1551 | netdev->ieee80211_ptr->wiphy); |
| 1552 | filter_wiphy = dev->wiphy_idx; |
| 1553 | } |
| 1554 | dev_put(netdev); |
| 1555 | } |
| 1556 | } |
| 1557 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1558 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1559 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1560 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1561 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1562 | continue; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1563 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
| 1564 | continue; |
| 1565 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1566 | do { |
| 1567 | ret = nl80211_send_wiphy(dev, skb, |
| 1568 | NETLINK_CB(cb->skb).portid, |
| 1569 | cb->nlh->nlmsg_seq, |
| 1570 | NLM_F_MULTI, |
| 1571 | split, &cb->args[1], |
| 1572 | &cb->args[2], |
| 1573 | &cb->args[3]); |
| 1574 | if (ret < 0) { |
| 1575 | /* |
| 1576 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1577 | * or EMSGSIZE returned), this SKB is still |
| 1578 | * empty (so it's not too big because another |
| 1579 | * wiphy dataset is already in the skb) and |
| 1580 | * we've not tried to adjust the dump allocation |
| 1581 | * yet ... then adjust the alloc size to be |
| 1582 | * bigger, and return 1 but with the empty skb. |
| 1583 | * This results in an empty message being RX'ed |
| 1584 | * in userspace, but that is ignored. |
| 1585 | * |
| 1586 | * We can then retry with the larger buffer. |
| 1587 | */ |
| 1588 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1589 | !skb->len && |
| 1590 | cb->min_dump_alloc < 4096) { |
| 1591 | cb->min_dump_alloc = 4096; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1592 | return 1; |
| 1593 | } |
| 1594 | idx--; |
| 1595 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1596 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1597 | } while (cb->args[1] > 0); |
| 1598 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1599 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1600 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1601 | |
| 1602 | cb->args[0] = idx; |
| 1603 | |
| 1604 | return skb->len; |
| 1605 | } |
| 1606 | |
| 1607 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1608 | { |
| 1609 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1610 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1611 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1612 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1613 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1614 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1615 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1616 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
| 1617 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1618 | nlmsg_free(msg); |
| 1619 | return -ENOBUFS; |
| 1620 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1621 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1622 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1623 | } |
| 1624 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1625 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1626 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1627 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1628 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1629 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1630 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1631 | }; |
| 1632 | |
| 1633 | static int parse_txq_params(struct nlattr *tb[], |
| 1634 | struct ieee80211_txq_params *txq_params) |
| 1635 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1636 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1637 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1638 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1639 | return -EINVAL; |
| 1640 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1641 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1642 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1643 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1644 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1645 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1646 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1647 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1648 | return -EINVAL; |
| 1649 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1650 | return 0; |
| 1651 | } |
| 1652 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1653 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1654 | { |
| 1655 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1656 | * You can only set the channel explicitly for WDS interfaces, |
| 1657 | * all others have their channel managed via their respective |
| 1658 | * "establish a connection" command (connect, join, ...) |
| 1659 | * |
| 1660 | * For AP/GO and mesh mode, the channel can be set with the |
| 1661 | * channel userspace API, but is only stored and passed to the |
| 1662 | * low-level driver when the AP starts or the mesh is joined. |
| 1663 | * This is for backward compatibility, userspace can also give |
| 1664 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1665 | * |
| 1666 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1667 | * whatever else is going on, so they have their own special |
| 1668 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1669 | */ |
| 1670 | return !wdev || |
| 1671 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1672 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1673 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1674 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1675 | } |
| 1676 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1677 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1678 | struct genl_info *info, |
| 1679 | struct cfg80211_chan_def *chandef) |
| 1680 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1681 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1682 | |
| 1683 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1684 | return -EINVAL; |
| 1685 | |
| 1686 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1687 | |
| 1688 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1689 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1690 | chandef->center_freq1 = control_freq; |
| 1691 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1692 | |
| 1693 | /* Primary channel not allowed */ |
| 1694 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1695 | return -EINVAL; |
| 1696 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1697 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1698 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1699 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1700 | chantype = nla_get_u32( |
| 1701 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1702 | |
| 1703 | switch (chantype) { |
| 1704 | case NL80211_CHAN_NO_HT: |
| 1705 | case NL80211_CHAN_HT20: |
| 1706 | case NL80211_CHAN_HT40PLUS: |
| 1707 | case NL80211_CHAN_HT40MINUS: |
| 1708 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1709 | chantype); |
| 1710 | break; |
| 1711 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1712 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1713 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1714 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1715 | chandef->width = |
| 1716 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1717 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1718 | chandef->center_freq1 = |
| 1719 | nla_get_u32( |
| 1720 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1721 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1722 | chandef->center_freq2 = |
| 1723 | nla_get_u32( |
| 1724 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1725 | } |
| 1726 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1727 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1728 | return -EINVAL; |
| 1729 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1730 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1731 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1732 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1733 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1734 | return 0; |
| 1735 | } |
| 1736 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1737 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1738 | struct wireless_dev *wdev, |
| 1739 | struct genl_info *info) |
| 1740 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1741 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1742 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1743 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1744 | |
| 1745 | if (wdev) |
| 1746 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1747 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1748 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1749 | return -EOPNOTSUPP; |
| 1750 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1751 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1752 | if (result) |
| 1753 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1754 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1755 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1756 | case NL80211_IFTYPE_AP: |
| 1757 | case NL80211_IFTYPE_P2P_GO: |
| 1758 | if (wdev->beacon_interval) { |
| 1759 | result = -EBUSY; |
| 1760 | break; |
| 1761 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1762 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1763 | result = -EINVAL; |
| 1764 | break; |
| 1765 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1766 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1767 | result = 0; |
| 1768 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1769 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1770 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1771 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1772 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1773 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1774 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1775 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1776 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1777 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1778 | |
| 1779 | return result; |
| 1780 | } |
| 1781 | |
| 1782 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1783 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1784 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1785 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1786 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1787 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1788 | } |
| 1789 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1790 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1791 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1793 | struct net_device *dev = info->user_ptr[1]; |
| 1794 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1795 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1796 | |
| 1797 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1798 | return -EINVAL; |
| 1799 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1800 | if (netif_running(dev)) |
| 1801 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1802 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1803 | if (!rdev->ops->set_wds_peer) |
| 1804 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1805 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1806 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1807 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1808 | |
| 1809 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1810 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1814 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1815 | { |
| 1816 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1817 | struct net_device *netdev = NULL; |
| 1818 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1819 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1820 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1821 | u32 changed; |
| 1822 | u8 retry_short = 0, retry_long = 0; |
| 1823 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1824 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1825 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1826 | ASSERT_RTNL(); |
| 1827 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1828 | /* |
| 1829 | * Try to find the wiphy and netdev. Normally this |
| 1830 | * function shouldn't need the netdev, but this is |
| 1831 | * done for backward compatibility -- previously |
| 1832 | * setting the channel was done per wiphy, but now |
| 1833 | * it is per netdev. Previous userland like hostapd |
| 1834 | * also passed a netdev to set_wiphy, so that it is |
| 1835 | * possible to let that go to the right netdev! |
| 1836 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1837 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1838 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1839 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1840 | |
| 1841 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1842 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1843 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1844 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1845 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1846 | } |
| 1847 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1848 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1849 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1850 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1851 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1852 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1853 | wdev = NULL; |
| 1854 | netdev = NULL; |
| 1855 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1856 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1857 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1858 | |
| 1859 | /* |
| 1860 | * end workaround code, by now the rdev is available |
| 1861 | * and locked, and wdev may or may not be NULL. |
| 1862 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1863 | |
| 1864 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1865 | result = cfg80211_dev_rename( |
| 1866 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1867 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1868 | if (result) |
| 1869 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1870 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1871 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1872 | struct ieee80211_txq_params txq_params; |
| 1873 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1874 | |
| 1875 | if (!rdev->ops->set_txq_params) { |
| 1876 | result = -EOPNOTSUPP; |
| 1877 | goto bad_res; |
| 1878 | } |
| 1879 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1880 | if (!netdev) { |
| 1881 | result = -EINVAL; |
| 1882 | goto bad_res; |
| 1883 | } |
| 1884 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1885 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1886 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1887 | result = -EINVAL; |
| 1888 | goto bad_res; |
| 1889 | } |
| 1890 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1891 | if (!netif_running(netdev)) { |
| 1892 | result = -ENETDOWN; |
| 1893 | goto bad_res; |
| 1894 | } |
| 1895 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1896 | nla_for_each_nested(nl_txq_params, |
| 1897 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1898 | rem_txq_params) { |
| 1899 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1900 | nla_data(nl_txq_params), |
| 1901 | nla_len(nl_txq_params), |
| 1902 | txq_params_policy); |
| 1903 | result = parse_txq_params(tb, &txq_params); |
| 1904 | if (result) |
| 1905 | goto bad_res; |
| 1906 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1907 | result = rdev_set_txq_params(rdev, netdev, |
| 1908 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1909 | if (result) |
| 1910 | goto bad_res; |
| 1911 | } |
| 1912 | } |
| 1913 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1914 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1915 | result = __nl80211_set_channel(rdev, |
| 1916 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1917 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1918 | if (result) |
| 1919 | goto bad_res; |
| 1920 | } |
| 1921 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1922 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1923 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1924 | enum nl80211_tx_power_setting type; |
| 1925 | int idx, mbm = 0; |
| 1926 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1927 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1928 | txp_wdev = NULL; |
| 1929 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1930 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1931 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1932 | goto bad_res; |
| 1933 | } |
| 1934 | |
| 1935 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1936 | type = nla_get_u32(info->attrs[idx]); |
| 1937 | |
| 1938 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1939 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1940 | result = -EINVAL; |
| 1941 | goto bad_res; |
| 1942 | } |
| 1943 | |
| 1944 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1945 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1946 | mbm = nla_get_u32(info->attrs[idx]); |
| 1947 | } |
| 1948 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1949 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1950 | if (result) |
| 1951 | goto bad_res; |
| 1952 | } |
| 1953 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1954 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1955 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1956 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1957 | if ((!rdev->wiphy.available_antennas_tx && |
| 1958 | !rdev->wiphy.available_antennas_rx) || |
| 1959 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1960 | result = -EOPNOTSUPP; |
| 1961 | goto bad_res; |
| 1962 | } |
| 1963 | |
| 1964 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1965 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1966 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1967 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1968 | * available antenna masks, except for the "all" mask */ |
| 1969 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1970 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1971 | result = -EINVAL; |
| 1972 | goto bad_res; |
| 1973 | } |
| 1974 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1975 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1976 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1977 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1978 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1979 | if (result) |
| 1980 | goto bad_res; |
| 1981 | } |
| 1982 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1983 | changed = 0; |
| 1984 | |
| 1985 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1986 | retry_short = nla_get_u8( |
| 1987 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1988 | if (retry_short == 0) { |
| 1989 | result = -EINVAL; |
| 1990 | goto bad_res; |
| 1991 | } |
| 1992 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1993 | } |
| 1994 | |
| 1995 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1996 | retry_long = nla_get_u8( |
| 1997 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1998 | if (retry_long == 0) { |
| 1999 | result = -EINVAL; |
| 2000 | goto bad_res; |
| 2001 | } |
| 2002 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2003 | } |
| 2004 | |
| 2005 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2006 | frag_threshold = nla_get_u32( |
| 2007 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2008 | if (frag_threshold < 256) { |
| 2009 | result = -EINVAL; |
| 2010 | goto bad_res; |
| 2011 | } |
| 2012 | if (frag_threshold != (u32) -1) { |
| 2013 | /* |
| 2014 | * Fragments (apart from the last one) are required to |
| 2015 | * have even length. Make the fragmentation code |
| 2016 | * simpler by stripping LSB should someone try to use |
| 2017 | * odd threshold value. |
| 2018 | */ |
| 2019 | frag_threshold &= ~0x1; |
| 2020 | } |
| 2021 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2022 | } |
| 2023 | |
| 2024 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2025 | rts_threshold = nla_get_u32( |
| 2026 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2027 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2028 | } |
| 2029 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2030 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2031 | coverage_class = nla_get_u8( |
| 2032 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2033 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2034 | } |
| 2035 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2036 | if (changed) { |
| 2037 | u8 old_retry_short, old_retry_long; |
| 2038 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2039 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2040 | |
| 2041 | if (!rdev->ops->set_wiphy_params) { |
| 2042 | result = -EOPNOTSUPP; |
| 2043 | goto bad_res; |
| 2044 | } |
| 2045 | |
| 2046 | old_retry_short = rdev->wiphy.retry_short; |
| 2047 | old_retry_long = rdev->wiphy.retry_long; |
| 2048 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2049 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2050 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2051 | |
| 2052 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2053 | rdev->wiphy.retry_short = retry_short; |
| 2054 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2055 | rdev->wiphy.retry_long = retry_long; |
| 2056 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2057 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2058 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2059 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2060 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2061 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2062 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2063 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2064 | if (result) { |
| 2065 | rdev->wiphy.retry_short = old_retry_short; |
| 2066 | rdev->wiphy.retry_long = old_retry_long; |
| 2067 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2068 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2069 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2070 | } |
| 2071 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2072 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2073 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2074 | if (netdev) |
| 2075 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2076 | return result; |
| 2077 | } |
| 2078 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2079 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2080 | { |
| 2081 | return (u64)wdev->identifier | |
| 2082 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2083 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2084 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2085 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2086 | struct cfg80211_chan_def *chandef) |
| 2087 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2088 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2089 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2090 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2091 | chandef->chan->center_freq)) |
| 2092 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2093 | switch (chandef->width) { |
| 2094 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2095 | case NL80211_CHAN_WIDTH_20: |
| 2096 | case NL80211_CHAN_WIDTH_40: |
| 2097 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2098 | cfg80211_get_chandef_type(chandef))) |
| 2099 | return -ENOBUFS; |
| 2100 | break; |
| 2101 | default: |
| 2102 | break; |
| 2103 | } |
| 2104 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2105 | return -ENOBUFS; |
| 2106 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2107 | return -ENOBUFS; |
| 2108 | if (chandef->center_freq2 && |
| 2109 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2110 | return -ENOBUFS; |
| 2111 | return 0; |
| 2112 | } |
| 2113 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2114 | 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] | 2115 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2116 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2117 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2118 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2119 | void *hdr; |
| 2120 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2121 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2122 | if (!hdr) |
| 2123 | return -1; |
| 2124 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2125 | if (dev && |
| 2126 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2127 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2128 | goto nla_put_failure; |
| 2129 | |
| 2130 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2131 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2132 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2133 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2134 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2135 | rdev->devlist_generation ^ |
| 2136 | (cfg80211_rdev_list_generation << 2))) |
| 2137 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2138 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2139 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2140 | int ret; |
| 2141 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2142 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2143 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2144 | if (ret == 0) { |
| 2145 | if (nl80211_send_chandef(msg, &chandef)) |
| 2146 | goto nla_put_failure; |
| 2147 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2148 | } |
| 2149 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2150 | if (wdev->ssid_len) { |
| 2151 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2152 | goto nla_put_failure; |
| 2153 | } |
| 2154 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2155 | return genlmsg_end(msg, hdr); |
| 2156 | |
| 2157 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2158 | genlmsg_cancel(msg, hdr); |
| 2159 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2163 | { |
| 2164 | int wp_idx = 0; |
| 2165 | int if_idx = 0; |
| 2166 | int wp_start = cb->args[0]; |
| 2167 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2168 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2169 | struct wireless_dev *wdev; |
| 2170 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2171 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2172 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2173 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2174 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2175 | if (wp_idx < wp_start) { |
| 2176 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2177 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2178 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2179 | if_idx = 0; |
| 2180 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2181 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2182 | if (if_idx < if_start) { |
| 2183 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2184 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2185 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2186 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2187 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2188 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2189 | goto out; |
| 2190 | } |
| 2191 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2192 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2193 | |
| 2194 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2195 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2196 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2197 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2198 | |
| 2199 | cb->args[0] = wp_idx; |
| 2200 | cb->args[1] = if_idx; |
| 2201 | |
| 2202 | return skb->len; |
| 2203 | } |
| 2204 | |
| 2205 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2206 | { |
| 2207 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2208 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2209 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2210 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2211 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2212 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2213 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2214 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2215 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2216 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2217 | nlmsg_free(msg); |
| 2218 | return -ENOBUFS; |
| 2219 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2220 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2221 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2222 | } |
| 2223 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2224 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2225 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2226 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2227 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2228 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2229 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 2230 | }; |
| 2231 | |
| 2232 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2233 | { |
| 2234 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2235 | int flag; |
| 2236 | |
| 2237 | *mntrflags = 0; |
| 2238 | |
| 2239 | if (!nla) |
| 2240 | return -EINVAL; |
| 2241 | |
| 2242 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2243 | nla, mntr_flags_policy)) |
| 2244 | return -EINVAL; |
| 2245 | |
| 2246 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2247 | if (flags[flag]) |
| 2248 | *mntrflags |= (1<<flag); |
| 2249 | |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2253 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2254 | struct net_device *netdev, u8 use_4addr, |
| 2255 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2256 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2257 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2258 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2259 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2260 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2261 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2262 | |
| 2263 | switch (iftype) { |
| 2264 | case NL80211_IFTYPE_AP_VLAN: |
| 2265 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2266 | return 0; |
| 2267 | break; |
| 2268 | case NL80211_IFTYPE_STATION: |
| 2269 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2270 | return 0; |
| 2271 | break; |
| 2272 | default: |
| 2273 | break; |
| 2274 | } |
| 2275 | |
| 2276 | return -EOPNOTSUPP; |
| 2277 | } |
| 2278 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2279 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2280 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2281 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2282 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2283 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2284 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2285 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2286 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2287 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2288 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2289 | memset(¶ms, 0, sizeof(params)); |
| 2290 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2291 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2292 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2293 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2294 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2295 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2296 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2297 | if (ntype > NL80211_IFTYPE_MAX) |
| 2298 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2299 | } |
| 2300 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2301 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2302 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2303 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2304 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2305 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2306 | if (netif_running(dev)) |
| 2307 | return -EBUSY; |
| 2308 | |
| 2309 | wdev_lock(wdev); |
| 2310 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2311 | IEEE80211_MAX_MESH_ID_LEN); |
| 2312 | wdev->mesh_id_up_len = |
| 2313 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2314 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2315 | wdev->mesh_id_up_len); |
| 2316 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2317 | } |
| 2318 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2319 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2320 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2321 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2322 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2323 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2324 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2325 | } else { |
| 2326 | params.use_4addr = -1; |
| 2327 | } |
| 2328 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2329 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2330 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2331 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2332 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2333 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2334 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2335 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2336 | |
| 2337 | flags = &_flags; |
| 2338 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2339 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2340 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2341 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2342 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2343 | else |
| 2344 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2345 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2346 | if (!err && params.use_4addr != -1) |
| 2347 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2348 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2349 | return err; |
| 2350 | } |
| 2351 | |
| 2352 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2353 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2355 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2356 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2357 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2358 | int err; |
| 2359 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2360 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2361 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2362 | memset(¶ms, 0, sizeof(params)); |
| 2363 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2364 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2365 | return -EINVAL; |
| 2366 | |
| 2367 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2368 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2369 | if (type > NL80211_IFTYPE_MAX) |
| 2370 | return -EINVAL; |
| 2371 | } |
| 2372 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2373 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2374 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2375 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2376 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2377 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2378 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2379 | ETH_ALEN); |
| 2380 | if (!is_valid_ether_addr(params.macaddr)) |
| 2381 | return -EADDRNOTAVAIL; |
| 2382 | } |
| 2383 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2384 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2385 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2386 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2387 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2388 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2389 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2390 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2391 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2392 | if (!msg) |
| 2393 | return -ENOMEM; |
| 2394 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2395 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2396 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2397 | &flags); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2398 | wdev = rdev_add_virtual_intf(rdev, |
| 2399 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2400 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2401 | if (IS_ERR(wdev)) { |
| 2402 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2403 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2404 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2405 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2406 | switch (type) { |
| 2407 | case NL80211_IFTYPE_MESH_POINT: |
| 2408 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2409 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2410 | wdev_lock(wdev); |
| 2411 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2412 | IEEE80211_MAX_MESH_ID_LEN); |
| 2413 | wdev->mesh_id_up_len = |
| 2414 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2415 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2416 | wdev->mesh_id_up_len); |
| 2417 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2418 | break; |
| 2419 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2420 | /* |
| 2421 | * P2P Device doesn't have a netdev, so doesn't go |
| 2422 | * through the netdev notifier and must be added here |
| 2423 | */ |
| 2424 | mutex_init(&wdev->mtx); |
| 2425 | INIT_LIST_HEAD(&wdev->event_list); |
| 2426 | spin_lock_init(&wdev->event_lock); |
| 2427 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2428 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2429 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2430 | wdev->identifier = ++rdev->wdev_id; |
| 2431 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2432 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2433 | break; |
| 2434 | default: |
| 2435 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2436 | } |
| 2437 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2438 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2439 | rdev, wdev) < 0) { |
| 2440 | nlmsg_free(msg); |
| 2441 | return -ENOBUFS; |
| 2442 | } |
| 2443 | |
| 2444 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2448 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2450 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2451 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2452 | if (!rdev->ops->del_virtual_intf) |
| 2453 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2454 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2455 | /* |
| 2456 | * If we remove a wireless device without a netdev then clear |
| 2457 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2458 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2459 | * since the wdev has been freed, unlike with a netdev where |
| 2460 | * we need the dev_put() for the netdev to really be freed. |
| 2461 | */ |
| 2462 | if (!wdev->netdev) |
| 2463 | info->user_ptr[1] = NULL; |
| 2464 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2465 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2466 | } |
| 2467 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2468 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2469 | { |
| 2470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2471 | struct net_device *dev = info->user_ptr[1]; |
| 2472 | u16 noack_map; |
| 2473 | |
| 2474 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2475 | return -EINVAL; |
| 2476 | |
| 2477 | if (!rdev->ops->set_noack_map) |
| 2478 | return -EOPNOTSUPP; |
| 2479 | |
| 2480 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2481 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2482 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2483 | } |
| 2484 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2485 | struct get_key_cookie { |
| 2486 | struct sk_buff *msg; |
| 2487 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2488 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2489 | }; |
| 2490 | |
| 2491 | static void get_key_callback(void *c, struct key_params *params) |
| 2492 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2493 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2494 | struct get_key_cookie *cookie = c; |
| 2495 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2496 | if ((params->key && |
| 2497 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2498 | params->key_len, params->key)) || |
| 2499 | (params->seq && |
| 2500 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2501 | params->seq_len, params->seq)) || |
| 2502 | (params->cipher && |
| 2503 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2504 | params->cipher))) |
| 2505 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2506 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2507 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2508 | if (!key) |
| 2509 | goto nla_put_failure; |
| 2510 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2511 | if ((params->key && |
| 2512 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2513 | params->key_len, params->key)) || |
| 2514 | (params->seq && |
| 2515 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2516 | params->seq_len, params->seq)) || |
| 2517 | (params->cipher && |
| 2518 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2519 | params->cipher))) |
| 2520 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2521 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2522 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2523 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2524 | |
| 2525 | nla_nest_end(cookie->msg, key); |
| 2526 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2527 | return; |
| 2528 | nla_put_failure: |
| 2529 | cookie->error = 1; |
| 2530 | } |
| 2531 | |
| 2532 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2533 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2534 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2535 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2536 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2537 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2538 | const u8 *mac_addr = NULL; |
| 2539 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2540 | struct get_key_cookie cookie = { |
| 2541 | .error = 0, |
| 2542 | }; |
| 2543 | void *hdr; |
| 2544 | struct sk_buff *msg; |
| 2545 | |
| 2546 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2547 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2548 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2549 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2550 | return -EINVAL; |
| 2551 | |
| 2552 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2553 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2554 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2555 | pairwise = !!mac_addr; |
| 2556 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2557 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2558 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2559 | return -EINVAL; |
| 2560 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2561 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2562 | return -EINVAL; |
| 2563 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2564 | } |
| 2565 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2566 | if (!rdev->ops->get_key) |
| 2567 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2568 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2569 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2570 | if (!msg) |
| 2571 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2572 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2573 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2574 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2575 | if (IS_ERR(hdr)) |
| 2576 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2577 | |
| 2578 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2579 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2580 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2581 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2582 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2583 | goto nla_put_failure; |
| 2584 | if (mac_addr && |
| 2585 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2586 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2587 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2588 | if (pairwise && mac_addr && |
| 2589 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2590 | return -ENOENT; |
| 2591 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2592 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2593 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2594 | |
| 2595 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2596 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2597 | |
| 2598 | if (cookie.error) |
| 2599 | goto nla_put_failure; |
| 2600 | |
| 2601 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2602 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2603 | |
| 2604 | nla_put_failure: |
| 2605 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2606 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2607 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2608 | return err; |
| 2609 | } |
| 2610 | |
| 2611 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2612 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2614 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2615 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2616 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2617 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2618 | err = nl80211_parse_key(info, &key); |
| 2619 | if (err) |
| 2620 | return err; |
| 2621 | |
| 2622 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2623 | return -EINVAL; |
| 2624 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2625 | /* only support setting default key */ |
| 2626 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2627 | return -EINVAL; |
| 2628 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2629 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2630 | |
| 2631 | if (key.def) { |
| 2632 | if (!rdev->ops->set_default_key) { |
| 2633 | err = -EOPNOTSUPP; |
| 2634 | goto out; |
| 2635 | } |
| 2636 | |
| 2637 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2638 | if (err) |
| 2639 | goto out; |
| 2640 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2641 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2642 | key.def_uni, key.def_multi); |
| 2643 | |
| 2644 | if (err) |
| 2645 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2646 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2647 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2648 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2649 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2650 | } else { |
| 2651 | if (key.def_uni || !key.def_multi) { |
| 2652 | err = -EINVAL; |
| 2653 | goto out; |
| 2654 | } |
| 2655 | |
| 2656 | if (!rdev->ops->set_default_mgmt_key) { |
| 2657 | err = -EOPNOTSUPP; |
| 2658 | goto out; |
| 2659 | } |
| 2660 | |
| 2661 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2662 | if (err) |
| 2663 | goto out; |
| 2664 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2665 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2666 | if (err) |
| 2667 | goto out; |
| 2668 | |
| 2669 | #ifdef CONFIG_CFG80211_WEXT |
| 2670 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2671 | #endif |
| 2672 | } |
| 2673 | |
| 2674 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2675 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2676 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2677 | return err; |
| 2678 | } |
| 2679 | |
| 2680 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2681 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2682 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2683 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2684 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2685 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2686 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2687 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2688 | err = nl80211_parse_key(info, &key); |
| 2689 | if (err) |
| 2690 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2691 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2692 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2693 | return -EINVAL; |
| 2694 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2695 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2696 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2697 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2698 | if (key.type == -1) { |
| 2699 | if (mac_addr) |
| 2700 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2701 | else |
| 2702 | key.type = NL80211_KEYTYPE_GROUP; |
| 2703 | } |
| 2704 | |
| 2705 | /* for now */ |
| 2706 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2707 | key.type != NL80211_KEYTYPE_GROUP) |
| 2708 | return -EINVAL; |
| 2709 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2710 | if (!rdev->ops->add_key) |
| 2711 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2712 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2713 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2714 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2715 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2716 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2717 | |
| 2718 | wdev_lock(dev->ieee80211_ptr); |
| 2719 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2720 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2721 | err = rdev_add_key(rdev, dev, key.idx, |
| 2722 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2723 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2724 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2725 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2726 | return err; |
| 2727 | } |
| 2728 | |
| 2729 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2730 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2732 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2733 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2734 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2735 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2736 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2737 | err = nl80211_parse_key(info, &key); |
| 2738 | if (err) |
| 2739 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2740 | |
| 2741 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2742 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2743 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2744 | if (key.type == -1) { |
| 2745 | if (mac_addr) |
| 2746 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2747 | else |
| 2748 | key.type = NL80211_KEYTYPE_GROUP; |
| 2749 | } |
| 2750 | |
| 2751 | /* for now */ |
| 2752 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2753 | key.type != NL80211_KEYTYPE_GROUP) |
| 2754 | return -EINVAL; |
| 2755 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2756 | if (!rdev->ops->del_key) |
| 2757 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2758 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2759 | wdev_lock(dev->ieee80211_ptr); |
| 2760 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2761 | |
| 2762 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2763 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2764 | err = -ENOENT; |
| 2765 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2766 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2767 | err = rdev_del_key(rdev, dev, key.idx, |
| 2768 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2769 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2770 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2771 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2772 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2773 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2774 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2775 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2776 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2777 | } |
| 2778 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2779 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2780 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2781 | return err; |
| 2782 | } |
| 2783 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2784 | /* This function returns an error or the number of nested attributes */ |
| 2785 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2786 | { |
| 2787 | struct nlattr *attr; |
| 2788 | int n_entries = 0, tmp; |
| 2789 | |
| 2790 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2791 | if (nla_len(attr) != ETH_ALEN) |
| 2792 | return -EINVAL; |
| 2793 | |
| 2794 | n_entries++; |
| 2795 | } |
| 2796 | |
| 2797 | return n_entries; |
| 2798 | } |
| 2799 | |
| 2800 | /* |
| 2801 | * This function parses ACL information and allocates memory for ACL data. |
| 2802 | * On successful return, the calling function is responsible to free the |
| 2803 | * ACL buffer returned by this function. |
| 2804 | */ |
| 2805 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2806 | struct genl_info *info) |
| 2807 | { |
| 2808 | enum nl80211_acl_policy acl_policy; |
| 2809 | struct nlattr *attr; |
| 2810 | struct cfg80211_acl_data *acl; |
| 2811 | int i = 0, n_entries, tmp; |
| 2812 | |
| 2813 | if (!wiphy->max_acl_mac_addrs) |
| 2814 | return ERR_PTR(-EOPNOTSUPP); |
| 2815 | |
| 2816 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2817 | return ERR_PTR(-EINVAL); |
| 2818 | |
| 2819 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2820 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2821 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2822 | return ERR_PTR(-EINVAL); |
| 2823 | |
| 2824 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2825 | return ERR_PTR(-EINVAL); |
| 2826 | |
| 2827 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2828 | if (n_entries < 0) |
| 2829 | return ERR_PTR(n_entries); |
| 2830 | |
| 2831 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2832 | return ERR_PTR(-ENOTSUPP); |
| 2833 | |
| 2834 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2835 | GFP_KERNEL); |
| 2836 | if (!acl) |
| 2837 | return ERR_PTR(-ENOMEM); |
| 2838 | |
| 2839 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2840 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2841 | i++; |
| 2842 | } |
| 2843 | |
| 2844 | acl->n_acl_entries = n_entries; |
| 2845 | acl->acl_policy = acl_policy; |
| 2846 | |
| 2847 | return acl; |
| 2848 | } |
| 2849 | |
| 2850 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2851 | { |
| 2852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2853 | struct net_device *dev = info->user_ptr[1]; |
| 2854 | struct cfg80211_acl_data *acl; |
| 2855 | int err; |
| 2856 | |
| 2857 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2858 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2859 | return -EOPNOTSUPP; |
| 2860 | |
| 2861 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2862 | return -EINVAL; |
| 2863 | |
| 2864 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2865 | if (IS_ERR(acl)) |
| 2866 | return PTR_ERR(acl); |
| 2867 | |
| 2868 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2869 | |
| 2870 | kfree(acl); |
| 2871 | |
| 2872 | return err; |
| 2873 | } |
| 2874 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2875 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2876 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2877 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2878 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2879 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2880 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2881 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2882 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2883 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2884 | return -EINVAL; |
| 2885 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2886 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2887 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2888 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2889 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2890 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2891 | if (!bcn->head_len) |
| 2892 | return -EINVAL; |
| 2893 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2897 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2898 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2899 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2900 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2901 | } |
| 2902 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2903 | if (!haveinfo) |
| 2904 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2905 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2906 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2907 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2908 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2912 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2913 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2914 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2915 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2916 | } |
| 2917 | |
| 2918 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2919 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2920 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2921 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2922 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2923 | } |
| 2924 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2925 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2926 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2927 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2928 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2929 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2930 | } |
| 2931 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2932 | return 0; |
| 2933 | } |
| 2934 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2935 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2936 | struct cfg80211_ap_settings *params) |
| 2937 | { |
| 2938 | struct wireless_dev *wdev; |
| 2939 | bool ret = false; |
| 2940 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2941 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2942 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2943 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2944 | continue; |
| 2945 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2946 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2947 | continue; |
| 2948 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2949 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2950 | ret = true; |
| 2951 | break; |
| 2952 | } |
| 2953 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2954 | return ret; |
| 2955 | } |
| 2956 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2957 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2958 | enum nl80211_auth_type auth_type, |
| 2959 | enum nl80211_commands cmd) |
| 2960 | { |
| 2961 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2962 | return false; |
| 2963 | |
| 2964 | switch (cmd) { |
| 2965 | case NL80211_CMD_AUTHENTICATE: |
| 2966 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2967 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2968 | return false; |
| 2969 | return true; |
| 2970 | case NL80211_CMD_CONNECT: |
| 2971 | case NL80211_CMD_START_AP: |
| 2972 | /* SAE not supported yet */ |
| 2973 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2974 | return false; |
| 2975 | return true; |
| 2976 | default: |
| 2977 | return false; |
| 2978 | } |
| 2979 | } |
| 2980 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2981 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2982 | { |
| 2983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2984 | struct net_device *dev = info->user_ptr[1]; |
| 2985 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2986 | struct cfg80211_ap_settings params; |
| 2987 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 2988 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2989 | |
| 2990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2992 | return -EOPNOTSUPP; |
| 2993 | |
| 2994 | if (!rdev->ops->start_ap) |
| 2995 | return -EOPNOTSUPP; |
| 2996 | |
| 2997 | if (wdev->beacon_interval) |
| 2998 | return -EALREADY; |
| 2999 | |
| 3000 | memset(¶ms, 0, sizeof(params)); |
| 3001 | |
| 3002 | /* these are required for START_AP */ |
| 3003 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3004 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3005 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3006 | return -EINVAL; |
| 3007 | |
| 3008 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 3009 | if (err) |
| 3010 | return err; |
| 3011 | |
| 3012 | params.beacon_interval = |
| 3013 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3014 | params.dtim_period = |
| 3015 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3016 | |
| 3017 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3018 | if (err) |
| 3019 | return err; |
| 3020 | |
| 3021 | /* |
| 3022 | * In theory, some of these attributes should be required here |
| 3023 | * but since they were not used when the command was originally |
| 3024 | * added, keep them optional for old user space programs to let |
| 3025 | * them continue to work with drivers that do not need the |
| 3026 | * additional information -- drivers must check! |
| 3027 | */ |
| 3028 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3029 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3030 | params.ssid_len = |
| 3031 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3032 | if (params.ssid_len == 0 || |
| 3033 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3034 | return -EINVAL; |
| 3035 | } |
| 3036 | |
| 3037 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3038 | params.hidden_ssid = nla_get_u32( |
| 3039 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3040 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3041 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3042 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3043 | return -EINVAL; |
| 3044 | } |
| 3045 | |
| 3046 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3047 | |
| 3048 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3049 | params.auth_type = nla_get_u32( |
| 3050 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3051 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3052 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3053 | return -EINVAL; |
| 3054 | } else |
| 3055 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3056 | |
| 3057 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3058 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3059 | if (err) |
| 3060 | return err; |
| 3061 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3062 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3063 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3064 | return -EOPNOTSUPP; |
| 3065 | params.inactivity_timeout = nla_get_u16( |
| 3066 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3067 | } |
| 3068 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3069 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3070 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3071 | return -EINVAL; |
| 3072 | params.p2p_ctwindow = |
| 3073 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3074 | if (params.p2p_ctwindow > 127) |
| 3075 | return -EINVAL; |
| 3076 | if (params.p2p_ctwindow != 0 && |
| 3077 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3078 | return -EINVAL; |
| 3079 | } |
| 3080 | |
| 3081 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3082 | u8 tmp; |
| 3083 | |
| 3084 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3085 | return -EINVAL; |
| 3086 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3087 | if (tmp > 1) |
| 3088 | return -EINVAL; |
| 3089 | params.p2p_opp_ps = tmp; |
| 3090 | if (params.p2p_opp_ps != 0 && |
| 3091 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3092 | return -EINVAL; |
| 3093 | } |
| 3094 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3095 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3096 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3097 | if (err) |
| 3098 | return err; |
| 3099 | } else if (wdev->preset_chandef.chan) { |
| 3100 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3101 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3102 | return -EINVAL; |
| 3103 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3104 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3105 | return -EINVAL; |
| 3106 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3107 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3108 | if (err < 0) |
| 3109 | return err; |
| 3110 | if (err) { |
| 3111 | radar_detect_width = BIT(params.chandef.width); |
| 3112 | params.radar_required = true; |
| 3113 | } |
| 3114 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3115 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3116 | params.chandef.chan, |
| 3117 | CHAN_MODE_SHARED, |
| 3118 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3119 | if (err) |
| 3120 | return err; |
| 3121 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3122 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3123 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3124 | if (IS_ERR(params.acl)) |
| 3125 | return PTR_ERR(params.acl); |
| 3126 | } |
| 3127 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3128 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3129 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3130 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3131 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3132 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3133 | wdev->ssid_len = params.ssid_len; |
| 3134 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3135 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3136 | |
| 3137 | kfree(params.acl); |
| 3138 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3139 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3140 | } |
| 3141 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3142 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3143 | { |
| 3144 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3145 | struct net_device *dev = info->user_ptr[1]; |
| 3146 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3147 | struct cfg80211_beacon_data params; |
| 3148 | int err; |
| 3149 | |
| 3150 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3151 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3152 | return -EOPNOTSUPP; |
| 3153 | |
| 3154 | if (!rdev->ops->change_beacon) |
| 3155 | return -EOPNOTSUPP; |
| 3156 | |
| 3157 | if (!wdev->beacon_interval) |
| 3158 | return -EINVAL; |
| 3159 | |
| 3160 | err = nl80211_parse_beacon(info, ¶ms); |
| 3161 | if (err) |
| 3162 | return err; |
| 3163 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3164 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | 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] | 3168 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3170 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3171 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3172 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3173 | } |
| 3174 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3175 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3176 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3177 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3178 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3179 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3180 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3181 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3182 | }; |
| 3183 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3184 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3185 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3186 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3187 | { |
| 3188 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3189 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3190 | int flag; |
| 3191 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3192 | /* |
| 3193 | * Try parsing the new attribute first so userspace |
| 3194 | * can specify both for older kernels. |
| 3195 | */ |
| 3196 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3197 | if (nla) { |
| 3198 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3199 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3200 | sta_flags = nla_data(nla); |
| 3201 | params->sta_flags_mask = sta_flags->mask; |
| 3202 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3203 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3204 | if ((params->sta_flags_mask | |
| 3205 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3206 | return -EINVAL; |
| 3207 | return 0; |
| 3208 | } |
| 3209 | |
| 3210 | /* if present, parse the old attribute */ |
| 3211 | |
| 3212 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3213 | if (!nla) |
| 3214 | return 0; |
| 3215 | |
| 3216 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3217 | nla, sta_flags_policy)) |
| 3218 | return -EINVAL; |
| 3219 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3220 | /* |
| 3221 | * Only allow certain flags for interface types so that |
| 3222 | * other attributes are silently ignored. Remember that |
| 3223 | * this is backward compatibility code with old userspace |
| 3224 | * and shouldn't be hit in other cases anyway. |
| 3225 | */ |
| 3226 | switch (iftype) { |
| 3227 | case NL80211_IFTYPE_AP: |
| 3228 | case NL80211_IFTYPE_AP_VLAN: |
| 3229 | case NL80211_IFTYPE_P2P_GO: |
| 3230 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3231 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3232 | BIT(NL80211_STA_FLAG_WME) | |
| 3233 | BIT(NL80211_STA_FLAG_MFP); |
| 3234 | break; |
| 3235 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3236 | case NL80211_IFTYPE_STATION: |
| 3237 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3238 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3239 | break; |
| 3240 | case NL80211_IFTYPE_MESH_POINT: |
| 3241 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3242 | BIT(NL80211_STA_FLAG_MFP) | |
| 3243 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3244 | default: |
| 3245 | return -EINVAL; |
| 3246 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3247 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3248 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3249 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3250 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3251 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3252 | /* no longer support new API additions in old API */ |
| 3253 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3254 | return -EINVAL; |
| 3255 | } |
| 3256 | } |
| 3257 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3258 | return 0; |
| 3259 | } |
| 3260 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3261 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3262 | int attr) |
| 3263 | { |
| 3264 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3265 | u32 bitrate; |
| 3266 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3267 | |
| 3268 | rate = nla_nest_start(msg, attr); |
| 3269 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3270 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3271 | |
| 3272 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3273 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3274 | /* report 16-bit bitrate only if we can */ |
| 3275 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3276 | if (bitrate > 0 && |
| 3277 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3278 | return false; |
| 3279 | if (bitrate_compat > 0 && |
| 3280 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3281 | return false; |
| 3282 | |
| 3283 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3284 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3285 | return false; |
| 3286 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3287 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3288 | return false; |
| 3289 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3290 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3291 | return false; |
| 3292 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3293 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3294 | return false; |
| 3295 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3296 | return false; |
| 3297 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3298 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3299 | return false; |
| 3300 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3301 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3302 | return false; |
| 3303 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3304 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3305 | return false; |
| 3306 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3307 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3308 | return false; |
| 3309 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3310 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3311 | return false; |
| 3312 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3313 | |
| 3314 | nla_nest_end(msg, rate); |
| 3315 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3316 | } |
| 3317 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3318 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3319 | int id) |
| 3320 | { |
| 3321 | void *attr; |
| 3322 | int i = 0; |
| 3323 | |
| 3324 | if (!mask) |
| 3325 | return true; |
| 3326 | |
| 3327 | attr = nla_nest_start(msg, id); |
| 3328 | if (!attr) |
| 3329 | return false; |
| 3330 | |
| 3331 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3332 | if (!(mask & BIT(i))) |
| 3333 | continue; |
| 3334 | |
| 3335 | if (nla_put_u8(msg, i, signal[i])) |
| 3336 | return false; |
| 3337 | } |
| 3338 | |
| 3339 | nla_nest_end(msg, attr); |
| 3340 | |
| 3341 | return true; |
| 3342 | } |
| 3343 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3344 | 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] | 3345 | int flags, |
| 3346 | struct cfg80211_registered_device *rdev, |
| 3347 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3348 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3349 | { |
| 3350 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3351 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3352 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3353 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3354 | if (!hdr) |
| 3355 | return -1; |
| 3356 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3357 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3358 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3359 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3360 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3361 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3362 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3363 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3364 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3365 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3366 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3367 | sinfo->connected_time)) |
| 3368 | goto nla_put_failure; |
| 3369 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3370 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3371 | sinfo->inactive_time)) |
| 3372 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3373 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3374 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3375 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3376 | (u32)sinfo->rx_bytes)) |
| 3377 | goto nla_put_failure; |
| 3378 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3379 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3380 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3381 | (u32)sinfo->tx_bytes)) |
| 3382 | goto nla_put_failure; |
| 3383 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3384 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3385 | sinfo->rx_bytes)) |
| 3386 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3387 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3388 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3389 | sinfo->tx_bytes)) |
| 3390 | goto nla_put_failure; |
| 3391 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3392 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3393 | goto nla_put_failure; |
| 3394 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3395 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3396 | goto nla_put_failure; |
| 3397 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3398 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3399 | sinfo->plink_state)) |
| 3400 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3401 | switch (rdev->wiphy.signal_type) { |
| 3402 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3403 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3404 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3405 | sinfo->signal)) |
| 3406 | goto nla_put_failure; |
| 3407 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3408 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3409 | sinfo->signal_avg)) |
| 3410 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3411 | break; |
| 3412 | default: |
| 3413 | break; |
| 3414 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3415 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3416 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3417 | sinfo->chain_signal, |
| 3418 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3419 | goto nla_put_failure; |
| 3420 | } |
| 3421 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3422 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3423 | sinfo->chain_signal_avg, |
| 3424 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3425 | goto nla_put_failure; |
| 3426 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3427 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3428 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3429 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3430 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3431 | } |
| 3432 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3433 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3434 | NL80211_STA_INFO_RX_BITRATE)) |
| 3435 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3436 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3437 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3438 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3439 | sinfo->rx_packets)) |
| 3440 | goto nla_put_failure; |
| 3441 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3442 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3443 | sinfo->tx_packets)) |
| 3444 | goto nla_put_failure; |
| 3445 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3446 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3447 | sinfo->tx_retries)) |
| 3448 | goto nla_put_failure; |
| 3449 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3450 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3451 | sinfo->tx_failed)) |
| 3452 | goto nla_put_failure; |
| 3453 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3454 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3455 | sinfo->beacon_loss_count)) |
| 3456 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3457 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3458 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3459 | sinfo->local_pm)) |
| 3460 | goto nla_put_failure; |
| 3461 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3462 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3463 | sinfo->peer_pm)) |
| 3464 | goto nla_put_failure; |
| 3465 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3466 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3467 | sinfo->nonpeer_pm)) |
| 3468 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3469 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3470 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3471 | if (!bss_param) |
| 3472 | goto nla_put_failure; |
| 3473 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3474 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3475 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3476 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3477 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3478 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3479 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3480 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3481 | sinfo->bss_param.dtim_period) || |
| 3482 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3483 | sinfo->bss_param.beacon_interval)) |
| 3484 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3485 | |
| 3486 | nla_nest_end(msg, bss_param); |
| 3487 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3488 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3489 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3490 | sizeof(struct nl80211_sta_flag_update), |
| 3491 | &sinfo->sta_flags)) |
| 3492 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3493 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3494 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3495 | sinfo->t_offset)) |
| 3496 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3497 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3498 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3499 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3500 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3501 | sinfo->assoc_req_ies)) |
| 3502 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3503 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3504 | return genlmsg_end(msg, hdr); |
| 3505 | |
| 3506 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3507 | genlmsg_cancel(msg, hdr); |
| 3508 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3509 | } |
| 3510 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3511 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3512 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3513 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3514 | struct station_info sinfo; |
| 3515 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3516 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3517 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3518 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3519 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3520 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3521 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3522 | if (err) |
| 3523 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3524 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3525 | if (!wdev->netdev) { |
| 3526 | err = -EINVAL; |
| 3527 | goto out_err; |
| 3528 | } |
| 3529 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3530 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3531 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3532 | goto out_err; |
| 3533 | } |
| 3534 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3535 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3536 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3537 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3538 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3539 | if (err == -ENOENT) |
| 3540 | break; |
| 3541 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3542 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3543 | |
| 3544 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3545 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3546 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3547 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3548 | &sinfo) < 0) |
| 3549 | goto out; |
| 3550 | |
| 3551 | sta_idx++; |
| 3552 | } |
| 3553 | |
| 3554 | |
| 3555 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3556 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3557 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3558 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3559 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3560 | |
| 3561 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3562 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3563 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3564 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3565 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3566 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3567 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3568 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3569 | struct sk_buff *msg; |
| 3570 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3571 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3572 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3573 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3574 | |
| 3575 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3576 | return -EINVAL; |
| 3577 | |
| 3578 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3579 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3580 | if (!rdev->ops->get_station) |
| 3581 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3582 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3583 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3584 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3585 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3586 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3588 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3589 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3590 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3591 | 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] | 3592 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3593 | nlmsg_free(msg); |
| 3594 | return -ENOBUFS; |
| 3595 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3596 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3597 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3598 | } |
| 3599 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3600 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3601 | struct station_parameters *params, |
| 3602 | enum cfg80211_station_type statype) |
| 3603 | { |
| 3604 | if (params->listen_interval != -1) |
| 3605 | return -EINVAL; |
| 3606 | if (params->aid) |
| 3607 | return -EINVAL; |
| 3608 | |
| 3609 | /* When you run into this, adjust the code below for the new flag */ |
| 3610 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3611 | |
| 3612 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3613 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3614 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3615 | /* |
| 3616 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3617 | * code doesn't have the bug of including TDLS in the |
| 3618 | * mask everywhere. |
| 3619 | */ |
| 3620 | if (params->sta_flags_mask & |
| 3621 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3622 | BIT(NL80211_STA_FLAG_MFP) | |
| 3623 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3624 | return -EINVAL; |
| 3625 | break; |
| 3626 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3627 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3628 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3629 | return -EINVAL; |
| 3630 | /* ignore since it can't change */ |
| 3631 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3632 | break; |
| 3633 | default: |
| 3634 | /* disallow mesh-specific things */ |
| 3635 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3636 | return -EINVAL; |
| 3637 | if (params->local_pm) |
| 3638 | return -EINVAL; |
| 3639 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3640 | return -EINVAL; |
| 3641 | } |
| 3642 | |
| 3643 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3644 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3645 | /* TDLS can't be set, ... */ |
| 3646 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3647 | return -EINVAL; |
| 3648 | /* |
| 3649 | * ... but don't bother the driver with it. This works around |
| 3650 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3651 | * TLDS_PEER flag in the mask even for AP mode. |
| 3652 | */ |
| 3653 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3654 | } |
| 3655 | |
| 3656 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3657 | /* reject other things that can't change */ |
| 3658 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3659 | return -EINVAL; |
| 3660 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3661 | return -EINVAL; |
| 3662 | if (params->supported_rates) |
| 3663 | return -EINVAL; |
| 3664 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3665 | return -EINVAL; |
| 3666 | } |
| 3667 | |
| 3668 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3669 | if (params->vlan) |
| 3670 | return -EINVAL; |
| 3671 | } |
| 3672 | |
| 3673 | switch (statype) { |
| 3674 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3675 | /* Use this only for authorizing/unauthorizing a station */ |
| 3676 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3677 | return -EOPNOTSUPP; |
| 3678 | break; |
| 3679 | case CFG80211_STA_AP_CLIENT: |
| 3680 | /* accept only the listed bits */ |
| 3681 | if (params->sta_flags_mask & |
| 3682 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3683 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3684 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3685 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3686 | BIT(NL80211_STA_FLAG_WME) | |
| 3687 | BIT(NL80211_STA_FLAG_MFP))) |
| 3688 | return -EINVAL; |
| 3689 | |
| 3690 | /* but authenticated/associated only if driver handles it */ |
| 3691 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3692 | params->sta_flags_mask & |
| 3693 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3694 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3695 | return -EINVAL; |
| 3696 | break; |
| 3697 | case CFG80211_STA_IBSS: |
| 3698 | case CFG80211_STA_AP_STA: |
| 3699 | /* reject any changes other than AUTHORIZED */ |
| 3700 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3701 | return -EINVAL; |
| 3702 | break; |
| 3703 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3704 | /* reject any changes other than AUTHORIZED or WME */ |
| 3705 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3706 | BIT(NL80211_STA_FLAG_WME))) |
| 3707 | return -EINVAL; |
| 3708 | /* force (at least) rates when authorizing */ |
| 3709 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3710 | !params->supported_rates) |
| 3711 | return -EINVAL; |
| 3712 | break; |
| 3713 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3714 | /* reject any changes */ |
| 3715 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3716 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3717 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3718 | return -EINVAL; |
| 3719 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3720 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3721 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3722 | return -EINVAL; |
| 3723 | break; |
| 3724 | } |
| 3725 | |
| 3726 | return 0; |
| 3727 | } |
| 3728 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3729 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3730 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3731 | * 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] | 3732 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3733 | static struct net_device *get_vlan(struct genl_info *info, |
| 3734 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3735 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3736 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3737 | struct net_device *v; |
| 3738 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3739 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3740 | if (!vlanattr) |
| 3741 | return NULL; |
| 3742 | |
| 3743 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3744 | if (!v) |
| 3745 | return ERR_PTR(-ENODEV); |
| 3746 | |
| 3747 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3748 | ret = -EINVAL; |
| 3749 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3750 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3751 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3752 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3753 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3754 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3755 | ret = -EINVAL; |
| 3756 | goto error; |
| 3757 | } |
| 3758 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3759 | if (!netif_running(v)) { |
| 3760 | ret = -ENETDOWN; |
| 3761 | goto error; |
| 3762 | } |
| 3763 | |
| 3764 | return v; |
| 3765 | error: |
| 3766 | dev_put(v); |
| 3767 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3768 | } |
| 3769 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3770 | static struct nla_policy |
| 3771 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3772 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3773 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3774 | }; |
| 3775 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3776 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3777 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3778 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3779 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3780 | struct nlattr *nla; |
| 3781 | int err; |
| 3782 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3783 | /* parse WME attributes if present */ |
| 3784 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3785 | return 0; |
| 3786 | |
| 3787 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3788 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3789 | nl80211_sta_wme_policy); |
| 3790 | if (err) |
| 3791 | return err; |
| 3792 | |
| 3793 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3794 | params->uapsd_queues = nla_get_u8( |
| 3795 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3796 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3797 | return -EINVAL; |
| 3798 | |
| 3799 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3800 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3801 | |
| 3802 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3803 | return -EINVAL; |
| 3804 | |
| 3805 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3806 | |
| 3807 | return 0; |
| 3808 | } |
| 3809 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3810 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3811 | struct station_parameters *params) |
| 3812 | { |
| 3813 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3814 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3815 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3816 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3817 | params->ht_capa = |
| 3818 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3819 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3820 | params->vht_capa = |
| 3821 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3822 | |
| 3823 | return nl80211_parse_sta_wme(info, params); |
| 3824 | } |
| 3825 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3826 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3827 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3829 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3830 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3831 | u8 *mac_addr; |
| 3832 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3833 | |
| 3834 | memset(¶ms, 0, sizeof(params)); |
| 3835 | |
| 3836 | params.listen_interval = -1; |
| 3837 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3838 | if (!rdev->ops->change_station) |
| 3839 | return -EOPNOTSUPP; |
| 3840 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3841 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3842 | return -EINVAL; |
| 3843 | |
| 3844 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3845 | return -EINVAL; |
| 3846 | |
| 3847 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3848 | |
| 3849 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3850 | params.supported_rates = |
| 3851 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3852 | params.supported_rates_len = |
| 3853 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3854 | } |
| 3855 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3856 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3857 | params.capability = |
| 3858 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3859 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3860 | } |
| 3861 | |
| 3862 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3863 | params.ext_capab = |
| 3864 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3865 | params.ext_capab_len = |
| 3866 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3867 | } |
| 3868 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3869 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3870 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3871 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3872 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3873 | return -EINVAL; |
| 3874 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3875 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3876 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3877 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3878 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3879 | return -EINVAL; |
| 3880 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3881 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3882 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3883 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3884 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3885 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3886 | return -EINVAL; |
| 3887 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3888 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3889 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3890 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3891 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3892 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3893 | |
| 3894 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3895 | pm > NL80211_MESH_POWER_MAX) |
| 3896 | return -EINVAL; |
| 3897 | |
| 3898 | params.local_pm = pm; |
| 3899 | } |
| 3900 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3901 | /* Include parameters for TDLS peer (will check later) */ |
| 3902 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3903 | if (err) |
| 3904 | return err; |
| 3905 | |
| 3906 | params.vlan = get_vlan(info, rdev); |
| 3907 | if (IS_ERR(params.vlan)) |
| 3908 | return PTR_ERR(params.vlan); |
| 3909 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3910 | switch (dev->ieee80211_ptr->iftype) { |
| 3911 | case NL80211_IFTYPE_AP: |
| 3912 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3913 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3914 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3915 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3916 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3917 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3918 | break; |
| 3919 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3920 | err = -EOPNOTSUPP; |
| 3921 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3922 | } |
| 3923 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3924 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3925 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3926 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3927 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3928 | if (params.vlan) |
| 3929 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3930 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3931 | return err; |
| 3932 | } |
| 3933 | |
| 3934 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3935 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3936 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3937 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3938 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3939 | struct station_parameters params; |
| 3940 | u8 *mac_addr = NULL; |
| 3941 | |
| 3942 | memset(¶ms, 0, sizeof(params)); |
| 3943 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3944 | if (!rdev->ops->add_station) |
| 3945 | return -EOPNOTSUPP; |
| 3946 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3947 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3948 | return -EINVAL; |
| 3949 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3950 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3951 | return -EINVAL; |
| 3952 | |
| 3953 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3954 | return -EINVAL; |
| 3955 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3956 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 3957 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3958 | return -EINVAL; |
| 3959 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3960 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3961 | params.supported_rates = |
| 3962 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3963 | params.supported_rates_len = |
| 3964 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3965 | params.listen_interval = |
| 3966 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3967 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3968 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3969 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3970 | else |
| 3971 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3972 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3973 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3974 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3975 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3976 | params.capability = |
| 3977 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3978 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3979 | } |
| 3980 | |
| 3981 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3982 | params.ext_capab = |
| 3983 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3984 | params.ext_capab_len = |
| 3985 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3986 | } |
| 3987 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3988 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3989 | params.ht_capa = |
| 3990 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3991 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 3992 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3993 | params.vht_capa = |
| 3994 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3995 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3996 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3997 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3998 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3999 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4000 | return -EINVAL; |
| 4001 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4002 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4003 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4004 | if (err) |
| 4005 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4006 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4007 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4008 | return -EINVAL; |
| 4009 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4010 | /* When you run into this, adjust the code below for the new flag */ |
| 4011 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4012 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4013 | switch (dev->ieee80211_ptr->iftype) { |
| 4014 | case NL80211_IFTYPE_AP: |
| 4015 | case NL80211_IFTYPE_AP_VLAN: |
| 4016 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4017 | /* ignore WME attributes if iface/sta is not capable */ |
| 4018 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4019 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4020 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4021 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4022 | /* TDLS peers cannot be added */ |
| 4023 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4024 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4025 | /* but don't bother the driver with it */ |
| 4026 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4027 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4028 | /* allow authenticated/associated only if driver handles it */ |
| 4029 | if (!(rdev->wiphy.features & |
| 4030 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4031 | params.sta_flags_mask & |
| 4032 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4033 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4034 | return -EINVAL; |
| 4035 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4036 | /* must be last in here for error handling */ |
| 4037 | params.vlan = get_vlan(info, rdev); |
| 4038 | if (IS_ERR(params.vlan)) |
| 4039 | return PTR_ERR(params.vlan); |
| 4040 | break; |
| 4041 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4042 | /* ignore uAPSD data */ |
| 4043 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4044 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4045 | /* associated is disallowed */ |
| 4046 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4047 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4048 | /* TDLS peers cannot be added */ |
| 4049 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4050 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4051 | break; |
| 4052 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4053 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4054 | /* ignore uAPSD data */ |
| 4055 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4056 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4057 | /* these are disallowed */ |
| 4058 | if (params.sta_flags_mask & |
| 4059 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4060 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4061 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4062 | /* Only TDLS peers can be added */ |
| 4063 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4064 | return -EINVAL; |
| 4065 | /* Can only add if TDLS ... */ |
| 4066 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4067 | return -EOPNOTSUPP; |
| 4068 | /* ... with external setup is supported */ |
| 4069 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4070 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4071 | /* |
| 4072 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4073 | * as authorized, but it shouldn't yet be. |
| 4074 | */ |
| 4075 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4076 | break; |
| 4077 | default: |
| 4078 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4079 | } |
| 4080 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4081 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4082 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4083 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4084 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4085 | if (params.vlan) |
| 4086 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4087 | return err; |
| 4088 | } |
| 4089 | |
| 4090 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4091 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4093 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4094 | u8 *mac_addr = NULL; |
| 4095 | |
| 4096 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4097 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4098 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4099 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4100 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4101 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4102 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4103 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4104 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4105 | if (!rdev->ops->del_station) |
| 4106 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4107 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4108 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4109 | } |
| 4110 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4111 | 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] | 4112 | int flags, struct net_device *dev, |
| 4113 | u8 *dst, u8 *next_hop, |
| 4114 | struct mpath_info *pinfo) |
| 4115 | { |
| 4116 | void *hdr; |
| 4117 | struct nlattr *pinfoattr; |
| 4118 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4119 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4120 | if (!hdr) |
| 4121 | return -1; |
| 4122 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4123 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4124 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4125 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4126 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4127 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4128 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4129 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4130 | if (!pinfoattr) |
| 4131 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4132 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4133 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4134 | pinfo->frame_qlen)) |
| 4135 | goto nla_put_failure; |
| 4136 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4137 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4138 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4139 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4140 | pinfo->metric)) || |
| 4141 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4142 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4143 | pinfo->exptime)) || |
| 4144 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4145 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4146 | pinfo->flags)) || |
| 4147 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4148 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4149 | pinfo->discovery_timeout)) || |
| 4150 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4151 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4152 | pinfo->discovery_retries))) |
| 4153 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4154 | |
| 4155 | nla_nest_end(msg, pinfoattr); |
| 4156 | |
| 4157 | return genlmsg_end(msg, hdr); |
| 4158 | |
| 4159 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4160 | genlmsg_cancel(msg, hdr); |
| 4161 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4165 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4166 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4167 | struct mpath_info pinfo; |
| 4168 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4169 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4170 | u8 dst[ETH_ALEN]; |
| 4171 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4172 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4173 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4174 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4175 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4176 | if (err) |
| 4177 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4178 | |
| 4179 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4180 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4181 | goto out_err; |
| 4182 | } |
| 4183 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4184 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4185 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4186 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4187 | } |
| 4188 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4189 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4190 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4191 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4192 | if (err == -ENOENT) |
| 4193 | break; |
| 4194 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4195 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4196 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4197 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4198 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4199 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4200 | &pinfo) < 0) |
| 4201 | goto out; |
| 4202 | |
| 4203 | path_idx++; |
| 4204 | } |
| 4205 | |
| 4206 | |
| 4207 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4208 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4209 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4210 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4211 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4212 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4216 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4217 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4218 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4219 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4220 | struct mpath_info pinfo; |
| 4221 | struct sk_buff *msg; |
| 4222 | u8 *dst = NULL; |
| 4223 | u8 next_hop[ETH_ALEN]; |
| 4224 | |
| 4225 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4226 | |
| 4227 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4228 | return -EINVAL; |
| 4229 | |
| 4230 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4231 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4232 | if (!rdev->ops->get_mpath) |
| 4233 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4234 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4235 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4236 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4237 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4238 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4239 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4240 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4241 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4242 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4243 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4244 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4245 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4246 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4247 | dev, dst, next_hop, &pinfo) < 0) { |
| 4248 | nlmsg_free(msg); |
| 4249 | return -ENOBUFS; |
| 4250 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4252 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4253 | } |
| 4254 | |
| 4255 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4256 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4258 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4259 | u8 *dst = NULL; |
| 4260 | u8 *next_hop = NULL; |
| 4261 | |
| 4262 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4263 | return -EINVAL; |
| 4264 | |
| 4265 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4266 | return -EINVAL; |
| 4267 | |
| 4268 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4269 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4270 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4271 | if (!rdev->ops->change_mpath) |
| 4272 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4274 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4275 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4276 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4277 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4278 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4279 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4280 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4281 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4283 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4284 | u8 *dst = NULL; |
| 4285 | u8 *next_hop = NULL; |
| 4286 | |
| 4287 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4288 | return -EINVAL; |
| 4289 | |
| 4290 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4291 | return -EINVAL; |
| 4292 | |
| 4293 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4294 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4295 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4296 | if (!rdev->ops->add_mpath) |
| 4297 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4298 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4300 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4301 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4302 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4306 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4308 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4309 | u8 *dst = NULL; |
| 4310 | |
| 4311 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4312 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4313 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4314 | if (!rdev->ops->del_mpath) |
| 4315 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4316 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4317 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4318 | } |
| 4319 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4320 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4321 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4323 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4324 | struct bss_parameters params; |
| 4325 | |
| 4326 | memset(¶ms, 0, sizeof(params)); |
| 4327 | /* default to not changing parameters */ |
| 4328 | params.use_cts_prot = -1; |
| 4329 | params.use_short_preamble = -1; |
| 4330 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4331 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4332 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4333 | params.p2p_ctwindow = -1; |
| 4334 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4335 | |
| 4336 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4337 | params.use_cts_prot = |
| 4338 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4339 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4340 | params.use_short_preamble = |
| 4341 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4342 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4343 | params.use_short_slot_time = |
| 4344 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4345 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4346 | params.basic_rates = |
| 4347 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4348 | params.basic_rates_len = |
| 4349 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4350 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4351 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4352 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4353 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4354 | params.ht_opmode = |
| 4355 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4356 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4357 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4358 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4359 | return -EINVAL; |
| 4360 | params.p2p_ctwindow = |
| 4361 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4362 | if (params.p2p_ctwindow < 0) |
| 4363 | return -EINVAL; |
| 4364 | if (params.p2p_ctwindow != 0 && |
| 4365 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4366 | return -EINVAL; |
| 4367 | } |
| 4368 | |
| 4369 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4370 | u8 tmp; |
| 4371 | |
| 4372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4373 | return -EINVAL; |
| 4374 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4375 | if (tmp > 1) |
| 4376 | return -EINVAL; |
| 4377 | params.p2p_opp_ps = tmp; |
| 4378 | if (params.p2p_opp_ps && |
| 4379 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4380 | return -EINVAL; |
| 4381 | } |
| 4382 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4383 | if (!rdev->ops->change_bss) |
| 4384 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4385 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4386 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4387 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4388 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4389 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4390 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4391 | } |
| 4392 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4393 | 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] | 4394 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4395 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4396 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4397 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4398 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4399 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4400 | }; |
| 4401 | |
| 4402 | static int parse_reg_rule(struct nlattr *tb[], |
| 4403 | struct ieee80211_reg_rule *reg_rule) |
| 4404 | { |
| 4405 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4406 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4407 | |
| 4408 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4409 | return -EINVAL; |
| 4410 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4411 | return -EINVAL; |
| 4412 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4413 | return -EINVAL; |
| 4414 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4415 | return -EINVAL; |
| 4416 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4417 | return -EINVAL; |
| 4418 | |
| 4419 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4420 | |
| 4421 | freq_range->start_freq_khz = |
| 4422 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4423 | freq_range->end_freq_khz = |
| 4424 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4425 | freq_range->max_bandwidth_khz = |
| 4426 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4427 | |
| 4428 | power_rule->max_eirp = |
| 4429 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4430 | |
| 4431 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4432 | power_rule->max_antenna_gain = |
| 4433 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4434 | |
| 4435 | return 0; |
| 4436 | } |
| 4437 | |
| 4438 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4439 | { |
| 4440 | int r; |
| 4441 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4442 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4443 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4444 | /* |
| 4445 | * You should only get this when cfg80211 hasn't yet initialized |
| 4446 | * completely when built-in to the kernel right between the time |
| 4447 | * window between nl80211_init() and regulatory_init(), if that is |
| 4448 | * even possible. |
| 4449 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4450 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4451 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4452 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4453 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4454 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4455 | |
| 4456 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4457 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4458 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4459 | user_reg_hint_type = |
| 4460 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4461 | else |
| 4462 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4463 | |
| 4464 | switch (user_reg_hint_type) { |
| 4465 | case NL80211_USER_REG_HINT_USER: |
| 4466 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4467 | break; |
| 4468 | default: |
| 4469 | return -EINVAL; |
| 4470 | } |
| 4471 | |
| 4472 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4473 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4474 | return r; |
| 4475 | } |
| 4476 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4477 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4478 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4479 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4481 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4482 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4483 | struct mesh_config cur_params; |
| 4484 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4485 | void *hdr; |
| 4486 | struct nlattr *pinfoattr; |
| 4487 | struct sk_buff *msg; |
| 4488 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4489 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4490 | return -EOPNOTSUPP; |
| 4491 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4492 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4493 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4494 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4495 | wdev_lock(wdev); |
| 4496 | /* If not connected, get default parameters */ |
| 4497 | if (!wdev->mesh_id_len) |
| 4498 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4499 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4500 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4501 | wdev_unlock(wdev); |
| 4502 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4503 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4504 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4505 | |
| 4506 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4507 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4508 | if (!msg) |
| 4509 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4510 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4511 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4512 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4513 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4514 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4515 | if (!pinfoattr) |
| 4516 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4517 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4518 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4519 | cur_params.dot11MeshRetryTimeout) || |
| 4520 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4521 | cur_params.dot11MeshConfirmTimeout) || |
| 4522 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4523 | cur_params.dot11MeshHoldingTimeout) || |
| 4524 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4525 | cur_params.dot11MeshMaxPeerLinks) || |
| 4526 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4527 | cur_params.dot11MeshMaxRetries) || |
| 4528 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4529 | cur_params.dot11MeshTTL) || |
| 4530 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4531 | cur_params.element_ttl) || |
| 4532 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4533 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4534 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4535 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4536 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4537 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4538 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4539 | cur_params.path_refresh_time) || |
| 4540 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4541 | cur_params.min_discovery_timeout) || |
| 4542 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4543 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4544 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4545 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4546 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4547 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4548 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4549 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4550 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4551 | cur_params.dot11MeshHWMPRootMode) || |
| 4552 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4553 | cur_params.dot11MeshHWMPRannInterval) || |
| 4554 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4555 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4556 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4557 | cur_params.dot11MeshForwarding) || |
| 4558 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4559 | cur_params.rssi_threshold) || |
| 4560 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4561 | cur_params.ht_opmode) || |
| 4562 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4563 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4564 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4565 | cur_params.dot11MeshHWMProotInterval) || |
| 4566 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4567 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4568 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4569 | cur_params.power_mode) || |
| 4570 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
| 4571 | cur_params.dot11MeshAwakeWindowDuration)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4572 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4573 | nla_nest_end(msg, pinfoattr); |
| 4574 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4575 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4576 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4577 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4578 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4579 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4580 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4581 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4582 | } |
| 4583 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4584 | 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] | 4585 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4586 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4587 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4588 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4589 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4590 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4591 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4592 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4593 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4594 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4595 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4596 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4597 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4598 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4599 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4600 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4601 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4602 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4603 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4604 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4605 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4606 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4607 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4608 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4609 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4610 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4611 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4612 | }; |
| 4613 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4614 | static const struct nla_policy |
| 4615 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4616 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4617 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4618 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4619 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4620 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4621 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4622 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4623 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4624 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4625 | }; |
| 4626 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4627 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4628 | struct mesh_config *cfg, |
| 4629 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4630 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4631 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4632 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4633 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4634 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4635 | do { \ |
| 4636 | if (tb[attr]) { \ |
| 4637 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4638 | return -EINVAL; \ |
| 4639 | cfg->param = fn(tb[attr]); \ |
| 4640 | mask |= (1 << (attr - 1)); \ |
| 4641 | } \ |
| 4642 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4643 | |
| 4644 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4645 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4646 | return -EINVAL; |
| 4647 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4648 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4649 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4650 | return -EINVAL; |
| 4651 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4652 | /* This makes sure that there aren't more than 32 mesh config |
| 4653 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4654 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4655 | |
| 4656 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4657 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4658 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4659 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4660 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4661 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4662 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4663 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4664 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4665 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4666 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4667 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4668 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4669 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4670 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4671 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4672 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4673 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4674 | 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] | 4675 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4676 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4677 | 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] | 4678 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4679 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4680 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4681 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4682 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4683 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4684 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4685 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4686 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4687 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4688 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4689 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4690 | 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] | 4691 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4692 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4693 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4694 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4695 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4696 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4697 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4698 | 1, 65535, mask, |
| 4699 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4700 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4701 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4702 | 1, 65535, mask, |
| 4703 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4704 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4706 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4707 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4708 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4709 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4710 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4711 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4712 | nla_get_u8); |
| 4713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4714 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4715 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4716 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4717 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4718 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4719 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4720 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4721 | mask, NL80211_MESHCONF_FORWARDING, |
| 4722 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4723 | 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] | 4724 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4725 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4726 | 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] | 4727 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4728 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4729 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4730 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4731 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4732 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4733 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4734 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4735 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4736 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4737 | dot11MeshHWMPconfirmationInterval, |
| 4738 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4739 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4740 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4741 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4742 | NL80211_MESH_POWER_ACTIVE, |
| 4743 | NL80211_MESH_POWER_MAX, |
| 4744 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4745 | nla_get_u32); |
| 4746 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4747 | 0, 65535, mask, |
| 4748 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4749 | if (mask_out) |
| 4750 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4751 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4752 | return 0; |
| 4753 | |
| 4754 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4755 | } |
| 4756 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4757 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4758 | struct mesh_setup *setup) |
| 4759 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4761 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4762 | |
| 4763 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4764 | return -EINVAL; |
| 4765 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4766 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4767 | nl80211_mesh_setup_params_policy)) |
| 4768 | return -EINVAL; |
| 4769 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4770 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4771 | setup->sync_method = |
| 4772 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4773 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4774 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4775 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4776 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4777 | setup->path_sel_proto = |
| 4778 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4779 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4780 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4781 | |
| 4782 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4783 | setup->path_metric = |
| 4784 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4785 | IEEE80211_PATH_METRIC_VENDOR : |
| 4786 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4787 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4788 | |
| 4789 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4790 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4791 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4792 | if (!is_valid_ie_attr(ieattr)) |
| 4793 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4794 | setup->ie = nla_data(ieattr); |
| 4795 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4796 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4797 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4798 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4799 | return -EINVAL; |
| 4800 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4801 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4802 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4803 | if (setup->is_secure) |
| 4804 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4805 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4806 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4807 | if (!setup->user_mpm) |
| 4808 | return -EINVAL; |
| 4809 | setup->auth_id = |
| 4810 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4811 | } |
| 4812 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4813 | return 0; |
| 4814 | } |
| 4815 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4816 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4817 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4818 | { |
| 4819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4820 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4821 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4822 | struct mesh_config cfg; |
| 4823 | u32 mask; |
| 4824 | int err; |
| 4825 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4826 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4827 | return -EOPNOTSUPP; |
| 4828 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4829 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4830 | return -EOPNOTSUPP; |
| 4831 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4832 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4833 | if (err) |
| 4834 | return err; |
| 4835 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4836 | wdev_lock(wdev); |
| 4837 | if (!wdev->mesh_id_len) |
| 4838 | err = -ENOLINK; |
| 4839 | |
| 4840 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4841 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4842 | |
| 4843 | wdev_unlock(wdev); |
| 4844 | |
| 4845 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4846 | } |
| 4847 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4848 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4849 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4850 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4851 | struct sk_buff *msg; |
| 4852 | void *hdr = NULL; |
| 4853 | struct nlattr *nl_reg_rules; |
| 4854 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4855 | |
| 4856 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4857 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4858 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4860 | if (!msg) |
| 4861 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4862 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4863 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4864 | NL80211_CMD_GET_REG); |
| 4865 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4866 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4867 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4868 | if (reg_last_request_cell_base() && |
| 4869 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4870 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4871 | goto nla_put_failure; |
| 4872 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4873 | rcu_read_lock(); |
| 4874 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4875 | |
| 4876 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4877 | (regdom->dfs_region && |
| 4878 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4879 | goto nla_put_failure_rcu; |
| 4880 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4881 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4882 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4883 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4884 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4885 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4886 | struct nlattr *nl_reg_rule; |
| 4887 | const struct ieee80211_reg_rule *reg_rule; |
| 4888 | const struct ieee80211_freq_range *freq_range; |
| 4889 | const struct ieee80211_power_rule *power_rule; |
| 4890 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4891 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4892 | freq_range = ®_rule->freq_range; |
| 4893 | power_rule = ®_rule->power_rule; |
| 4894 | |
| 4895 | nl_reg_rule = nla_nest_start(msg, i); |
| 4896 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4897 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4898 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4899 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4900 | reg_rule->flags) || |
| 4901 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4902 | freq_range->start_freq_khz) || |
| 4903 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4904 | freq_range->end_freq_khz) || |
| 4905 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4906 | freq_range->max_bandwidth_khz) || |
| 4907 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4908 | power_rule->max_antenna_gain) || |
| 4909 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4910 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4911 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4912 | |
| 4913 | nla_nest_end(msg, nl_reg_rule); |
| 4914 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4915 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4916 | |
| 4917 | nla_nest_end(msg, nl_reg_rules); |
| 4918 | |
| 4919 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4920 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4921 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4922 | nla_put_failure_rcu: |
| 4923 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4924 | nla_put_failure: |
| 4925 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4926 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4927 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4928 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4929 | } |
| 4930 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4931 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4932 | { |
| 4933 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4934 | struct nlattr *nl_reg_rule; |
| 4935 | char *alpha2 = NULL; |
| 4936 | int rem_reg_rules = 0, r = 0; |
| 4937 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4938 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4939 | struct ieee80211_regdomain *rd = NULL; |
| 4940 | |
| 4941 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4942 | return -EINVAL; |
| 4943 | |
| 4944 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4945 | return -EINVAL; |
| 4946 | |
| 4947 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4948 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4949 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4950 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4951 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4952 | 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] | 4953 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4954 | num_rules++; |
| 4955 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4956 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4957 | } |
| 4958 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4959 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4960 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4961 | |
| 4962 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4963 | if (!rd) |
| 4964 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4965 | |
| 4966 | rd->n_reg_rules = num_rules; |
| 4967 | rd->alpha2[0] = alpha2[0]; |
| 4968 | rd->alpha2[1] = alpha2[1]; |
| 4969 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4970 | /* |
| 4971 | * Disable DFS master mode if the DFS region was |
| 4972 | * not supported or known on this kernel. |
| 4973 | */ |
| 4974 | if (reg_supported_dfs_region(dfs_region)) |
| 4975 | rd->dfs_region = dfs_region; |
| 4976 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4977 | 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] | 4978 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4979 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4980 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 4981 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4982 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 4983 | if (r) |
| 4984 | goto bad_reg; |
| 4985 | |
| 4986 | rule_idx++; |
| 4987 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4988 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 4989 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4990 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4991 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4992 | } |
| 4993 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4994 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4995 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4996 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4997 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4998 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4999 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5000 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5001 | } |
| 5002 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5003 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5004 | { |
| 5005 | struct nlattr *attr1, *attr2; |
| 5006 | int n_channels = 0, tmp1, tmp2; |
| 5007 | |
| 5008 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5009 | n_channels++; |
| 5010 | /* |
| 5011 | * Some hardware has a limited channel list for |
| 5012 | * scanning, and it is pretty much nonsensical |
| 5013 | * to scan for a channel twice, so disallow that |
| 5014 | * and don't require drivers to check that the |
| 5015 | * channel list they get isn't longer than what |
| 5016 | * they can scan, as long as they can scan all |
| 5017 | * the channels they registered at once. |
| 5018 | */ |
| 5019 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5020 | if (attr1 != attr2 && |
| 5021 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5022 | return 0; |
| 5023 | } |
| 5024 | |
| 5025 | return n_channels; |
| 5026 | } |
| 5027 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5028 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5029 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5031 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5032 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5033 | struct nlattr *attr; |
| 5034 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5035 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5036 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5037 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5038 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5039 | return -EINVAL; |
| 5040 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5041 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5042 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5043 | if (!rdev->ops->scan) |
| 5044 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5045 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5046 | if (rdev->scan_req) { |
| 5047 | err = -EBUSY; |
| 5048 | goto unlock; |
| 5049 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5050 | |
| 5051 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5052 | n_channels = validate_scan_freqs( |
| 5053 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5054 | if (!n_channels) { |
| 5055 | err = -EINVAL; |
| 5056 | goto unlock; |
| 5057 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5058 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5059 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5060 | n_channels = 0; |
| 5061 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5062 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5063 | if (wiphy->bands[band]) |
| 5064 | n_channels += wiphy->bands[band]->n_channels; |
| 5065 | } |
| 5066 | |
| 5067 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5068 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5069 | n_ssids++; |
| 5070 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5071 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5072 | err = -EINVAL; |
| 5073 | goto unlock; |
| 5074 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5075 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5076 | if (info->attrs[NL80211_ATTR_IE]) |
| 5077 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5078 | else |
| 5079 | ie_len = 0; |
| 5080 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5081 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5082 | err = -EINVAL; |
| 5083 | goto unlock; |
| 5084 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5085 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5086 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5087 | + sizeof(*request->ssids) * n_ssids |
| 5088 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5089 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5090 | if (!request) { |
| 5091 | err = -ENOMEM; |
| 5092 | goto unlock; |
| 5093 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5094 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5095 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5096 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5097 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5098 | if (ie_len) { |
| 5099 | if (request->ssids) |
| 5100 | request->ie = (void *)(request->ssids + n_ssids); |
| 5101 | else |
| 5102 | request->ie = (void *)(request->channels + n_channels); |
| 5103 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5104 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5105 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5106 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5107 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5108 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5109 | struct ieee80211_channel *chan; |
| 5110 | |
| 5111 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5112 | |
| 5113 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5114 | err = -EINVAL; |
| 5115 | goto out_free; |
| 5116 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5117 | |
| 5118 | /* ignore disabled channels */ |
| 5119 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5120 | continue; |
| 5121 | |
| 5122 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5123 | i++; |
| 5124 | } |
| 5125 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5126 | enum ieee80211_band band; |
| 5127 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5128 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5129 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5130 | int j; |
| 5131 | if (!wiphy->bands[band]) |
| 5132 | continue; |
| 5133 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5134 | struct ieee80211_channel *chan; |
| 5135 | |
| 5136 | chan = &wiphy->bands[band]->channels[j]; |
| 5137 | |
| 5138 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5139 | continue; |
| 5140 | |
| 5141 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5142 | i++; |
| 5143 | } |
| 5144 | } |
| 5145 | } |
| 5146 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5147 | if (!i) { |
| 5148 | err = -EINVAL; |
| 5149 | goto out_free; |
| 5150 | } |
| 5151 | |
| 5152 | request->n_channels = i; |
| 5153 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5154 | i = 0; |
| 5155 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5156 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5157 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5158 | err = -EINVAL; |
| 5159 | goto out_free; |
| 5160 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5161 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5162 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5163 | i++; |
| 5164 | } |
| 5165 | } |
| 5166 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5167 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5168 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5169 | memcpy((void *)request->ie, |
| 5170 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5171 | request->ie_len); |
| 5172 | } |
| 5173 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5174 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5175 | if (wiphy->bands[i]) |
| 5176 | request->rates[i] = |
| 5177 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5178 | |
| 5179 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5180 | nla_for_each_nested(attr, |
| 5181 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5182 | tmp) { |
| 5183 | enum ieee80211_band band = nla_type(attr); |
| 5184 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5185 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5186 | err = -EINVAL; |
| 5187 | goto out_free; |
| 5188 | } |
| 5189 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5190 | nla_data(attr), |
| 5191 | nla_len(attr), |
| 5192 | &request->rates[band]); |
| 5193 | if (err) |
| 5194 | goto out_free; |
| 5195 | } |
| 5196 | } |
| 5197 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5198 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5199 | request->flags = nla_get_u32( |
| 5200 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5201 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5202 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5203 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5204 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5205 | err = -EOPNOTSUPP; |
| 5206 | goto out_free; |
| 5207 | } |
| 5208 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5209 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5210 | request->no_cck = |
| 5211 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5212 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5213 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5214 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5215 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5216 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5217 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5218 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5219 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5220 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5221 | nl80211_send_scan_start(rdev, wdev); |
| 5222 | if (wdev->netdev) |
| 5223 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5224 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5225 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5226 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5227 | kfree(request); |
| 5228 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5229 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5230 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5231 | return err; |
| 5232 | } |
| 5233 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5234 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5235 | struct genl_info *info) |
| 5236 | { |
| 5237 | struct cfg80211_sched_scan_request *request; |
| 5238 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5239 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5240 | struct nlattr *attr; |
| 5241 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5242 | 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] | 5243 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5244 | enum ieee80211_band band; |
| 5245 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5246 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5247 | |
| 5248 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5249 | !rdev->ops->sched_scan_start) |
| 5250 | return -EOPNOTSUPP; |
| 5251 | |
| 5252 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5253 | return -EINVAL; |
| 5254 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5255 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5256 | return -EINVAL; |
| 5257 | |
| 5258 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5259 | if (interval == 0) |
| 5260 | return -EINVAL; |
| 5261 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5262 | wiphy = &rdev->wiphy; |
| 5263 | |
| 5264 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5265 | n_channels = validate_scan_freqs( |
| 5266 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5267 | if (!n_channels) |
| 5268 | return -EINVAL; |
| 5269 | } else { |
| 5270 | n_channels = 0; |
| 5271 | |
| 5272 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5273 | if (wiphy->bands[band]) |
| 5274 | n_channels += wiphy->bands[band]->n_channels; |
| 5275 | } |
| 5276 | |
| 5277 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5278 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5279 | tmp) |
| 5280 | n_ssids++; |
| 5281 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5282 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5283 | return -EINVAL; |
| 5284 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5285 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5286 | nla_for_each_nested(attr, |
| 5287 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5288 | tmp) |
| 5289 | n_match_sets++; |
| 5290 | |
| 5291 | if (n_match_sets > wiphy->max_match_sets) |
| 5292 | return -EINVAL; |
| 5293 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5294 | if (info->attrs[NL80211_ATTR_IE]) |
| 5295 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5296 | else |
| 5297 | ie_len = 0; |
| 5298 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5299 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5300 | return -EINVAL; |
| 5301 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5302 | if (rdev->sched_scan_req) { |
| 5303 | err = -EINPROGRESS; |
| 5304 | goto out; |
| 5305 | } |
| 5306 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5307 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5308 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5309 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5310 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5311 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5312 | if (!request) { |
| 5313 | err = -ENOMEM; |
| 5314 | goto out; |
| 5315 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5316 | |
| 5317 | if (n_ssids) |
| 5318 | request->ssids = (void *)&request->channels[n_channels]; |
| 5319 | request->n_ssids = n_ssids; |
| 5320 | if (ie_len) { |
| 5321 | if (request->ssids) |
| 5322 | request->ie = (void *)(request->ssids + n_ssids); |
| 5323 | else |
| 5324 | request->ie = (void *)(request->channels + n_channels); |
| 5325 | } |
| 5326 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5327 | if (n_match_sets) { |
| 5328 | if (request->ie) |
| 5329 | request->match_sets = (void *)(request->ie + ie_len); |
| 5330 | else if (request->ssids) |
| 5331 | request->match_sets = |
| 5332 | (void *)(request->ssids + n_ssids); |
| 5333 | else |
| 5334 | request->match_sets = |
| 5335 | (void *)(request->channels + n_channels); |
| 5336 | } |
| 5337 | request->n_match_sets = n_match_sets; |
| 5338 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5339 | i = 0; |
| 5340 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5341 | /* user specified, bail out if channel not found */ |
| 5342 | nla_for_each_nested(attr, |
| 5343 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5344 | tmp) { |
| 5345 | struct ieee80211_channel *chan; |
| 5346 | |
| 5347 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5348 | |
| 5349 | if (!chan) { |
| 5350 | err = -EINVAL; |
| 5351 | goto out_free; |
| 5352 | } |
| 5353 | |
| 5354 | /* ignore disabled channels */ |
| 5355 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5356 | continue; |
| 5357 | |
| 5358 | request->channels[i] = chan; |
| 5359 | i++; |
| 5360 | } |
| 5361 | } else { |
| 5362 | /* all channels */ |
| 5363 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5364 | int j; |
| 5365 | if (!wiphy->bands[band]) |
| 5366 | continue; |
| 5367 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5368 | struct ieee80211_channel *chan; |
| 5369 | |
| 5370 | chan = &wiphy->bands[band]->channels[j]; |
| 5371 | |
| 5372 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5373 | continue; |
| 5374 | |
| 5375 | request->channels[i] = chan; |
| 5376 | i++; |
| 5377 | } |
| 5378 | } |
| 5379 | } |
| 5380 | |
| 5381 | if (!i) { |
| 5382 | err = -EINVAL; |
| 5383 | goto out_free; |
| 5384 | } |
| 5385 | |
| 5386 | request->n_channels = i; |
| 5387 | |
| 5388 | i = 0; |
| 5389 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5390 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5391 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5392 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5393 | err = -EINVAL; |
| 5394 | goto out_free; |
| 5395 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5396 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5397 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5398 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5399 | i++; |
| 5400 | } |
| 5401 | } |
| 5402 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5403 | i = 0; |
| 5404 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5405 | nla_for_each_nested(attr, |
| 5406 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5407 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5408 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5409 | |
| 5410 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5411 | nla_data(attr), nla_len(attr), |
| 5412 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5413 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5414 | if (ssid) { |
| 5415 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5416 | err = -EINVAL; |
| 5417 | goto out_free; |
| 5418 | } |
| 5419 | memcpy(request->match_sets[i].ssid.ssid, |
| 5420 | nla_data(ssid), nla_len(ssid)); |
| 5421 | request->match_sets[i].ssid.ssid_len = |
| 5422 | nla_len(ssid); |
| 5423 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5424 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5425 | if (rssi) |
| 5426 | request->rssi_thold = nla_get_u32(rssi); |
| 5427 | else |
| 5428 | request->rssi_thold = |
| 5429 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5430 | i++; |
| 5431 | } |
| 5432 | } |
| 5433 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5434 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5435 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5436 | memcpy((void *)request->ie, |
| 5437 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5438 | request->ie_len); |
| 5439 | } |
| 5440 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5441 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5442 | request->flags = nla_get_u32( |
| 5443 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5444 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5445 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5446 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5447 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5448 | err = -EOPNOTSUPP; |
| 5449 | goto out_free; |
| 5450 | } |
| 5451 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5452 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5453 | request->dev = dev; |
| 5454 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5455 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5456 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5457 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5458 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5459 | if (!err) { |
| 5460 | rdev->sched_scan_req = request; |
| 5461 | nl80211_send_sched_scan(rdev, dev, |
| 5462 | NL80211_CMD_START_SCHED_SCAN); |
| 5463 | goto out; |
| 5464 | } |
| 5465 | |
| 5466 | out_free: |
| 5467 | kfree(request); |
| 5468 | out: |
| 5469 | return err; |
| 5470 | } |
| 5471 | |
| 5472 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5473 | struct genl_info *info) |
| 5474 | { |
| 5475 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5476 | |
| 5477 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5478 | !rdev->ops->sched_scan_stop) |
| 5479 | return -EOPNOTSUPP; |
| 5480 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5481 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5482 | } |
| 5483 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5484 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5485 | struct genl_info *info) |
| 5486 | { |
| 5487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5488 | struct net_device *dev = info->user_ptr[1]; |
| 5489 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5490 | struct cfg80211_chan_def chandef; |
| 5491 | int err; |
| 5492 | |
| 5493 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5494 | if (err) |
| 5495 | return err; |
| 5496 | |
| 5497 | if (wdev->cac_started) |
| 5498 | return -EBUSY; |
| 5499 | |
| 5500 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5501 | if (err < 0) |
| 5502 | return err; |
| 5503 | |
| 5504 | if (err == 0) |
| 5505 | return -EINVAL; |
| 5506 | |
| 5507 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5508 | return -EINVAL; |
| 5509 | |
| 5510 | if (!rdev->ops->start_radar_detection) |
| 5511 | return -EOPNOTSUPP; |
| 5512 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5513 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5514 | chandef.chan, CHAN_MODE_SHARED, |
| 5515 | BIT(chandef.width)); |
| 5516 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5517 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5518 | |
| 5519 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5520 | if (!err) { |
| 5521 | wdev->channel = chandef.chan; |
| 5522 | wdev->cac_started = true; |
| 5523 | wdev->cac_start_time = jiffies; |
| 5524 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5525 | return err; |
| 5526 | } |
| 5527 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5528 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5529 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5530 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5531 | struct wireless_dev *wdev, |
| 5532 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5533 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5534 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5535 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5536 | void *hdr; |
| 5537 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5538 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5539 | |
| 5540 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5541 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5542 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5543 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5544 | if (!hdr) |
| 5545 | return -1; |
| 5546 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5547 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5548 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5549 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5550 | goto nla_put_failure; |
| 5551 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5552 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5553 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5554 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5555 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5556 | |
| 5557 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5558 | if (!bss) |
| 5559 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5560 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5561 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5562 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5563 | |
| 5564 | rcu_read_lock(); |
| 5565 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5566 | if (ies) { |
| 5567 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5568 | goto fail_unlock_rcu; |
| 5569 | tsf = true; |
| 5570 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5571 | ies->len, ies->data)) |
| 5572 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5573 | } |
| 5574 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5575 | if (ies) { |
| 5576 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5577 | goto fail_unlock_rcu; |
| 5578 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5579 | ies->len, ies->data)) |
| 5580 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5581 | } |
| 5582 | rcu_read_unlock(); |
| 5583 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5584 | if (res->beacon_interval && |
| 5585 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5586 | goto nla_put_failure; |
| 5587 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5588 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5589 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5590 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5591 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5592 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5593 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5594 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5595 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5596 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5597 | break; |
| 5598 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5599 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5600 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5601 | break; |
| 5602 | default: |
| 5603 | break; |
| 5604 | } |
| 5605 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5606 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5607 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5608 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5609 | if (intbss == wdev->current_bss && |
| 5610 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5611 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5612 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5613 | break; |
| 5614 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5615 | if (intbss == wdev->current_bss && |
| 5616 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5617 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5618 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5619 | break; |
| 5620 | default: |
| 5621 | break; |
| 5622 | } |
| 5623 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5624 | nla_nest_end(msg, bss); |
| 5625 | |
| 5626 | return genlmsg_end(msg, hdr); |
| 5627 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5628 | fail_unlock_rcu: |
| 5629 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5630 | nla_put_failure: |
| 5631 | genlmsg_cancel(msg, hdr); |
| 5632 | return -EMSGSIZE; |
| 5633 | } |
| 5634 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5635 | 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] | 5636 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5637 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5638 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5639 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5640 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5641 | int err; |
| 5642 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5643 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5644 | if (err) |
| 5645 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5646 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5647 | wdev_lock(wdev); |
| 5648 | spin_lock_bh(&rdev->bss_lock); |
| 5649 | cfg80211_bss_expire(rdev); |
| 5650 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5651 | cb->seq = rdev->bss_generation; |
| 5652 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5653 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5654 | if (++idx <= start) |
| 5655 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5656 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5657 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5658 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5659 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5660 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5661 | } |
| 5662 | } |
| 5663 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5664 | spin_unlock_bh(&rdev->bss_lock); |
| 5665 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5666 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5667 | cb->args[2] = idx; |
| 5668 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5669 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5670 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5671 | } |
| 5672 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5673 | 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] | 5674 | int flags, struct net_device *dev, |
| 5675 | struct survey_info *survey) |
| 5676 | { |
| 5677 | void *hdr; |
| 5678 | struct nlattr *infoattr; |
| 5679 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5680 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5681 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5682 | if (!hdr) |
| 5683 | return -ENOMEM; |
| 5684 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5685 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5686 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5687 | |
| 5688 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5689 | if (!infoattr) |
| 5690 | goto nla_put_failure; |
| 5691 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5692 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5693 | survey->channel->center_freq)) |
| 5694 | goto nla_put_failure; |
| 5695 | |
| 5696 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5697 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5698 | goto nla_put_failure; |
| 5699 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5700 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5701 | goto nla_put_failure; |
| 5702 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5703 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5704 | survey->channel_time)) |
| 5705 | goto nla_put_failure; |
| 5706 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5707 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5708 | survey->channel_time_busy)) |
| 5709 | goto nla_put_failure; |
| 5710 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5711 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5712 | survey->channel_time_ext_busy)) |
| 5713 | goto nla_put_failure; |
| 5714 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5715 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5716 | survey->channel_time_rx)) |
| 5717 | goto nla_put_failure; |
| 5718 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5719 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5720 | survey->channel_time_tx)) |
| 5721 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5722 | |
| 5723 | nla_nest_end(msg, infoattr); |
| 5724 | |
| 5725 | return genlmsg_end(msg, hdr); |
| 5726 | |
| 5727 | nla_put_failure: |
| 5728 | genlmsg_cancel(msg, hdr); |
| 5729 | return -EMSGSIZE; |
| 5730 | } |
| 5731 | |
| 5732 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5733 | struct netlink_callback *cb) |
| 5734 | { |
| 5735 | struct survey_info survey; |
| 5736 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5737 | struct wireless_dev *wdev; |
| 5738 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5739 | int res; |
| 5740 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5741 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5742 | if (res) |
| 5743 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5744 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5745 | if (!wdev->netdev) { |
| 5746 | res = -EINVAL; |
| 5747 | goto out_err; |
| 5748 | } |
| 5749 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5750 | if (!dev->ops->dump_survey) { |
| 5751 | res = -EOPNOTSUPP; |
| 5752 | goto out_err; |
| 5753 | } |
| 5754 | |
| 5755 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5756 | struct ieee80211_channel *chan; |
| 5757 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5758 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5759 | if (res == -ENOENT) |
| 5760 | break; |
| 5761 | if (res) |
| 5762 | goto out_err; |
| 5763 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5764 | /* Survey without a channel doesn't make sense */ |
| 5765 | if (!survey.channel) { |
| 5766 | res = -EINVAL; |
| 5767 | goto out; |
| 5768 | } |
| 5769 | |
| 5770 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5771 | survey.channel->center_freq); |
| 5772 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5773 | survey_idx++; |
| 5774 | continue; |
| 5775 | } |
| 5776 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5777 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5778 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5779 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5780 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5781 | goto out; |
| 5782 | survey_idx++; |
| 5783 | } |
| 5784 | |
| 5785 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5786 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5787 | res = skb->len; |
| 5788 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5789 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5790 | return res; |
| 5791 | } |
| 5792 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5793 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5794 | { |
| 5795 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5796 | NL80211_WPA_VERSION_2)); |
| 5797 | } |
| 5798 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5799 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5800 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5801 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5802 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5803 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5804 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5805 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5806 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5807 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5808 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5809 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5810 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5811 | return -EINVAL; |
| 5812 | |
| 5813 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5814 | return -EINVAL; |
| 5815 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5816 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5817 | return -EINVAL; |
| 5818 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5819 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5820 | return -EINVAL; |
| 5821 | |
| 5822 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5823 | return -EINVAL; |
| 5824 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5825 | err = nl80211_parse_key(info, &key); |
| 5826 | if (err) |
| 5827 | return err; |
| 5828 | |
| 5829 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5830 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5831 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5832 | if (!key.p.key || !key.p.key_len) |
| 5833 | return -EINVAL; |
| 5834 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5835 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5836 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5837 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5838 | return -EINVAL; |
| 5839 | if (key.idx > 4) |
| 5840 | return -EINVAL; |
| 5841 | } else { |
| 5842 | key.p.key_len = 0; |
| 5843 | key.p.key = NULL; |
| 5844 | } |
| 5845 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5846 | if (key.idx >= 0) { |
| 5847 | int i; |
| 5848 | bool ok = false; |
| 5849 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5850 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5851 | ok = true; |
| 5852 | break; |
| 5853 | } |
| 5854 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5855 | if (!ok) |
| 5856 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5857 | } |
| 5858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5859 | if (!rdev->ops->auth) |
| 5860 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5861 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5863 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5864 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5865 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5866 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5867 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5868 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5869 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5870 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5871 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5872 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5873 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5874 | |
| 5875 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5876 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5877 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5878 | } |
| 5879 | |
| 5880 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5881 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5882 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5883 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5884 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5885 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5886 | return -EINVAL; |
| 5887 | |
| 5888 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5889 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5890 | return -EINVAL; |
| 5891 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5892 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5893 | /* need to include at least Auth Transaction and Status Code */ |
| 5894 | if (sae_data_len < 4) |
| 5895 | return -EINVAL; |
| 5896 | } |
| 5897 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5898 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5899 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5900 | /* |
| 5901 | * Since we no longer track auth state, ignore |
| 5902 | * requests to only change local state. |
| 5903 | */ |
| 5904 | if (local_state_change) |
| 5905 | return 0; |
| 5906 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 5907 | wdev_lock(dev->ieee80211_ptr); |
| 5908 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5909 | ssid, ssid_len, ie, ie_len, |
| 5910 | key.p.key, key.p.key_len, key.idx, |
| 5911 | sae_data, sae_data_len); |
| 5912 | wdev_unlock(dev->ieee80211_ptr); |
| 5913 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5914 | } |
| 5915 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5916 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5917 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5918 | struct cfg80211_crypto_settings *settings, |
| 5919 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5920 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5921 | memset(settings, 0, sizeof(*settings)); |
| 5922 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5923 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5924 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5925 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5926 | u16 proto; |
| 5927 | proto = nla_get_u16( |
| 5928 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5929 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5930 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5931 | proto != ETH_P_PAE) |
| 5932 | return -EINVAL; |
| 5933 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5934 | settings->control_port_no_encrypt = true; |
| 5935 | } else |
| 5936 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5937 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5938 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5939 | void *data; |
| 5940 | int len, i; |
| 5941 | |
| 5942 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5943 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5944 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5945 | |
| 5946 | if (len % sizeof(u32)) |
| 5947 | return -EINVAL; |
| 5948 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5949 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5950 | return -EINVAL; |
| 5951 | |
| 5952 | memcpy(settings->ciphers_pairwise, data, len); |
| 5953 | |
| 5954 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5955 | if (!cfg80211_supported_cipher_suite( |
| 5956 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5957 | settings->ciphers_pairwise[i])) |
| 5958 | return -EINVAL; |
| 5959 | } |
| 5960 | |
| 5961 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5962 | settings->cipher_group = |
| 5963 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5964 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5965 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5966 | return -EINVAL; |
| 5967 | } |
| 5968 | |
| 5969 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5970 | settings->wpa_versions = |
| 5971 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5972 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5973 | return -EINVAL; |
| 5974 | } |
| 5975 | |
| 5976 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 5977 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 5978 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5979 | |
| 5980 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5981 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 5982 | settings->n_akm_suites = len / sizeof(u32); |
| 5983 | |
| 5984 | if (len % sizeof(u32)) |
| 5985 | return -EINVAL; |
| 5986 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 5987 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 5988 | return -EINVAL; |
| 5989 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5990 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5991 | } |
| 5992 | |
| 5993 | return 0; |
| 5994 | } |
| 5995 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5996 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 5997 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5998 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5999 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6000 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6001 | struct cfg80211_assoc_request req = {}; |
| 6002 | const u8 *bssid, *ssid; |
| 6003 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6004 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6005 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6006 | return -EINVAL; |
| 6007 | |
| 6008 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6009 | !info->attrs[NL80211_ATTR_SSID] || |
| 6010 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6011 | return -EINVAL; |
| 6012 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6013 | if (!rdev->ops->assoc) |
| 6014 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6015 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6016 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6017 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6018 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6019 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6020 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6021 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6022 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6023 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6024 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6025 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6026 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6027 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6028 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6029 | |
| 6030 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6031 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6032 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6033 | } |
| 6034 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6035 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6036 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6037 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6038 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6039 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6040 | else if (mfp != NL80211_MFP_NO) |
| 6041 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6042 | } |
| 6043 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6044 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6045 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6046 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6047 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6048 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6049 | |
| 6050 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6051 | memcpy(&req.ht_capa_mask, |
| 6052 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6053 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6054 | |
| 6055 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6056 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6057 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6058 | memcpy(&req.ht_capa, |
| 6059 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6060 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6061 | } |
| 6062 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6063 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6064 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6065 | |
| 6066 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6067 | memcpy(&req.vht_capa_mask, |
| 6068 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6069 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6070 | |
| 6071 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6072 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6073 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6074 | memcpy(&req.vht_capa, |
| 6075 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6076 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6077 | } |
| 6078 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6079 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6080 | if (!err) { |
| 6081 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6082 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6083 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6084 | wdev_unlock(dev->ieee80211_ptr); |
| 6085 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6086 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6087 | return err; |
| 6088 | } |
| 6089 | |
| 6090 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6091 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6093 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6094 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6095 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6096 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6097 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6098 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6099 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6100 | return -EINVAL; |
| 6101 | |
| 6102 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6103 | return -EINVAL; |
| 6104 | |
| 6105 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6106 | return -EINVAL; |
| 6107 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6108 | if (!rdev->ops->deauth) |
| 6109 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6110 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6111 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6112 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6113 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6114 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6115 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6116 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6117 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6118 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6119 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6120 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6121 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6122 | |
| 6123 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6124 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6125 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6126 | } |
| 6127 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6128 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6129 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6130 | wdev_lock(dev->ieee80211_ptr); |
| 6131 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6132 | local_state_change); |
| 6133 | wdev_unlock(dev->ieee80211_ptr); |
| 6134 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6135 | } |
| 6136 | |
| 6137 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6138 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6139 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6140 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6141 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6142 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6143 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6144 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6145 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6146 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6147 | return -EINVAL; |
| 6148 | |
| 6149 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6150 | return -EINVAL; |
| 6151 | |
| 6152 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6153 | return -EINVAL; |
| 6154 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6155 | if (!rdev->ops->disassoc) |
| 6156 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6157 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6158 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6159 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6160 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6161 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6162 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6163 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6164 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6165 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6166 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6167 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6168 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6169 | |
| 6170 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6171 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6172 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6173 | } |
| 6174 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6175 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6176 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6177 | wdev_lock(dev->ieee80211_ptr); |
| 6178 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6179 | local_state_change); |
| 6180 | wdev_unlock(dev->ieee80211_ptr); |
| 6181 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6182 | } |
| 6183 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6184 | static bool |
| 6185 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6186 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6187 | int rateval) |
| 6188 | { |
| 6189 | struct wiphy *wiphy = &rdev->wiphy; |
| 6190 | bool found = false; |
| 6191 | int band, i; |
| 6192 | |
| 6193 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6194 | struct ieee80211_supported_band *sband; |
| 6195 | |
| 6196 | sband = wiphy->bands[band]; |
| 6197 | if (!sband) |
| 6198 | continue; |
| 6199 | |
| 6200 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6201 | if (sband->bitrates[i].bitrate == rateval) { |
| 6202 | mcast_rate[band] = i + 1; |
| 6203 | found = true; |
| 6204 | break; |
| 6205 | } |
| 6206 | } |
| 6207 | } |
| 6208 | |
| 6209 | return found; |
| 6210 | } |
| 6211 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6212 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6213 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6215 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6216 | struct cfg80211_ibss_params ibss; |
| 6217 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6218 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6219 | int err; |
| 6220 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6221 | memset(&ibss, 0, sizeof(ibss)); |
| 6222 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6223 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6224 | return -EINVAL; |
| 6225 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6226 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6227 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6228 | return -EINVAL; |
| 6229 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6230 | ibss.beacon_interval = 100; |
| 6231 | |
| 6232 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6233 | ibss.beacon_interval = |
| 6234 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6235 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6236 | return -EINVAL; |
| 6237 | } |
| 6238 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6239 | if (!rdev->ops->join_ibss) |
| 6240 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6241 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6242 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6243 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6244 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6245 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6246 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6247 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6248 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6249 | |
| 6250 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6251 | return -EINVAL; |
| 6252 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6253 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6254 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6255 | |
| 6256 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6257 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6258 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6259 | } |
| 6260 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6261 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6262 | if (err) |
| 6263 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6264 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6265 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6266 | return -EINVAL; |
| 6267 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6268 | if (ibss.chandef.width > NL80211_CHAN_WIDTH_40) |
| 6269 | return -EINVAL; |
| 6270 | if (ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 6271 | !(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
Simon Wunderlich | c04d615 | 2012-11-29 18:37:22 +0100 | [diff] [blame] | 6272 | return -EINVAL; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6273 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6274 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6275 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6276 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6277 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6278 | u8 *rates = |
| 6279 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6280 | int n_rates = |
| 6281 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6282 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6283 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6284 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6285 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6286 | &ibss.basic_rates); |
| 6287 | if (err) |
| 6288 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6289 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6290 | |
| 6291 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6292 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6293 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6294 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6295 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6296 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6297 | bool no_ht = false; |
| 6298 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6299 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6300 | info->attrs[NL80211_ATTR_KEYS], |
| 6301 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6302 | if (IS_ERR(connkeys)) |
| 6303 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6304 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6305 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6306 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6307 | kfree(connkeys); |
| 6308 | return -EINVAL; |
| 6309 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6310 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6311 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6312 | ibss.control_port = |
| 6313 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6314 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6315 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6316 | if (err) |
| 6317 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6318 | return err; |
| 6319 | } |
| 6320 | |
| 6321 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6322 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6324 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6326 | if (!rdev->ops->leave_ibss) |
| 6327 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6328 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6329 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6330 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6332 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6333 | } |
| 6334 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6335 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6336 | { |
| 6337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6338 | struct net_device *dev = info->user_ptr[1]; |
| 6339 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6340 | u32 nla_rate; |
| 6341 | int err; |
| 6342 | |
| 6343 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6344 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6345 | return -EOPNOTSUPP; |
| 6346 | |
| 6347 | if (!rdev->ops->set_mcast_rate) |
| 6348 | return -EOPNOTSUPP; |
| 6349 | |
| 6350 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6351 | |
| 6352 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6353 | return -EINVAL; |
| 6354 | |
| 6355 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6356 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6357 | return -EINVAL; |
| 6358 | |
| 6359 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6360 | |
| 6361 | return err; |
| 6362 | } |
| 6363 | |
| 6364 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6365 | #ifdef CONFIG_NL80211_TESTMODE |
| 6366 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6367 | .name = "testmode", |
| 6368 | }; |
| 6369 | |
| 6370 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6371 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6372 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6373 | int err; |
| 6374 | |
| 6375 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6376 | return -EINVAL; |
| 6377 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6378 | err = -EOPNOTSUPP; |
| 6379 | if (rdev->ops->testmode_cmd) { |
| 6380 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6381 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6382 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6383 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6384 | rdev->testmode_info = NULL; |
| 6385 | } |
| 6386 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6387 | return err; |
| 6388 | } |
| 6389 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6390 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6391 | struct netlink_callback *cb) |
| 6392 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6393 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6394 | int err; |
| 6395 | long phy_idx; |
| 6396 | void *data = NULL; |
| 6397 | int data_len = 0; |
| 6398 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6399 | rtnl_lock(); |
| 6400 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6401 | if (cb->args[0]) { |
| 6402 | /* |
| 6403 | * 0 is a valid index, but not valid for args[0], |
| 6404 | * so we need to offset by 1. |
| 6405 | */ |
| 6406 | phy_idx = cb->args[0] - 1; |
| 6407 | } else { |
| 6408 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6409 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6410 | nl80211_policy); |
| 6411 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6412 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6413 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6414 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6415 | nl80211_fam.attrbuf); |
| 6416 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6417 | err = PTR_ERR(rdev); |
| 6418 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6419 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6420 | phy_idx = rdev->wiphy_idx; |
| 6421 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6422 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6423 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6424 | cb->args[1] = |
| 6425 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6426 | } |
| 6427 | |
| 6428 | if (cb->args[1]) { |
| 6429 | data = nla_data((void *)cb->args[1]); |
| 6430 | data_len = nla_len((void *)cb->args[1]); |
| 6431 | } |
| 6432 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6433 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6434 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6435 | err = -ENOENT; |
| 6436 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6437 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6438 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6439 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6440 | err = -EOPNOTSUPP; |
| 6441 | goto out_err; |
| 6442 | } |
| 6443 | |
| 6444 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6445 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6446 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6447 | NL80211_CMD_TESTMODE); |
| 6448 | struct nlattr *tmdata; |
| 6449 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6450 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6451 | genlmsg_cancel(skb, hdr); |
| 6452 | break; |
| 6453 | } |
| 6454 | |
| 6455 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6456 | if (!tmdata) { |
| 6457 | genlmsg_cancel(skb, hdr); |
| 6458 | break; |
| 6459 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6460 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6461 | nla_nest_end(skb, tmdata); |
| 6462 | |
| 6463 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6464 | genlmsg_cancel(skb, hdr); |
| 6465 | break; |
| 6466 | } else if (err) { |
| 6467 | genlmsg_cancel(skb, hdr); |
| 6468 | goto out_err; |
| 6469 | } |
| 6470 | |
| 6471 | genlmsg_end(skb, hdr); |
| 6472 | } |
| 6473 | |
| 6474 | err = skb->len; |
| 6475 | /* see above */ |
| 6476 | cb->args[0] = phy_idx + 1; |
| 6477 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6478 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6479 | return err; |
| 6480 | } |
| 6481 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6482 | static struct sk_buff * |
| 6483 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6484 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6485 | { |
| 6486 | struct sk_buff *skb; |
| 6487 | void *hdr; |
| 6488 | struct nlattr *data; |
| 6489 | |
| 6490 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6491 | if (!skb) |
| 6492 | return NULL; |
| 6493 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6494 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6495 | if (!hdr) { |
| 6496 | kfree_skb(skb); |
| 6497 | return NULL; |
| 6498 | } |
| 6499 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6500 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6501 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6502 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6503 | |
| 6504 | ((void **)skb->cb)[0] = rdev; |
| 6505 | ((void **)skb->cb)[1] = hdr; |
| 6506 | ((void **)skb->cb)[2] = data; |
| 6507 | |
| 6508 | return skb; |
| 6509 | |
| 6510 | nla_put_failure: |
| 6511 | kfree_skb(skb); |
| 6512 | return NULL; |
| 6513 | } |
| 6514 | |
| 6515 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6516 | int approxlen) |
| 6517 | { |
| 6518 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6519 | |
| 6520 | if (WARN_ON(!rdev->testmode_info)) |
| 6521 | return NULL; |
| 6522 | |
| 6523 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6524 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6525 | rdev->testmode_info->snd_seq, |
| 6526 | GFP_KERNEL); |
| 6527 | } |
| 6528 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6529 | |
| 6530 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6531 | { |
| 6532 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6533 | void *hdr = ((void **)skb->cb)[1]; |
| 6534 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6535 | |
| 6536 | if (WARN_ON(!rdev->testmode_info)) { |
| 6537 | kfree_skb(skb); |
| 6538 | return -EINVAL; |
| 6539 | } |
| 6540 | |
| 6541 | nla_nest_end(skb, data); |
| 6542 | genlmsg_end(skb, hdr); |
| 6543 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6544 | } |
| 6545 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6546 | |
| 6547 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6548 | int approxlen, gfp_t gfp) |
| 6549 | { |
| 6550 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6551 | |
| 6552 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6553 | } |
| 6554 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6555 | |
| 6556 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6557 | { |
| 6558 | void *hdr = ((void **)skb->cb)[1]; |
| 6559 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6560 | |
| 6561 | nla_nest_end(skb, data); |
| 6562 | genlmsg_end(skb, hdr); |
| 6563 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6564 | } |
| 6565 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6566 | #endif |
| 6567 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6568 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6569 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6571 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6572 | struct cfg80211_connect_params connect; |
| 6573 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6574 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6575 | int err; |
| 6576 | |
| 6577 | memset(&connect, 0, sizeof(connect)); |
| 6578 | |
| 6579 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6580 | return -EINVAL; |
| 6581 | |
| 6582 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6583 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6584 | return -EINVAL; |
| 6585 | |
| 6586 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6587 | connect.auth_type = |
| 6588 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6589 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6590 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6591 | return -EINVAL; |
| 6592 | } else |
| 6593 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6594 | |
| 6595 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6596 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6597 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6598 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6599 | if (err) |
| 6600 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6601 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6602 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6603 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6604 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6605 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6606 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6607 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6608 | connect.bg_scan_period = -1; |
| 6609 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6610 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6611 | connect.bg_scan_period = |
| 6612 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6613 | } |
| 6614 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6615 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6616 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6617 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6618 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6619 | |
| 6620 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6621 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6622 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6623 | } |
| 6624 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6625 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6626 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6627 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6628 | connect.mfp != NL80211_MFP_NO) |
| 6629 | return -EINVAL; |
| 6630 | } else { |
| 6631 | connect.mfp = NL80211_MFP_NO; |
| 6632 | } |
| 6633 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6634 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6635 | connect.channel = |
| 6636 | ieee80211_get_channel(wiphy, |
| 6637 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6638 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6639 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6640 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6641 | } |
| 6642 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6643 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6644 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6645 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6646 | if (IS_ERR(connkeys)) |
| 6647 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6648 | } |
| 6649 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6650 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6651 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6652 | |
| 6653 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6654 | memcpy(&connect.ht_capa_mask, |
| 6655 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6656 | sizeof(connect.ht_capa_mask)); |
| 6657 | |
| 6658 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6659 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6660 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6661 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6662 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6663 | memcpy(&connect.ht_capa, |
| 6664 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6665 | sizeof(connect.ht_capa)); |
| 6666 | } |
| 6667 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6668 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6669 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6670 | |
| 6671 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6672 | memcpy(&connect.vht_capa_mask, |
| 6673 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6674 | sizeof(connect.vht_capa_mask)); |
| 6675 | |
| 6676 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6677 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6678 | kfree(connkeys); |
| 6679 | return -EINVAL; |
| 6680 | } |
| 6681 | memcpy(&connect.vht_capa, |
| 6682 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6683 | sizeof(connect.vht_capa)); |
| 6684 | } |
| 6685 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6686 | wdev_lock(dev->ieee80211_ptr); |
| 6687 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6688 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6689 | if (err) |
| 6690 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6691 | return err; |
| 6692 | } |
| 6693 | |
| 6694 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6695 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6697 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6698 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6699 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6700 | |
| 6701 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6702 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6703 | else |
| 6704 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6705 | |
| 6706 | if (reason == 0) |
| 6707 | return -EINVAL; |
| 6708 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6709 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6710 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6711 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6712 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6713 | wdev_lock(dev->ieee80211_ptr); |
| 6714 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 6715 | wdev_unlock(dev->ieee80211_ptr); |
| 6716 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6717 | } |
| 6718 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6719 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6720 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6721 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6722 | struct net *net; |
| 6723 | int err; |
| 6724 | u32 pid; |
| 6725 | |
| 6726 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6727 | return -EINVAL; |
| 6728 | |
| 6729 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6730 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6731 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6732 | if (IS_ERR(net)) |
| 6733 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6734 | |
| 6735 | err = 0; |
| 6736 | |
| 6737 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6738 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6739 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6740 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6741 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6742 | return err; |
| 6743 | } |
| 6744 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6745 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6746 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6747 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6748 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6749 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6750 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6751 | struct cfg80211_pmksa pmksa; |
| 6752 | |
| 6753 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6754 | |
| 6755 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6756 | return -EINVAL; |
| 6757 | |
| 6758 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6759 | return -EINVAL; |
| 6760 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6761 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6762 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6763 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6764 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6765 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6766 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6767 | |
| 6768 | switch (info->genlhdr->cmd) { |
| 6769 | case NL80211_CMD_SET_PMKSA: |
| 6770 | rdev_ops = rdev->ops->set_pmksa; |
| 6771 | break; |
| 6772 | case NL80211_CMD_DEL_PMKSA: |
| 6773 | rdev_ops = rdev->ops->del_pmksa; |
| 6774 | break; |
| 6775 | default: |
| 6776 | WARN_ON(1); |
| 6777 | break; |
| 6778 | } |
| 6779 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6780 | if (!rdev_ops) |
| 6781 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6782 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6783 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6787 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6789 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6790 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6791 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6792 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6793 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6794 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6795 | if (!rdev->ops->flush_pmksa) |
| 6796 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6797 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6798 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6799 | } |
| 6800 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6801 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6802 | { |
| 6803 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6804 | struct net_device *dev = info->user_ptr[1]; |
| 6805 | u8 action_code, dialog_token; |
| 6806 | u16 status_code; |
| 6807 | u8 *peer; |
| 6808 | |
| 6809 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6810 | !rdev->ops->tdls_mgmt) |
| 6811 | return -EOPNOTSUPP; |
| 6812 | |
| 6813 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6814 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6815 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6816 | !info->attrs[NL80211_ATTR_IE] || |
| 6817 | !info->attrs[NL80211_ATTR_MAC]) |
| 6818 | return -EINVAL; |
| 6819 | |
| 6820 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6821 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6822 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6823 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6824 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6825 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6826 | dialog_token, status_code, |
| 6827 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6828 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6829 | } |
| 6830 | |
| 6831 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6832 | { |
| 6833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6834 | struct net_device *dev = info->user_ptr[1]; |
| 6835 | enum nl80211_tdls_operation operation; |
| 6836 | u8 *peer; |
| 6837 | |
| 6838 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6839 | !rdev->ops->tdls_oper) |
| 6840 | return -EOPNOTSUPP; |
| 6841 | |
| 6842 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6843 | !info->attrs[NL80211_ATTR_MAC]) |
| 6844 | return -EINVAL; |
| 6845 | |
| 6846 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6847 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6848 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6849 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6850 | } |
| 6851 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6852 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6853 | struct genl_info *info) |
| 6854 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6856 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6857 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6858 | struct sk_buff *msg; |
| 6859 | void *hdr; |
| 6860 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6861 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6862 | int err; |
| 6863 | |
| 6864 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6865 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6866 | return -EINVAL; |
| 6867 | |
| 6868 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6869 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6870 | if (!rdev->ops->remain_on_channel || |
| 6871 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6872 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6873 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6874 | /* |
| 6875 | * We should be on that channel for at least a minimum amount of |
| 6876 | * time (10ms) but no longer than the driver supports. |
| 6877 | */ |
| 6878 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6879 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6880 | return -EINVAL; |
| 6881 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6882 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6883 | if (err) |
| 6884 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6885 | |
| 6886 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6887 | if (!msg) |
| 6888 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6889 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6890 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6891 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6892 | |
| 6893 | if (IS_ERR(hdr)) { |
| 6894 | err = PTR_ERR(hdr); |
| 6895 | goto free_msg; |
| 6896 | } |
| 6897 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6898 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6899 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6900 | |
| 6901 | if (err) |
| 6902 | goto free_msg; |
| 6903 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6904 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6905 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6906 | |
| 6907 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6908 | |
| 6909 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6910 | |
| 6911 | nla_put_failure: |
| 6912 | err = -ENOBUFS; |
| 6913 | free_msg: |
| 6914 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6915 | return err; |
| 6916 | } |
| 6917 | |
| 6918 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6919 | struct genl_info *info) |
| 6920 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6921 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6922 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6923 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6924 | |
| 6925 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6926 | return -EINVAL; |
| 6927 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6928 | if (!rdev->ops->cancel_remain_on_channel) |
| 6929 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6930 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6931 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6932 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6933 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6934 | } |
| 6935 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6936 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6937 | u8 *rates, u8 rates_len) |
| 6938 | { |
| 6939 | u8 i; |
| 6940 | u32 mask = 0; |
| 6941 | |
| 6942 | for (i = 0; i < rates_len; i++) { |
| 6943 | int rate = (rates[i] & 0x7f) * 5; |
| 6944 | int ridx; |
| 6945 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6946 | struct ieee80211_rate *srate = |
| 6947 | &sband->bitrates[ridx]; |
| 6948 | if (rate == srate->bitrate) { |
| 6949 | mask |= 1 << ridx; |
| 6950 | break; |
| 6951 | } |
| 6952 | } |
| 6953 | if (ridx == sband->n_bitrates) |
| 6954 | return 0; /* rate not found */ |
| 6955 | } |
| 6956 | |
| 6957 | return mask; |
| 6958 | } |
| 6959 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6960 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6961 | u8 *rates, u8 rates_len, |
| 6962 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6963 | { |
| 6964 | u8 i; |
| 6965 | |
| 6966 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6967 | |
| 6968 | for (i = 0; i < rates_len; i++) { |
| 6969 | int ridx, rbit; |
| 6970 | |
| 6971 | ridx = rates[i] / 8; |
| 6972 | rbit = BIT(rates[i] % 8); |
| 6973 | |
| 6974 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 6975 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6976 | return false; |
| 6977 | |
| 6978 | /* check availability */ |
| 6979 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 6980 | mcs[ridx] |= rbit; |
| 6981 | else |
| 6982 | return false; |
| 6983 | } |
| 6984 | |
| 6985 | return true; |
| 6986 | } |
| 6987 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 6988 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6989 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 6990 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6991 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 6992 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6993 | }; |
| 6994 | |
| 6995 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 6996 | struct genl_info *info) |
| 6997 | { |
| 6998 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6999 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7000 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7001 | int rem, i; |
| 7002 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7003 | struct nlattr *tx_rates; |
| 7004 | struct ieee80211_supported_band *sband; |
| 7005 | |
| 7006 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7007 | return -EINVAL; |
| 7008 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7009 | if (!rdev->ops->set_bitrate_mask) |
| 7010 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7011 | |
| 7012 | memset(&mask, 0, sizeof(mask)); |
| 7013 | /* Default to all rates enabled */ |
| 7014 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7015 | sband = rdev->wiphy.bands[i]; |
| 7016 | mask.control[i].legacy = |
| 7017 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7018 | if (sband) |
| 7019 | memcpy(mask.control[i].mcs, |
| 7020 | sband->ht_cap.mcs.rx_mask, |
| 7021 | sizeof(mask.control[i].mcs)); |
| 7022 | else |
| 7023 | memset(mask.control[i].mcs, 0, |
| 7024 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7025 | } |
| 7026 | |
| 7027 | /* |
| 7028 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7029 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7030 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7031 | 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] | 7032 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7033 | { |
| 7034 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7035 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7036 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7037 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7038 | if (sband == NULL) |
| 7039 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7040 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7041 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7042 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7043 | mask.control[band].legacy = rateset_to_mask( |
| 7044 | sband, |
| 7045 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7046 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7047 | if ((mask.control[band].legacy == 0) && |
| 7048 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7049 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7050 | } |
| 7051 | if (tb[NL80211_TXRATE_MCS]) { |
| 7052 | if (!ht_rateset_to_mask( |
| 7053 | sband, |
| 7054 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7055 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7056 | mask.control[band].mcs)) |
| 7057 | return -EINVAL; |
| 7058 | } |
| 7059 | |
| 7060 | if (mask.control[band].legacy == 0) { |
| 7061 | /* don't allow empty legacy rates if HT |
| 7062 | * is not even supported. */ |
| 7063 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7064 | return -EINVAL; |
| 7065 | |
| 7066 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7067 | if (mask.control[band].mcs[i]) |
| 7068 | break; |
| 7069 | |
| 7070 | /* legacy and mcs rates may not be both empty */ |
| 7071 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7072 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7073 | } |
| 7074 | } |
| 7075 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7076 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7077 | } |
| 7078 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7079 | 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] | 7080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7082 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7083 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7084 | |
| 7085 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7086 | return -EINVAL; |
| 7087 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7088 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7089 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7090 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7091 | switch (wdev->iftype) { |
| 7092 | case NL80211_IFTYPE_STATION: |
| 7093 | case NL80211_IFTYPE_ADHOC: |
| 7094 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7095 | case NL80211_IFTYPE_AP: |
| 7096 | case NL80211_IFTYPE_AP_VLAN: |
| 7097 | case NL80211_IFTYPE_MESH_POINT: |
| 7098 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7099 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7100 | break; |
| 7101 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7102 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7103 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7104 | |
| 7105 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7106 | if (!rdev->ops->mgmt_tx) |
| 7107 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7108 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7109 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7110 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7111 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7112 | } |
| 7113 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7114 | 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] | 7115 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7117 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7118 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7119 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7120 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7121 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7122 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7123 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7124 | bool offchan, no_cck, dont_wait_for_ack; |
| 7125 | |
| 7126 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7127 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7128 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7129 | return -EINVAL; |
| 7130 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7131 | if (!rdev->ops->mgmt_tx) |
| 7132 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7133 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7134 | switch (wdev->iftype) { |
| 7135 | case NL80211_IFTYPE_STATION: |
| 7136 | case NL80211_IFTYPE_ADHOC: |
| 7137 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7138 | case NL80211_IFTYPE_AP: |
| 7139 | case NL80211_IFTYPE_AP_VLAN: |
| 7140 | case NL80211_IFTYPE_MESH_POINT: |
| 7141 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7142 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7143 | break; |
| 7144 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7145 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7146 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7147 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7148 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7149 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7150 | return -EINVAL; |
| 7151 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7152 | |
| 7153 | /* |
| 7154 | * We should wait on the channel for at least a minimum amount |
| 7155 | * of time (10ms) but no longer than the driver supports. |
| 7156 | */ |
| 7157 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7158 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7159 | return -EINVAL; |
| 7160 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7161 | } |
| 7162 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7163 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7164 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7165 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7166 | return -EINVAL; |
| 7167 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7168 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7169 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7170 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7171 | if (err) |
| 7172 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7173 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7174 | if (!dont_wait_for_ack) { |
| 7175 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7176 | if (!msg) |
| 7177 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7178 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7179 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7180 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7181 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7182 | if (IS_ERR(hdr)) { |
| 7183 | err = PTR_ERR(hdr); |
| 7184 | goto free_msg; |
| 7185 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7186 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7187 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7188 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7189 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7190 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7191 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7192 | if (err) |
| 7193 | goto free_msg; |
| 7194 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7195 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7196 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7197 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7198 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7199 | genlmsg_end(msg, hdr); |
| 7200 | return genlmsg_reply(msg, info); |
| 7201 | } |
| 7202 | |
| 7203 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7204 | |
| 7205 | nla_put_failure: |
| 7206 | err = -ENOBUFS; |
| 7207 | free_msg: |
| 7208 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7209 | return err; |
| 7210 | } |
| 7211 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7212 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7213 | { |
| 7214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7215 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7216 | u64 cookie; |
| 7217 | |
| 7218 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7219 | return -EINVAL; |
| 7220 | |
| 7221 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7222 | return -EOPNOTSUPP; |
| 7223 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7224 | switch (wdev->iftype) { |
| 7225 | case NL80211_IFTYPE_STATION: |
| 7226 | case NL80211_IFTYPE_ADHOC: |
| 7227 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7228 | case NL80211_IFTYPE_AP: |
| 7229 | case NL80211_IFTYPE_AP_VLAN: |
| 7230 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7231 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7232 | break; |
| 7233 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7234 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7235 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7236 | |
| 7237 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7238 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7239 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7240 | } |
| 7241 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7242 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7243 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7245 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7246 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7247 | u8 ps_state; |
| 7248 | bool state; |
| 7249 | int err; |
| 7250 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7251 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7252 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7253 | |
| 7254 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7255 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7256 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7257 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7258 | |
| 7259 | wdev = dev->ieee80211_ptr; |
| 7260 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7261 | if (!rdev->ops->set_power_mgmt) |
| 7262 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7263 | |
| 7264 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7265 | |
| 7266 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7267 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7268 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7269 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7270 | if (!err) |
| 7271 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7272 | return err; |
| 7273 | } |
| 7274 | |
| 7275 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7276 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7277 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7278 | enum nl80211_ps_state ps_state; |
| 7279 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7280 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7281 | struct sk_buff *msg; |
| 7282 | void *hdr; |
| 7283 | int err; |
| 7284 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7285 | wdev = dev->ieee80211_ptr; |
| 7286 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7287 | if (!rdev->ops->set_power_mgmt) |
| 7288 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7289 | |
| 7290 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7291 | if (!msg) |
| 7292 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7293 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7294 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7295 | NL80211_CMD_GET_POWER_SAVE); |
| 7296 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7297 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7298 | goto free_msg; |
| 7299 | } |
| 7300 | |
| 7301 | if (wdev->ps) |
| 7302 | ps_state = NL80211_PS_ENABLED; |
| 7303 | else |
| 7304 | ps_state = NL80211_PS_DISABLED; |
| 7305 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7306 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7307 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7308 | |
| 7309 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7310 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7311 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7312 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7313 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7314 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7315 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7316 | return err; |
| 7317 | } |
| 7318 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7319 | static struct nla_policy |
| 7320 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7321 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7322 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7323 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7324 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7325 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7326 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7327 | }; |
| 7328 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7329 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7330 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7331 | { |
| 7332 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7333 | struct wireless_dev *wdev; |
| 7334 | struct net_device *dev = info->user_ptr[1]; |
| 7335 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7336 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7337 | return -EINVAL; |
| 7338 | |
| 7339 | wdev = dev->ieee80211_ptr; |
| 7340 | |
| 7341 | if (!rdev->ops->set_cqm_txe_config) |
| 7342 | return -EOPNOTSUPP; |
| 7343 | |
| 7344 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7345 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7346 | return -EOPNOTSUPP; |
| 7347 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7348 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7349 | } |
| 7350 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7351 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7352 | s32 threshold, u32 hysteresis) |
| 7353 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7354 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7355 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7356 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7357 | |
| 7358 | if (threshold > 0) |
| 7359 | return -EINVAL; |
| 7360 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7361 | wdev = dev->ieee80211_ptr; |
| 7362 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7363 | if (!rdev->ops->set_cqm_rssi_config) |
| 7364 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7365 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7366 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7367 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7368 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7369 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7370 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7371 | } |
| 7372 | |
| 7373 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7374 | { |
| 7375 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7376 | struct nlattr *cqm; |
| 7377 | int err; |
| 7378 | |
| 7379 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7380 | if (!cqm) { |
| 7381 | err = -EINVAL; |
| 7382 | goto out; |
| 7383 | } |
| 7384 | |
| 7385 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7386 | nl80211_attr_cqm_policy); |
| 7387 | if (err) |
| 7388 | goto out; |
| 7389 | |
| 7390 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7391 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7392 | s32 threshold; |
| 7393 | u32 hysteresis; |
| 7394 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7395 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7396 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7397 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7398 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7399 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7400 | u32 rate, pkts, intvl; |
| 7401 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7402 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7403 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7404 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7405 | } else |
| 7406 | err = -EINVAL; |
| 7407 | |
| 7408 | out: |
| 7409 | return err; |
| 7410 | } |
| 7411 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7412 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7413 | { |
| 7414 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7415 | struct net_device *dev = info->user_ptr[1]; |
| 7416 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7417 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7418 | int err; |
| 7419 | |
| 7420 | /* start with default */ |
| 7421 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7422 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7423 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7424 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7425 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7426 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7427 | if (err) |
| 7428 | return err; |
| 7429 | } |
| 7430 | |
| 7431 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7432 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7433 | return -EINVAL; |
| 7434 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7435 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7436 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7437 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7438 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7439 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7440 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7441 | return -EINVAL; |
| 7442 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7443 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7444 | setup.beacon_interval = |
| 7445 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7446 | if (setup.beacon_interval < 10 || |
| 7447 | setup.beacon_interval > 10000) |
| 7448 | return -EINVAL; |
| 7449 | } |
| 7450 | |
| 7451 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7452 | setup.dtim_period = |
| 7453 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7454 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7455 | return -EINVAL; |
| 7456 | } |
| 7457 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7458 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7459 | /* parse additional setup parameters if given */ |
| 7460 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7461 | if (err) |
| 7462 | return err; |
| 7463 | } |
| 7464 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7465 | if (setup.user_mpm) |
| 7466 | cfg.auto_open_plinks = false; |
| 7467 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7468 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7469 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7470 | if (err) |
| 7471 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7472 | } else { |
| 7473 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7474 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7475 | } |
| 7476 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7477 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7478 | } |
| 7479 | |
| 7480 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7481 | { |
| 7482 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7483 | struct net_device *dev = info->user_ptr[1]; |
| 7484 | |
| 7485 | return cfg80211_leave_mesh(rdev, dev); |
| 7486 | } |
| 7487 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7488 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7489 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7490 | struct cfg80211_registered_device *rdev) |
| 7491 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7492 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7493 | struct nlattr *nl_pats, *nl_pat; |
| 7494 | int i, pat_len; |
| 7495 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7496 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7497 | return 0; |
| 7498 | |
| 7499 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7500 | if (!nl_pats) |
| 7501 | return -ENOBUFS; |
| 7502 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7503 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7504 | nl_pat = nla_nest_start(msg, i + 1); |
| 7505 | if (!nl_pat) |
| 7506 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7507 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7508 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7509 | DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7510 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7511 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7512 | pat_len, wowlan->patterns[i].pattern) || |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7513 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7514 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7515 | return -ENOBUFS; |
| 7516 | nla_nest_end(msg, nl_pat); |
| 7517 | } |
| 7518 | nla_nest_end(msg, nl_pats); |
| 7519 | |
| 7520 | return 0; |
| 7521 | } |
| 7522 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7523 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7524 | struct cfg80211_wowlan_tcp *tcp) |
| 7525 | { |
| 7526 | struct nlattr *nl_tcp; |
| 7527 | |
| 7528 | if (!tcp) |
| 7529 | return 0; |
| 7530 | |
| 7531 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7532 | if (!nl_tcp) |
| 7533 | return -ENOBUFS; |
| 7534 | |
| 7535 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7536 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7537 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7538 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7539 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7540 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7541 | tcp->payload_len, tcp->payload) || |
| 7542 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7543 | tcp->data_interval) || |
| 7544 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7545 | tcp->wake_len, tcp->wake_data) || |
| 7546 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7547 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7548 | return -ENOBUFS; |
| 7549 | |
| 7550 | if (tcp->payload_seq.len && |
| 7551 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7552 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7553 | return -ENOBUFS; |
| 7554 | |
| 7555 | if (tcp->payload_tok.len && |
| 7556 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7557 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7558 | &tcp->payload_tok)) |
| 7559 | return -ENOBUFS; |
| 7560 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7561 | nla_nest_end(msg, nl_tcp); |
| 7562 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7563 | return 0; |
| 7564 | } |
| 7565 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7566 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7567 | { |
| 7568 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7569 | struct sk_buff *msg; |
| 7570 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7571 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7572 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7573 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7574 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7575 | return -EOPNOTSUPP; |
| 7576 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7577 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7578 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7579 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7580 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7581 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7582 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7583 | } |
| 7584 | |
| 7585 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7586 | if (!msg) |
| 7587 | return -ENOMEM; |
| 7588 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7589 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7590 | NL80211_CMD_GET_WOWLAN); |
| 7591 | if (!hdr) |
| 7592 | goto nla_put_failure; |
| 7593 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7594 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7595 | struct nlattr *nl_wowlan; |
| 7596 | |
| 7597 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7598 | if (!nl_wowlan) |
| 7599 | goto nla_put_failure; |
| 7600 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7601 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7602 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7603 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7604 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7605 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7606 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7607 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7608 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7609 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7610 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7611 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7612 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7613 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7614 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7615 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7616 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7617 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7618 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7619 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7620 | if (nl80211_send_wowlan_tcp(msg, |
| 7621 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7622 | goto nla_put_failure; |
| 7623 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7624 | nla_nest_end(msg, nl_wowlan); |
| 7625 | } |
| 7626 | |
| 7627 | genlmsg_end(msg, hdr); |
| 7628 | return genlmsg_reply(msg, info); |
| 7629 | |
| 7630 | nla_put_failure: |
| 7631 | nlmsg_free(msg); |
| 7632 | return -ENOBUFS; |
| 7633 | } |
| 7634 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7635 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7636 | struct nlattr *attr, |
| 7637 | struct cfg80211_wowlan *trig) |
| 7638 | { |
| 7639 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7640 | struct cfg80211_wowlan_tcp *cfg; |
| 7641 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7642 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7643 | u32 size; |
| 7644 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7645 | int err, port; |
| 7646 | |
| 7647 | if (!rdev->wiphy.wowlan.tcp) |
| 7648 | return -EINVAL; |
| 7649 | |
| 7650 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7651 | nla_data(attr), nla_len(attr), |
| 7652 | nl80211_wowlan_tcp_policy); |
| 7653 | if (err) |
| 7654 | return err; |
| 7655 | |
| 7656 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7657 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7658 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7659 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7660 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7661 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7662 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7663 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7664 | return -EINVAL; |
| 7665 | |
| 7666 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
| 7667 | if (data_size > rdev->wiphy.wowlan.tcp->data_payload_max) |
| 7668 | return -EINVAL; |
| 7669 | |
| 7670 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7671 | rdev->wiphy.wowlan.tcp->data_interval_max || |
| 7672 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7673 | return -EINVAL; |
| 7674 | |
| 7675 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
| 7676 | if (wake_size > rdev->wiphy.wowlan.tcp->wake_payload_max) |
| 7677 | return -EINVAL; |
| 7678 | |
| 7679 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7680 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7681 | return -EINVAL; |
| 7682 | |
| 7683 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7684 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7685 | |
| 7686 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7687 | tokens_size = tokln - sizeof(*tok); |
| 7688 | |
| 7689 | if (!tok->len || tokens_size % tok->len) |
| 7690 | return -EINVAL; |
| 7691 | if (!rdev->wiphy.wowlan.tcp->tok) |
| 7692 | return -EINVAL; |
| 7693 | if (tok->len > rdev->wiphy.wowlan.tcp->tok->max_len) |
| 7694 | return -EINVAL; |
| 7695 | if (tok->len < rdev->wiphy.wowlan.tcp->tok->min_len) |
| 7696 | return -EINVAL; |
| 7697 | if (tokens_size > rdev->wiphy.wowlan.tcp->tok->bufsize) |
| 7698 | return -EINVAL; |
| 7699 | if (tok->offset + tok->len > data_size) |
| 7700 | return -EINVAL; |
| 7701 | } |
| 7702 | |
| 7703 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7704 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
| 7705 | if (!rdev->wiphy.wowlan.tcp->seq) |
| 7706 | return -EINVAL; |
| 7707 | if (seq->len == 0 || seq->len > 4) |
| 7708 | return -EINVAL; |
| 7709 | if (seq->len + seq->offset > data_size) |
| 7710 | return -EINVAL; |
| 7711 | } |
| 7712 | |
| 7713 | size = sizeof(*cfg); |
| 7714 | size += data_size; |
| 7715 | size += wake_size + wake_mask_size; |
| 7716 | size += tokens_size; |
| 7717 | |
| 7718 | cfg = kzalloc(size, GFP_KERNEL); |
| 7719 | if (!cfg) |
| 7720 | return -ENOMEM; |
| 7721 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7722 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7723 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7724 | ETH_ALEN); |
| 7725 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7726 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7727 | else |
| 7728 | port = 0; |
| 7729 | #ifdef CONFIG_INET |
| 7730 | /* allocate a socket and port for it and use it */ |
| 7731 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7732 | IPPROTO_TCP, &cfg->sock, 1); |
| 7733 | if (err) { |
| 7734 | kfree(cfg); |
| 7735 | return err; |
| 7736 | } |
| 7737 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7738 | sock_release(cfg->sock); |
| 7739 | kfree(cfg); |
| 7740 | return -EADDRINUSE; |
| 7741 | } |
| 7742 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7743 | #else |
| 7744 | if (!port) { |
| 7745 | kfree(cfg); |
| 7746 | return -EINVAL; |
| 7747 | } |
| 7748 | cfg->src_port = port; |
| 7749 | #endif |
| 7750 | |
| 7751 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7752 | cfg->payload_len = data_size; |
| 7753 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7754 | memcpy((void *)cfg->payload, |
| 7755 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7756 | data_size); |
| 7757 | if (seq) |
| 7758 | cfg->payload_seq = *seq; |
| 7759 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7760 | cfg->wake_len = wake_size; |
| 7761 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7762 | memcpy((void *)cfg->wake_data, |
| 7763 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7764 | wake_size); |
| 7765 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7766 | data_size + wake_size; |
| 7767 | memcpy((void *)cfg->wake_mask, |
| 7768 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7769 | wake_mask_size); |
| 7770 | if (tok) { |
| 7771 | cfg->tokens_size = tokens_size; |
| 7772 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7773 | } |
| 7774 | |
| 7775 | trig->tcp = cfg; |
| 7776 | |
| 7777 | return 0; |
| 7778 | } |
| 7779 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7780 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7781 | { |
| 7782 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7783 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7784 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7785 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7786 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 7787 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7788 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7789 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7790 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns && |
| 7791 | !rdev->wiphy.wowlan.tcp) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7792 | return -EOPNOTSUPP; |
| 7793 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7794 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7795 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7796 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7797 | goto set_wakeup; |
| 7798 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7799 | |
| 7800 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7801 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7802 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7803 | nl80211_wowlan_policy); |
| 7804 | if (err) |
| 7805 | return err; |
| 7806 | |
| 7807 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7808 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7809 | return -EINVAL; |
| 7810 | new_triggers.any = true; |
| 7811 | } |
| 7812 | |
| 7813 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7814 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7815 | return -EINVAL; |
| 7816 | new_triggers.disconnect = true; |
| 7817 | } |
| 7818 | |
| 7819 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7820 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7821 | return -EINVAL; |
| 7822 | new_triggers.magic_pkt = true; |
| 7823 | } |
| 7824 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7825 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7826 | return -EINVAL; |
| 7827 | |
| 7828 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7829 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7830 | return -EINVAL; |
| 7831 | new_triggers.gtk_rekey_failure = true; |
| 7832 | } |
| 7833 | |
| 7834 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7835 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7836 | return -EINVAL; |
| 7837 | new_triggers.eap_identity_req = true; |
| 7838 | } |
| 7839 | |
| 7840 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7841 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7842 | return -EINVAL; |
| 7843 | new_triggers.four_way_handshake = true; |
| 7844 | } |
| 7845 | |
| 7846 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7847 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7848 | return -EINVAL; |
| 7849 | new_triggers.rfkill_release = true; |
| 7850 | } |
| 7851 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7852 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7853 | struct nlattr *pat; |
| 7854 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7855 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7856 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7857 | |
| 7858 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7859 | rem) |
| 7860 | n_patterns++; |
| 7861 | if (n_patterns > wowlan->n_patterns) |
| 7862 | return -EINVAL; |
| 7863 | |
| 7864 | new_triggers.patterns = kcalloc(n_patterns, |
| 7865 | sizeof(new_triggers.patterns[0]), |
| 7866 | GFP_KERNEL); |
| 7867 | if (!new_triggers.patterns) |
| 7868 | return -ENOMEM; |
| 7869 | |
| 7870 | new_triggers.n_patterns = n_patterns; |
| 7871 | i = 0; |
| 7872 | |
| 7873 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7874 | rem) { |
| 7875 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7876 | nla_data(pat), nla_len(pat), NULL); |
| 7877 | err = -EINVAL; |
| 7878 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7879 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7880 | goto error; |
| 7881 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7882 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7883 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7884 | mask_len) |
| 7885 | goto error; |
| 7886 | if (pat_len > wowlan->pattern_max_len || |
| 7887 | pat_len < wowlan->pattern_min_len) |
| 7888 | goto error; |
| 7889 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7890 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7891 | pkt_offset = 0; |
| 7892 | else |
| 7893 | pkt_offset = nla_get_u32( |
| 7894 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7895 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7896 | goto error; |
| 7897 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7898 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7899 | new_triggers.patterns[i].mask = |
| 7900 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7901 | if (!new_triggers.patterns[i].mask) { |
| 7902 | err = -ENOMEM; |
| 7903 | goto error; |
| 7904 | } |
| 7905 | new_triggers.patterns[i].pattern = |
| 7906 | new_triggers.patterns[i].mask + mask_len; |
| 7907 | memcpy(new_triggers.patterns[i].mask, |
| 7908 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7909 | mask_len); |
| 7910 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7911 | memcpy(new_triggers.patterns[i].pattern, |
| 7912 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7913 | pat_len); |
| 7914 | i++; |
| 7915 | } |
| 7916 | } |
| 7917 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7918 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7919 | err = nl80211_parse_wowlan_tcp( |
| 7920 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7921 | &new_triggers); |
| 7922 | if (err) |
| 7923 | goto error; |
| 7924 | } |
| 7925 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7926 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7927 | if (!ntrig) { |
| 7928 | err = -ENOMEM; |
| 7929 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7930 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7931 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7932 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7933 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7934 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame^] | 7935 | if (rdev->ops->set_wakeup && |
| 7936 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 7937 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7938 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7939 | return 0; |
| 7940 | error: |
| 7941 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7942 | kfree(new_triggers.patterns[i].mask); |
| 7943 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7944 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7945 | sock_release(new_triggers.tcp->sock); |
| 7946 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7947 | return err; |
| 7948 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7949 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7950 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7951 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 7952 | { |
| 7953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7954 | struct net_device *dev = info->user_ptr[1]; |
| 7955 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7956 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 7957 | struct cfg80211_gtk_rekey_data rekey_data; |
| 7958 | int err; |
| 7959 | |
| 7960 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 7961 | return -EINVAL; |
| 7962 | |
| 7963 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 7964 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7965 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 7966 | nl80211_rekey_policy); |
| 7967 | if (err) |
| 7968 | return err; |
| 7969 | |
| 7970 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 7971 | return -ERANGE; |
| 7972 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 7973 | return -ERANGE; |
| 7974 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 7975 | return -ERANGE; |
| 7976 | |
| 7977 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 7978 | NL80211_KEK_LEN); |
| 7979 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 7980 | NL80211_KCK_LEN); |
| 7981 | memcpy(rekey_data.replay_ctr, |
| 7982 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 7983 | NL80211_REPLAY_CTR_LEN); |
| 7984 | |
| 7985 | wdev_lock(wdev); |
| 7986 | if (!wdev->current_bss) { |
| 7987 | err = -ENOTCONN; |
| 7988 | goto out; |
| 7989 | } |
| 7990 | |
| 7991 | if (!rdev->ops->set_rekey_data) { |
| 7992 | err = -EOPNOTSUPP; |
| 7993 | goto out; |
| 7994 | } |
| 7995 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7996 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7997 | out: |
| 7998 | wdev_unlock(wdev); |
| 7999 | return err; |
| 8000 | } |
| 8001 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8002 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8003 | struct genl_info *info) |
| 8004 | { |
| 8005 | struct net_device *dev = info->user_ptr[1]; |
| 8006 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8007 | |
| 8008 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8009 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8010 | return -EINVAL; |
| 8011 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8012 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8013 | return -EBUSY; |
| 8014 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8015 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8016 | return 0; |
| 8017 | } |
| 8018 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8019 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8020 | struct genl_info *info) |
| 8021 | { |
| 8022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8023 | struct net_device *dev = info->user_ptr[1]; |
| 8024 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8025 | struct sk_buff *msg; |
| 8026 | void *hdr; |
| 8027 | const u8 *addr; |
| 8028 | u64 cookie; |
| 8029 | int err; |
| 8030 | |
| 8031 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8032 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8033 | return -EOPNOTSUPP; |
| 8034 | |
| 8035 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8036 | return -EINVAL; |
| 8037 | |
| 8038 | if (!rdev->ops->probe_client) |
| 8039 | return -EOPNOTSUPP; |
| 8040 | |
| 8041 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8042 | if (!msg) |
| 8043 | return -ENOMEM; |
| 8044 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8045 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8046 | NL80211_CMD_PROBE_CLIENT); |
| 8047 | |
| 8048 | if (IS_ERR(hdr)) { |
| 8049 | err = PTR_ERR(hdr); |
| 8050 | goto free_msg; |
| 8051 | } |
| 8052 | |
| 8053 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8054 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8055 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8056 | if (err) |
| 8057 | goto free_msg; |
| 8058 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8059 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8060 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8061 | |
| 8062 | genlmsg_end(msg, hdr); |
| 8063 | |
| 8064 | return genlmsg_reply(msg, info); |
| 8065 | |
| 8066 | nla_put_failure: |
| 8067 | err = -ENOBUFS; |
| 8068 | free_msg: |
| 8069 | nlmsg_free(msg); |
| 8070 | return err; |
| 8071 | } |
| 8072 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8073 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8074 | { |
| 8075 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8076 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8077 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8078 | |
| 8079 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8080 | return -EOPNOTSUPP; |
| 8081 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8082 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8083 | if (!nreg) |
| 8084 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8085 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8086 | /* First, check if already registered. */ |
| 8087 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8088 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8089 | if (reg->nlportid == info->snd_portid) { |
| 8090 | rv = -EALREADY; |
| 8091 | goto out_err; |
| 8092 | } |
| 8093 | } |
| 8094 | /* Add it to the list */ |
| 8095 | nreg->nlportid = info->snd_portid; |
| 8096 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8097 | |
| 8098 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8099 | |
| 8100 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8101 | out_err: |
| 8102 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8103 | kfree(nreg); |
| 8104 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8105 | } |
| 8106 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8107 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8108 | { |
| 8109 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8110 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8111 | int err; |
| 8112 | |
| 8113 | if (!rdev->ops->start_p2p_device) |
| 8114 | return -EOPNOTSUPP; |
| 8115 | |
| 8116 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8117 | return -EOPNOTSUPP; |
| 8118 | |
| 8119 | if (wdev->p2p_started) |
| 8120 | return 0; |
| 8121 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8122 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8123 | if (err) |
| 8124 | return err; |
| 8125 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8126 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8127 | if (err) |
| 8128 | return err; |
| 8129 | |
| 8130 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8131 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8132 | |
| 8133 | return 0; |
| 8134 | } |
| 8135 | |
| 8136 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8137 | { |
| 8138 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8139 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8140 | |
| 8141 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8142 | return -EOPNOTSUPP; |
| 8143 | |
| 8144 | if (!rdev->ops->stop_p2p_device) |
| 8145 | return -EOPNOTSUPP; |
| 8146 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8147 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8148 | |
| 8149 | return 0; |
| 8150 | } |
| 8151 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8152 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8153 | struct genl_info *info) |
| 8154 | { |
| 8155 | void *hdr; |
| 8156 | struct sk_buff *msg; |
| 8157 | |
| 8158 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8159 | if (!msg) |
| 8160 | return -ENOMEM; |
| 8161 | |
| 8162 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8163 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8164 | if (!hdr) |
| 8165 | goto nla_put_failure; |
| 8166 | |
| 8167 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8168 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8169 | goto nla_put_failure; |
| 8170 | |
| 8171 | genlmsg_end(msg, hdr); |
| 8172 | return genlmsg_reply(msg, info); |
| 8173 | |
| 8174 | nla_put_failure: |
| 8175 | kfree_skb(msg); |
| 8176 | return -ENOBUFS; |
| 8177 | } |
| 8178 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8179 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8180 | { |
| 8181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8182 | struct cfg80211_update_ft_ies_params ft_params; |
| 8183 | struct net_device *dev = info->user_ptr[1]; |
| 8184 | |
| 8185 | if (!rdev->ops->update_ft_ies) |
| 8186 | return -EOPNOTSUPP; |
| 8187 | |
| 8188 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8189 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8190 | return -EINVAL; |
| 8191 | |
| 8192 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8193 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8194 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8195 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8196 | |
| 8197 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8198 | } |
| 8199 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8200 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8201 | struct genl_info *info) |
| 8202 | { |
| 8203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8204 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8205 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8206 | u16 duration; |
| 8207 | int ret; |
| 8208 | |
| 8209 | if (!rdev->ops->crit_proto_start) |
| 8210 | return -EOPNOTSUPP; |
| 8211 | |
| 8212 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8213 | return -EINVAL; |
| 8214 | |
| 8215 | if (rdev->crit_proto_nlportid) |
| 8216 | return -EBUSY; |
| 8217 | |
| 8218 | /* determine protocol if provided */ |
| 8219 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8220 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8221 | |
| 8222 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8223 | return -EINVAL; |
| 8224 | |
| 8225 | /* timeout must be provided */ |
| 8226 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8227 | return -EINVAL; |
| 8228 | |
| 8229 | duration = |
| 8230 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8231 | |
| 8232 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8233 | return -ERANGE; |
| 8234 | |
| 8235 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8236 | if (!ret) |
| 8237 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8238 | |
| 8239 | return ret; |
| 8240 | } |
| 8241 | |
| 8242 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8243 | struct genl_info *info) |
| 8244 | { |
| 8245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8246 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8247 | |
| 8248 | if (!rdev->ops->crit_proto_stop) |
| 8249 | return -EOPNOTSUPP; |
| 8250 | |
| 8251 | if (rdev->crit_proto_nlportid) { |
| 8252 | rdev->crit_proto_nlportid = 0; |
| 8253 | rdev_crit_proto_stop(rdev, wdev); |
| 8254 | } |
| 8255 | return 0; |
| 8256 | } |
| 8257 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8258 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8259 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8260 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8261 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8262 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8263 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8264 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8265 | /* 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] | 8266 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8267 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8268 | |
| 8269 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8270 | struct genl_info *info) |
| 8271 | { |
| 8272 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8273 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8274 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8275 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8276 | |
| 8277 | if (rtnl) |
| 8278 | rtnl_lock(); |
| 8279 | |
| 8280 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8281 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8282 | if (IS_ERR(rdev)) { |
| 8283 | if (rtnl) |
| 8284 | rtnl_unlock(); |
| 8285 | return PTR_ERR(rdev); |
| 8286 | } |
| 8287 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8288 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8289 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8290 | ASSERT_RTNL(); |
| 8291 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8292 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8293 | info->attrs); |
| 8294 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8295 | if (rtnl) |
| 8296 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8297 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8298 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8299 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8300 | dev = wdev->netdev; |
| 8301 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8302 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8303 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8304 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8305 | if (rtnl) |
| 8306 | rtnl_unlock(); |
| 8307 | return -EINVAL; |
| 8308 | } |
| 8309 | |
| 8310 | info->user_ptr[1] = dev; |
| 8311 | } else { |
| 8312 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8313 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8314 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8315 | if (dev) { |
| 8316 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8317 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8318 | if (rtnl) |
| 8319 | rtnl_unlock(); |
| 8320 | return -ENETDOWN; |
| 8321 | } |
| 8322 | |
| 8323 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8324 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8325 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8326 | if (rtnl) |
| 8327 | rtnl_unlock(); |
| 8328 | return -ENETDOWN; |
| 8329 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8330 | } |
| 8331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8332 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8333 | } |
| 8334 | |
| 8335 | return 0; |
| 8336 | } |
| 8337 | |
| 8338 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8339 | struct genl_info *info) |
| 8340 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8341 | if (info->user_ptr[1]) { |
| 8342 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8343 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8344 | |
| 8345 | if (wdev->netdev) |
| 8346 | dev_put(wdev->netdev); |
| 8347 | } else { |
| 8348 | dev_put(info->user_ptr[1]); |
| 8349 | } |
| 8350 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8351 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8352 | rtnl_unlock(); |
| 8353 | } |
| 8354 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8355 | static struct genl_ops nl80211_ops[] = { |
| 8356 | { |
| 8357 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8358 | .doit = nl80211_get_wiphy, |
| 8359 | .dumpit = nl80211_dump_wiphy, |
| 8360 | .policy = nl80211_policy, |
| 8361 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8362 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8363 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8364 | }, |
| 8365 | { |
| 8366 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8367 | .doit = nl80211_set_wiphy, |
| 8368 | .policy = nl80211_policy, |
| 8369 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8370 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8371 | }, |
| 8372 | { |
| 8373 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8374 | .doit = nl80211_get_interface, |
| 8375 | .dumpit = nl80211_dump_interface, |
| 8376 | .policy = nl80211_policy, |
| 8377 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8378 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8379 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8380 | }, |
| 8381 | { |
| 8382 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8383 | .doit = nl80211_set_interface, |
| 8384 | .policy = nl80211_policy, |
| 8385 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8386 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8387 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8388 | }, |
| 8389 | { |
| 8390 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8391 | .doit = nl80211_new_interface, |
| 8392 | .policy = nl80211_policy, |
| 8393 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8394 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8395 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8396 | }, |
| 8397 | { |
| 8398 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8399 | .doit = nl80211_del_interface, |
| 8400 | .policy = nl80211_policy, |
| 8401 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8402 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8403 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8404 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8405 | { |
| 8406 | .cmd = NL80211_CMD_GET_KEY, |
| 8407 | .doit = nl80211_get_key, |
| 8408 | .policy = nl80211_policy, |
| 8409 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8411 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8412 | }, |
| 8413 | { |
| 8414 | .cmd = NL80211_CMD_SET_KEY, |
| 8415 | .doit = nl80211_set_key, |
| 8416 | .policy = nl80211_policy, |
| 8417 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8419 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8420 | }, |
| 8421 | { |
| 8422 | .cmd = NL80211_CMD_NEW_KEY, |
| 8423 | .doit = nl80211_new_key, |
| 8424 | .policy = nl80211_policy, |
| 8425 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8427 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8428 | }, |
| 8429 | { |
| 8430 | .cmd = NL80211_CMD_DEL_KEY, |
| 8431 | .doit = nl80211_del_key, |
| 8432 | .policy = nl80211_policy, |
| 8433 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8435 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8436 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8437 | { |
| 8438 | .cmd = NL80211_CMD_SET_BEACON, |
| 8439 | .policy = nl80211_policy, |
| 8440 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8441 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8443 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8444 | }, |
| 8445 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8446 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8447 | .policy = nl80211_policy, |
| 8448 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8449 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8451 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8452 | }, |
| 8453 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8454 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8455 | .policy = nl80211_policy, |
| 8456 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8457 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8459 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8460 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8461 | { |
| 8462 | .cmd = NL80211_CMD_GET_STATION, |
| 8463 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8464 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8465 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8466 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8467 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8468 | }, |
| 8469 | { |
| 8470 | .cmd = NL80211_CMD_SET_STATION, |
| 8471 | .doit = nl80211_set_station, |
| 8472 | .policy = nl80211_policy, |
| 8473 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8474 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8475 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8476 | }, |
| 8477 | { |
| 8478 | .cmd = NL80211_CMD_NEW_STATION, |
| 8479 | .doit = nl80211_new_station, |
| 8480 | .policy = nl80211_policy, |
| 8481 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8482 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8483 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8484 | }, |
| 8485 | { |
| 8486 | .cmd = NL80211_CMD_DEL_STATION, |
| 8487 | .doit = nl80211_del_station, |
| 8488 | .policy = nl80211_policy, |
| 8489 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8490 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8491 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8492 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8493 | { |
| 8494 | .cmd = NL80211_CMD_GET_MPATH, |
| 8495 | .doit = nl80211_get_mpath, |
| 8496 | .dumpit = nl80211_dump_mpath, |
| 8497 | .policy = nl80211_policy, |
| 8498 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8500 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8501 | }, |
| 8502 | { |
| 8503 | .cmd = NL80211_CMD_SET_MPATH, |
| 8504 | .doit = nl80211_set_mpath, |
| 8505 | .policy = nl80211_policy, |
| 8506 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8507 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8508 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8509 | }, |
| 8510 | { |
| 8511 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8512 | .doit = nl80211_new_mpath, |
| 8513 | .policy = nl80211_policy, |
| 8514 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8515 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8516 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8517 | }, |
| 8518 | { |
| 8519 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8520 | .doit = nl80211_del_mpath, |
| 8521 | .policy = nl80211_policy, |
| 8522 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8523 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8524 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8525 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8526 | { |
| 8527 | .cmd = NL80211_CMD_SET_BSS, |
| 8528 | .doit = nl80211_set_bss, |
| 8529 | .policy = nl80211_policy, |
| 8530 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8531 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8532 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8533 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8534 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8535 | .cmd = NL80211_CMD_GET_REG, |
| 8536 | .doit = nl80211_get_reg, |
| 8537 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8538 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8539 | /* can be retrieved by unprivileged users */ |
| 8540 | }, |
| 8541 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8542 | .cmd = NL80211_CMD_SET_REG, |
| 8543 | .doit = nl80211_set_reg, |
| 8544 | .policy = nl80211_policy, |
| 8545 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8546 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8547 | }, |
| 8548 | { |
| 8549 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8550 | .doit = nl80211_req_set_reg, |
| 8551 | .policy = nl80211_policy, |
| 8552 | .flags = GENL_ADMIN_PERM, |
| 8553 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8554 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8555 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8556 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8557 | .policy = nl80211_policy, |
| 8558 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8559 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8560 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8561 | }, |
| 8562 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8563 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8564 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8565 | .policy = nl80211_policy, |
| 8566 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8567 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8568 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8569 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8570 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8571 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8572 | .doit = nl80211_trigger_scan, |
| 8573 | .policy = nl80211_policy, |
| 8574 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8575 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8576 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8577 | }, |
| 8578 | { |
| 8579 | .cmd = NL80211_CMD_GET_SCAN, |
| 8580 | .policy = nl80211_policy, |
| 8581 | .dumpit = nl80211_dump_scan, |
| 8582 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8583 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8584 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8585 | .doit = nl80211_start_sched_scan, |
| 8586 | .policy = nl80211_policy, |
| 8587 | .flags = GENL_ADMIN_PERM, |
| 8588 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8589 | NL80211_FLAG_NEED_RTNL, |
| 8590 | }, |
| 8591 | { |
| 8592 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8593 | .doit = nl80211_stop_sched_scan, |
| 8594 | .policy = nl80211_policy, |
| 8595 | .flags = GENL_ADMIN_PERM, |
| 8596 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8597 | NL80211_FLAG_NEED_RTNL, |
| 8598 | }, |
| 8599 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8600 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8601 | .doit = nl80211_authenticate, |
| 8602 | .policy = nl80211_policy, |
| 8603 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8604 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8605 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8606 | }, |
| 8607 | { |
| 8608 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8609 | .doit = nl80211_associate, |
| 8610 | .policy = nl80211_policy, |
| 8611 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8612 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8613 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8614 | }, |
| 8615 | { |
| 8616 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8617 | .doit = nl80211_deauthenticate, |
| 8618 | .policy = nl80211_policy, |
| 8619 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8620 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8621 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8622 | }, |
| 8623 | { |
| 8624 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8625 | .doit = nl80211_disassociate, |
| 8626 | .policy = nl80211_policy, |
| 8627 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8628 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8629 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8630 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8631 | { |
| 8632 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8633 | .doit = nl80211_join_ibss, |
| 8634 | .policy = nl80211_policy, |
| 8635 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8636 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8637 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8638 | }, |
| 8639 | { |
| 8640 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8641 | .doit = nl80211_leave_ibss, |
| 8642 | .policy = nl80211_policy, |
| 8643 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8644 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8645 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8646 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8647 | #ifdef CONFIG_NL80211_TESTMODE |
| 8648 | { |
| 8649 | .cmd = NL80211_CMD_TESTMODE, |
| 8650 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8651 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8652 | .policy = nl80211_policy, |
| 8653 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8654 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8655 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8656 | }, |
| 8657 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8658 | { |
| 8659 | .cmd = NL80211_CMD_CONNECT, |
| 8660 | .doit = nl80211_connect, |
| 8661 | .policy = nl80211_policy, |
| 8662 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8663 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8664 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8665 | }, |
| 8666 | { |
| 8667 | .cmd = NL80211_CMD_DISCONNECT, |
| 8668 | .doit = nl80211_disconnect, |
| 8669 | .policy = nl80211_policy, |
| 8670 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8672 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8673 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8674 | { |
| 8675 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8676 | .doit = nl80211_wiphy_netns, |
| 8677 | .policy = nl80211_policy, |
| 8678 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8679 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8680 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8681 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8682 | { |
| 8683 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8684 | .policy = nl80211_policy, |
| 8685 | .dumpit = nl80211_dump_survey, |
| 8686 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8687 | { |
| 8688 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8689 | .doit = nl80211_setdel_pmksa, |
| 8690 | .policy = nl80211_policy, |
| 8691 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8692 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8693 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8694 | }, |
| 8695 | { |
| 8696 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8697 | .doit = nl80211_setdel_pmksa, |
| 8698 | .policy = nl80211_policy, |
| 8699 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8700 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8701 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8702 | }, |
| 8703 | { |
| 8704 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8705 | .doit = nl80211_flush_pmksa, |
| 8706 | .policy = nl80211_policy, |
| 8707 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8708 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8709 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8710 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8711 | { |
| 8712 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8713 | .doit = nl80211_remain_on_channel, |
| 8714 | .policy = nl80211_policy, |
| 8715 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8716 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8717 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8718 | }, |
| 8719 | { |
| 8720 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8721 | .doit = nl80211_cancel_remain_on_channel, |
| 8722 | .policy = nl80211_policy, |
| 8723 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8724 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8725 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8726 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8727 | { |
| 8728 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8729 | .doit = nl80211_set_tx_bitrate_mask, |
| 8730 | .policy = nl80211_policy, |
| 8731 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8732 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8733 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8734 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8735 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8736 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8737 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8738 | .policy = nl80211_policy, |
| 8739 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8740 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8741 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8742 | }, |
| 8743 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8744 | .cmd = NL80211_CMD_FRAME, |
| 8745 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8746 | .policy = nl80211_policy, |
| 8747 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8748 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8749 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8750 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8751 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8752 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8753 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8754 | .policy = nl80211_policy, |
| 8755 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8756 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8757 | NL80211_FLAG_NEED_RTNL, |
| 8758 | }, |
| 8759 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8760 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8761 | .doit = nl80211_set_power_save, |
| 8762 | .policy = nl80211_policy, |
| 8763 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8764 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8765 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8766 | }, |
| 8767 | { |
| 8768 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8769 | .doit = nl80211_get_power_save, |
| 8770 | .policy = nl80211_policy, |
| 8771 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8772 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8773 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8774 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8775 | { |
| 8776 | .cmd = NL80211_CMD_SET_CQM, |
| 8777 | .doit = nl80211_set_cqm, |
| 8778 | .policy = nl80211_policy, |
| 8779 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8780 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8781 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8782 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8783 | { |
| 8784 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8785 | .doit = nl80211_set_channel, |
| 8786 | .policy = nl80211_policy, |
| 8787 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8788 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8789 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8790 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8791 | { |
| 8792 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8793 | .doit = nl80211_set_wds_peer, |
| 8794 | .policy = nl80211_policy, |
| 8795 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8796 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8797 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8798 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8799 | { |
| 8800 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8801 | .doit = nl80211_join_mesh, |
| 8802 | .policy = nl80211_policy, |
| 8803 | .flags = GENL_ADMIN_PERM, |
| 8804 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8805 | NL80211_FLAG_NEED_RTNL, |
| 8806 | }, |
| 8807 | { |
| 8808 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8809 | .doit = nl80211_leave_mesh, |
| 8810 | .policy = nl80211_policy, |
| 8811 | .flags = GENL_ADMIN_PERM, |
| 8812 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8813 | NL80211_FLAG_NEED_RTNL, |
| 8814 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8815 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8816 | { |
| 8817 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8818 | .doit = nl80211_get_wowlan, |
| 8819 | .policy = nl80211_policy, |
| 8820 | /* can be retrieved by unprivileged users */ |
| 8821 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8822 | NL80211_FLAG_NEED_RTNL, |
| 8823 | }, |
| 8824 | { |
| 8825 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8826 | .doit = nl80211_set_wowlan, |
| 8827 | .policy = nl80211_policy, |
| 8828 | .flags = GENL_ADMIN_PERM, |
| 8829 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8830 | NL80211_FLAG_NEED_RTNL, |
| 8831 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8832 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8833 | { |
| 8834 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8835 | .doit = nl80211_set_rekey_data, |
| 8836 | .policy = nl80211_policy, |
| 8837 | .flags = GENL_ADMIN_PERM, |
| 8838 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8839 | NL80211_FLAG_NEED_RTNL, |
| 8840 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8841 | { |
| 8842 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8843 | .doit = nl80211_tdls_mgmt, |
| 8844 | .policy = nl80211_policy, |
| 8845 | .flags = GENL_ADMIN_PERM, |
| 8846 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8847 | NL80211_FLAG_NEED_RTNL, |
| 8848 | }, |
| 8849 | { |
| 8850 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8851 | .doit = nl80211_tdls_oper, |
| 8852 | .policy = nl80211_policy, |
| 8853 | .flags = GENL_ADMIN_PERM, |
| 8854 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8855 | NL80211_FLAG_NEED_RTNL, |
| 8856 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8857 | { |
| 8858 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8859 | .doit = nl80211_register_unexpected_frame, |
| 8860 | .policy = nl80211_policy, |
| 8861 | .flags = GENL_ADMIN_PERM, |
| 8862 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8863 | NL80211_FLAG_NEED_RTNL, |
| 8864 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8865 | { |
| 8866 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8867 | .doit = nl80211_probe_client, |
| 8868 | .policy = nl80211_policy, |
| 8869 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8870 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8871 | NL80211_FLAG_NEED_RTNL, |
| 8872 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8873 | { |
| 8874 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8875 | .doit = nl80211_register_beacons, |
| 8876 | .policy = nl80211_policy, |
| 8877 | .flags = GENL_ADMIN_PERM, |
| 8878 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8879 | NL80211_FLAG_NEED_RTNL, |
| 8880 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8881 | { |
| 8882 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8883 | .doit = nl80211_set_noack_map, |
| 8884 | .policy = nl80211_policy, |
| 8885 | .flags = GENL_ADMIN_PERM, |
| 8886 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8887 | NL80211_FLAG_NEED_RTNL, |
| 8888 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8889 | { |
| 8890 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8891 | .doit = nl80211_start_p2p_device, |
| 8892 | .policy = nl80211_policy, |
| 8893 | .flags = GENL_ADMIN_PERM, |
| 8894 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8895 | NL80211_FLAG_NEED_RTNL, |
| 8896 | }, |
| 8897 | { |
| 8898 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8899 | .doit = nl80211_stop_p2p_device, |
| 8900 | .policy = nl80211_policy, |
| 8901 | .flags = GENL_ADMIN_PERM, |
| 8902 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8903 | NL80211_FLAG_NEED_RTNL, |
| 8904 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8905 | { |
| 8906 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8907 | .doit = nl80211_set_mcast_rate, |
| 8908 | .policy = nl80211_policy, |
| 8909 | .flags = GENL_ADMIN_PERM, |
| 8910 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8911 | NL80211_FLAG_NEED_RTNL, |
| 8912 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8913 | { |
| 8914 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8915 | .doit = nl80211_set_mac_acl, |
| 8916 | .policy = nl80211_policy, |
| 8917 | .flags = GENL_ADMIN_PERM, |
| 8918 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8919 | NL80211_FLAG_NEED_RTNL, |
| 8920 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8921 | { |
| 8922 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8923 | .doit = nl80211_start_radar_detection, |
| 8924 | .policy = nl80211_policy, |
| 8925 | .flags = GENL_ADMIN_PERM, |
| 8926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8927 | NL80211_FLAG_NEED_RTNL, |
| 8928 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8929 | { |
| 8930 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 8931 | .doit = nl80211_get_protocol_features, |
| 8932 | .policy = nl80211_policy, |
| 8933 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8934 | { |
| 8935 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 8936 | .doit = nl80211_update_ft_ies, |
| 8937 | .policy = nl80211_policy, |
| 8938 | .flags = GENL_ADMIN_PERM, |
| 8939 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8940 | NL80211_FLAG_NEED_RTNL, |
| 8941 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8942 | { |
| 8943 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 8944 | .doit = nl80211_crit_protocol_start, |
| 8945 | .policy = nl80211_policy, |
| 8946 | .flags = GENL_ADMIN_PERM, |
| 8947 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8948 | NL80211_FLAG_NEED_RTNL, |
| 8949 | }, |
| 8950 | { |
| 8951 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 8952 | .doit = nl80211_crit_protocol_stop, |
| 8953 | .policy = nl80211_policy, |
| 8954 | .flags = GENL_ADMIN_PERM, |
| 8955 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8956 | NL80211_FLAG_NEED_RTNL, |
| 8957 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8958 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8959 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8960 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 8961 | .name = "mlme", |
| 8962 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8963 | |
| 8964 | /* multicast groups */ |
| 8965 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 8966 | .name = "config", |
| 8967 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8968 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 8969 | .name = "scan", |
| 8970 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8971 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 8972 | .name = "regulatory", |
| 8973 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8974 | |
| 8975 | /* notification functions */ |
| 8976 | |
| 8977 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 8978 | { |
| 8979 | struct sk_buff *msg; |
| 8980 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 8981 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8982 | if (!msg) |
| 8983 | return; |
| 8984 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8985 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
| 8986 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8987 | nlmsg_free(msg); |
| 8988 | return; |
| 8989 | } |
| 8990 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8991 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8992 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8993 | } |
| 8994 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 8995 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 8996 | struct cfg80211_registered_device *rdev) |
| 8997 | { |
| 8998 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 8999 | struct nlattr *nest; |
| 9000 | int i; |
| 9001 | |
| 9002 | if (WARN_ON(!req)) |
| 9003 | return 0; |
| 9004 | |
| 9005 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9006 | if (!nest) |
| 9007 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9008 | for (i = 0; i < req->n_ssids; i++) { |
| 9009 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9010 | goto nla_put_failure; |
| 9011 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9012 | nla_nest_end(msg, nest); |
| 9013 | |
| 9014 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9015 | if (!nest) |
| 9016 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9017 | for (i = 0; i < req->n_channels; i++) { |
| 9018 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9019 | goto nla_put_failure; |
| 9020 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9021 | nla_nest_end(msg, nest); |
| 9022 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9023 | if (req->ie && |
| 9024 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9025 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9026 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9027 | if (req->flags) |
| 9028 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9029 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9030 | return 0; |
| 9031 | nla_put_failure: |
| 9032 | return -ENOBUFS; |
| 9033 | } |
| 9034 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9035 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9036 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9037 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9038 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9039 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9040 | { |
| 9041 | void *hdr; |
| 9042 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9043 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9044 | if (!hdr) |
| 9045 | return -1; |
| 9046 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9047 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9048 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9049 | wdev->netdev->ifindex)) || |
| 9050 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9051 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9052 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9053 | /* ignore errors and send incomplete event anyway */ |
| 9054 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9055 | |
| 9056 | return genlmsg_end(msg, hdr); |
| 9057 | |
| 9058 | nla_put_failure: |
| 9059 | genlmsg_cancel(msg, hdr); |
| 9060 | return -EMSGSIZE; |
| 9061 | } |
| 9062 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9063 | static int |
| 9064 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9065 | struct cfg80211_registered_device *rdev, |
| 9066 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9067 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9068 | { |
| 9069 | void *hdr; |
| 9070 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9071 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9072 | if (!hdr) |
| 9073 | return -1; |
| 9074 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9075 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9076 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9077 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9078 | |
| 9079 | return genlmsg_end(msg, hdr); |
| 9080 | |
| 9081 | nla_put_failure: |
| 9082 | genlmsg_cancel(msg, hdr); |
| 9083 | return -EMSGSIZE; |
| 9084 | } |
| 9085 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9086 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9087 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9088 | { |
| 9089 | struct sk_buff *msg; |
| 9090 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9091 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9092 | if (!msg) |
| 9093 | return; |
| 9094 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9095 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9096 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9097 | nlmsg_free(msg); |
| 9098 | return; |
| 9099 | } |
| 9100 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9101 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9102 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9103 | } |
| 9104 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9105 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9106 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9107 | { |
| 9108 | struct sk_buff *msg; |
| 9109 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9110 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9111 | if (!msg) |
| 9112 | return; |
| 9113 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9114 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9115 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9116 | nlmsg_free(msg); |
| 9117 | return; |
| 9118 | } |
| 9119 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9120 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9121 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9122 | } |
| 9123 | |
| 9124 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9125 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9126 | { |
| 9127 | struct sk_buff *msg; |
| 9128 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9129 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9130 | if (!msg) |
| 9131 | return; |
| 9132 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9133 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9134 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9135 | nlmsg_free(msg); |
| 9136 | return; |
| 9137 | } |
| 9138 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9139 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9140 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9141 | } |
| 9142 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9143 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9144 | struct net_device *netdev) |
| 9145 | { |
| 9146 | struct sk_buff *msg; |
| 9147 | |
| 9148 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9149 | if (!msg) |
| 9150 | return; |
| 9151 | |
| 9152 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9153 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9154 | nlmsg_free(msg); |
| 9155 | return; |
| 9156 | } |
| 9157 | |
| 9158 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9159 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9160 | } |
| 9161 | |
| 9162 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9163 | struct net_device *netdev, u32 cmd) |
| 9164 | { |
| 9165 | struct sk_buff *msg; |
| 9166 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9167 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9168 | if (!msg) |
| 9169 | return; |
| 9170 | |
| 9171 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9172 | nlmsg_free(msg); |
| 9173 | return; |
| 9174 | } |
| 9175 | |
| 9176 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9177 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9178 | } |
| 9179 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9180 | /* |
| 9181 | * This can happen on global regulatory changes or device specific settings |
| 9182 | * based on custom world regulatory domains. |
| 9183 | */ |
| 9184 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9185 | { |
| 9186 | struct sk_buff *msg; |
| 9187 | void *hdr; |
| 9188 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9189 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9190 | if (!msg) |
| 9191 | return; |
| 9192 | |
| 9193 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9194 | if (!hdr) { |
| 9195 | nlmsg_free(msg); |
| 9196 | return; |
| 9197 | } |
| 9198 | |
| 9199 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9200 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9201 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9202 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9203 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9204 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9205 | NL80211_REGDOM_TYPE_WORLD)) |
| 9206 | goto nla_put_failure; |
| 9207 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9208 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9209 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9210 | goto nla_put_failure; |
| 9211 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9212 | request->intersect) { |
| 9213 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9214 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9215 | goto nla_put_failure; |
| 9216 | } else { |
| 9217 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9218 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9219 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9220 | request->alpha2)) |
| 9221 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9222 | } |
| 9223 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9224 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9225 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9226 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9227 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9228 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9229 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9230 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9231 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9232 | GFP_ATOMIC); |
| 9233 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9234 | |
| 9235 | return; |
| 9236 | |
| 9237 | nla_put_failure: |
| 9238 | genlmsg_cancel(msg, hdr); |
| 9239 | nlmsg_free(msg); |
| 9240 | } |
| 9241 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9242 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9243 | struct net_device *netdev, |
| 9244 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9245 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9246 | { |
| 9247 | struct sk_buff *msg; |
| 9248 | void *hdr; |
| 9249 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9250 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9251 | if (!msg) |
| 9252 | return; |
| 9253 | |
| 9254 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9255 | if (!hdr) { |
| 9256 | nlmsg_free(msg); |
| 9257 | return; |
| 9258 | } |
| 9259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9260 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9261 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9262 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9263 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9264 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9265 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9266 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9267 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9268 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9269 | return; |
| 9270 | |
| 9271 | nla_put_failure: |
| 9272 | genlmsg_cancel(msg, hdr); |
| 9273 | nlmsg_free(msg); |
| 9274 | } |
| 9275 | |
| 9276 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9277 | struct net_device *netdev, const u8 *buf, |
| 9278 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9279 | { |
| 9280 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9281 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9282 | } |
| 9283 | |
| 9284 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9285 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9286 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9287 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9288 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9289 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9290 | } |
| 9291 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9292 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9293 | struct net_device *netdev, const u8 *buf, |
| 9294 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9295 | { |
| 9296 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9297 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9298 | } |
| 9299 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9300 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9301 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9302 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9303 | { |
| 9304 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9305 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9306 | } |
| 9307 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9308 | void cfg80211_send_unprot_deauth(struct net_device *dev, const u8 *buf, |
| 9309 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9310 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9311 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9312 | struct wiphy *wiphy = wdev->wiphy; |
| 9313 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9314 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9315 | trace_cfg80211_send_unprot_deauth(dev); |
| 9316 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9317 | NL80211_CMD_UNPROT_DEAUTHENTICATE, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9318 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9319 | EXPORT_SYMBOL(cfg80211_send_unprot_deauth); |
| 9320 | |
| 9321 | void cfg80211_send_unprot_disassoc(struct net_device *dev, const u8 *buf, |
| 9322 | size_t len) |
| 9323 | { |
| 9324 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9325 | struct wiphy *wiphy = wdev->wiphy; |
| 9326 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9327 | |
| 9328 | trace_cfg80211_send_unprot_disassoc(dev); |
| 9329 | nl80211_send_mlme_event(rdev, dev, buf, len, |
| 9330 | NL80211_CMD_UNPROT_DISASSOCIATE, GFP_ATOMIC); |
| 9331 | } |
| 9332 | EXPORT_SYMBOL(cfg80211_send_unprot_disassoc); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9333 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9334 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9335 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9336 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9337 | { |
| 9338 | struct sk_buff *msg; |
| 9339 | void *hdr; |
| 9340 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9341 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9342 | if (!msg) |
| 9343 | return; |
| 9344 | |
| 9345 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9346 | if (!hdr) { |
| 9347 | nlmsg_free(msg); |
| 9348 | return; |
| 9349 | } |
| 9350 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9351 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9352 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9353 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9354 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9355 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9356 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9357 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9358 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9359 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9360 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9361 | return; |
| 9362 | |
| 9363 | nla_put_failure: |
| 9364 | genlmsg_cancel(msg, hdr); |
| 9365 | nlmsg_free(msg); |
| 9366 | } |
| 9367 | |
| 9368 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9369 | struct net_device *netdev, const u8 *addr, |
| 9370 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9371 | { |
| 9372 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9373 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9374 | } |
| 9375 | |
| 9376 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9377 | struct net_device *netdev, const u8 *addr, |
| 9378 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9379 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9380 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9381 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9382 | } |
| 9383 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9384 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9385 | struct net_device *netdev, const u8 *bssid, |
| 9386 | const u8 *req_ie, size_t req_ie_len, |
| 9387 | const u8 *resp_ie, size_t resp_ie_len, |
| 9388 | u16 status, gfp_t gfp) |
| 9389 | { |
| 9390 | struct sk_buff *msg; |
| 9391 | void *hdr; |
| 9392 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9393 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9394 | if (!msg) |
| 9395 | return; |
| 9396 | |
| 9397 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9398 | if (!hdr) { |
| 9399 | nlmsg_free(msg); |
| 9400 | return; |
| 9401 | } |
| 9402 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9403 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9404 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9405 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9406 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9407 | (req_ie && |
| 9408 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9409 | (resp_ie && |
| 9410 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9411 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9412 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9413 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9414 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9415 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9416 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9417 | return; |
| 9418 | |
| 9419 | nla_put_failure: |
| 9420 | genlmsg_cancel(msg, hdr); |
| 9421 | nlmsg_free(msg); |
| 9422 | |
| 9423 | } |
| 9424 | |
| 9425 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9426 | struct net_device *netdev, const u8 *bssid, |
| 9427 | const u8 *req_ie, size_t req_ie_len, |
| 9428 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9429 | { |
| 9430 | struct sk_buff *msg; |
| 9431 | void *hdr; |
| 9432 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9433 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9434 | if (!msg) |
| 9435 | return; |
| 9436 | |
| 9437 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9438 | if (!hdr) { |
| 9439 | nlmsg_free(msg); |
| 9440 | return; |
| 9441 | } |
| 9442 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9443 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9444 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9445 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9446 | (req_ie && |
| 9447 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9448 | (resp_ie && |
| 9449 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9450 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9451 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9452 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9453 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9454 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9455 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9456 | return; |
| 9457 | |
| 9458 | nla_put_failure: |
| 9459 | genlmsg_cancel(msg, hdr); |
| 9460 | nlmsg_free(msg); |
| 9461 | |
| 9462 | } |
| 9463 | |
| 9464 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9465 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9466 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9467 | { |
| 9468 | struct sk_buff *msg; |
| 9469 | void *hdr; |
| 9470 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9471 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9472 | if (!msg) |
| 9473 | return; |
| 9474 | |
| 9475 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9476 | if (!hdr) { |
| 9477 | nlmsg_free(msg); |
| 9478 | return; |
| 9479 | } |
| 9480 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9481 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9482 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9483 | (from_ap && reason && |
| 9484 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9485 | (from_ap && |
| 9486 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9487 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9488 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9489 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9490 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9491 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9492 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9493 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9494 | return; |
| 9495 | |
| 9496 | nla_put_failure: |
| 9497 | genlmsg_cancel(msg, hdr); |
| 9498 | nlmsg_free(msg); |
| 9499 | |
| 9500 | } |
| 9501 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9502 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9503 | struct net_device *netdev, const u8 *bssid, |
| 9504 | gfp_t gfp) |
| 9505 | { |
| 9506 | struct sk_buff *msg; |
| 9507 | void *hdr; |
| 9508 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9510 | if (!msg) |
| 9511 | return; |
| 9512 | |
| 9513 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9514 | if (!hdr) { |
| 9515 | nlmsg_free(msg); |
| 9516 | return; |
| 9517 | } |
| 9518 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9519 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9520 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9521 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9522 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9523 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9524 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 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_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9528 | return; |
| 9529 | |
| 9530 | nla_put_failure: |
| 9531 | genlmsg_cancel(msg, hdr); |
| 9532 | nlmsg_free(msg); |
| 9533 | } |
| 9534 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9535 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 9536 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9537 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9538 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9539 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9540 | struct sk_buff *msg; |
| 9541 | void *hdr; |
| 9542 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9543 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 9544 | return; |
| 9545 | |
| 9546 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 9547 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9548 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9549 | if (!msg) |
| 9550 | return; |
| 9551 | |
| 9552 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9553 | if (!hdr) { |
| 9554 | nlmsg_free(msg); |
| 9555 | return; |
| 9556 | } |
| 9557 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9558 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9559 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9560 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9561 | (ie_len && ie && |
| 9562 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9563 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9564 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9565 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9566 | |
| 9567 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9568 | nl80211_mlme_mcgrp.id, gfp); |
| 9569 | return; |
| 9570 | |
| 9571 | nla_put_failure: |
| 9572 | genlmsg_cancel(msg, hdr); |
| 9573 | nlmsg_free(msg); |
| 9574 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9575 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9576 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9577 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9578 | struct net_device *netdev, const u8 *addr, |
| 9579 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9580 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9581 | { |
| 9582 | struct sk_buff *msg; |
| 9583 | void *hdr; |
| 9584 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9585 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9586 | if (!msg) |
| 9587 | return; |
| 9588 | |
| 9589 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9590 | if (!hdr) { |
| 9591 | nlmsg_free(msg); |
| 9592 | return; |
| 9593 | } |
| 9594 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9595 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9596 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9597 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9598 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9599 | (key_id != -1 && |
| 9600 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9601 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9602 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9603 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9604 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9605 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9606 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9607 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9608 | return; |
| 9609 | |
| 9610 | nla_put_failure: |
| 9611 | genlmsg_cancel(msg, hdr); |
| 9612 | nlmsg_free(msg); |
| 9613 | } |
| 9614 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9615 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9616 | struct ieee80211_channel *channel_before, |
| 9617 | struct ieee80211_channel *channel_after) |
| 9618 | { |
| 9619 | struct sk_buff *msg; |
| 9620 | void *hdr; |
| 9621 | struct nlattr *nl_freq; |
| 9622 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9623 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9624 | if (!msg) |
| 9625 | return; |
| 9626 | |
| 9627 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9628 | if (!hdr) { |
| 9629 | nlmsg_free(msg); |
| 9630 | return; |
| 9631 | } |
| 9632 | |
| 9633 | /* |
| 9634 | * Since we are applying the beacon hint to a wiphy we know its |
| 9635 | * wiphy_idx is valid |
| 9636 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9637 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9638 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9639 | |
| 9640 | /* Before */ |
| 9641 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9642 | if (!nl_freq) |
| 9643 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9644 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9645 | goto nla_put_failure; |
| 9646 | nla_nest_end(msg, nl_freq); |
| 9647 | |
| 9648 | /* After */ |
| 9649 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9650 | if (!nl_freq) |
| 9651 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9652 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9653 | goto nla_put_failure; |
| 9654 | nla_nest_end(msg, nl_freq); |
| 9655 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9656 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9657 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9658 | rcu_read_lock(); |
| 9659 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9660 | GFP_ATOMIC); |
| 9661 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9662 | |
| 9663 | return; |
| 9664 | |
| 9665 | nla_put_failure: |
| 9666 | genlmsg_cancel(msg, hdr); |
| 9667 | nlmsg_free(msg); |
| 9668 | } |
| 9669 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9670 | static void nl80211_send_remain_on_chan_event( |
| 9671 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9672 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9673 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9674 | unsigned int duration, gfp_t gfp) |
| 9675 | { |
| 9676 | struct sk_buff *msg; |
| 9677 | void *hdr; |
| 9678 | |
| 9679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9680 | if (!msg) |
| 9681 | return; |
| 9682 | |
| 9683 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9684 | if (!hdr) { |
| 9685 | nlmsg_free(msg); |
| 9686 | return; |
| 9687 | } |
| 9688 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9689 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9690 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9691 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9692 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9693 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9694 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9695 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9696 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9697 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9698 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9699 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9700 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9701 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9702 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9703 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9704 | |
| 9705 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9706 | nl80211_mlme_mcgrp.id, gfp); |
| 9707 | return; |
| 9708 | |
| 9709 | nla_put_failure: |
| 9710 | genlmsg_cancel(msg, hdr); |
| 9711 | nlmsg_free(msg); |
| 9712 | } |
| 9713 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9714 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 9715 | struct ieee80211_channel *chan, |
| 9716 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9717 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9718 | struct wiphy *wiphy = wdev->wiphy; |
| 9719 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9720 | |
| 9721 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9722 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9723 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9724 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9725 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9726 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9727 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9728 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 9729 | struct ieee80211_channel *chan, |
| 9730 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9731 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9732 | struct wiphy *wiphy = wdev->wiphy; |
| 9733 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9734 | |
| 9735 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9736 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9737 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9738 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9739 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9740 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9741 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 9742 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9743 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9744 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9745 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9746 | struct sk_buff *msg; |
| 9747 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9748 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 9749 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9750 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9751 | if (!msg) |
| 9752 | return; |
| 9753 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9754 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9755 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9756 | nlmsg_free(msg); |
| 9757 | return; |
| 9758 | } |
| 9759 | |
| 9760 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9761 | nl80211_mlme_mcgrp.id, gfp); |
| 9762 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9763 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9764 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9765 | 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] | 9766 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9767 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9768 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9769 | struct sk_buff *msg; |
| 9770 | void *hdr; |
| 9771 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9772 | trace_cfg80211_del_sta(dev, mac_addr); |
| 9773 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9775 | if (!msg) |
| 9776 | return; |
| 9777 | |
| 9778 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9779 | if (!hdr) { |
| 9780 | nlmsg_free(msg); |
| 9781 | return; |
| 9782 | } |
| 9783 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9784 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9785 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9786 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9787 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9788 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9789 | |
| 9790 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9791 | nl80211_mlme_mcgrp.id, gfp); |
| 9792 | return; |
| 9793 | |
| 9794 | nla_put_failure: |
| 9795 | genlmsg_cancel(msg, hdr); |
| 9796 | nlmsg_free(msg); |
| 9797 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9798 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9799 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9800 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 9801 | enum nl80211_connect_failed_reason reason, |
| 9802 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9803 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9804 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9805 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9806 | struct sk_buff *msg; |
| 9807 | void *hdr; |
| 9808 | |
| 9809 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9810 | if (!msg) |
| 9811 | return; |
| 9812 | |
| 9813 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9814 | if (!hdr) { |
| 9815 | nlmsg_free(msg); |
| 9816 | return; |
| 9817 | } |
| 9818 | |
| 9819 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9820 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9821 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9822 | goto nla_put_failure; |
| 9823 | |
| 9824 | genlmsg_end(msg, hdr); |
| 9825 | |
| 9826 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9827 | nl80211_mlme_mcgrp.id, gfp); |
| 9828 | return; |
| 9829 | |
| 9830 | nla_put_failure: |
| 9831 | genlmsg_cancel(msg, hdr); |
| 9832 | nlmsg_free(msg); |
| 9833 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9834 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9835 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9836 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9837 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9838 | { |
| 9839 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9840 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9841 | struct sk_buff *msg; |
| 9842 | void *hdr; |
| 9843 | int err; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9844 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9845 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9846 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9847 | return false; |
| 9848 | |
| 9849 | msg = nlmsg_new(100, gfp); |
| 9850 | if (!msg) |
| 9851 | return true; |
| 9852 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9853 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9854 | if (!hdr) { |
| 9855 | nlmsg_free(msg); |
| 9856 | return true; |
| 9857 | } |
| 9858 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9859 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9860 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9861 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9862 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9863 | |
| 9864 | err = genlmsg_end(msg, hdr); |
| 9865 | if (err < 0) { |
| 9866 | nlmsg_free(msg); |
| 9867 | return true; |
| 9868 | } |
| 9869 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9870 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9871 | return true; |
| 9872 | |
| 9873 | nla_put_failure: |
| 9874 | genlmsg_cancel(msg, hdr); |
| 9875 | nlmsg_free(msg); |
| 9876 | return true; |
| 9877 | } |
| 9878 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9879 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 9880 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9881 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9882 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9883 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9884 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9885 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 9886 | |
| 9887 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9888 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 9889 | trace_cfg80211_return_bool(false); |
| 9890 | return false; |
| 9891 | } |
| 9892 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9893 | addr, gfp); |
| 9894 | trace_cfg80211_return_bool(ret); |
| 9895 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9896 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9897 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 9898 | |
| 9899 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 9900 | const u8 *addr, gfp_t gfp) |
| 9901 | { |
| 9902 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9903 | bool ret; |
| 9904 | |
| 9905 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 9906 | |
| 9907 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9908 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 9909 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 9910 | trace_cfg80211_return_bool(false); |
| 9911 | return false; |
| 9912 | } |
| 9913 | ret = __nl80211_unexpected_frame(dev, |
| 9914 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9915 | addr, gfp); |
| 9916 | trace_cfg80211_return_bool(ret); |
| 9917 | return ret; |
| 9918 | } |
| 9919 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9920 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9921 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9922 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9923 | int freq, int sig_dbm, |
| 9924 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9925 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9926 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9927 | struct sk_buff *msg; |
| 9928 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9929 | |
| 9930 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9931 | if (!msg) |
| 9932 | return -ENOMEM; |
| 9933 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9934 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9935 | if (!hdr) { |
| 9936 | nlmsg_free(msg); |
| 9937 | return -ENOMEM; |
| 9938 | } |
| 9939 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9940 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9941 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9942 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 9943 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9944 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9945 | (sig_dbm && |
| 9946 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9947 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9948 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9949 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9950 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9951 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9952 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9953 | |
| 9954 | nla_put_failure: |
| 9955 | genlmsg_cancel(msg, hdr); |
| 9956 | nlmsg_free(msg); |
| 9957 | return -ENOBUFS; |
| 9958 | } |
| 9959 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9960 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 9961 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9962 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9963 | struct wiphy *wiphy = wdev->wiphy; |
| 9964 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9965 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9966 | struct sk_buff *msg; |
| 9967 | void *hdr; |
| 9968 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9969 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 9970 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9972 | if (!msg) |
| 9973 | return; |
| 9974 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9975 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9976 | if (!hdr) { |
| 9977 | nlmsg_free(msg); |
| 9978 | return; |
| 9979 | } |
| 9980 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9981 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9982 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9983 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 9984 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9985 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 9986 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 9987 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 9988 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9989 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9990 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9991 | |
| 9992 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 9993 | return; |
| 9994 | |
| 9995 | nla_put_failure: |
| 9996 | genlmsg_cancel(msg, hdr); |
| 9997 | nlmsg_free(msg); |
| 9998 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9999 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10000 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10001 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10002 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10003 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10004 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10005 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10006 | struct wiphy *wiphy = wdev->wiphy; |
| 10007 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10008 | struct sk_buff *msg; |
| 10009 | struct nlattr *pinfoattr; |
| 10010 | void *hdr; |
| 10011 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10012 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10013 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10015 | if (!msg) |
| 10016 | return; |
| 10017 | |
| 10018 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10019 | if (!hdr) { |
| 10020 | nlmsg_free(msg); |
| 10021 | return; |
| 10022 | } |
| 10023 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10024 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10025 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10026 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10027 | |
| 10028 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10029 | if (!pinfoattr) |
| 10030 | goto nla_put_failure; |
| 10031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10032 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10033 | rssi_event)) |
| 10034 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10035 | |
| 10036 | nla_nest_end(msg, pinfoattr); |
| 10037 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10038 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10039 | |
| 10040 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10041 | nl80211_mlme_mcgrp.id, gfp); |
| 10042 | return; |
| 10043 | |
| 10044 | nla_put_failure: |
| 10045 | genlmsg_cancel(msg, hdr); |
| 10046 | nlmsg_free(msg); |
| 10047 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10048 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10049 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10050 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10051 | struct net_device *netdev, const u8 *bssid, |
| 10052 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10053 | { |
| 10054 | struct sk_buff *msg; |
| 10055 | struct nlattr *rekey_attr; |
| 10056 | void *hdr; |
| 10057 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10059 | if (!msg) |
| 10060 | return; |
| 10061 | |
| 10062 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10063 | if (!hdr) { |
| 10064 | nlmsg_free(msg); |
| 10065 | return; |
| 10066 | } |
| 10067 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10068 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10069 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10070 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10071 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10072 | |
| 10073 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10074 | if (!rekey_attr) |
| 10075 | goto nla_put_failure; |
| 10076 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10077 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10078 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10079 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10080 | |
| 10081 | nla_nest_end(msg, rekey_attr); |
| 10082 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10083 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10084 | |
| 10085 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10086 | nl80211_mlme_mcgrp.id, gfp); |
| 10087 | return; |
| 10088 | |
| 10089 | nla_put_failure: |
| 10090 | genlmsg_cancel(msg, hdr); |
| 10091 | nlmsg_free(msg); |
| 10092 | } |
| 10093 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10094 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10095 | const u8 *replay_ctr, gfp_t gfp) |
| 10096 | { |
| 10097 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10098 | struct wiphy *wiphy = wdev->wiphy; |
| 10099 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10100 | |
| 10101 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10102 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10103 | } |
| 10104 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10105 | |
| 10106 | static void |
| 10107 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10108 | struct net_device *netdev, int index, |
| 10109 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10110 | { |
| 10111 | struct sk_buff *msg; |
| 10112 | struct nlattr *attr; |
| 10113 | void *hdr; |
| 10114 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10116 | if (!msg) |
| 10117 | return; |
| 10118 | |
| 10119 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10120 | if (!hdr) { |
| 10121 | nlmsg_free(msg); |
| 10122 | return; |
| 10123 | } |
| 10124 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10125 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10126 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10127 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10128 | |
| 10129 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10130 | if (!attr) |
| 10131 | goto nla_put_failure; |
| 10132 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10133 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10134 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10135 | (preauth && |
| 10136 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10137 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10138 | |
| 10139 | nla_nest_end(msg, attr); |
| 10140 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10141 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10142 | |
| 10143 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10144 | nl80211_mlme_mcgrp.id, gfp); |
| 10145 | return; |
| 10146 | |
| 10147 | nla_put_failure: |
| 10148 | genlmsg_cancel(msg, hdr); |
| 10149 | nlmsg_free(msg); |
| 10150 | } |
| 10151 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10152 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10153 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10154 | { |
| 10155 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10156 | struct wiphy *wiphy = wdev->wiphy; |
| 10157 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10158 | |
| 10159 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10160 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10161 | } |
| 10162 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10163 | |
| 10164 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10165 | struct net_device *netdev, |
| 10166 | struct cfg80211_chan_def *chandef, |
| 10167 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10168 | { |
| 10169 | struct sk_buff *msg; |
| 10170 | void *hdr; |
| 10171 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10172 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10173 | if (!msg) |
| 10174 | return; |
| 10175 | |
| 10176 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10177 | if (!hdr) { |
| 10178 | nlmsg_free(msg); |
| 10179 | return; |
| 10180 | } |
| 10181 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10182 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10183 | goto nla_put_failure; |
| 10184 | |
| 10185 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10186 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10187 | |
| 10188 | genlmsg_end(msg, hdr); |
| 10189 | |
| 10190 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10191 | nl80211_mlme_mcgrp.id, gfp); |
| 10192 | return; |
| 10193 | |
| 10194 | nla_put_failure: |
| 10195 | genlmsg_cancel(msg, hdr); |
| 10196 | nlmsg_free(msg); |
| 10197 | } |
| 10198 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10199 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10200 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10201 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10202 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10203 | struct wiphy *wiphy = wdev->wiphy; |
| 10204 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10205 | |
| 10206 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10207 | |
| 10208 | wdev_lock(wdev); |
| 10209 | |
| 10210 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10211 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10212 | goto out; |
| 10213 | |
| 10214 | wdev->channel = chandef->chan; |
| 10215 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10216 | out: |
| 10217 | wdev_unlock(wdev); |
| 10218 | return; |
| 10219 | } |
| 10220 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10221 | |
| 10222 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10223 | const u8 *peer, u32 num_packets, |
| 10224 | u32 rate, u32 intvl, gfp_t gfp) |
| 10225 | { |
| 10226 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10227 | struct wiphy *wiphy = wdev->wiphy; |
| 10228 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10229 | struct sk_buff *msg; |
| 10230 | struct nlattr *pinfoattr; |
| 10231 | void *hdr; |
| 10232 | |
| 10233 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10234 | if (!msg) |
| 10235 | return; |
| 10236 | |
| 10237 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10238 | if (!hdr) { |
| 10239 | nlmsg_free(msg); |
| 10240 | return; |
| 10241 | } |
| 10242 | |
| 10243 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10244 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10245 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10246 | goto nla_put_failure; |
| 10247 | |
| 10248 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10249 | if (!pinfoattr) |
| 10250 | goto nla_put_failure; |
| 10251 | |
| 10252 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10253 | goto nla_put_failure; |
| 10254 | |
| 10255 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10256 | goto nla_put_failure; |
| 10257 | |
| 10258 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10259 | goto nla_put_failure; |
| 10260 | |
| 10261 | nla_nest_end(msg, pinfoattr); |
| 10262 | |
| 10263 | genlmsg_end(msg, hdr); |
| 10264 | |
| 10265 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10266 | nl80211_mlme_mcgrp.id, gfp); |
| 10267 | return; |
| 10268 | |
| 10269 | nla_put_failure: |
| 10270 | genlmsg_cancel(msg, hdr); |
| 10271 | nlmsg_free(msg); |
| 10272 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10273 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10274 | |
| 10275 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10276 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10277 | struct cfg80211_chan_def *chandef, |
| 10278 | enum nl80211_radar_event event, |
| 10279 | struct net_device *netdev, gfp_t gfp) |
| 10280 | { |
| 10281 | struct sk_buff *msg; |
| 10282 | void *hdr; |
| 10283 | |
| 10284 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10285 | if (!msg) |
| 10286 | return; |
| 10287 | |
| 10288 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10289 | if (!hdr) { |
| 10290 | nlmsg_free(msg); |
| 10291 | return; |
| 10292 | } |
| 10293 | |
| 10294 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10295 | goto nla_put_failure; |
| 10296 | |
| 10297 | /* NOP and radar events don't need a netdev parameter */ |
| 10298 | if (netdev) { |
| 10299 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10300 | |
| 10301 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10302 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10303 | goto nla_put_failure; |
| 10304 | } |
| 10305 | |
| 10306 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10307 | goto nla_put_failure; |
| 10308 | |
| 10309 | if (nl80211_send_chandef(msg, chandef)) |
| 10310 | goto nla_put_failure; |
| 10311 | |
| 10312 | if (genlmsg_end(msg, hdr) < 0) { |
| 10313 | nlmsg_free(msg); |
| 10314 | return; |
| 10315 | } |
| 10316 | |
| 10317 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10318 | nl80211_mlme_mcgrp.id, gfp); |
| 10319 | return; |
| 10320 | |
| 10321 | nla_put_failure: |
| 10322 | genlmsg_cancel(msg, hdr); |
| 10323 | nlmsg_free(msg); |
| 10324 | } |
| 10325 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10326 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10327 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10328 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10329 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10330 | struct wiphy *wiphy = wdev->wiphy; |
| 10331 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10332 | struct sk_buff *msg; |
| 10333 | struct nlattr *pinfoattr; |
| 10334 | void *hdr; |
| 10335 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10336 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10337 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10338 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10339 | if (!msg) |
| 10340 | return; |
| 10341 | |
| 10342 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10343 | if (!hdr) { |
| 10344 | nlmsg_free(msg); |
| 10345 | return; |
| 10346 | } |
| 10347 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10348 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10349 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10350 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10351 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10352 | |
| 10353 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10354 | if (!pinfoattr) |
| 10355 | goto nla_put_failure; |
| 10356 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10357 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10358 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10359 | |
| 10360 | nla_nest_end(msg, pinfoattr); |
| 10361 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10362 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10363 | |
| 10364 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10365 | nl80211_mlme_mcgrp.id, gfp); |
| 10366 | return; |
| 10367 | |
| 10368 | nla_put_failure: |
| 10369 | genlmsg_cancel(msg, hdr); |
| 10370 | nlmsg_free(msg); |
| 10371 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10372 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10373 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10374 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10375 | u64 cookie, bool acked, gfp_t gfp) |
| 10376 | { |
| 10377 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10378 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10379 | struct sk_buff *msg; |
| 10380 | void *hdr; |
| 10381 | int err; |
| 10382 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10383 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10384 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10386 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10387 | if (!msg) |
| 10388 | return; |
| 10389 | |
| 10390 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10391 | if (!hdr) { |
| 10392 | nlmsg_free(msg); |
| 10393 | return; |
| 10394 | } |
| 10395 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10396 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10397 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10398 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10399 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10400 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10401 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10402 | |
| 10403 | err = genlmsg_end(msg, hdr); |
| 10404 | if (err < 0) { |
| 10405 | nlmsg_free(msg); |
| 10406 | return; |
| 10407 | } |
| 10408 | |
| 10409 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10410 | nl80211_mlme_mcgrp.id, gfp); |
| 10411 | return; |
| 10412 | |
| 10413 | nla_put_failure: |
| 10414 | genlmsg_cancel(msg, hdr); |
| 10415 | nlmsg_free(msg); |
| 10416 | } |
| 10417 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10418 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10419 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10420 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10421 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10422 | { |
| 10423 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10424 | struct sk_buff *msg; |
| 10425 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10426 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10427 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10428 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10429 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10430 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10431 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10432 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10433 | if (!msg) { |
| 10434 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10435 | return; |
| 10436 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10437 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10438 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10439 | if (!hdr) |
| 10440 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10441 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10442 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10443 | (freq && |
| 10444 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10445 | (sig_dbm && |
| 10446 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10447 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10448 | goto nla_put_failure; |
| 10449 | |
| 10450 | genlmsg_end(msg, hdr); |
| 10451 | |
| 10452 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10453 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10454 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10455 | return; |
| 10456 | |
| 10457 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10458 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10459 | if (hdr) |
| 10460 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10461 | nlmsg_free(msg); |
| 10462 | } |
| 10463 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10464 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10465 | #ifdef CONFIG_PM |
| 10466 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10467 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10468 | gfp_t gfp) |
| 10469 | { |
| 10470 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10471 | struct sk_buff *msg; |
| 10472 | void *hdr; |
| 10473 | int err, size = 200; |
| 10474 | |
| 10475 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10476 | |
| 10477 | if (wakeup) |
| 10478 | size += wakeup->packet_present_len; |
| 10479 | |
| 10480 | msg = nlmsg_new(size, gfp); |
| 10481 | if (!msg) |
| 10482 | return; |
| 10483 | |
| 10484 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 10485 | if (!hdr) |
| 10486 | goto free_msg; |
| 10487 | |
| 10488 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10489 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10490 | goto free_msg; |
| 10491 | |
| 10492 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10493 | wdev->netdev->ifindex)) |
| 10494 | goto free_msg; |
| 10495 | |
| 10496 | if (wakeup) { |
| 10497 | struct nlattr *reasons; |
| 10498 | |
| 10499 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10500 | |
| 10501 | if (wakeup->disconnect && |
| 10502 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 10503 | goto free_msg; |
| 10504 | if (wakeup->magic_pkt && |
| 10505 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 10506 | goto free_msg; |
| 10507 | if (wakeup->gtk_rekey_failure && |
| 10508 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 10509 | goto free_msg; |
| 10510 | if (wakeup->eap_identity_req && |
| 10511 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 10512 | goto free_msg; |
| 10513 | if (wakeup->four_way_handshake && |
| 10514 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 10515 | goto free_msg; |
| 10516 | if (wakeup->rfkill_release && |
| 10517 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 10518 | goto free_msg; |
| 10519 | |
| 10520 | if (wakeup->pattern_idx >= 0 && |
| 10521 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 10522 | wakeup->pattern_idx)) |
| 10523 | goto free_msg; |
| 10524 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10525 | if (wakeup->tcp_match) |
| 10526 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 10527 | |
| 10528 | if (wakeup->tcp_connlost) |
| 10529 | nla_put_flag(msg, |
| 10530 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 10531 | |
| 10532 | if (wakeup->tcp_nomoretokens) |
| 10533 | nla_put_flag(msg, |
| 10534 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 10535 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10536 | if (wakeup->packet) { |
| 10537 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 10538 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 10539 | |
| 10540 | if (!wakeup->packet_80211) { |
| 10541 | pkt_attr = |
| 10542 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 10543 | len_attr = |
| 10544 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 10545 | } |
| 10546 | |
| 10547 | if (wakeup->packet_len && |
| 10548 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 10549 | goto free_msg; |
| 10550 | |
| 10551 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 10552 | wakeup->packet)) |
| 10553 | goto free_msg; |
| 10554 | } |
| 10555 | |
| 10556 | nla_nest_end(msg, reasons); |
| 10557 | } |
| 10558 | |
| 10559 | err = genlmsg_end(msg, hdr); |
| 10560 | if (err < 0) |
| 10561 | goto free_msg; |
| 10562 | |
| 10563 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10564 | nl80211_mlme_mcgrp.id, gfp); |
| 10565 | return; |
| 10566 | |
| 10567 | free_msg: |
| 10568 | nlmsg_free(msg); |
| 10569 | } |
| 10570 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 10571 | #endif |
| 10572 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10573 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10574 | enum nl80211_tdls_operation oper, |
| 10575 | u16 reason_code, gfp_t gfp) |
| 10576 | { |
| 10577 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10578 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10579 | struct sk_buff *msg; |
| 10580 | void *hdr; |
| 10581 | int err; |
| 10582 | |
| 10583 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10584 | reason_code); |
| 10585 | |
| 10586 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10587 | if (!msg) |
| 10588 | return; |
| 10589 | |
| 10590 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10591 | if (!hdr) { |
| 10592 | nlmsg_free(msg); |
| 10593 | return; |
| 10594 | } |
| 10595 | |
| 10596 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10597 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10598 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10599 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10600 | (reason_code > 0 && |
| 10601 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10602 | goto nla_put_failure; |
| 10603 | |
| 10604 | err = genlmsg_end(msg, hdr); |
| 10605 | if (err < 0) { |
| 10606 | nlmsg_free(msg); |
| 10607 | return; |
| 10608 | } |
| 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 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10619 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10620 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10621 | unsigned long state, |
| 10622 | void *_notify) |
| 10623 | { |
| 10624 | struct netlink_notify *notify = _notify; |
| 10625 | struct cfg80211_registered_device *rdev; |
| 10626 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10627 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10628 | |
| 10629 | if (state != NETLINK_URELEASE) |
| 10630 | return NOTIFY_DONE; |
| 10631 | |
| 10632 | rcu_read_lock(); |
| 10633 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10634 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10635 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10636 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10637 | |
| 10638 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10639 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10640 | list) { |
| 10641 | if (reg->nlportid == notify->portid) { |
| 10642 | list_del(®->list); |
| 10643 | kfree(reg); |
| 10644 | break; |
| 10645 | } |
| 10646 | } |
| 10647 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10648 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10649 | |
| 10650 | rcu_read_unlock(); |
| 10651 | |
| 10652 | return NOTIFY_DONE; |
| 10653 | } |
| 10654 | |
| 10655 | static struct notifier_block nl80211_netlink_notifier = { |
| 10656 | .notifier_call = nl80211_netlink_notify, |
| 10657 | }; |
| 10658 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10659 | void cfg80211_ft_event(struct net_device *netdev, |
| 10660 | struct cfg80211_ft_event_params *ft_event) |
| 10661 | { |
| 10662 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 10663 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10664 | struct sk_buff *msg; |
| 10665 | void *hdr; |
| 10666 | int err; |
| 10667 | |
| 10668 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 10669 | |
| 10670 | if (!ft_event->target_ap) |
| 10671 | return; |
| 10672 | |
| 10673 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10674 | if (!msg) |
| 10675 | return; |
| 10676 | |
| 10677 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 10678 | if (!hdr) { |
| 10679 | nlmsg_free(msg); |
| 10680 | return; |
| 10681 | } |
| 10682 | |
| 10683 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 10684 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 10685 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 10686 | if (ft_event->ies) |
| 10687 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 10688 | if (ft_event->ric_ies) |
| 10689 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 10690 | ft_event->ric_ies); |
| 10691 | |
| 10692 | err = genlmsg_end(msg, hdr); |
| 10693 | if (err < 0) { |
| 10694 | nlmsg_free(msg); |
| 10695 | return; |
| 10696 | } |
| 10697 | |
| 10698 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10699 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 10700 | } |
| 10701 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 10702 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10703 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 10704 | { |
| 10705 | struct cfg80211_registered_device *rdev; |
| 10706 | struct sk_buff *msg; |
| 10707 | void *hdr; |
| 10708 | u32 nlportid; |
| 10709 | |
| 10710 | rdev = wiphy_to_dev(wdev->wiphy); |
| 10711 | if (!rdev->crit_proto_nlportid) |
| 10712 | return; |
| 10713 | |
| 10714 | nlportid = rdev->crit_proto_nlportid; |
| 10715 | rdev->crit_proto_nlportid = 0; |
| 10716 | |
| 10717 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10718 | if (!msg) |
| 10719 | return; |
| 10720 | |
| 10721 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 10722 | if (!hdr) |
| 10723 | goto nla_put_failure; |
| 10724 | |
| 10725 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10726 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10727 | goto nla_put_failure; |
| 10728 | |
| 10729 | genlmsg_end(msg, hdr); |
| 10730 | |
| 10731 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 10732 | return; |
| 10733 | |
| 10734 | nla_put_failure: |
| 10735 | if (hdr) |
| 10736 | genlmsg_cancel(msg, hdr); |
| 10737 | nlmsg_free(msg); |
| 10738 | |
| 10739 | } |
| 10740 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 10741 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10742 | /* initialisation/exit functions */ |
| 10743 | |
| 10744 | int nl80211_init(void) |
| 10745 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10746 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10747 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10748 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10749 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10750 | if (err) |
| 10751 | return err; |
| 10752 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10753 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10754 | if (err) |
| 10755 | goto err_out; |
| 10756 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10757 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10758 | if (err) |
| 10759 | goto err_out; |
| 10760 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10761 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10762 | if (err) |
| 10763 | goto err_out; |
| 10764 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10765 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10766 | if (err) |
| 10767 | goto err_out; |
| 10768 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10769 | #ifdef CONFIG_NL80211_TESTMODE |
| 10770 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10771 | if (err) |
| 10772 | goto err_out; |
| 10773 | #endif |
| 10774 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10775 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10776 | if (err) |
| 10777 | goto err_out; |
| 10778 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10779 | return 0; |
| 10780 | err_out: |
| 10781 | genl_unregister_family(&nl80211_fam); |
| 10782 | return err; |
| 10783 | } |
| 10784 | |
| 10785 | void nl80211_exit(void) |
| 10786 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10787 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10788 | genl_unregister_family(&nl80211_fam); |
| 10789 | } |