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 | 36aedc90 | 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: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 803 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 804 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 805 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 806 | return -ENOLINK; |
| 807 | break; |
| 808 | default: |
| 809 | return -EINVAL; |
| 810 | } |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 815 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 816 | { |
| 817 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 818 | int i; |
| 819 | |
| 820 | if (!nl_modes) |
| 821 | goto nla_put_failure; |
| 822 | |
| 823 | i = 0; |
| 824 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 825 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 826 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 827 | ifmodes >>= 1; |
| 828 | i++; |
| 829 | } |
| 830 | |
| 831 | nla_nest_end(msg, nl_modes); |
| 832 | return 0; |
| 833 | |
| 834 | nla_put_failure: |
| 835 | return -ENOBUFS; |
| 836 | } |
| 837 | |
| 838 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 839 | struct sk_buff *msg, |
| 840 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 841 | { |
| 842 | struct nlattr *nl_combis; |
| 843 | int i, j; |
| 844 | |
| 845 | nl_combis = nla_nest_start(msg, |
| 846 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 847 | if (!nl_combis) |
| 848 | goto nla_put_failure; |
| 849 | |
| 850 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 851 | const struct ieee80211_iface_combination *c; |
| 852 | struct nlattr *nl_combi, *nl_limits; |
| 853 | |
| 854 | c = &wiphy->iface_combinations[i]; |
| 855 | |
| 856 | nl_combi = nla_nest_start(msg, i + 1); |
| 857 | if (!nl_combi) |
| 858 | goto nla_put_failure; |
| 859 | |
| 860 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 861 | if (!nl_limits) |
| 862 | goto nla_put_failure; |
| 863 | |
| 864 | for (j = 0; j < c->n_limits; j++) { |
| 865 | struct nlattr *nl_limit; |
| 866 | |
| 867 | nl_limit = nla_nest_start(msg, j + 1); |
| 868 | if (!nl_limit) |
| 869 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 870 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 871 | c->limits[j].max)) |
| 872 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 873 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 874 | c->limits[j].types)) |
| 875 | goto nla_put_failure; |
| 876 | nla_nest_end(msg, nl_limit); |
| 877 | } |
| 878 | |
| 879 | nla_nest_end(msg, nl_limits); |
| 880 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 881 | if (c->beacon_int_infra_match && |
| 882 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 883 | goto nla_put_failure; |
| 884 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 885 | c->num_different_channels) || |
| 886 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 887 | c->max_interfaces)) |
| 888 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 889 | if (large && |
| 890 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 891 | c->radar_detect_widths)) |
| 892 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 893 | |
| 894 | nla_nest_end(msg, nl_combi); |
| 895 | } |
| 896 | |
| 897 | nla_nest_end(msg, nl_combis); |
| 898 | |
| 899 | return 0; |
| 900 | nla_put_failure: |
| 901 | return -ENOBUFS; |
| 902 | } |
| 903 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 904 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 905 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 906 | struct sk_buff *msg) |
| 907 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 908 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 909 | struct nlattr *nl_tcp; |
| 910 | |
| 911 | if (!tcp) |
| 912 | return 0; |
| 913 | |
| 914 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 915 | if (!nl_tcp) |
| 916 | return -ENOBUFS; |
| 917 | |
| 918 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 919 | tcp->data_payload_max)) |
| 920 | return -ENOBUFS; |
| 921 | |
| 922 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 923 | tcp->data_payload_max)) |
| 924 | return -ENOBUFS; |
| 925 | |
| 926 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 927 | return -ENOBUFS; |
| 928 | |
| 929 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 930 | sizeof(*tcp->tok), tcp->tok)) |
| 931 | return -ENOBUFS; |
| 932 | |
| 933 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 934 | tcp->data_interval_max)) |
| 935 | return -ENOBUFS; |
| 936 | |
| 937 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 938 | tcp->wake_payload_max)) |
| 939 | return -ENOBUFS; |
| 940 | |
| 941 | nla_nest_end(msg, nl_tcp); |
| 942 | return 0; |
| 943 | } |
| 944 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 945 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 946 | struct cfg80211_registered_device *dev, |
| 947 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 948 | { |
| 949 | struct nlattr *nl_wowlan; |
| 950 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 951 | if (!dev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 952 | return 0; |
| 953 | |
| 954 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 955 | if (!nl_wowlan) |
| 956 | return -ENOBUFS; |
| 957 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 958 | if (((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 959 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 960 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 961 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 962 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 963 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 964 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 965 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 966 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 967 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 968 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 969 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 970 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 971 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 972 | ((dev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 973 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 974 | return -ENOBUFS; |
| 975 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 976 | if (dev->wiphy.wowlan->n_patterns) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 977 | struct nl80211_wowlan_pattern_support pat = { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 978 | .max_patterns = dev->wiphy.wowlan->n_patterns, |
| 979 | .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, |
| 980 | .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, |
| 981 | .max_pkt_offset = dev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 982 | }; |
| 983 | |
| 984 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 985 | sizeof(pat), &pat)) |
| 986 | return -ENOBUFS; |
| 987 | } |
| 988 | |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 989 | if (large && nl80211_send_wowlan_tcp_caps(dev, msg)) |
| 990 | return -ENOBUFS; |
| 991 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 992 | nla_nest_end(msg, nl_wowlan); |
| 993 | |
| 994 | return 0; |
| 995 | } |
| 996 | #endif |
| 997 | |
| 998 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 999 | struct ieee80211_supported_band *sband) |
| 1000 | { |
| 1001 | struct nlattr *nl_rates, *nl_rate; |
| 1002 | struct ieee80211_rate *rate; |
| 1003 | int i; |
| 1004 | |
| 1005 | /* add HT info */ |
| 1006 | if (sband->ht_cap.ht_supported && |
| 1007 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1008 | sizeof(sband->ht_cap.mcs), |
| 1009 | &sband->ht_cap.mcs) || |
| 1010 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1011 | sband->ht_cap.cap) || |
| 1012 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1013 | sband->ht_cap.ampdu_factor) || |
| 1014 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1015 | sband->ht_cap.ampdu_density))) |
| 1016 | return -ENOBUFS; |
| 1017 | |
| 1018 | /* add VHT info */ |
| 1019 | if (sband->vht_cap.vht_supported && |
| 1020 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1021 | sizeof(sband->vht_cap.vht_mcs), |
| 1022 | &sband->vht_cap.vht_mcs) || |
| 1023 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1024 | sband->vht_cap.cap))) |
| 1025 | return -ENOBUFS; |
| 1026 | |
| 1027 | /* add bitrates */ |
| 1028 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1029 | if (!nl_rates) |
| 1030 | return -ENOBUFS; |
| 1031 | |
| 1032 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1033 | nl_rate = nla_nest_start(msg, i); |
| 1034 | if (!nl_rate) |
| 1035 | return -ENOBUFS; |
| 1036 | |
| 1037 | rate = &sband->bitrates[i]; |
| 1038 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1039 | rate->bitrate)) |
| 1040 | return -ENOBUFS; |
| 1041 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1042 | nla_put_flag(msg, |
| 1043 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1044 | return -ENOBUFS; |
| 1045 | |
| 1046 | nla_nest_end(msg, nl_rate); |
| 1047 | } |
| 1048 | |
| 1049 | nla_nest_end(msg, nl_rates); |
| 1050 | |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | static int |
| 1055 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1056 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1057 | { |
| 1058 | u16 stypes; |
| 1059 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1060 | enum nl80211_iftype ift; |
| 1061 | int i; |
| 1062 | |
| 1063 | if (!mgmt_stypes) |
| 1064 | return 0; |
| 1065 | |
| 1066 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1067 | if (!nl_ifs) |
| 1068 | return -ENOBUFS; |
| 1069 | |
| 1070 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1071 | nl_ftypes = nla_nest_start(msg, ift); |
| 1072 | if (!nl_ftypes) |
| 1073 | return -ENOBUFS; |
| 1074 | i = 0; |
| 1075 | stypes = mgmt_stypes[ift].tx; |
| 1076 | while (stypes) { |
| 1077 | if ((stypes & 1) && |
| 1078 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1079 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1080 | return -ENOBUFS; |
| 1081 | stypes >>= 1; |
| 1082 | i++; |
| 1083 | } |
| 1084 | nla_nest_end(msg, nl_ftypes); |
| 1085 | } |
| 1086 | |
| 1087 | nla_nest_end(msg, nl_ifs); |
| 1088 | |
| 1089 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1090 | if (!nl_ifs) |
| 1091 | return -ENOBUFS; |
| 1092 | |
| 1093 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1094 | nl_ftypes = nla_nest_start(msg, ift); |
| 1095 | if (!nl_ftypes) |
| 1096 | return -ENOBUFS; |
| 1097 | i = 0; |
| 1098 | stypes = mgmt_stypes[ift].rx; |
| 1099 | while (stypes) { |
| 1100 | if ((stypes & 1) && |
| 1101 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1102 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1103 | return -ENOBUFS; |
| 1104 | stypes >>= 1; |
| 1105 | i++; |
| 1106 | } |
| 1107 | nla_nest_end(msg, nl_ftypes); |
| 1108 | } |
| 1109 | nla_nest_end(msg, nl_ifs); |
| 1110 | |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
| 1114 | static int nl80211_send_wiphy(struct cfg80211_registered_device *dev, |
| 1115 | struct sk_buff *msg, u32 portid, u32 seq, |
| 1116 | int flags, bool split, long *split_start, |
| 1117 | long *band_start, long *chan_start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1118 | { |
| 1119 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1120 | struct nlattr *nl_bands, *nl_band; |
| 1121 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1122 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1123 | enum ieee80211_band band; |
| 1124 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1125 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1126 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 1127 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1128 | long start = 0, start_chan = 0, start_band = 0; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1129 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1130 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1131 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1132 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1133 | return -ENOBUFS; |
| 1134 | |
| 1135 | /* allow always using the variables */ |
| 1136 | if (!split) { |
| 1137 | split_start = &start; |
| 1138 | band_start = &start_band; |
| 1139 | chan_start = &start_chan; |
| 1140 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1141 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1143 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
| 1144 | wiphy_name(&dev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1145 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1146 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1147 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1148 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1149 | switch (*split_start) { |
| 1150 | case 0: |
| 1151 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 1152 | dev->wiphy.retry_short) || |
| 1153 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 1154 | dev->wiphy.retry_long) || |
| 1155 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 1156 | dev->wiphy.frag_threshold) || |
| 1157 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 1158 | dev->wiphy.rts_threshold) || |
| 1159 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 1160 | dev->wiphy.coverage_class) || |
| 1161 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 1162 | dev->wiphy.max_scan_ssids) || |
| 1163 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 1164 | dev->wiphy.max_sched_scan_ssids) || |
| 1165 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 1166 | dev->wiphy.max_scan_ie_len) || |
| 1167 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 1168 | dev->wiphy.max_sched_scan_ie_len) || |
| 1169 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 1170 | dev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1171 | goto nla_put_failure; |
| 1172 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1173 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 1174 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1175 | goto nla_put_failure; |
| 1176 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 1177 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1178 | goto nla_put_failure; |
| 1179 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 1180 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1181 | goto nla_put_failure; |
| 1182 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 1183 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1184 | goto nla_put_failure; |
| 1185 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 1186 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1187 | goto nla_put_failure; |
| 1188 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 1189 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1190 | goto nla_put_failure; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame^] | 1191 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
| 1192 | nla_put_flag(msg, WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 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 | 940d0ac | 2013-06-11 16:51:03 +0200 | [diff] [blame] | 1547 | if (!netdev) { |
| 1548 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | return -ENODEV; |
Johannes Berg | 940d0ac | 2013-06-11 16:51:03 +0200 | [diff] [blame] | 1550 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1551 | if (netdev->ieee80211_ptr) { |
| 1552 | dev = wiphy_to_dev( |
| 1553 | netdev->ieee80211_ptr->wiphy); |
| 1554 | filter_wiphy = dev->wiphy_idx; |
| 1555 | } |
| 1556 | dev_put(netdev); |
| 1557 | } |
| 1558 | } |
| 1559 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1560 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1561 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1562 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1563 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1564 | continue; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | if (filter_wiphy != -1 && dev->wiphy_idx != filter_wiphy) |
| 1566 | continue; |
| 1567 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1568 | do { |
| 1569 | ret = nl80211_send_wiphy(dev, skb, |
| 1570 | NETLINK_CB(cb->skb).portid, |
| 1571 | cb->nlh->nlmsg_seq, |
| 1572 | NLM_F_MULTI, |
| 1573 | split, &cb->args[1], |
| 1574 | &cb->args[2], |
| 1575 | &cb->args[3]); |
| 1576 | if (ret < 0) { |
| 1577 | /* |
| 1578 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1579 | * or EMSGSIZE returned), this SKB is still |
| 1580 | * empty (so it's not too big because another |
| 1581 | * wiphy dataset is already in the skb) and |
| 1582 | * we've not tried to adjust the dump allocation |
| 1583 | * yet ... then adjust the alloc size to be |
| 1584 | * bigger, and return 1 but with the empty skb. |
| 1585 | * This results in an empty message being RX'ed |
| 1586 | * in userspace, but that is ignored. |
| 1587 | * |
| 1588 | * We can then retry with the larger buffer. |
| 1589 | */ |
| 1590 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
| 1591 | !skb->len && |
| 1592 | cb->min_dump_alloc < 4096) { |
| 1593 | cb->min_dump_alloc = 4096; |
Johannes Berg | 940d0ac | 2013-06-11 16:51:03 +0200 | [diff] [blame] | 1594 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1595 | return 1; |
| 1596 | } |
| 1597 | idx--; |
| 1598 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1599 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1600 | } while (cb->args[1] > 0); |
| 1601 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1602 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1603 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1604 | |
| 1605 | cb->args[0] = idx; |
| 1606 | |
| 1607 | return skb->len; |
| 1608 | } |
| 1609 | |
| 1610 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1611 | { |
| 1612 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1613 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1614 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1615 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1616 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1617 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1618 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1619 | if (nl80211_send_wiphy(dev, msg, info->snd_portid, info->snd_seq, 0, |
| 1620 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1621 | nlmsg_free(msg); |
| 1622 | return -ENOBUFS; |
| 1623 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1624 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1625 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1626 | } |
| 1627 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1628 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1629 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1630 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1631 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1632 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1633 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1634 | }; |
| 1635 | |
| 1636 | static int parse_txq_params(struct nlattr *tb[], |
| 1637 | struct ieee80211_txq_params *txq_params) |
| 1638 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1639 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1640 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1641 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1642 | return -EINVAL; |
| 1643 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1644 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1645 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1646 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1647 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1648 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1649 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1650 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1651 | return -EINVAL; |
| 1652 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1653 | return 0; |
| 1654 | } |
| 1655 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1656 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1657 | { |
| 1658 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1659 | * You can only set the channel explicitly for WDS interfaces, |
| 1660 | * all others have their channel managed via their respective |
| 1661 | * "establish a connection" command (connect, join, ...) |
| 1662 | * |
| 1663 | * For AP/GO and mesh mode, the channel can be set with the |
| 1664 | * channel userspace API, but is only stored and passed to the |
| 1665 | * low-level driver when the AP starts or the mesh is joined. |
| 1666 | * This is for backward compatibility, userspace can also give |
| 1667 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1668 | * |
| 1669 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1670 | * whatever else is going on, so they have their own special |
| 1671 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1672 | */ |
| 1673 | return !wdev || |
| 1674 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1675 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1676 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1677 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1678 | } |
| 1679 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1680 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1681 | struct genl_info *info, |
| 1682 | struct cfg80211_chan_def *chandef) |
| 1683 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1684 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1685 | |
| 1686 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1687 | return -EINVAL; |
| 1688 | |
| 1689 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1690 | |
| 1691 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1692 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1693 | chandef->center_freq1 = control_freq; |
| 1694 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1695 | |
| 1696 | /* Primary channel not allowed */ |
| 1697 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1698 | return -EINVAL; |
| 1699 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1700 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1701 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1702 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1703 | chantype = nla_get_u32( |
| 1704 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1705 | |
| 1706 | switch (chantype) { |
| 1707 | case NL80211_CHAN_NO_HT: |
| 1708 | case NL80211_CHAN_HT20: |
| 1709 | case NL80211_CHAN_HT40PLUS: |
| 1710 | case NL80211_CHAN_HT40MINUS: |
| 1711 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1712 | chantype); |
| 1713 | break; |
| 1714 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1715 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1716 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1717 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1718 | chandef->width = |
| 1719 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1720 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1721 | chandef->center_freq1 = |
| 1722 | nla_get_u32( |
| 1723 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1724 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1725 | chandef->center_freq2 = |
| 1726 | nla_get_u32( |
| 1727 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1728 | } |
| 1729 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1730 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1731 | return -EINVAL; |
| 1732 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1733 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1734 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1735 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1736 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame^] | 1737 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1738 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1739 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1740 | return -EINVAL; |
| 1741 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1742 | return 0; |
| 1743 | } |
| 1744 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1745 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1746 | struct wireless_dev *wdev, |
| 1747 | struct genl_info *info) |
| 1748 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1749 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1750 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1751 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1752 | |
| 1753 | if (wdev) |
| 1754 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1755 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1756 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1757 | return -EOPNOTSUPP; |
| 1758 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1759 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1760 | if (result) |
| 1761 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1762 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1763 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1764 | case NL80211_IFTYPE_AP: |
| 1765 | case NL80211_IFTYPE_P2P_GO: |
| 1766 | if (wdev->beacon_interval) { |
| 1767 | result = -EBUSY; |
| 1768 | break; |
| 1769 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1770 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1771 | result = -EINVAL; |
| 1772 | break; |
| 1773 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1774 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1775 | result = 0; |
| 1776 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1777 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1778 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1779 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1780 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1781 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1782 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1783 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1784 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1785 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1786 | |
| 1787 | return result; |
| 1788 | } |
| 1789 | |
| 1790 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1791 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1793 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1794 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1795 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1796 | } |
| 1797 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1798 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1799 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1801 | struct net_device *dev = info->user_ptr[1]; |
| 1802 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1803 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1804 | |
| 1805 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1806 | return -EINVAL; |
| 1807 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1808 | if (netif_running(dev)) |
| 1809 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1810 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1811 | if (!rdev->ops->set_wds_peer) |
| 1812 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1813 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1814 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1815 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1816 | |
| 1817 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1818 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1822 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1823 | { |
| 1824 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1825 | struct net_device *netdev = NULL; |
| 1826 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1827 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1828 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1829 | u32 changed; |
| 1830 | u8 retry_short = 0, retry_long = 0; |
| 1831 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1832 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1833 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1834 | ASSERT_RTNL(); |
| 1835 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1836 | /* |
| 1837 | * Try to find the wiphy and netdev. Normally this |
| 1838 | * function shouldn't need the netdev, but this is |
| 1839 | * done for backward compatibility -- previously |
| 1840 | * setting the channel was done per wiphy, but now |
| 1841 | * it is per netdev. Previous userland like hostapd |
| 1842 | * also passed a netdev to set_wiphy, so that it is |
| 1843 | * possible to let that go to the right netdev! |
| 1844 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1845 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1846 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1847 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1848 | |
| 1849 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1850 | if (netdev && netdev->ieee80211_ptr) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1851 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1852 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1853 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1854 | } |
| 1855 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1856 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1857 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1858 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1859 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1860 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1861 | wdev = NULL; |
| 1862 | netdev = NULL; |
| 1863 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1864 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1865 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1866 | |
| 1867 | /* |
| 1868 | * end workaround code, by now the rdev is available |
| 1869 | * and locked, and wdev may or may not be NULL. |
| 1870 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1871 | |
| 1872 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1873 | result = cfg80211_dev_rename( |
| 1874 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1875 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1876 | if (result) |
| 1877 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1878 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1879 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1880 | struct ieee80211_txq_params txq_params; |
| 1881 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1882 | |
| 1883 | if (!rdev->ops->set_txq_params) { |
| 1884 | result = -EOPNOTSUPP; |
| 1885 | goto bad_res; |
| 1886 | } |
| 1887 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1888 | if (!netdev) { |
| 1889 | result = -EINVAL; |
| 1890 | goto bad_res; |
| 1891 | } |
| 1892 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1893 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1894 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1895 | result = -EINVAL; |
| 1896 | goto bad_res; |
| 1897 | } |
| 1898 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1899 | if (!netif_running(netdev)) { |
| 1900 | result = -ENETDOWN; |
| 1901 | goto bad_res; |
| 1902 | } |
| 1903 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1904 | nla_for_each_nested(nl_txq_params, |
| 1905 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1906 | rem_txq_params) { |
| 1907 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1908 | nla_data(nl_txq_params), |
| 1909 | nla_len(nl_txq_params), |
| 1910 | txq_params_policy); |
| 1911 | result = parse_txq_params(tb, &txq_params); |
| 1912 | if (result) |
| 1913 | goto bad_res; |
| 1914 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1915 | result = rdev_set_txq_params(rdev, netdev, |
| 1916 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1917 | if (result) |
| 1918 | goto bad_res; |
| 1919 | } |
| 1920 | } |
| 1921 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1922 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 1923 | result = __nl80211_set_channel(rdev, |
| 1924 | nl80211_can_set_dev_channel(wdev) ? wdev : NULL, |
| 1925 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1926 | if (result) |
| 1927 | goto bad_res; |
| 1928 | } |
| 1929 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1930 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1931 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1932 | enum nl80211_tx_power_setting type; |
| 1933 | int idx, mbm = 0; |
| 1934 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1935 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 1936 | txp_wdev = NULL; |
| 1937 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1938 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1939 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1940 | goto bad_res; |
| 1941 | } |
| 1942 | |
| 1943 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1944 | type = nla_get_u32(info->attrs[idx]); |
| 1945 | |
| 1946 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1947 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1948 | result = -EINVAL; |
| 1949 | goto bad_res; |
| 1950 | } |
| 1951 | |
| 1952 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1953 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1954 | mbm = nla_get_u32(info->attrs[idx]); |
| 1955 | } |
| 1956 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 1957 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1958 | if (result) |
| 1959 | goto bad_res; |
| 1960 | } |
| 1961 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1962 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1963 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1964 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1965 | if ((!rdev->wiphy.available_antennas_tx && |
| 1966 | !rdev->wiphy.available_antennas_rx) || |
| 1967 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1968 | result = -EOPNOTSUPP; |
| 1969 | goto bad_res; |
| 1970 | } |
| 1971 | |
| 1972 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1973 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1974 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1975 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1976 | * available antenna masks, except for the "all" mask */ |
| 1977 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1978 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1979 | result = -EINVAL; |
| 1980 | goto bad_res; |
| 1981 | } |
| 1982 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1983 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1984 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1985 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 1986 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1987 | if (result) |
| 1988 | goto bad_res; |
| 1989 | } |
| 1990 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1991 | changed = 0; |
| 1992 | |
| 1993 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1994 | retry_short = nla_get_u8( |
| 1995 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1996 | if (retry_short == 0) { |
| 1997 | result = -EINVAL; |
| 1998 | goto bad_res; |
| 1999 | } |
| 2000 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2001 | } |
| 2002 | |
| 2003 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2004 | retry_long = nla_get_u8( |
| 2005 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 2006 | if (retry_long == 0) { |
| 2007 | result = -EINVAL; |
| 2008 | goto bad_res; |
| 2009 | } |
| 2010 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2011 | } |
| 2012 | |
| 2013 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2014 | frag_threshold = nla_get_u32( |
| 2015 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 2016 | if (frag_threshold < 256) { |
| 2017 | result = -EINVAL; |
| 2018 | goto bad_res; |
| 2019 | } |
| 2020 | if (frag_threshold != (u32) -1) { |
| 2021 | /* |
| 2022 | * Fragments (apart from the last one) are required to |
| 2023 | * have even length. Make the fragmentation code |
| 2024 | * simpler by stripping LSB should someone try to use |
| 2025 | * odd threshold value. |
| 2026 | */ |
| 2027 | frag_threshold &= ~0x1; |
| 2028 | } |
| 2029 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2030 | } |
| 2031 | |
| 2032 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2033 | rts_threshold = nla_get_u32( |
| 2034 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2035 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2036 | } |
| 2037 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2038 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 2039 | coverage_class = nla_get_u8( |
| 2040 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2041 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2042 | } |
| 2043 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2044 | if (changed) { |
| 2045 | u8 old_retry_short, old_retry_long; |
| 2046 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2047 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2048 | |
| 2049 | if (!rdev->ops->set_wiphy_params) { |
| 2050 | result = -EOPNOTSUPP; |
| 2051 | goto bad_res; |
| 2052 | } |
| 2053 | |
| 2054 | old_retry_short = rdev->wiphy.retry_short; |
| 2055 | old_retry_long = rdev->wiphy.retry_long; |
| 2056 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2057 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2058 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2059 | |
| 2060 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2061 | rdev->wiphy.retry_short = retry_short; |
| 2062 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2063 | rdev->wiphy.retry_long = retry_long; |
| 2064 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2065 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2066 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2067 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2068 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2069 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2070 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2071 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2072 | if (result) { |
| 2073 | rdev->wiphy.retry_short = old_retry_short; |
| 2074 | rdev->wiphy.retry_long = old_retry_long; |
| 2075 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2076 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2077 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2078 | } |
| 2079 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2080 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 2081 | bad_res: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2082 | if (netdev) |
| 2083 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2084 | return result; |
| 2085 | } |
| 2086 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2087 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2088 | { |
| 2089 | return (u64)wdev->identifier | |
| 2090 | ((u64)wiphy_to_dev(wdev->wiphy)->wiphy_idx << 32); |
| 2091 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2092 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2093 | static int nl80211_send_chandef(struct sk_buff *msg, |
| 2094 | struct cfg80211_chan_def *chandef) |
| 2095 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2096 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2097 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2098 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2099 | chandef->chan->center_freq)) |
| 2100 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2101 | switch (chandef->width) { |
| 2102 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2103 | case NL80211_CHAN_WIDTH_20: |
| 2104 | case NL80211_CHAN_WIDTH_40: |
| 2105 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2106 | cfg80211_get_chandef_type(chandef))) |
| 2107 | return -ENOBUFS; |
| 2108 | break; |
| 2109 | default: |
| 2110 | break; |
| 2111 | } |
| 2112 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2113 | return -ENOBUFS; |
| 2114 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2115 | return -ENOBUFS; |
| 2116 | if (chandef->center_freq2 && |
| 2117 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2118 | return -ENOBUFS; |
| 2119 | return 0; |
| 2120 | } |
| 2121 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2122 | 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] | 2123 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2124 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2125 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2126 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2127 | void *hdr; |
| 2128 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2129 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2130 | if (!hdr) |
| 2131 | return -1; |
| 2132 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2133 | if (dev && |
| 2134 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2135 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2136 | goto nla_put_failure; |
| 2137 | |
| 2138 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2139 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2140 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2141 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2142 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2143 | rdev->devlist_generation ^ |
| 2144 | (cfg80211_rdev_list_generation << 2))) |
| 2145 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2146 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2147 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2148 | int ret; |
| 2149 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2150 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2151 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2152 | if (ret == 0) { |
| 2153 | if (nl80211_send_chandef(msg, &chandef)) |
| 2154 | goto nla_put_failure; |
| 2155 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2156 | } |
| 2157 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2158 | if (wdev->ssid_len) { |
| 2159 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2160 | goto nla_put_failure; |
| 2161 | } |
| 2162 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2163 | return genlmsg_end(msg, hdr); |
| 2164 | |
| 2165 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2166 | genlmsg_cancel(msg, hdr); |
| 2167 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2171 | { |
| 2172 | int wp_idx = 0; |
| 2173 | int if_idx = 0; |
| 2174 | int wp_start = cb->args[0]; |
| 2175 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2176 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2177 | struct wireless_dev *wdev; |
| 2178 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2179 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2180 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2181 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2182 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2183 | if (wp_idx < wp_start) { |
| 2184 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2185 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2186 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2187 | if_idx = 0; |
| 2188 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2189 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2190 | if (if_idx < if_start) { |
| 2191 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2192 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2193 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2194 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2195 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2196 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2197 | goto out; |
| 2198 | } |
| 2199 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2200 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2201 | |
| 2202 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2203 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2204 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2205 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2206 | |
| 2207 | cb->args[0] = wp_idx; |
| 2208 | cb->args[1] = if_idx; |
| 2209 | |
| 2210 | return skb->len; |
| 2211 | } |
| 2212 | |
| 2213 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2214 | { |
| 2215 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2216 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2217 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2218 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2219 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2220 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2221 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2222 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2223 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2224 | dev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2225 | nlmsg_free(msg); |
| 2226 | return -ENOBUFS; |
| 2227 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2228 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2229 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2230 | } |
| 2231 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2232 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2233 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2234 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2235 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2236 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2237 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2238 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2239 | }; |
| 2240 | |
| 2241 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2242 | { |
| 2243 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2244 | int flag; |
| 2245 | |
| 2246 | *mntrflags = 0; |
| 2247 | |
| 2248 | if (!nla) |
| 2249 | return -EINVAL; |
| 2250 | |
| 2251 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2252 | nla, mntr_flags_policy)) |
| 2253 | return -EINVAL; |
| 2254 | |
| 2255 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2256 | if (flags[flag]) |
| 2257 | *mntrflags |= (1<<flag); |
| 2258 | |
| 2259 | return 0; |
| 2260 | } |
| 2261 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2262 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2263 | struct net_device *netdev, u8 use_4addr, |
| 2264 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2265 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2266 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2267 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2268 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2269 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2270 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2271 | |
| 2272 | switch (iftype) { |
| 2273 | case NL80211_IFTYPE_AP_VLAN: |
| 2274 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2275 | return 0; |
| 2276 | break; |
| 2277 | case NL80211_IFTYPE_STATION: |
| 2278 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2279 | return 0; |
| 2280 | break; |
| 2281 | default: |
| 2282 | break; |
| 2283 | } |
| 2284 | |
| 2285 | return -EOPNOTSUPP; |
| 2286 | } |
| 2287 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2288 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2289 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2291 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2292 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2293 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2294 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2295 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2296 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2297 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2298 | memset(¶ms, 0, sizeof(params)); |
| 2299 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2300 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2301 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2302 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2303 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2304 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2305 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2306 | if (ntype > NL80211_IFTYPE_MAX) |
| 2307 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2308 | } |
| 2309 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2310 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2311 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2312 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2313 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2314 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2315 | if (netif_running(dev)) |
| 2316 | return -EBUSY; |
| 2317 | |
| 2318 | wdev_lock(wdev); |
| 2319 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2320 | IEEE80211_MAX_MESH_ID_LEN); |
| 2321 | wdev->mesh_id_up_len = |
| 2322 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2323 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2324 | wdev->mesh_id_up_len); |
| 2325 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2326 | } |
| 2327 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2328 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2329 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2330 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2331 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2332 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2333 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2334 | } else { |
| 2335 | params.use_4addr = -1; |
| 2336 | } |
| 2337 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2338 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2339 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2340 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2341 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2342 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2343 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2344 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2345 | |
| 2346 | flags = &_flags; |
| 2347 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2348 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2349 | |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2350 | if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2351 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2352 | return -EOPNOTSUPP; |
| 2353 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2354 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2355 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2356 | else |
| 2357 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2358 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2359 | if (!err && params.use_4addr != -1) |
| 2360 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2361 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2362 | return err; |
| 2363 | } |
| 2364 | |
| 2365 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2366 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2368 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2369 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2370 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2371 | int err; |
| 2372 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2373 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2374 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2375 | memset(¶ms, 0, sizeof(params)); |
| 2376 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2377 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2378 | return -EINVAL; |
| 2379 | |
| 2380 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2381 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2382 | if (type > NL80211_IFTYPE_MAX) |
| 2383 | return -EINVAL; |
| 2384 | } |
| 2385 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2386 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2387 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2388 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2389 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2390 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2391 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2392 | ETH_ALEN); |
| 2393 | if (!is_valid_ether_addr(params.macaddr)) |
| 2394 | return -EADDRNOTAVAIL; |
| 2395 | } |
| 2396 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2397 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2398 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2399 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2400 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2401 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2402 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2403 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2405 | if (!msg) |
| 2406 | return -ENOMEM; |
| 2407 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2408 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2409 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2410 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2411 | |
| 2412 | if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) && |
| 2413 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2414 | return -EOPNOTSUPP; |
| 2415 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2416 | wdev = rdev_add_virtual_intf(rdev, |
| 2417 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2418 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2419 | if (IS_ERR(wdev)) { |
| 2420 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2421 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2422 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2423 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2424 | switch (type) { |
| 2425 | case NL80211_IFTYPE_MESH_POINT: |
| 2426 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2427 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2428 | wdev_lock(wdev); |
| 2429 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2430 | IEEE80211_MAX_MESH_ID_LEN); |
| 2431 | wdev->mesh_id_up_len = |
| 2432 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2433 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2434 | wdev->mesh_id_up_len); |
| 2435 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2436 | break; |
| 2437 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2438 | /* |
| 2439 | * P2P Device doesn't have a netdev, so doesn't go |
| 2440 | * through the netdev notifier and must be added here |
| 2441 | */ |
| 2442 | mutex_init(&wdev->mtx); |
| 2443 | INIT_LIST_HEAD(&wdev->event_list); |
| 2444 | spin_lock_init(&wdev->event_lock); |
| 2445 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2446 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2447 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2448 | wdev->identifier = ++rdev->wdev_id; |
| 2449 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2450 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2451 | break; |
| 2452 | default: |
| 2453 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2454 | } |
| 2455 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2456 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2457 | rdev, wdev) < 0) { |
| 2458 | nlmsg_free(msg); |
| 2459 | return -ENOBUFS; |
| 2460 | } |
| 2461 | |
| 2462 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2466 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2468 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2470 | if (!rdev->ops->del_virtual_intf) |
| 2471 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2472 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2473 | /* |
| 2474 | * If we remove a wireless device without a netdev then clear |
| 2475 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2476 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2477 | * since the wdev has been freed, unlike with a netdev where |
| 2478 | * we need the dev_put() for the netdev to really be freed. |
| 2479 | */ |
| 2480 | if (!wdev->netdev) |
| 2481 | info->user_ptr[1] = NULL; |
| 2482 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2483 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2484 | } |
| 2485 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2486 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2487 | { |
| 2488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2489 | struct net_device *dev = info->user_ptr[1]; |
| 2490 | u16 noack_map; |
| 2491 | |
| 2492 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2493 | return -EINVAL; |
| 2494 | |
| 2495 | if (!rdev->ops->set_noack_map) |
| 2496 | return -EOPNOTSUPP; |
| 2497 | |
| 2498 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2499 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2500 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2501 | } |
| 2502 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2503 | struct get_key_cookie { |
| 2504 | struct sk_buff *msg; |
| 2505 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2506 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2507 | }; |
| 2508 | |
| 2509 | static void get_key_callback(void *c, struct key_params *params) |
| 2510 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2511 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2512 | struct get_key_cookie *cookie = c; |
| 2513 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2514 | if ((params->key && |
| 2515 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2516 | params->key_len, params->key)) || |
| 2517 | (params->seq && |
| 2518 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2519 | params->seq_len, params->seq)) || |
| 2520 | (params->cipher && |
| 2521 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2522 | params->cipher))) |
| 2523 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2524 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2525 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2526 | if (!key) |
| 2527 | goto nla_put_failure; |
| 2528 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2529 | if ((params->key && |
| 2530 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2531 | params->key_len, params->key)) || |
| 2532 | (params->seq && |
| 2533 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2534 | params->seq_len, params->seq)) || |
| 2535 | (params->cipher && |
| 2536 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2537 | params->cipher))) |
| 2538 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2539 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2540 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2541 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2542 | |
| 2543 | nla_nest_end(cookie->msg, key); |
| 2544 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2545 | return; |
| 2546 | nla_put_failure: |
| 2547 | cookie->error = 1; |
| 2548 | } |
| 2549 | |
| 2550 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2551 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2552 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2553 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2554 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2555 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2556 | const u8 *mac_addr = NULL; |
| 2557 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2558 | struct get_key_cookie cookie = { |
| 2559 | .error = 0, |
| 2560 | }; |
| 2561 | void *hdr; |
| 2562 | struct sk_buff *msg; |
| 2563 | |
| 2564 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2565 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2566 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2567 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2568 | return -EINVAL; |
| 2569 | |
| 2570 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2571 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2572 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2573 | pairwise = !!mac_addr; |
| 2574 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2575 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2576 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2577 | return -EINVAL; |
| 2578 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2579 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2580 | return -EINVAL; |
| 2581 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2582 | } |
| 2583 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2584 | if (!rdev->ops->get_key) |
| 2585 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2586 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2588 | if (!msg) |
| 2589 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2590 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2591 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2592 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2593 | if (IS_ERR(hdr)) |
| 2594 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2595 | |
| 2596 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2597 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2598 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2599 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2600 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2601 | goto nla_put_failure; |
| 2602 | if (mac_addr && |
| 2603 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2604 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2605 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2606 | if (pairwise && mac_addr && |
| 2607 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2608 | return -ENOENT; |
| 2609 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2610 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2611 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2612 | |
| 2613 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2614 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2615 | |
| 2616 | if (cookie.error) |
| 2617 | goto nla_put_failure; |
| 2618 | |
| 2619 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2620 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2621 | |
| 2622 | nla_put_failure: |
| 2623 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2624 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2625 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2626 | return err; |
| 2627 | } |
| 2628 | |
| 2629 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2630 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2631 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2632 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2633 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2634 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2635 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2636 | err = nl80211_parse_key(info, &key); |
| 2637 | if (err) |
| 2638 | return err; |
| 2639 | |
| 2640 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2641 | return -EINVAL; |
| 2642 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2643 | /* only support setting default key */ |
| 2644 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2645 | return -EINVAL; |
| 2646 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2647 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2648 | |
| 2649 | if (key.def) { |
| 2650 | if (!rdev->ops->set_default_key) { |
| 2651 | err = -EOPNOTSUPP; |
| 2652 | goto out; |
| 2653 | } |
| 2654 | |
| 2655 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2656 | if (err) |
| 2657 | goto out; |
| 2658 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2659 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2660 | key.def_uni, key.def_multi); |
| 2661 | |
| 2662 | if (err) |
| 2663 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2664 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2665 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2666 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2667 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2668 | } else { |
| 2669 | if (key.def_uni || !key.def_multi) { |
| 2670 | err = -EINVAL; |
| 2671 | goto out; |
| 2672 | } |
| 2673 | |
| 2674 | if (!rdev->ops->set_default_mgmt_key) { |
| 2675 | err = -EOPNOTSUPP; |
| 2676 | goto out; |
| 2677 | } |
| 2678 | |
| 2679 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2680 | if (err) |
| 2681 | goto out; |
| 2682 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2683 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2684 | if (err) |
| 2685 | goto out; |
| 2686 | |
| 2687 | #ifdef CONFIG_CFG80211_WEXT |
| 2688 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2689 | #endif |
| 2690 | } |
| 2691 | |
| 2692 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2693 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2694 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2695 | return err; |
| 2696 | } |
| 2697 | |
| 2698 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2699 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2701 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2702 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2703 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2704 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2705 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2706 | err = nl80211_parse_key(info, &key); |
| 2707 | if (err) |
| 2708 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2709 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2710 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2711 | return -EINVAL; |
| 2712 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2713 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2714 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2715 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2716 | if (key.type == -1) { |
| 2717 | if (mac_addr) |
| 2718 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2719 | else |
| 2720 | key.type = NL80211_KEYTYPE_GROUP; |
| 2721 | } |
| 2722 | |
| 2723 | /* for now */ |
| 2724 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2725 | key.type != NL80211_KEYTYPE_GROUP) |
| 2726 | return -EINVAL; |
| 2727 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2728 | if (!rdev->ops->add_key) |
| 2729 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2730 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2731 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2732 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2733 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2734 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2735 | |
| 2736 | wdev_lock(dev->ieee80211_ptr); |
| 2737 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2738 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2739 | err = rdev_add_key(rdev, dev, key.idx, |
| 2740 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2741 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2742 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2743 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2744 | return err; |
| 2745 | } |
| 2746 | |
| 2747 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2748 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2750 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2751 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2752 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2753 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2754 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2755 | err = nl80211_parse_key(info, &key); |
| 2756 | if (err) |
| 2757 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2758 | |
| 2759 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2760 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2761 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2762 | if (key.type == -1) { |
| 2763 | if (mac_addr) |
| 2764 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2765 | else |
| 2766 | key.type = NL80211_KEYTYPE_GROUP; |
| 2767 | } |
| 2768 | |
| 2769 | /* for now */ |
| 2770 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2771 | key.type != NL80211_KEYTYPE_GROUP) |
| 2772 | return -EINVAL; |
| 2773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2774 | if (!rdev->ops->del_key) |
| 2775 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2776 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2777 | wdev_lock(dev->ieee80211_ptr); |
| 2778 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2779 | |
| 2780 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2781 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2782 | err = -ENOENT; |
| 2783 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2784 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2785 | err = rdev_del_key(rdev, dev, key.idx, |
| 2786 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2787 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2788 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2789 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2790 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2791 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2792 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2793 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2794 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2795 | } |
| 2796 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2797 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2798 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2799 | return err; |
| 2800 | } |
| 2801 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 2802 | /* This function returns an error or the number of nested attributes */ |
| 2803 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 2804 | { |
| 2805 | struct nlattr *attr; |
| 2806 | int n_entries = 0, tmp; |
| 2807 | |
| 2808 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 2809 | if (nla_len(attr) != ETH_ALEN) |
| 2810 | return -EINVAL; |
| 2811 | |
| 2812 | n_entries++; |
| 2813 | } |
| 2814 | |
| 2815 | return n_entries; |
| 2816 | } |
| 2817 | |
| 2818 | /* |
| 2819 | * This function parses ACL information and allocates memory for ACL data. |
| 2820 | * On successful return, the calling function is responsible to free the |
| 2821 | * ACL buffer returned by this function. |
| 2822 | */ |
| 2823 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 2824 | struct genl_info *info) |
| 2825 | { |
| 2826 | enum nl80211_acl_policy acl_policy; |
| 2827 | struct nlattr *attr; |
| 2828 | struct cfg80211_acl_data *acl; |
| 2829 | int i = 0, n_entries, tmp; |
| 2830 | |
| 2831 | if (!wiphy->max_acl_mac_addrs) |
| 2832 | return ERR_PTR(-EOPNOTSUPP); |
| 2833 | |
| 2834 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 2835 | return ERR_PTR(-EINVAL); |
| 2836 | |
| 2837 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 2838 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 2839 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 2840 | return ERR_PTR(-EINVAL); |
| 2841 | |
| 2842 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 2843 | return ERR_PTR(-EINVAL); |
| 2844 | |
| 2845 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 2846 | if (n_entries < 0) |
| 2847 | return ERR_PTR(n_entries); |
| 2848 | |
| 2849 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 2850 | return ERR_PTR(-ENOTSUPP); |
| 2851 | |
| 2852 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 2853 | GFP_KERNEL); |
| 2854 | if (!acl) |
| 2855 | return ERR_PTR(-ENOMEM); |
| 2856 | |
| 2857 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 2858 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 2859 | i++; |
| 2860 | } |
| 2861 | |
| 2862 | acl->n_acl_entries = n_entries; |
| 2863 | acl->acl_policy = acl_policy; |
| 2864 | |
| 2865 | return acl; |
| 2866 | } |
| 2867 | |
| 2868 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 2869 | { |
| 2870 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2871 | struct net_device *dev = info->user_ptr[1]; |
| 2872 | struct cfg80211_acl_data *acl; |
| 2873 | int err; |
| 2874 | |
| 2875 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2876 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2877 | return -EOPNOTSUPP; |
| 2878 | |
| 2879 | if (!dev->ieee80211_ptr->beacon_interval) |
| 2880 | return -EINVAL; |
| 2881 | |
| 2882 | acl = parse_acl_data(&rdev->wiphy, info); |
| 2883 | if (IS_ERR(acl)) |
| 2884 | return PTR_ERR(acl); |
| 2885 | |
| 2886 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 2887 | |
| 2888 | kfree(acl); |
| 2889 | |
| 2890 | return err; |
| 2891 | } |
| 2892 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2893 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2894 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2895 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2896 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2897 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2898 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2899 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 2900 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2901 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2902 | return -EINVAL; |
| 2903 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2904 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2905 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2906 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2907 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2908 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2909 | if (!bcn->head_len) |
| 2910 | return -EINVAL; |
| 2911 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2912 | } |
| 2913 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2914 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2915 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2916 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2917 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2918 | } |
| 2919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2920 | if (!haveinfo) |
| 2921 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2922 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2923 | if (attrs[NL80211_ATTR_IE]) { |
| 2924 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 2925 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2926 | } |
| 2927 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2928 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2929 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2930 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2931 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2932 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2933 | } |
| 2934 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2935 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2936 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2937 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2938 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2939 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2940 | } |
| 2941 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 2942 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 2943 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 2944 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2945 | } |
| 2946 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2947 | return 0; |
| 2948 | } |
| 2949 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2950 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2951 | struct cfg80211_ap_settings *params) |
| 2952 | { |
| 2953 | struct wireless_dev *wdev; |
| 2954 | bool ret = false; |
| 2955 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2956 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2957 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2958 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2959 | continue; |
| 2960 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2961 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2962 | continue; |
| 2963 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2964 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2965 | ret = true; |
| 2966 | break; |
| 2967 | } |
| 2968 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 2969 | return ret; |
| 2970 | } |
| 2971 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 2972 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 2973 | enum nl80211_auth_type auth_type, |
| 2974 | enum nl80211_commands cmd) |
| 2975 | { |
| 2976 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 2977 | return false; |
| 2978 | |
| 2979 | switch (cmd) { |
| 2980 | case NL80211_CMD_AUTHENTICATE: |
| 2981 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 2982 | auth_type == NL80211_AUTHTYPE_SAE) |
| 2983 | return false; |
| 2984 | return true; |
| 2985 | case NL80211_CMD_CONNECT: |
| 2986 | case NL80211_CMD_START_AP: |
| 2987 | /* SAE not supported yet */ |
| 2988 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 2989 | return false; |
| 2990 | return true; |
| 2991 | default: |
| 2992 | return false; |
| 2993 | } |
| 2994 | } |
| 2995 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2996 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2997 | { |
| 2998 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2999 | struct net_device *dev = info->user_ptr[1]; |
| 3000 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3001 | struct cfg80211_ap_settings params; |
| 3002 | int err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3003 | u8 radar_detect_width = 0; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3004 | |
| 3005 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3006 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3007 | return -EOPNOTSUPP; |
| 3008 | |
| 3009 | if (!rdev->ops->start_ap) |
| 3010 | return -EOPNOTSUPP; |
| 3011 | |
| 3012 | if (wdev->beacon_interval) |
| 3013 | return -EALREADY; |
| 3014 | |
| 3015 | memset(¶ms, 0, sizeof(params)); |
| 3016 | |
| 3017 | /* these are required for START_AP */ |
| 3018 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3019 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3020 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3021 | return -EINVAL; |
| 3022 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3023 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3024 | if (err) |
| 3025 | return err; |
| 3026 | |
| 3027 | params.beacon_interval = |
| 3028 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3029 | params.dtim_period = |
| 3030 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3031 | |
| 3032 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3033 | if (err) |
| 3034 | return err; |
| 3035 | |
| 3036 | /* |
| 3037 | * In theory, some of these attributes should be required here |
| 3038 | * but since they were not used when the command was originally |
| 3039 | * added, keep them optional for old user space programs to let |
| 3040 | * them continue to work with drivers that do not need the |
| 3041 | * additional information -- drivers must check! |
| 3042 | */ |
| 3043 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3044 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3045 | params.ssid_len = |
| 3046 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3047 | if (params.ssid_len == 0 || |
| 3048 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3049 | return -EINVAL; |
| 3050 | } |
| 3051 | |
| 3052 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3053 | params.hidden_ssid = nla_get_u32( |
| 3054 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3055 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3056 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3057 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3058 | return -EINVAL; |
| 3059 | } |
| 3060 | |
| 3061 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3062 | |
| 3063 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3064 | params.auth_type = nla_get_u32( |
| 3065 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3066 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3067 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3068 | return -EINVAL; |
| 3069 | } else |
| 3070 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3071 | |
| 3072 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3073 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3074 | if (err) |
| 3075 | return err; |
| 3076 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3077 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3078 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3079 | return -EOPNOTSUPP; |
| 3080 | params.inactivity_timeout = nla_get_u16( |
| 3081 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3082 | } |
| 3083 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3084 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3085 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3086 | return -EINVAL; |
| 3087 | params.p2p_ctwindow = |
| 3088 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3089 | if (params.p2p_ctwindow > 127) |
| 3090 | return -EINVAL; |
| 3091 | if (params.p2p_ctwindow != 0 && |
| 3092 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3093 | return -EINVAL; |
| 3094 | } |
| 3095 | |
| 3096 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3097 | u8 tmp; |
| 3098 | |
| 3099 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3100 | return -EINVAL; |
| 3101 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3102 | if (tmp > 1) |
| 3103 | return -EINVAL; |
| 3104 | params.p2p_opp_ps = tmp; |
| 3105 | if (params.p2p_opp_ps != 0 && |
| 3106 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3107 | return -EINVAL; |
| 3108 | } |
| 3109 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3110 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3111 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3112 | if (err) |
| 3113 | return err; |
| 3114 | } else if (wdev->preset_chandef.chan) { |
| 3115 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3116 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3117 | return -EINVAL; |
| 3118 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3119 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3120 | return -EINVAL; |
| 3121 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3122 | err = cfg80211_chandef_dfs_required(wdev->wiphy, ¶ms.chandef); |
| 3123 | if (err < 0) |
| 3124 | return err; |
| 3125 | if (err) { |
| 3126 | radar_detect_width = BIT(params.chandef.width); |
| 3127 | params.radar_required = true; |
| 3128 | } |
| 3129 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 3130 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 3131 | params.chandef.chan, |
| 3132 | CHAN_MODE_SHARED, |
| 3133 | radar_detect_width); |
Michal Kazior | e4e3245 | 2012-06-29 12:47:08 +0200 | [diff] [blame] | 3134 | if (err) |
| 3135 | return err; |
| 3136 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3137 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3138 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3139 | if (IS_ERR(params.acl)) |
| 3140 | return PTR_ERR(params.acl); |
| 3141 | } |
| 3142 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3143 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3144 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3145 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3146 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3147 | wdev->channel = params.chandef.chan; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3148 | wdev->ssid_len = params.ssid_len; |
| 3149 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3150 | } |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3151 | |
| 3152 | kfree(params.acl); |
| 3153 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3154 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3155 | } |
| 3156 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3157 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3158 | { |
| 3159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3160 | struct net_device *dev = info->user_ptr[1]; |
| 3161 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3162 | struct cfg80211_beacon_data params; |
| 3163 | int err; |
| 3164 | |
| 3165 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3166 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3167 | return -EOPNOTSUPP; |
| 3168 | |
| 3169 | if (!rdev->ops->change_beacon) |
| 3170 | return -EOPNOTSUPP; |
| 3171 | |
| 3172 | if (!wdev->beacon_interval) |
| 3173 | return -EINVAL; |
| 3174 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3175 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3176 | if (err) |
| 3177 | return err; |
| 3178 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3179 | return rdev_change_beacon(rdev, dev, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | 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] | 3183 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3184 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3185 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3186 | |
Michal Kazior | 6077178 | 2012-06-29 12:46:56 +0200 | [diff] [blame] | 3187 | return cfg80211_stop_ap(rdev, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3188 | } |
| 3189 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3190 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3191 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3192 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3193 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3194 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3195 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3196 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3197 | }; |
| 3198 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3199 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3200 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3201 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3202 | { |
| 3203 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3204 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3205 | int flag; |
| 3206 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3207 | /* |
| 3208 | * Try parsing the new attribute first so userspace |
| 3209 | * can specify both for older kernels. |
| 3210 | */ |
| 3211 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3212 | if (nla) { |
| 3213 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3214 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3215 | sta_flags = nla_data(nla); |
| 3216 | params->sta_flags_mask = sta_flags->mask; |
| 3217 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3218 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3219 | if ((params->sta_flags_mask | |
| 3220 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3221 | return -EINVAL; |
| 3222 | return 0; |
| 3223 | } |
| 3224 | |
| 3225 | /* if present, parse the old attribute */ |
| 3226 | |
| 3227 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3228 | if (!nla) |
| 3229 | return 0; |
| 3230 | |
| 3231 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3232 | nla, sta_flags_policy)) |
| 3233 | return -EINVAL; |
| 3234 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3235 | /* |
| 3236 | * Only allow certain flags for interface types so that |
| 3237 | * other attributes are silently ignored. Remember that |
| 3238 | * this is backward compatibility code with old userspace |
| 3239 | * and shouldn't be hit in other cases anyway. |
| 3240 | */ |
| 3241 | switch (iftype) { |
| 3242 | case NL80211_IFTYPE_AP: |
| 3243 | case NL80211_IFTYPE_AP_VLAN: |
| 3244 | case NL80211_IFTYPE_P2P_GO: |
| 3245 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3246 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3247 | BIT(NL80211_STA_FLAG_WME) | |
| 3248 | BIT(NL80211_STA_FLAG_MFP); |
| 3249 | break; |
| 3250 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3251 | case NL80211_IFTYPE_STATION: |
| 3252 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3253 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3254 | break; |
| 3255 | case NL80211_IFTYPE_MESH_POINT: |
| 3256 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3257 | BIT(NL80211_STA_FLAG_MFP) | |
| 3258 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3259 | default: |
| 3260 | return -EINVAL; |
| 3261 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3262 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3263 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3264 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3265 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3266 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3267 | /* no longer support new API additions in old API */ |
| 3268 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3269 | return -EINVAL; |
| 3270 | } |
| 3271 | } |
| 3272 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3273 | return 0; |
| 3274 | } |
| 3275 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3276 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3277 | int attr) |
| 3278 | { |
| 3279 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3280 | u32 bitrate; |
| 3281 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3282 | |
| 3283 | rate = nla_nest_start(msg, attr); |
| 3284 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3285 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3286 | |
| 3287 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3288 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3289 | /* report 16-bit bitrate only if we can */ |
| 3290 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3291 | if (bitrate > 0 && |
| 3292 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3293 | return false; |
| 3294 | if (bitrate_compat > 0 && |
| 3295 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3296 | return false; |
| 3297 | |
| 3298 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3299 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3300 | return false; |
| 3301 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3302 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3303 | return false; |
| 3304 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3305 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3306 | return false; |
| 3307 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3308 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3309 | return false; |
| 3310 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3311 | return false; |
| 3312 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3313 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3314 | return false; |
| 3315 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3316 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3317 | return false; |
| 3318 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3319 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3320 | return false; |
| 3321 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3322 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3323 | return false; |
| 3324 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3325 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3326 | return false; |
| 3327 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3328 | |
| 3329 | nla_nest_end(msg, rate); |
| 3330 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3331 | } |
| 3332 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3333 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3334 | int id) |
| 3335 | { |
| 3336 | void *attr; |
| 3337 | int i = 0; |
| 3338 | |
| 3339 | if (!mask) |
| 3340 | return true; |
| 3341 | |
| 3342 | attr = nla_nest_start(msg, id); |
| 3343 | if (!attr) |
| 3344 | return false; |
| 3345 | |
| 3346 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3347 | if (!(mask & BIT(i))) |
| 3348 | continue; |
| 3349 | |
| 3350 | if (nla_put_u8(msg, i, signal[i])) |
| 3351 | return false; |
| 3352 | } |
| 3353 | |
| 3354 | nla_nest_end(msg, attr); |
| 3355 | |
| 3356 | return true; |
| 3357 | } |
| 3358 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3359 | 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] | 3360 | int flags, |
| 3361 | struct cfg80211_registered_device *rdev, |
| 3362 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3363 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3364 | { |
| 3365 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3366 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3367 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3368 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3369 | if (!hdr) |
| 3370 | return -1; |
| 3371 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3372 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3373 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3374 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3375 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3376 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3377 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3378 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3379 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3380 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3381 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3382 | sinfo->connected_time)) |
| 3383 | goto nla_put_failure; |
| 3384 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3385 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3386 | sinfo->inactive_time)) |
| 3387 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3388 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3389 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3390 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3391 | (u32)sinfo->rx_bytes)) |
| 3392 | goto nla_put_failure; |
| 3393 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3394 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3395 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3396 | (u32)sinfo->tx_bytes)) |
| 3397 | goto nla_put_failure; |
| 3398 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3399 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3400 | sinfo->rx_bytes)) |
| 3401 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3402 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3403 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3404 | sinfo->tx_bytes)) |
| 3405 | goto nla_put_failure; |
| 3406 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3407 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3408 | goto nla_put_failure; |
| 3409 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3410 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3411 | goto nla_put_failure; |
| 3412 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3413 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3414 | sinfo->plink_state)) |
| 3415 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3416 | switch (rdev->wiphy.signal_type) { |
| 3417 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3418 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3419 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3420 | sinfo->signal)) |
| 3421 | goto nla_put_failure; |
| 3422 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3423 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3424 | sinfo->signal_avg)) |
| 3425 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3426 | break; |
| 3427 | default: |
| 3428 | break; |
| 3429 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3430 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3431 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3432 | sinfo->chain_signal, |
| 3433 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3434 | goto nla_put_failure; |
| 3435 | } |
| 3436 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3437 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3438 | sinfo->chain_signal_avg, |
| 3439 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3440 | goto nla_put_failure; |
| 3441 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3442 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3443 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3444 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3445 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3446 | } |
| 3447 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3448 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3449 | NL80211_STA_INFO_RX_BITRATE)) |
| 3450 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3451 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3452 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3453 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3454 | sinfo->rx_packets)) |
| 3455 | goto nla_put_failure; |
| 3456 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3457 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3458 | sinfo->tx_packets)) |
| 3459 | goto nla_put_failure; |
| 3460 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3461 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3462 | sinfo->tx_retries)) |
| 3463 | goto nla_put_failure; |
| 3464 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3465 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3466 | sinfo->tx_failed)) |
| 3467 | goto nla_put_failure; |
| 3468 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3469 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3470 | sinfo->beacon_loss_count)) |
| 3471 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3472 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3473 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3474 | sinfo->local_pm)) |
| 3475 | goto nla_put_failure; |
| 3476 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3477 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3478 | sinfo->peer_pm)) |
| 3479 | goto nla_put_failure; |
| 3480 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3481 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3482 | sinfo->nonpeer_pm)) |
| 3483 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3484 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3485 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3486 | if (!bss_param) |
| 3487 | goto nla_put_failure; |
| 3488 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3489 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3490 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3491 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3492 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3493 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3494 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3495 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3496 | sinfo->bss_param.dtim_period) || |
| 3497 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3498 | sinfo->bss_param.beacon_interval)) |
| 3499 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3500 | |
| 3501 | nla_nest_end(msg, bss_param); |
| 3502 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3503 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3504 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3505 | sizeof(struct nl80211_sta_flag_update), |
| 3506 | &sinfo->sta_flags)) |
| 3507 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3508 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3509 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3510 | sinfo->t_offset)) |
| 3511 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3512 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3513 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3514 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3515 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3516 | sinfo->assoc_req_ies)) |
| 3517 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3518 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3519 | return genlmsg_end(msg, hdr); |
| 3520 | |
| 3521 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3522 | genlmsg_cancel(msg, hdr); |
| 3523 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3524 | } |
| 3525 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3526 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3527 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3528 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3529 | struct station_info sinfo; |
| 3530 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3531 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3532 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3533 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3534 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3535 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3536 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3537 | if (err) |
| 3538 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3539 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3540 | if (!wdev->netdev) { |
| 3541 | err = -EINVAL; |
| 3542 | goto out_err; |
| 3543 | } |
| 3544 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3545 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3546 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3547 | goto out_err; |
| 3548 | } |
| 3549 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3550 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3551 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3552 | err = rdev_dump_station(dev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3553 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3554 | if (err == -ENOENT) |
| 3555 | break; |
| 3556 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3557 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3558 | |
| 3559 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3560 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3561 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3562 | dev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3563 | &sinfo) < 0) |
| 3564 | goto out; |
| 3565 | |
| 3566 | sta_idx++; |
| 3567 | } |
| 3568 | |
| 3569 | |
| 3570 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3571 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3572 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3573 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3574 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3575 | |
| 3576 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3577 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3578 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3579 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3580 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3582 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3583 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3584 | struct sk_buff *msg; |
| 3585 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3586 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3587 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3588 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3589 | |
| 3590 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3591 | return -EINVAL; |
| 3592 | |
| 3593 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3594 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3595 | if (!rdev->ops->get_station) |
| 3596 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3597 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3598 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3599 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3600 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3601 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3603 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3604 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3605 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3606 | 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] | 3607 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3608 | nlmsg_free(msg); |
| 3609 | return -ENOBUFS; |
| 3610 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3611 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3612 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3613 | } |
| 3614 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3615 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3616 | struct station_parameters *params, |
| 3617 | enum cfg80211_station_type statype) |
| 3618 | { |
| 3619 | if (params->listen_interval != -1) |
| 3620 | return -EINVAL; |
| 3621 | if (params->aid) |
| 3622 | return -EINVAL; |
| 3623 | |
| 3624 | /* When you run into this, adjust the code below for the new flag */ |
| 3625 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3626 | |
| 3627 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3628 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3629 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3630 | /* |
| 3631 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3632 | * code doesn't have the bug of including TDLS in the |
| 3633 | * mask everywhere. |
| 3634 | */ |
| 3635 | if (params->sta_flags_mask & |
| 3636 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3637 | BIT(NL80211_STA_FLAG_MFP) | |
| 3638 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3639 | return -EINVAL; |
| 3640 | break; |
| 3641 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3642 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3643 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3644 | return -EINVAL; |
| 3645 | /* ignore since it can't change */ |
| 3646 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3647 | break; |
| 3648 | default: |
| 3649 | /* disallow mesh-specific things */ |
| 3650 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3651 | return -EINVAL; |
| 3652 | if (params->local_pm) |
| 3653 | return -EINVAL; |
| 3654 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3655 | return -EINVAL; |
| 3656 | } |
| 3657 | |
| 3658 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3659 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3660 | /* TDLS can't be set, ... */ |
| 3661 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3662 | return -EINVAL; |
| 3663 | /* |
| 3664 | * ... but don't bother the driver with it. This works around |
| 3665 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3666 | * TLDS_PEER flag in the mask even for AP mode. |
| 3667 | */ |
| 3668 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3669 | } |
| 3670 | |
| 3671 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3672 | /* reject other things that can't change */ |
| 3673 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3674 | return -EINVAL; |
| 3675 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3676 | return -EINVAL; |
| 3677 | if (params->supported_rates) |
| 3678 | return -EINVAL; |
| 3679 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3680 | return -EINVAL; |
| 3681 | } |
| 3682 | |
| 3683 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3684 | if (params->vlan) |
| 3685 | return -EINVAL; |
| 3686 | } |
| 3687 | |
| 3688 | switch (statype) { |
| 3689 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3690 | /* Use this only for authorizing/unauthorizing a station */ |
| 3691 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3692 | return -EOPNOTSUPP; |
| 3693 | break; |
| 3694 | case CFG80211_STA_AP_CLIENT: |
| 3695 | /* accept only the listed bits */ |
| 3696 | if (params->sta_flags_mask & |
| 3697 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3698 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3699 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3700 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3701 | BIT(NL80211_STA_FLAG_WME) | |
| 3702 | BIT(NL80211_STA_FLAG_MFP))) |
| 3703 | return -EINVAL; |
| 3704 | |
| 3705 | /* but authenticated/associated only if driver handles it */ |
| 3706 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3707 | params->sta_flags_mask & |
| 3708 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3709 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3710 | return -EINVAL; |
| 3711 | break; |
| 3712 | case CFG80211_STA_IBSS: |
| 3713 | case CFG80211_STA_AP_STA: |
| 3714 | /* reject any changes other than AUTHORIZED */ |
| 3715 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3716 | return -EINVAL; |
| 3717 | break; |
| 3718 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3719 | /* reject any changes other than AUTHORIZED or WME */ |
| 3720 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3721 | BIT(NL80211_STA_FLAG_WME))) |
| 3722 | return -EINVAL; |
| 3723 | /* force (at least) rates when authorizing */ |
| 3724 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3725 | !params->supported_rates) |
| 3726 | return -EINVAL; |
| 3727 | break; |
| 3728 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3729 | /* reject any changes */ |
| 3730 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3731 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3732 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3733 | return -EINVAL; |
| 3734 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3735 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3736 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3737 | return -EINVAL; |
| 3738 | break; |
| 3739 | } |
| 3740 | |
| 3741 | return 0; |
| 3742 | } |
| 3743 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3744 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3745 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3746 | * 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] | 3747 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3748 | static struct net_device *get_vlan(struct genl_info *info, |
| 3749 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3750 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3751 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3752 | struct net_device *v; |
| 3753 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3754 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3755 | if (!vlanattr) |
| 3756 | return NULL; |
| 3757 | |
| 3758 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3759 | if (!v) |
| 3760 | return ERR_PTR(-ENODEV); |
| 3761 | |
| 3762 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3763 | ret = -EINVAL; |
| 3764 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3765 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3766 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3767 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3768 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3769 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3770 | ret = -EINVAL; |
| 3771 | goto error; |
| 3772 | } |
| 3773 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3774 | if (!netif_running(v)) { |
| 3775 | ret = -ENETDOWN; |
| 3776 | goto error; |
| 3777 | } |
| 3778 | |
| 3779 | return v; |
| 3780 | error: |
| 3781 | dev_put(v); |
| 3782 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3783 | } |
| 3784 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3785 | static struct nla_policy |
| 3786 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3787 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3788 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3789 | }; |
| 3790 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3791 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 3792 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3793 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3794 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3795 | struct nlattr *nla; |
| 3796 | int err; |
| 3797 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3798 | /* parse WME attributes if present */ |
| 3799 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 3800 | return 0; |
| 3801 | |
| 3802 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3803 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3804 | nl80211_sta_wme_policy); |
| 3805 | if (err) |
| 3806 | return err; |
| 3807 | |
| 3808 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3809 | params->uapsd_queues = nla_get_u8( |
| 3810 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3811 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3812 | return -EINVAL; |
| 3813 | |
| 3814 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3815 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3816 | |
| 3817 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3818 | return -EINVAL; |
| 3819 | |
| 3820 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3821 | |
| 3822 | return 0; |
| 3823 | } |
| 3824 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3825 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 3826 | struct station_parameters *params) |
| 3827 | { |
| 3828 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3829 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 3830 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 3831 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3832 | params->ht_capa = |
| 3833 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 3834 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 3835 | params->vht_capa = |
| 3836 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 3837 | |
| 3838 | return nl80211_parse_sta_wme(info, params); |
| 3839 | } |
| 3840 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3841 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 3842 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3843 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3844 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3845 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3846 | u8 *mac_addr; |
| 3847 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3848 | |
| 3849 | memset(¶ms, 0, sizeof(params)); |
| 3850 | |
| 3851 | params.listen_interval = -1; |
| 3852 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3853 | if (!rdev->ops->change_station) |
| 3854 | return -EOPNOTSUPP; |
| 3855 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3856 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 3857 | return -EINVAL; |
| 3858 | |
| 3859 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3860 | return -EINVAL; |
| 3861 | |
| 3862 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3863 | |
| 3864 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 3865 | params.supported_rates = |
| 3866 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3867 | params.supported_rates_len = |
| 3868 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3869 | } |
| 3870 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3871 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3872 | params.capability = |
| 3873 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3874 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3875 | } |
| 3876 | |
| 3877 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3878 | params.ext_capab = |
| 3879 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3880 | params.ext_capab_len = |
| 3881 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3882 | } |
| 3883 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 3884 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 3885 | return -EINVAL; |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3886 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3887 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3888 | return -EINVAL; |
| 3889 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3890 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3891 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3892 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3893 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 3894 | return -EINVAL; |
| 3895 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3896 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3897 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3898 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 3899 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 3900 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 3901 | return -EINVAL; |
| 3902 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 3903 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 3904 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3905 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 3906 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 3907 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 3908 | |
| 3909 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 3910 | pm > NL80211_MESH_POWER_MAX) |
| 3911 | return -EINVAL; |
| 3912 | |
| 3913 | params.local_pm = pm; |
| 3914 | } |
| 3915 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3916 | /* Include parameters for TDLS peer (will check later) */ |
| 3917 | err = nl80211_set_station_tdls(info, ¶ms); |
| 3918 | if (err) |
| 3919 | return err; |
| 3920 | |
| 3921 | params.vlan = get_vlan(info, rdev); |
| 3922 | if (IS_ERR(params.vlan)) |
| 3923 | return PTR_ERR(params.vlan); |
| 3924 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3925 | switch (dev->ieee80211_ptr->iftype) { |
| 3926 | case NL80211_IFTYPE_AP: |
| 3927 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3928 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3929 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3930 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 3931 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3932 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3933 | break; |
| 3934 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3935 | err = -EOPNOTSUPP; |
| 3936 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3937 | } |
| 3938 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3939 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3940 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3941 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3942 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3943 | if (params.vlan) |
| 3944 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3945 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3946 | return err; |
| 3947 | } |
| 3948 | |
| 3949 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3950 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3951 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3952 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3953 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3954 | struct station_parameters params; |
| 3955 | u8 *mac_addr = NULL; |
| 3956 | |
| 3957 | memset(¶ms, 0, sizeof(params)); |
| 3958 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 3959 | if (!rdev->ops->add_station) |
| 3960 | return -EOPNOTSUPP; |
| 3961 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3962 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3963 | return -EINVAL; |
| 3964 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3965 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3966 | return -EINVAL; |
| 3967 | |
| 3968 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3969 | return -EINVAL; |
| 3970 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3971 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 3972 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3973 | return -EINVAL; |
| 3974 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3975 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3976 | params.supported_rates = |
| 3977 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3978 | params.supported_rates_len = |
| 3979 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3980 | params.listen_interval = |
| 3981 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3982 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 3983 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 3984 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 3985 | else |
| 3986 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3987 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3988 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3989 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 3990 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 3991 | params.capability = |
| 3992 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 3993 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 3994 | } |
| 3995 | |
| 3996 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 3997 | params.ext_capab = |
| 3998 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 3999 | params.ext_capab_len = |
| 4000 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4001 | } |
| 4002 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4003 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4004 | params.ht_capa = |
| 4005 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4006 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4007 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4008 | params.vht_capa = |
| 4009 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4010 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4011 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4012 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4013 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4014 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4015 | return -EINVAL; |
| 4016 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4017 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4018 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4019 | if (err) |
| 4020 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4021 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4022 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4023 | return -EINVAL; |
| 4024 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4025 | /* When you run into this, adjust the code below for the new flag */ |
| 4026 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4027 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4028 | switch (dev->ieee80211_ptr->iftype) { |
| 4029 | case NL80211_IFTYPE_AP: |
| 4030 | case NL80211_IFTYPE_AP_VLAN: |
| 4031 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4032 | /* ignore WME attributes if iface/sta is not capable */ |
| 4033 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4034 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4035 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4036 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4037 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4038 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4039 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4040 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4041 | /* but don't bother the driver with it */ |
| 4042 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4043 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4044 | /* allow authenticated/associated only if driver handles it */ |
| 4045 | if (!(rdev->wiphy.features & |
| 4046 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4047 | params.sta_flags_mask & |
| 4048 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4049 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4050 | return -EINVAL; |
| 4051 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4052 | /* must be last in here for error handling */ |
| 4053 | params.vlan = get_vlan(info, rdev); |
| 4054 | if (IS_ERR(params.vlan)) |
| 4055 | return PTR_ERR(params.vlan); |
| 4056 | break; |
| 4057 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4058 | /* ignore uAPSD data */ |
| 4059 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4060 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4061 | /* associated is disallowed */ |
| 4062 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4063 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4064 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4065 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4066 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4067 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4068 | break; |
| 4069 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4070 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4071 | /* ignore uAPSD data */ |
| 4072 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4073 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4074 | /* these are disallowed */ |
| 4075 | if (params.sta_flags_mask & |
| 4076 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4077 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4078 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4079 | /* Only TDLS peers can be added */ |
| 4080 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4081 | return -EINVAL; |
| 4082 | /* Can only add if TDLS ... */ |
| 4083 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4084 | return -EOPNOTSUPP; |
| 4085 | /* ... with external setup is supported */ |
| 4086 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4087 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4088 | /* |
| 4089 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4090 | * as authorized, but it shouldn't yet be. |
| 4091 | */ |
| 4092 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4093 | break; |
| 4094 | default: |
| 4095 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4096 | } |
| 4097 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4098 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4099 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4100 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4101 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4102 | if (params.vlan) |
| 4103 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4104 | return err; |
| 4105 | } |
| 4106 | |
| 4107 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4108 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4109 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4110 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4111 | u8 *mac_addr = NULL; |
| 4112 | |
| 4113 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4114 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4115 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4116 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4117 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4118 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4119 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4120 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4121 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4122 | if (!rdev->ops->del_station) |
| 4123 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4124 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4125 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4126 | } |
| 4127 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4128 | 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] | 4129 | int flags, struct net_device *dev, |
| 4130 | u8 *dst, u8 *next_hop, |
| 4131 | struct mpath_info *pinfo) |
| 4132 | { |
| 4133 | void *hdr; |
| 4134 | struct nlattr *pinfoattr; |
| 4135 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4136 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4137 | if (!hdr) |
| 4138 | return -1; |
| 4139 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4140 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4141 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4142 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4143 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4144 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4145 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4146 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4147 | if (!pinfoattr) |
| 4148 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4149 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4150 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4151 | pinfo->frame_qlen)) |
| 4152 | goto nla_put_failure; |
| 4153 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4154 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4155 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4156 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4157 | pinfo->metric)) || |
| 4158 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4159 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4160 | pinfo->exptime)) || |
| 4161 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4162 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4163 | pinfo->flags)) || |
| 4164 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4165 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4166 | pinfo->discovery_timeout)) || |
| 4167 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4168 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4169 | pinfo->discovery_retries))) |
| 4170 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4171 | |
| 4172 | nla_nest_end(msg, pinfoattr); |
| 4173 | |
| 4174 | return genlmsg_end(msg, hdr); |
| 4175 | |
| 4176 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4177 | genlmsg_cancel(msg, hdr); |
| 4178 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4182 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4183 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4184 | struct mpath_info pinfo; |
| 4185 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4186 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4187 | u8 dst[ETH_ALEN]; |
| 4188 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4189 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4190 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4191 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4192 | err = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4193 | if (err) |
| 4194 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4195 | |
| 4196 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4197 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4198 | goto out_err; |
| 4199 | } |
| 4200 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4201 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4202 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4203 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4204 | } |
| 4205 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4206 | while (1) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4207 | err = rdev_dump_mpath(dev, wdev->netdev, path_idx, dst, |
| 4208 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4209 | if (err == -ENOENT) |
| 4210 | break; |
| 4211 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4212 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4213 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4214 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4215 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4216 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4217 | &pinfo) < 0) |
| 4218 | goto out; |
| 4219 | |
| 4220 | path_idx++; |
| 4221 | } |
| 4222 | |
| 4223 | |
| 4224 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4225 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4226 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4227 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4228 | nl80211_finish_wdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4229 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4233 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4234 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4235 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4236 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4237 | struct mpath_info pinfo; |
| 4238 | struct sk_buff *msg; |
| 4239 | u8 *dst = NULL; |
| 4240 | u8 next_hop[ETH_ALEN]; |
| 4241 | |
| 4242 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4243 | |
| 4244 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4245 | return -EINVAL; |
| 4246 | |
| 4247 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4248 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4249 | if (!rdev->ops->get_mpath) |
| 4250 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4252 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4253 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4254 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4255 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4256 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4257 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4258 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4260 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4261 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4262 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4263 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4264 | dev, dst, next_hop, &pinfo) < 0) { |
| 4265 | nlmsg_free(msg); |
| 4266 | return -ENOBUFS; |
| 4267 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4268 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4269 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4270 | } |
| 4271 | |
| 4272 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4273 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4275 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4276 | u8 *dst = NULL; |
| 4277 | u8 *next_hop = NULL; |
| 4278 | |
| 4279 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4280 | return -EINVAL; |
| 4281 | |
| 4282 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4283 | return -EINVAL; |
| 4284 | |
| 4285 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4286 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4287 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4288 | if (!rdev->ops->change_mpath) |
| 4289 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4291 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4292 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4293 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4294 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4295 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4296 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4297 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4298 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4300 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4301 | u8 *dst = NULL; |
| 4302 | u8 *next_hop = NULL; |
| 4303 | |
| 4304 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4305 | return -EINVAL; |
| 4306 | |
| 4307 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4308 | return -EINVAL; |
| 4309 | |
| 4310 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4311 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4312 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4313 | if (!rdev->ops->add_mpath) |
| 4314 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4315 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4316 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4317 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4318 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4319 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4323 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4324 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4325 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4326 | u8 *dst = NULL; |
| 4327 | |
| 4328 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4329 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4330 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4331 | if (!rdev->ops->del_mpath) |
| 4332 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4333 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4334 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4335 | } |
| 4336 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4337 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4338 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4340 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4341 | struct bss_parameters params; |
| 4342 | |
| 4343 | memset(¶ms, 0, sizeof(params)); |
| 4344 | /* default to not changing parameters */ |
| 4345 | params.use_cts_prot = -1; |
| 4346 | params.use_short_preamble = -1; |
| 4347 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4348 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4349 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4350 | params.p2p_ctwindow = -1; |
| 4351 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4352 | |
| 4353 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4354 | params.use_cts_prot = |
| 4355 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4356 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4357 | params.use_short_preamble = |
| 4358 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4359 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4360 | params.use_short_slot_time = |
| 4361 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4362 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4363 | params.basic_rates = |
| 4364 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4365 | params.basic_rates_len = |
| 4366 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4367 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4368 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4369 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4370 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4371 | params.ht_opmode = |
| 4372 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4373 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4374 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4375 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4376 | return -EINVAL; |
| 4377 | params.p2p_ctwindow = |
| 4378 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4379 | if (params.p2p_ctwindow < 0) |
| 4380 | return -EINVAL; |
| 4381 | if (params.p2p_ctwindow != 0 && |
| 4382 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4383 | return -EINVAL; |
| 4384 | } |
| 4385 | |
| 4386 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4387 | u8 tmp; |
| 4388 | |
| 4389 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4390 | return -EINVAL; |
| 4391 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4392 | if (tmp > 1) |
| 4393 | return -EINVAL; |
| 4394 | params.p2p_opp_ps = tmp; |
| 4395 | if (params.p2p_opp_ps && |
| 4396 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4397 | return -EINVAL; |
| 4398 | } |
| 4399 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4400 | if (!rdev->ops->change_bss) |
| 4401 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4402 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4403 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4404 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4405 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4406 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4407 | return rdev_change_bss(rdev, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4408 | } |
| 4409 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4410 | 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] | 4411 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4412 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4413 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4414 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4415 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4416 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 4417 | }; |
| 4418 | |
| 4419 | static int parse_reg_rule(struct nlattr *tb[], |
| 4420 | struct ieee80211_reg_rule *reg_rule) |
| 4421 | { |
| 4422 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4423 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4424 | |
| 4425 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4426 | return -EINVAL; |
| 4427 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4428 | return -EINVAL; |
| 4429 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4430 | return -EINVAL; |
| 4431 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4432 | return -EINVAL; |
| 4433 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4434 | return -EINVAL; |
| 4435 | |
| 4436 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4437 | |
| 4438 | freq_range->start_freq_khz = |
| 4439 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4440 | freq_range->end_freq_khz = |
| 4441 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 4442 | freq_range->max_bandwidth_khz = |
| 4443 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 4444 | |
| 4445 | power_rule->max_eirp = |
| 4446 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4447 | |
| 4448 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4449 | power_rule->max_antenna_gain = |
| 4450 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4451 | |
| 4452 | return 0; |
| 4453 | } |
| 4454 | |
| 4455 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4456 | { |
| 4457 | int r; |
| 4458 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4459 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4460 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4461 | /* |
| 4462 | * You should only get this when cfg80211 hasn't yet initialized |
| 4463 | * completely when built-in to the kernel right between the time |
| 4464 | * window between nl80211_init() and regulatory_init(), if that is |
| 4465 | * even possible. |
| 4466 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4467 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4468 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4469 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4470 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4471 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4472 | |
| 4473 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4474 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4475 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4476 | user_reg_hint_type = |
| 4477 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4478 | else |
| 4479 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4480 | |
| 4481 | switch (user_reg_hint_type) { |
| 4482 | case NL80211_USER_REG_HINT_USER: |
| 4483 | case NL80211_USER_REG_HINT_CELL_BASE: |
| 4484 | break; |
| 4485 | default: |
| 4486 | return -EINVAL; |
| 4487 | } |
| 4488 | |
| 4489 | r = regulatory_hint_user(data, user_reg_hint_type); |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4490 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4491 | return r; |
| 4492 | } |
| 4493 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4494 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4495 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4496 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4497 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4498 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4499 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4500 | struct mesh_config cur_params; |
| 4501 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4502 | void *hdr; |
| 4503 | struct nlattr *pinfoattr; |
| 4504 | struct sk_buff *msg; |
| 4505 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4506 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4507 | return -EOPNOTSUPP; |
| 4508 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4509 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4510 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4511 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4512 | wdev_lock(wdev); |
| 4513 | /* If not connected, get default parameters */ |
| 4514 | if (!wdev->mesh_id_len) |
| 4515 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4516 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4517 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4518 | wdev_unlock(wdev); |
| 4519 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4520 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4521 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4522 | |
| 4523 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4524 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4525 | if (!msg) |
| 4526 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4527 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4528 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4529 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4530 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4531 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4532 | if (!pinfoattr) |
| 4533 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4534 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4535 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4536 | cur_params.dot11MeshRetryTimeout) || |
| 4537 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4538 | cur_params.dot11MeshConfirmTimeout) || |
| 4539 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4540 | cur_params.dot11MeshHoldingTimeout) || |
| 4541 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4542 | cur_params.dot11MeshMaxPeerLinks) || |
| 4543 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4544 | cur_params.dot11MeshMaxRetries) || |
| 4545 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4546 | cur_params.dot11MeshTTL) || |
| 4547 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4548 | cur_params.element_ttl) || |
| 4549 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4550 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4551 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4552 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4553 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4554 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4555 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4556 | cur_params.path_refresh_time) || |
| 4557 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4558 | cur_params.min_discovery_timeout) || |
| 4559 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4560 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4561 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4562 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4563 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4564 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4565 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4566 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4567 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4568 | cur_params.dot11MeshHWMPRootMode) || |
| 4569 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4570 | cur_params.dot11MeshHWMPRannInterval) || |
| 4571 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4572 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4573 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4574 | cur_params.dot11MeshForwarding) || |
| 4575 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4576 | cur_params.rssi_threshold) || |
| 4577 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4578 | cur_params.ht_opmode) || |
| 4579 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4580 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4581 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4582 | cur_params.dot11MeshHWMProotInterval) || |
| 4583 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4584 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4585 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4586 | cur_params.power_mode) || |
| 4587 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4588 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4589 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4590 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4591 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4592 | nla_nest_end(msg, pinfoattr); |
| 4593 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4594 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4595 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4596 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4597 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4598 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4599 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4600 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4603 | 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] | 4604 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4605 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4606 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4607 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4608 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4609 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4610 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4611 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4612 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4613 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4614 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4615 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4616 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4617 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4618 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4619 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4620 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4621 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4622 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4623 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4624 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4625 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4626 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4627 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4628 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4629 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4630 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4631 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4632 | }; |
| 4633 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4634 | static const struct nla_policy |
| 4635 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4636 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4637 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4638 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4639 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4640 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4641 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4642 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4643 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4644 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4645 | }; |
| 4646 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4647 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4648 | struct mesh_config *cfg, |
| 4649 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4650 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4651 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4652 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4653 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4654 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4655 | do { \ |
| 4656 | if (tb[attr]) { \ |
| 4657 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4658 | return -EINVAL; \ |
| 4659 | cfg->param = fn(tb[attr]); \ |
| 4660 | mask |= (1 << (attr - 1)); \ |
| 4661 | } \ |
| 4662 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4663 | |
| 4664 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4665 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4666 | return -EINVAL; |
| 4667 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4668 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4669 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4670 | return -EINVAL; |
| 4671 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4672 | /* This makes sure that there aren't more than 32 mesh config |
| 4673 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4674 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4675 | |
| 4676 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4677 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4678 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4679 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4680 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4681 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4682 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4683 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4684 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4685 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4686 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4687 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4688 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4689 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4690 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4691 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4693 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4694 | 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] | 4695 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4696 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4697 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4698 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4699 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4700 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4701 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4702 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4703 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4704 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4705 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4706 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4707 | 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] | 4708 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4709 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4710 | 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] | 4711 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4712 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4713 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4714 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4715 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4716 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4717 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4718 | 1, 65535, mask, |
| 4719 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4720 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4721 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4722 | 1, 65535, mask, |
| 4723 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4724 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4725 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4726 | dot11MeshHWMPnetDiameterTraversalTime, |
| 4727 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4728 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4729 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4730 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 4731 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4732 | nla_get_u8); |
| 4733 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 4734 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4735 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 4736 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4737 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 4738 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4739 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4740 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4741 | mask, NL80211_MESHCONF_FORWARDING, |
| 4742 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4743 | 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] | 4744 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 4745 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4746 | 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] | 4747 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 4748 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4749 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4750 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4751 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4752 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4753 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4754 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 4755 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4756 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4757 | dot11MeshHWMPconfirmationInterval, |
| 4758 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4759 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 4760 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4761 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 4762 | NL80211_MESH_POWER_ACTIVE, |
| 4763 | NL80211_MESH_POWER_MAX, |
| 4764 | mask, NL80211_MESHCONF_POWER_MODE, |
| 4765 | nla_get_u32); |
| 4766 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 4767 | 0, 65535, mask, |
| 4768 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4769 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 4770 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4771 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4772 | if (mask_out) |
| 4773 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4774 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4775 | return 0; |
| 4776 | |
| 4777 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 4778 | } |
| 4779 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4780 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 4781 | struct mesh_setup *setup) |
| 4782 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4783 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4784 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 4785 | |
| 4786 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 4787 | return -EINVAL; |
| 4788 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 4789 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 4790 | nl80211_mesh_setup_params_policy)) |
| 4791 | return -EINVAL; |
| 4792 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4793 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 4794 | setup->sync_method = |
| 4795 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 4796 | IEEE80211_SYNC_METHOD_VENDOR : |
| 4797 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 4798 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4799 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 4800 | setup->path_sel_proto = |
| 4801 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 4802 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 4803 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 4804 | |
| 4805 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 4806 | setup->path_metric = |
| 4807 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 4808 | IEEE80211_PATH_METRIC_VENDOR : |
| 4809 | IEEE80211_PATH_METRIC_AIRTIME; |
| 4810 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4811 | |
| 4812 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4813 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4814 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4815 | if (!is_valid_ie_attr(ieattr)) |
| 4816 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4817 | setup->ie = nla_data(ieattr); |
| 4818 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4819 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4820 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 4821 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 4822 | return -EINVAL; |
| 4823 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4824 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 4825 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4826 | if (setup->is_secure) |
| 4827 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4828 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4829 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 4830 | if (!setup->user_mpm) |
| 4831 | return -EINVAL; |
| 4832 | setup->auth_id = |
| 4833 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 4834 | } |
| 4835 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4836 | return 0; |
| 4837 | } |
| 4838 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4839 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4840 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4841 | { |
| 4842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4843 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4844 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4845 | struct mesh_config cfg; |
| 4846 | u32 mask; |
| 4847 | int err; |
| 4848 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4849 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4850 | return -EOPNOTSUPP; |
| 4851 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4852 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4853 | return -EOPNOTSUPP; |
| 4854 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4855 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4856 | if (err) |
| 4857 | return err; |
| 4858 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4859 | wdev_lock(wdev); |
| 4860 | if (!wdev->mesh_id_len) |
| 4861 | err = -ENOLINK; |
| 4862 | |
| 4863 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4864 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4865 | |
| 4866 | wdev_unlock(wdev); |
| 4867 | |
| 4868 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4871 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 4872 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4873 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4874 | struct sk_buff *msg; |
| 4875 | void *hdr = NULL; |
| 4876 | struct nlattr *nl_reg_rules; |
| 4877 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4878 | |
| 4879 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4880 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4881 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4882 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4883 | if (!msg) |
| 4884 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4885 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4886 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4887 | NL80211_CMD_GET_REG); |
| 4888 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4889 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4890 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4891 | if (reg_last_request_cell_base() && |
| 4892 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 4893 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 4894 | goto nla_put_failure; |
| 4895 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4896 | rcu_read_lock(); |
| 4897 | regdom = rcu_dereference(cfg80211_regdomain); |
| 4898 | |
| 4899 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 4900 | (regdom->dfs_region && |
| 4901 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 4902 | goto nla_put_failure_rcu; |
| 4903 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4904 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 4905 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4906 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4907 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4908 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4909 | struct nlattr *nl_reg_rule; |
| 4910 | const struct ieee80211_reg_rule *reg_rule; |
| 4911 | const struct ieee80211_freq_range *freq_range; |
| 4912 | const struct ieee80211_power_rule *power_rule; |
| 4913 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4914 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4915 | freq_range = ®_rule->freq_range; |
| 4916 | power_rule = ®_rule->power_rule; |
| 4917 | |
| 4918 | nl_reg_rule = nla_nest_start(msg, i); |
| 4919 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4920 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4921 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4922 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 4923 | reg_rule->flags) || |
| 4924 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 4925 | freq_range->start_freq_khz) || |
| 4926 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 4927 | freq_range->end_freq_khz) || |
| 4928 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 4929 | freq_range->max_bandwidth_khz) || |
| 4930 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 4931 | power_rule->max_antenna_gain) || |
| 4932 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 4933 | power_rule->max_eirp)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4934 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4935 | |
| 4936 | nla_nest_end(msg, nl_reg_rule); |
| 4937 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4938 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4939 | |
| 4940 | nla_nest_end(msg, nl_reg_rules); |
| 4941 | |
| 4942 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4943 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4944 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4945 | nla_put_failure_rcu: |
| 4946 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4947 | nla_put_failure: |
| 4948 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4949 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4950 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 4951 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4952 | } |
| 4953 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4954 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4955 | { |
| 4956 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 4957 | struct nlattr *nl_reg_rule; |
| 4958 | char *alpha2 = NULL; |
| 4959 | int rem_reg_rules = 0, r = 0; |
| 4960 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4961 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4962 | struct ieee80211_regdomain *rd = NULL; |
| 4963 | |
| 4964 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4965 | return -EINVAL; |
| 4966 | |
| 4967 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 4968 | return -EINVAL; |
| 4969 | |
| 4970 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4971 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4972 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 4973 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 4974 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4975 | 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] | 4976 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4977 | num_rules++; |
| 4978 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 4979 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4980 | } |
| 4981 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4982 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 4983 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4984 | |
| 4985 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 4986 | if (!rd) |
| 4987 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4988 | |
| 4989 | rd->n_reg_rules = num_rules; |
| 4990 | rd->alpha2[0] = alpha2[0]; |
| 4991 | rd->alpha2[1] = alpha2[1]; |
| 4992 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 4993 | /* |
| 4994 | * Disable DFS master mode if the DFS region was |
| 4995 | * not supported or known on this kernel. |
| 4996 | */ |
| 4997 | if (reg_supported_dfs_region(dfs_region)) |
| 4998 | rd->dfs_region = dfs_region; |
| 4999 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5000 | 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] | 5001 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5002 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5003 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5004 | reg_rule_policy); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5005 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5006 | if (r) |
| 5007 | goto bad_reg; |
| 5008 | |
| 5009 | rule_idx++; |
| 5010 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5011 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5012 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5013 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5014 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5015 | } |
| 5016 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5017 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5018 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5019 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5020 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5021 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5022 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5023 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5024 | } |
| 5025 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5026 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5027 | { |
| 5028 | struct nlattr *attr1, *attr2; |
| 5029 | int n_channels = 0, tmp1, tmp2; |
| 5030 | |
| 5031 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5032 | n_channels++; |
| 5033 | /* |
| 5034 | * Some hardware has a limited channel list for |
| 5035 | * scanning, and it is pretty much nonsensical |
| 5036 | * to scan for a channel twice, so disallow that |
| 5037 | * and don't require drivers to check that the |
| 5038 | * channel list they get isn't longer than what |
| 5039 | * they can scan, as long as they can scan all |
| 5040 | * the channels they registered at once. |
| 5041 | */ |
| 5042 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5043 | if (attr1 != attr2 && |
| 5044 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5045 | return 0; |
| 5046 | } |
| 5047 | |
| 5048 | return n_channels; |
| 5049 | } |
| 5050 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5051 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5052 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5054 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5055 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5056 | struct nlattr *attr; |
| 5057 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5058 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5059 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5060 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5061 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5062 | return -EINVAL; |
| 5063 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5064 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5065 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5066 | if (!rdev->ops->scan) |
| 5067 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5068 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5069 | if (rdev->scan_req) { |
| 5070 | err = -EBUSY; |
| 5071 | goto unlock; |
| 5072 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5073 | |
| 5074 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5075 | n_channels = validate_scan_freqs( |
| 5076 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5077 | if (!n_channels) { |
| 5078 | err = -EINVAL; |
| 5079 | goto unlock; |
| 5080 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5081 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5082 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5083 | n_channels = 0; |
| 5084 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5085 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5086 | if (wiphy->bands[band]) |
| 5087 | n_channels += wiphy->bands[band]->n_channels; |
| 5088 | } |
| 5089 | |
| 5090 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5091 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5092 | n_ssids++; |
| 5093 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5094 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5095 | err = -EINVAL; |
| 5096 | goto unlock; |
| 5097 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5098 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5099 | if (info->attrs[NL80211_ATTR_IE]) |
| 5100 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5101 | else |
| 5102 | ie_len = 0; |
| 5103 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5104 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5105 | err = -EINVAL; |
| 5106 | goto unlock; |
| 5107 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5108 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5109 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5110 | + sizeof(*request->ssids) * n_ssids |
| 5111 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5112 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5113 | if (!request) { |
| 5114 | err = -ENOMEM; |
| 5115 | goto unlock; |
| 5116 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5117 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5118 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5119 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5120 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5121 | if (ie_len) { |
| 5122 | if (request->ssids) |
| 5123 | request->ie = (void *)(request->ssids + n_ssids); |
| 5124 | else |
| 5125 | request->ie = (void *)(request->channels + n_channels); |
| 5126 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5127 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5128 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5129 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5130 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5131 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5132 | struct ieee80211_channel *chan; |
| 5133 | |
| 5134 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5135 | |
| 5136 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5137 | err = -EINVAL; |
| 5138 | goto out_free; |
| 5139 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5140 | |
| 5141 | /* ignore disabled channels */ |
| 5142 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5143 | continue; |
| 5144 | |
| 5145 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5146 | i++; |
| 5147 | } |
| 5148 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5149 | enum ieee80211_band band; |
| 5150 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5151 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5152 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5153 | int j; |
| 5154 | if (!wiphy->bands[band]) |
| 5155 | continue; |
| 5156 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5157 | struct ieee80211_channel *chan; |
| 5158 | |
| 5159 | chan = &wiphy->bands[band]->channels[j]; |
| 5160 | |
| 5161 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5162 | continue; |
| 5163 | |
| 5164 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5165 | i++; |
| 5166 | } |
| 5167 | } |
| 5168 | } |
| 5169 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5170 | if (!i) { |
| 5171 | err = -EINVAL; |
| 5172 | goto out_free; |
| 5173 | } |
| 5174 | |
| 5175 | request->n_channels = i; |
| 5176 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5177 | i = 0; |
| 5178 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5179 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5180 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5181 | err = -EINVAL; |
| 5182 | goto out_free; |
| 5183 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5184 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5185 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5186 | i++; |
| 5187 | } |
| 5188 | } |
| 5189 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5190 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5191 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5192 | memcpy((void *)request->ie, |
| 5193 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5194 | request->ie_len); |
| 5195 | } |
| 5196 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5197 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5198 | if (wiphy->bands[i]) |
| 5199 | request->rates[i] = |
| 5200 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5201 | |
| 5202 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5203 | nla_for_each_nested(attr, |
| 5204 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5205 | tmp) { |
| 5206 | enum ieee80211_band band = nla_type(attr); |
| 5207 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5208 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5209 | err = -EINVAL; |
| 5210 | goto out_free; |
| 5211 | } |
| 5212 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5213 | nla_data(attr), |
| 5214 | nla_len(attr), |
| 5215 | &request->rates[band]); |
| 5216 | if (err) |
| 5217 | goto out_free; |
| 5218 | } |
| 5219 | } |
| 5220 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5221 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5222 | request->flags = nla_get_u32( |
| 5223 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5224 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5225 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5226 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5227 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5228 | err = -EOPNOTSUPP; |
| 5229 | goto out_free; |
| 5230 | } |
| 5231 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5232 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5233 | request->no_cck = |
| 5234 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5235 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5236 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5237 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5238 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5239 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5240 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5241 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5242 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5243 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5244 | nl80211_send_scan_start(rdev, wdev); |
| 5245 | if (wdev->netdev) |
| 5246 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5247 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5248 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5249 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5250 | kfree(request); |
| 5251 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5252 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5253 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5254 | return err; |
| 5255 | } |
| 5256 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5257 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5258 | struct genl_info *info) |
| 5259 | { |
| 5260 | struct cfg80211_sched_scan_request *request; |
| 5261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5262 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5263 | struct nlattr *attr; |
| 5264 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5265 | 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] | 5266 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5267 | enum ieee80211_band band; |
| 5268 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5269 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5270 | |
| 5271 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5272 | !rdev->ops->sched_scan_start) |
| 5273 | return -EOPNOTSUPP; |
| 5274 | |
| 5275 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5276 | return -EINVAL; |
| 5277 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5278 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5279 | return -EINVAL; |
| 5280 | |
| 5281 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5282 | if (interval == 0) |
| 5283 | return -EINVAL; |
| 5284 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5285 | wiphy = &rdev->wiphy; |
| 5286 | |
| 5287 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5288 | n_channels = validate_scan_freqs( |
| 5289 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5290 | if (!n_channels) |
| 5291 | return -EINVAL; |
| 5292 | } else { |
| 5293 | n_channels = 0; |
| 5294 | |
| 5295 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 5296 | if (wiphy->bands[band]) |
| 5297 | n_channels += wiphy->bands[band]->n_channels; |
| 5298 | } |
| 5299 | |
| 5300 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5301 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5302 | tmp) |
| 5303 | n_ssids++; |
| 5304 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5305 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5306 | return -EINVAL; |
| 5307 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5308 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 5309 | nla_for_each_nested(attr, |
| 5310 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5311 | tmp) |
| 5312 | n_match_sets++; |
| 5313 | |
| 5314 | if (n_match_sets > wiphy->max_match_sets) |
| 5315 | return -EINVAL; |
| 5316 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5317 | if (info->attrs[NL80211_ATTR_IE]) |
| 5318 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5319 | else |
| 5320 | ie_len = 0; |
| 5321 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5322 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5323 | return -EINVAL; |
| 5324 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5325 | if (rdev->sched_scan_req) { |
| 5326 | err = -EINPROGRESS; |
| 5327 | goto out; |
| 5328 | } |
| 5329 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5330 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5331 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5332 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5333 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5334 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5335 | if (!request) { |
| 5336 | err = -ENOMEM; |
| 5337 | goto out; |
| 5338 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5339 | |
| 5340 | if (n_ssids) |
| 5341 | request->ssids = (void *)&request->channels[n_channels]; |
| 5342 | request->n_ssids = n_ssids; |
| 5343 | if (ie_len) { |
| 5344 | if (request->ssids) |
| 5345 | request->ie = (void *)(request->ssids + n_ssids); |
| 5346 | else |
| 5347 | request->ie = (void *)(request->channels + n_channels); |
| 5348 | } |
| 5349 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5350 | if (n_match_sets) { |
| 5351 | if (request->ie) |
| 5352 | request->match_sets = (void *)(request->ie + ie_len); |
| 5353 | else if (request->ssids) |
| 5354 | request->match_sets = |
| 5355 | (void *)(request->ssids + n_ssids); |
| 5356 | else |
| 5357 | request->match_sets = |
| 5358 | (void *)(request->channels + n_channels); |
| 5359 | } |
| 5360 | request->n_match_sets = n_match_sets; |
| 5361 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5362 | i = 0; |
| 5363 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5364 | /* user specified, bail out if channel not found */ |
| 5365 | nla_for_each_nested(attr, |
| 5366 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5367 | tmp) { |
| 5368 | struct ieee80211_channel *chan; |
| 5369 | |
| 5370 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5371 | |
| 5372 | if (!chan) { |
| 5373 | err = -EINVAL; |
| 5374 | goto out_free; |
| 5375 | } |
| 5376 | |
| 5377 | /* ignore disabled channels */ |
| 5378 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5379 | continue; |
| 5380 | |
| 5381 | request->channels[i] = chan; |
| 5382 | i++; |
| 5383 | } |
| 5384 | } else { |
| 5385 | /* all channels */ |
| 5386 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5387 | int j; |
| 5388 | if (!wiphy->bands[band]) |
| 5389 | continue; |
| 5390 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5391 | struct ieee80211_channel *chan; |
| 5392 | |
| 5393 | chan = &wiphy->bands[band]->channels[j]; |
| 5394 | |
| 5395 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5396 | continue; |
| 5397 | |
| 5398 | request->channels[i] = chan; |
| 5399 | i++; |
| 5400 | } |
| 5401 | } |
| 5402 | } |
| 5403 | |
| 5404 | if (!i) { |
| 5405 | err = -EINVAL; |
| 5406 | goto out_free; |
| 5407 | } |
| 5408 | |
| 5409 | request->n_channels = i; |
| 5410 | |
| 5411 | i = 0; |
| 5412 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5413 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5414 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5415 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5416 | err = -EINVAL; |
| 5417 | goto out_free; |
| 5418 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5419 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5420 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5421 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5422 | i++; |
| 5423 | } |
| 5424 | } |
| 5425 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5426 | i = 0; |
| 5427 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5428 | nla_for_each_nested(attr, |
| 5429 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5430 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5431 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5432 | |
| 5433 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5434 | nla_data(attr), nla_len(attr), |
| 5435 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5436 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5437 | if (ssid) { |
| 5438 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5439 | err = -EINVAL; |
| 5440 | goto out_free; |
| 5441 | } |
| 5442 | memcpy(request->match_sets[i].ssid.ssid, |
| 5443 | nla_data(ssid), nla_len(ssid)); |
| 5444 | request->match_sets[i].ssid.ssid_len = |
| 5445 | nla_len(ssid); |
| 5446 | } |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5447 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5448 | if (rssi) |
| 5449 | request->rssi_thold = nla_get_u32(rssi); |
| 5450 | else |
| 5451 | request->rssi_thold = |
| 5452 | NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5453 | i++; |
| 5454 | } |
| 5455 | } |
| 5456 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5457 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5458 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5459 | memcpy((void *)request->ie, |
| 5460 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5461 | request->ie_len); |
| 5462 | } |
| 5463 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5464 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5465 | request->flags = nla_get_u32( |
| 5466 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5467 | if (((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5468 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
| 5469 | ((request->flags & NL80211_SCAN_FLAG_FLUSH) && |
| 5470 | !(wiphy->features & NL80211_FEATURE_SCAN_FLUSH))) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5471 | err = -EOPNOTSUPP; |
| 5472 | goto out_free; |
| 5473 | } |
| 5474 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5475 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5476 | request->dev = dev; |
| 5477 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5478 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5479 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5480 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5481 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5482 | if (!err) { |
| 5483 | rdev->sched_scan_req = request; |
| 5484 | nl80211_send_sched_scan(rdev, dev, |
| 5485 | NL80211_CMD_START_SCHED_SCAN); |
| 5486 | goto out; |
| 5487 | } |
| 5488 | |
| 5489 | out_free: |
| 5490 | kfree(request); |
| 5491 | out: |
| 5492 | return err; |
| 5493 | } |
| 5494 | |
| 5495 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5496 | struct genl_info *info) |
| 5497 | { |
| 5498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5499 | |
| 5500 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5501 | !rdev->ops->sched_scan_stop) |
| 5502 | return -EOPNOTSUPP; |
| 5503 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5504 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5505 | } |
| 5506 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5507 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5508 | struct genl_info *info) |
| 5509 | { |
| 5510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5511 | struct net_device *dev = info->user_ptr[1]; |
| 5512 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5513 | struct cfg80211_chan_def chandef; |
| 5514 | int err; |
| 5515 | |
| 5516 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5517 | if (err) |
| 5518 | return err; |
| 5519 | |
| 5520 | if (wdev->cac_started) |
| 5521 | return -EBUSY; |
| 5522 | |
| 5523 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef); |
| 5524 | if (err < 0) |
| 5525 | return err; |
| 5526 | |
| 5527 | if (err == 0) |
| 5528 | return -EINVAL; |
| 5529 | |
| 5530 | if (chandef.chan->dfs_state != NL80211_DFS_USABLE) |
| 5531 | return -EINVAL; |
| 5532 | |
| 5533 | if (!rdev->ops->start_radar_detection) |
| 5534 | return -EOPNOTSUPP; |
| 5535 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5536 | err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype, |
| 5537 | chandef.chan, CHAN_MODE_SHARED, |
| 5538 | BIT(chandef.width)); |
| 5539 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5540 | return err; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5541 | |
| 5542 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef); |
| 5543 | if (!err) { |
| 5544 | wdev->channel = chandef.chan; |
| 5545 | wdev->cac_started = true; |
| 5546 | wdev->cac_start_time = jiffies; |
| 5547 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5548 | return err; |
| 5549 | } |
| 5550 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5551 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 5552 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5553 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5554 | struct wireless_dev *wdev, |
| 5555 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5556 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5557 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5558 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5559 | void *hdr; |
| 5560 | struct nlattr *bss; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5561 | bool tsf = false; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5562 | |
| 5563 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5564 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5565 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5566 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 5567 | if (!hdr) |
| 5568 | return -1; |
| 5569 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5570 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5571 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5572 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 5573 | goto nla_put_failure; |
| 5574 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5575 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 5576 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5577 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 5578 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5579 | |
| 5580 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 5581 | if (!bss) |
| 5582 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5583 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5584 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5585 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5586 | |
| 5587 | rcu_read_lock(); |
| 5588 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5589 | if (ies) { |
| 5590 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5591 | goto fail_unlock_rcu; |
| 5592 | tsf = true; |
| 5593 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 5594 | ies->len, ies->data)) |
| 5595 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5596 | } |
| 5597 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5598 | if (ies) { |
| 5599 | if (!tsf && nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 5600 | goto fail_unlock_rcu; |
| 5601 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 5602 | ies->len, ies->data)) |
| 5603 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 5604 | } |
| 5605 | rcu_read_unlock(); |
| 5606 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5607 | if (res->beacon_interval && |
| 5608 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 5609 | goto nla_put_failure; |
| 5610 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 5611 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 5612 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 5613 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 5614 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5615 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 5616 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5617 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5618 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 5619 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5620 | break; |
| 5621 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5622 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 5623 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5624 | break; |
| 5625 | default: |
| 5626 | break; |
| 5627 | } |
| 5628 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5629 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5630 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5631 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5632 | if (intbss == wdev->current_bss && |
| 5633 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5634 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 5635 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5636 | break; |
| 5637 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5638 | if (intbss == wdev->current_bss && |
| 5639 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 5640 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 5641 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5642 | break; |
| 5643 | default: |
| 5644 | break; |
| 5645 | } |
| 5646 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5647 | nla_nest_end(msg, bss); |
| 5648 | |
| 5649 | return genlmsg_end(msg, hdr); |
| 5650 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 5651 | fail_unlock_rcu: |
| 5652 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5653 | nla_put_failure: |
| 5654 | genlmsg_cancel(msg, hdr); |
| 5655 | return -EMSGSIZE; |
| 5656 | } |
| 5657 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5658 | 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] | 5659 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5660 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5661 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5662 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5663 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5664 | int err; |
| 5665 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5666 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5667 | if (err) |
| 5668 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5669 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5670 | wdev_lock(wdev); |
| 5671 | spin_lock_bh(&rdev->bss_lock); |
| 5672 | cfg80211_bss_expire(rdev); |
| 5673 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5674 | cb->seq = rdev->bss_generation; |
| 5675 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5676 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5677 | if (++idx <= start) |
| 5678 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 5679 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5680 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5681 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5682 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5683 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5684 | } |
| 5685 | } |
| 5686 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 5687 | spin_unlock_bh(&rdev->bss_lock); |
| 5688 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5689 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5690 | cb->args[2] = idx; |
| 5691 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5692 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5693 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5694 | } |
| 5695 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5696 | 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] | 5697 | int flags, struct net_device *dev, |
| 5698 | struct survey_info *survey) |
| 5699 | { |
| 5700 | void *hdr; |
| 5701 | struct nlattr *infoattr; |
| 5702 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5703 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5704 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 5705 | if (!hdr) |
| 5706 | return -ENOMEM; |
| 5707 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5708 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 5709 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5710 | |
| 5711 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 5712 | if (!infoattr) |
| 5713 | goto nla_put_failure; |
| 5714 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5715 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 5716 | survey->channel->center_freq)) |
| 5717 | goto nla_put_failure; |
| 5718 | |
| 5719 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 5720 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 5721 | goto nla_put_failure; |
| 5722 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 5723 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 5724 | goto nla_put_failure; |
| 5725 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 5726 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 5727 | survey->channel_time)) |
| 5728 | goto nla_put_failure; |
| 5729 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 5730 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 5731 | survey->channel_time_busy)) |
| 5732 | goto nla_put_failure; |
| 5733 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 5734 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 5735 | survey->channel_time_ext_busy)) |
| 5736 | goto nla_put_failure; |
| 5737 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 5738 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 5739 | survey->channel_time_rx)) |
| 5740 | goto nla_put_failure; |
| 5741 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 5742 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 5743 | survey->channel_time_tx)) |
| 5744 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5745 | |
| 5746 | nla_nest_end(msg, infoattr); |
| 5747 | |
| 5748 | return genlmsg_end(msg, hdr); |
| 5749 | |
| 5750 | nla_put_failure: |
| 5751 | genlmsg_cancel(msg, hdr); |
| 5752 | return -EMSGSIZE; |
| 5753 | } |
| 5754 | |
| 5755 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 5756 | struct netlink_callback *cb) |
| 5757 | { |
| 5758 | struct survey_info survey; |
| 5759 | struct cfg80211_registered_device *dev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5760 | struct wireless_dev *wdev; |
| 5761 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5762 | int res; |
| 5763 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5764 | res = nl80211_prepare_wdev_dump(skb, cb, &dev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5765 | if (res) |
| 5766 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5767 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5768 | if (!wdev->netdev) { |
| 5769 | res = -EINVAL; |
| 5770 | goto out_err; |
| 5771 | } |
| 5772 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5773 | if (!dev->ops->dump_survey) { |
| 5774 | res = -EOPNOTSUPP; |
| 5775 | goto out_err; |
| 5776 | } |
| 5777 | |
| 5778 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5779 | struct ieee80211_channel *chan; |
| 5780 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5781 | res = rdev_dump_survey(dev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5782 | if (res == -ENOENT) |
| 5783 | break; |
| 5784 | if (res) |
| 5785 | goto out_err; |
| 5786 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 5787 | /* Survey without a channel doesn't make sense */ |
| 5788 | if (!survey.channel) { |
| 5789 | res = -EINVAL; |
| 5790 | goto out; |
| 5791 | } |
| 5792 | |
| 5793 | chan = ieee80211_get_channel(&dev->wiphy, |
| 5794 | survey.channel->center_freq); |
| 5795 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 5796 | survey_idx++; |
| 5797 | continue; |
| 5798 | } |
| 5799 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5800 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5801 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5802 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5803 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5804 | goto out; |
| 5805 | survey_idx++; |
| 5806 | } |
| 5807 | |
| 5808 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5809 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5810 | res = skb->len; |
| 5811 | out_err: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5812 | nl80211_finish_wdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5813 | return res; |
| 5814 | } |
| 5815 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5816 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 5817 | { |
| 5818 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 5819 | NL80211_WPA_VERSION_2)); |
| 5820 | } |
| 5821 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5822 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 5823 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5824 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5825 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5826 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5827 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 5828 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5829 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5830 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5831 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5832 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5833 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5834 | return -EINVAL; |
| 5835 | |
| 5836 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5837 | return -EINVAL; |
| 5838 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 5839 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 5840 | return -EINVAL; |
| 5841 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5842 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 5843 | return -EINVAL; |
| 5844 | |
| 5845 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5846 | return -EINVAL; |
| 5847 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5848 | err = nl80211_parse_key(info, &key); |
| 5849 | if (err) |
| 5850 | return err; |
| 5851 | |
| 5852 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 5853 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 5854 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5855 | if (!key.p.key || !key.p.key_len) |
| 5856 | return -EINVAL; |
| 5857 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 5858 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 5859 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 5860 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 5861 | return -EINVAL; |
| 5862 | if (key.idx > 4) |
| 5863 | return -EINVAL; |
| 5864 | } else { |
| 5865 | key.p.key_len = 0; |
| 5866 | key.p.key = NULL; |
| 5867 | } |
| 5868 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5869 | if (key.idx >= 0) { |
| 5870 | int i; |
| 5871 | bool ok = false; |
| 5872 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 5873 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 5874 | ok = true; |
| 5875 | break; |
| 5876 | } |
| 5877 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5878 | if (!ok) |
| 5879 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 5880 | } |
| 5881 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5882 | if (!rdev->ops->auth) |
| 5883 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5884 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5885 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5886 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5887 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5888 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5889 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5890 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5891 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5892 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 5893 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5894 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5895 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5896 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5897 | |
| 5898 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5899 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5900 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5901 | } |
| 5902 | |
| 5903 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5904 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5905 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5906 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5907 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 5908 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 5909 | return -EINVAL; |
| 5910 | |
| 5911 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 5912 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 5913 | return -EINVAL; |
| 5914 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5915 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 5916 | /* need to include at least Auth Transaction and Status Code */ |
| 5917 | if (sae_data_len < 4) |
| 5918 | return -EINVAL; |
| 5919 | } |
| 5920 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5921 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5922 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 5923 | /* |
| 5924 | * Since we no longer track auth state, ignore |
| 5925 | * requests to only change local state. |
| 5926 | */ |
| 5927 | if (local_state_change) |
| 5928 | return 0; |
| 5929 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 5930 | wdev_lock(dev->ieee80211_ptr); |
| 5931 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 5932 | ssid, ssid_len, ie, ie_len, |
| 5933 | key.p.key, key.p.key_len, key.idx, |
| 5934 | sae_data, sae_data_len); |
| 5935 | wdev_unlock(dev->ieee80211_ptr); |
| 5936 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5937 | } |
| 5938 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5939 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 5940 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5941 | struct cfg80211_crypto_settings *settings, |
| 5942 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5943 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 5944 | memset(settings, 0, sizeof(*settings)); |
| 5945 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5946 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 5947 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5948 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 5949 | u16 proto; |
| 5950 | proto = nla_get_u16( |
| 5951 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 5952 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 5953 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 5954 | proto != ETH_P_PAE) |
| 5955 | return -EINVAL; |
| 5956 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 5957 | settings->control_port_no_encrypt = true; |
| 5958 | } else |
| 5959 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 5960 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5961 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 5962 | void *data; |
| 5963 | int len, i; |
| 5964 | |
| 5965 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5966 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 5967 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 5968 | |
| 5969 | if (len % sizeof(u32)) |
| 5970 | return -EINVAL; |
| 5971 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5972 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5973 | return -EINVAL; |
| 5974 | |
| 5975 | memcpy(settings->ciphers_pairwise, data, len); |
| 5976 | |
| 5977 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5978 | if (!cfg80211_supported_cipher_suite( |
| 5979 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5980 | settings->ciphers_pairwise[i])) |
| 5981 | return -EINVAL; |
| 5982 | } |
| 5983 | |
| 5984 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 5985 | settings->cipher_group = |
| 5986 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 5987 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 5988 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5989 | return -EINVAL; |
| 5990 | } |
| 5991 | |
| 5992 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 5993 | settings->wpa_versions = |
| 5994 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 5995 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 5996 | return -EINVAL; |
| 5997 | } |
| 5998 | |
| 5999 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6000 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6001 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6002 | |
| 6003 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6004 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6005 | settings->n_akm_suites = len / sizeof(u32); |
| 6006 | |
| 6007 | if (len % sizeof(u32)) |
| 6008 | return -EINVAL; |
| 6009 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6010 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6011 | return -EINVAL; |
| 6012 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6013 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | return 0; |
| 6017 | } |
| 6018 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6019 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6020 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6021 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6022 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6023 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6024 | struct cfg80211_assoc_request req = {}; |
| 6025 | const u8 *bssid, *ssid; |
| 6026 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6027 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6028 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6029 | return -EINVAL; |
| 6030 | |
| 6031 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6032 | !info->attrs[NL80211_ATTR_SSID] || |
| 6033 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6034 | return -EINVAL; |
| 6035 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6036 | if (!rdev->ops->assoc) |
| 6037 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6038 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6039 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6040 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6041 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6042 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6043 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6044 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6045 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 6046 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6047 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 6048 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6049 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6050 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6051 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6052 | |
| 6053 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6054 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6055 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6056 | } |
| 6057 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6058 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6059 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6060 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6061 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6062 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6063 | else if (mfp != NL80211_MFP_NO) |
| 6064 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6065 | } |
| 6066 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6067 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6068 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6069 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6070 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6071 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6072 | |
| 6073 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6074 | memcpy(&req.ht_capa_mask, |
| 6075 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6076 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6077 | |
| 6078 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6079 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6080 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6081 | memcpy(&req.ht_capa, |
| 6082 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6083 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6084 | } |
| 6085 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6086 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6087 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6088 | |
| 6089 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6090 | memcpy(&req.vht_capa_mask, |
| 6091 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6092 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6093 | |
| 6094 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6095 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6096 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6097 | memcpy(&req.vht_capa, |
| 6098 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6099 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6100 | } |
| 6101 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6102 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6103 | if (!err) { |
| 6104 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6105 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6106 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6107 | wdev_unlock(dev->ieee80211_ptr); |
| 6108 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6109 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6110 | return err; |
| 6111 | } |
| 6112 | |
| 6113 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6114 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6115 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6116 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6117 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6118 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6119 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6120 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6121 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6122 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6123 | return -EINVAL; |
| 6124 | |
| 6125 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6126 | return -EINVAL; |
| 6127 | |
| 6128 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6129 | return -EINVAL; |
| 6130 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6131 | if (!rdev->ops->deauth) |
| 6132 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6133 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6134 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6135 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6136 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6137 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6138 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6139 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6140 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6141 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6142 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6143 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6144 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6145 | |
| 6146 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6147 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6148 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6149 | } |
| 6150 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6151 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6152 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6153 | wdev_lock(dev->ieee80211_ptr); |
| 6154 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6155 | local_state_change); |
| 6156 | wdev_unlock(dev->ieee80211_ptr); |
| 6157 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6158 | } |
| 6159 | |
| 6160 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6161 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6163 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6164 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6165 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6166 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6167 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6168 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6169 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6170 | return -EINVAL; |
| 6171 | |
| 6172 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6173 | return -EINVAL; |
| 6174 | |
| 6175 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6176 | return -EINVAL; |
| 6177 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6178 | if (!rdev->ops->disassoc) |
| 6179 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6180 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6181 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6182 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6183 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6184 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6185 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6186 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6187 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6188 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6189 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6190 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6191 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6192 | |
| 6193 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6194 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6195 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6196 | } |
| 6197 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6198 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6199 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6200 | wdev_lock(dev->ieee80211_ptr); |
| 6201 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6202 | local_state_change); |
| 6203 | wdev_unlock(dev->ieee80211_ptr); |
| 6204 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6205 | } |
| 6206 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6207 | static bool |
| 6208 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6209 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6210 | int rateval) |
| 6211 | { |
| 6212 | struct wiphy *wiphy = &rdev->wiphy; |
| 6213 | bool found = false; |
| 6214 | int band, i; |
| 6215 | |
| 6216 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6217 | struct ieee80211_supported_band *sband; |
| 6218 | |
| 6219 | sband = wiphy->bands[band]; |
| 6220 | if (!sband) |
| 6221 | continue; |
| 6222 | |
| 6223 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6224 | if (sband->bitrates[i].bitrate == rateval) { |
| 6225 | mcast_rate[band] = i + 1; |
| 6226 | found = true; |
| 6227 | break; |
| 6228 | } |
| 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | return found; |
| 6233 | } |
| 6234 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6235 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6236 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6238 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6239 | struct cfg80211_ibss_params ibss; |
| 6240 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6241 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6242 | int err; |
| 6243 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6244 | memset(&ibss, 0, sizeof(ibss)); |
| 6245 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6246 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6247 | return -EINVAL; |
| 6248 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6249 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6250 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6251 | return -EINVAL; |
| 6252 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6253 | ibss.beacon_interval = 100; |
| 6254 | |
| 6255 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6256 | ibss.beacon_interval = |
| 6257 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6258 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6259 | return -EINVAL; |
| 6260 | } |
| 6261 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6262 | if (!rdev->ops->join_ibss) |
| 6263 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6264 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6265 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6266 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6267 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6268 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6269 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6270 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6271 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6272 | |
| 6273 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6274 | return -EINVAL; |
| 6275 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6276 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6277 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6278 | |
| 6279 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6280 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6281 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6282 | } |
| 6283 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6284 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6285 | if (err) |
| 6286 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6287 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6288 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6289 | return -EINVAL; |
| 6290 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame^] | 6291 | switch (ibss.chandef.width) { |
| 6292 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6293 | break; |
| 6294 | case NL80211_CHAN_WIDTH_20: |
| 6295 | case NL80211_CHAN_WIDTH_40: |
| 6296 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6297 | break; |
| 6298 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6299 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame^] | 6300 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6301 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6302 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6303 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6304 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6305 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6306 | u8 *rates = |
| 6307 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6308 | int n_rates = |
| 6309 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6310 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6311 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6312 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6313 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6314 | &ibss.basic_rates); |
| 6315 | if (err) |
| 6316 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6317 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6318 | |
| 6319 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6320 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6321 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6322 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6323 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6324 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6325 | bool no_ht = false; |
| 6326 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6327 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6328 | info->attrs[NL80211_ATTR_KEYS], |
| 6329 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6330 | if (IS_ERR(connkeys)) |
| 6331 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6332 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6333 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6334 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6335 | kfree(connkeys); |
| 6336 | return -EINVAL; |
| 6337 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6338 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6339 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6340 | ibss.control_port = |
| 6341 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6342 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6343 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6344 | if (err) |
| 6345 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6346 | return err; |
| 6347 | } |
| 6348 | |
| 6349 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6350 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6352 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6353 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6354 | if (!rdev->ops->leave_ibss) |
| 6355 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6356 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6357 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6358 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6359 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6360 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6361 | } |
| 6362 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6363 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6364 | { |
| 6365 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6366 | struct net_device *dev = info->user_ptr[1]; |
| 6367 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6368 | u32 nla_rate; |
| 6369 | int err; |
| 6370 | |
| 6371 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6372 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6373 | return -EOPNOTSUPP; |
| 6374 | |
| 6375 | if (!rdev->ops->set_mcast_rate) |
| 6376 | return -EOPNOTSUPP; |
| 6377 | |
| 6378 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6379 | |
| 6380 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6381 | return -EINVAL; |
| 6382 | |
| 6383 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6384 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6385 | return -EINVAL; |
| 6386 | |
| 6387 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6388 | |
| 6389 | return err; |
| 6390 | } |
| 6391 | |
| 6392 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6393 | #ifdef CONFIG_NL80211_TESTMODE |
| 6394 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 6395 | .name = "testmode", |
| 6396 | }; |
| 6397 | |
| 6398 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 6399 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6400 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6401 | int err; |
| 6402 | |
| 6403 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 6404 | return -EINVAL; |
| 6405 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6406 | err = -EOPNOTSUPP; |
| 6407 | if (rdev->ops->testmode_cmd) { |
| 6408 | rdev->testmode_info = info; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6409 | err = rdev_testmode_cmd(rdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6410 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 6411 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 6412 | rdev->testmode_info = NULL; |
| 6413 | } |
| 6414 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6415 | return err; |
| 6416 | } |
| 6417 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6418 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 6419 | struct netlink_callback *cb) |
| 6420 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6421 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6422 | int err; |
| 6423 | long phy_idx; |
| 6424 | void *data = NULL; |
| 6425 | int data_len = 0; |
| 6426 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6427 | rtnl_lock(); |
| 6428 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6429 | if (cb->args[0]) { |
| 6430 | /* |
| 6431 | * 0 is a valid index, but not valid for args[0], |
| 6432 | * so we need to offset by 1. |
| 6433 | */ |
| 6434 | phy_idx = cb->args[0] - 1; |
| 6435 | } else { |
| 6436 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 6437 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 6438 | nl80211_policy); |
| 6439 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6440 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6441 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6442 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 6443 | nl80211_fam.attrbuf); |
| 6444 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6445 | err = PTR_ERR(rdev); |
| 6446 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6447 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6448 | phy_idx = rdev->wiphy_idx; |
| 6449 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 6450 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6451 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 6452 | cb->args[1] = |
| 6453 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 6454 | } |
| 6455 | |
| 6456 | if (cb->args[1]) { |
| 6457 | data = nla_data((void *)cb->args[1]); |
| 6458 | data_len = nla_len((void *)cb->args[1]); |
| 6459 | } |
| 6460 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6461 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 6462 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6463 | err = -ENOENT; |
| 6464 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6465 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6466 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6467 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6468 | err = -EOPNOTSUPP; |
| 6469 | goto out_err; |
| 6470 | } |
| 6471 | |
| 6472 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6473 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6474 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6475 | NL80211_CMD_TESTMODE); |
| 6476 | struct nlattr *tmdata; |
| 6477 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6478 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6479 | genlmsg_cancel(skb, hdr); |
| 6480 | break; |
| 6481 | } |
| 6482 | |
| 6483 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6484 | if (!tmdata) { |
| 6485 | genlmsg_cancel(skb, hdr); |
| 6486 | break; |
| 6487 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6488 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6489 | nla_nest_end(skb, tmdata); |
| 6490 | |
| 6491 | if (err == -ENOBUFS || err == -ENOENT) { |
| 6492 | genlmsg_cancel(skb, hdr); |
| 6493 | break; |
| 6494 | } else if (err) { |
| 6495 | genlmsg_cancel(skb, hdr); |
| 6496 | goto out_err; |
| 6497 | } |
| 6498 | |
| 6499 | genlmsg_end(skb, hdr); |
| 6500 | } |
| 6501 | |
| 6502 | err = skb->len; |
| 6503 | /* see above */ |
| 6504 | cb->args[0] = phy_idx + 1; |
| 6505 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6506 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6507 | return err; |
| 6508 | } |
| 6509 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6510 | static struct sk_buff * |
| 6511 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6512 | int approxlen, u32 portid, u32 seq, gfp_t gfp) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6513 | { |
| 6514 | struct sk_buff *skb; |
| 6515 | void *hdr; |
| 6516 | struct nlattr *data; |
| 6517 | |
| 6518 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6519 | if (!skb) |
| 6520 | return NULL; |
| 6521 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6522 | hdr = nl80211hdr_put(skb, portid, seq, 0, NL80211_CMD_TESTMODE); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6523 | if (!hdr) { |
| 6524 | kfree_skb(skb); |
| 6525 | return NULL; |
| 6526 | } |
| 6527 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6528 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6529 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6530 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 6531 | |
| 6532 | ((void **)skb->cb)[0] = rdev; |
| 6533 | ((void **)skb->cb)[1] = hdr; |
| 6534 | ((void **)skb->cb)[2] = data; |
| 6535 | |
| 6536 | return skb; |
| 6537 | |
| 6538 | nla_put_failure: |
| 6539 | kfree_skb(skb); |
| 6540 | return NULL; |
| 6541 | } |
| 6542 | |
| 6543 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 6544 | int approxlen) |
| 6545 | { |
| 6546 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6547 | |
| 6548 | if (WARN_ON(!rdev->testmode_info)) |
| 6549 | return NULL; |
| 6550 | |
| 6551 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6552 | rdev->testmode_info->snd_portid, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6553 | rdev->testmode_info->snd_seq, |
| 6554 | GFP_KERNEL); |
| 6555 | } |
| 6556 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 6557 | |
| 6558 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 6559 | { |
| 6560 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 6561 | void *hdr = ((void **)skb->cb)[1]; |
| 6562 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6563 | |
| 6564 | if (WARN_ON(!rdev->testmode_info)) { |
| 6565 | kfree_skb(skb); |
| 6566 | return -EINVAL; |
| 6567 | } |
| 6568 | |
| 6569 | nla_nest_end(skb, data); |
| 6570 | genlmsg_end(skb, hdr); |
| 6571 | return genlmsg_reply(skb, rdev->testmode_info); |
| 6572 | } |
| 6573 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 6574 | |
| 6575 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 6576 | int approxlen, gfp_t gfp) |
| 6577 | { |
| 6578 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 6579 | |
| 6580 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 6581 | } |
| 6582 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 6583 | |
| 6584 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 6585 | { |
| 6586 | void *hdr = ((void **)skb->cb)[1]; |
| 6587 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 6588 | |
| 6589 | nla_nest_end(skb, data); |
| 6590 | genlmsg_end(skb, hdr); |
| 6591 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 6592 | } |
| 6593 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 6594 | #endif |
| 6595 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6596 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 6597 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6598 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6599 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6600 | struct cfg80211_connect_params connect; |
| 6601 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6602 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6603 | int err; |
| 6604 | |
| 6605 | memset(&connect, 0, sizeof(connect)); |
| 6606 | |
| 6607 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6608 | return -EINVAL; |
| 6609 | |
| 6610 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 6611 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6612 | return -EINVAL; |
| 6613 | |
| 6614 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 6615 | connect.auth_type = |
| 6616 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6617 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 6618 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6619 | return -EINVAL; |
| 6620 | } else |
| 6621 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 6622 | |
| 6623 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 6624 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6625 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6626 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6627 | if (err) |
| 6628 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6629 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6630 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6631 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6632 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6633 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6634 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6635 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 6636 | connect.bg_scan_period = -1; |
| 6637 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 6638 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 6639 | connect.bg_scan_period = |
| 6640 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 6641 | } |
| 6642 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6643 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6644 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6645 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6646 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6647 | |
| 6648 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6649 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6650 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6651 | } |
| 6652 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 6653 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 6654 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 6655 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 6656 | connect.mfp != NL80211_MFP_NO) |
| 6657 | return -EINVAL; |
| 6658 | } else { |
| 6659 | connect.mfp = NL80211_MFP_NO; |
| 6660 | } |
| 6661 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6662 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6663 | connect.channel = |
| 6664 | ieee80211_get_channel(wiphy, |
| 6665 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 6666 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6667 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 6668 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6669 | } |
| 6670 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6671 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 6672 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6673 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6674 | if (IS_ERR(connkeys)) |
| 6675 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6676 | } |
| 6677 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6678 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 6679 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 6680 | |
| 6681 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6682 | memcpy(&connect.ht_capa_mask, |
| 6683 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6684 | sizeof(connect.ht_capa_mask)); |
| 6685 | |
| 6686 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6687 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
| 6688 | kfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6689 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 6690 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6691 | memcpy(&connect.ht_capa, |
| 6692 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6693 | sizeof(connect.ht_capa)); |
| 6694 | } |
| 6695 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6696 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 6697 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 6698 | |
| 6699 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 6700 | memcpy(&connect.vht_capa_mask, |
| 6701 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6702 | sizeof(connect.vht_capa_mask)); |
| 6703 | |
| 6704 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 6705 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
| 6706 | kfree(connkeys); |
| 6707 | return -EINVAL; |
| 6708 | } |
| 6709 | memcpy(&connect.vht_capa, |
| 6710 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6711 | sizeof(connect.vht_capa)); |
| 6712 | } |
| 6713 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6714 | wdev_lock(dev->ieee80211_ptr); |
| 6715 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 6716 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6717 | if (err) |
| 6718 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6719 | return err; |
| 6720 | } |
| 6721 | |
| 6722 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 6723 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6725 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6726 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6727 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6728 | |
| 6729 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6730 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 6731 | else |
| 6732 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6733 | |
| 6734 | if (reason == 0) |
| 6735 | return -EINVAL; |
| 6736 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6737 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6738 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6739 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6740 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6741 | wdev_lock(dev->ieee80211_ptr); |
| 6742 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 6743 | wdev_unlock(dev->ieee80211_ptr); |
| 6744 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6745 | } |
| 6746 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6747 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 6748 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6750 | struct net *net; |
| 6751 | int err; |
| 6752 | u32 pid; |
| 6753 | |
| 6754 | if (!info->attrs[NL80211_ATTR_PID]) |
| 6755 | return -EINVAL; |
| 6756 | |
| 6757 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 6758 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6759 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6760 | if (IS_ERR(net)) |
| 6761 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6762 | |
| 6763 | err = 0; |
| 6764 | |
| 6765 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6766 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 6767 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6768 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6769 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6770 | return err; |
| 6771 | } |
| 6772 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6773 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6774 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6776 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 6777 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6778 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6779 | struct cfg80211_pmksa pmksa; |
| 6780 | |
| 6781 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 6782 | |
| 6783 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6784 | return -EINVAL; |
| 6785 | |
| 6786 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 6787 | return -EINVAL; |
| 6788 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6789 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 6790 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6791 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6792 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6793 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6794 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6795 | |
| 6796 | switch (info->genlhdr->cmd) { |
| 6797 | case NL80211_CMD_SET_PMKSA: |
| 6798 | rdev_ops = rdev->ops->set_pmksa; |
| 6799 | break; |
| 6800 | case NL80211_CMD_DEL_PMKSA: |
| 6801 | rdev_ops = rdev->ops->del_pmksa; |
| 6802 | break; |
| 6803 | default: |
| 6804 | WARN_ON(1); |
| 6805 | break; |
| 6806 | } |
| 6807 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6808 | if (!rdev_ops) |
| 6809 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6810 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6811 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6812 | } |
| 6813 | |
| 6814 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 6815 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6816 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6817 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6818 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6819 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6820 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6821 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6822 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6823 | if (!rdev->ops->flush_pmksa) |
| 6824 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6825 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6826 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6827 | } |
| 6828 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6829 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 6830 | { |
| 6831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6832 | struct net_device *dev = info->user_ptr[1]; |
| 6833 | u8 action_code, dialog_token; |
| 6834 | u16 status_code; |
| 6835 | u8 *peer; |
| 6836 | |
| 6837 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6838 | !rdev->ops->tdls_mgmt) |
| 6839 | return -EOPNOTSUPP; |
| 6840 | |
| 6841 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 6842 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 6843 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 6844 | !info->attrs[NL80211_ATTR_IE] || |
| 6845 | !info->attrs[NL80211_ATTR_MAC]) |
| 6846 | return -EINVAL; |
| 6847 | |
| 6848 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6849 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 6850 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 6851 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 6852 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6853 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
| 6854 | dialog_token, status_code, |
| 6855 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 6856 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 6860 | { |
| 6861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6862 | struct net_device *dev = info->user_ptr[1]; |
| 6863 | enum nl80211_tdls_operation operation; |
| 6864 | u8 *peer; |
| 6865 | |
| 6866 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 6867 | !rdev->ops->tdls_oper) |
| 6868 | return -EOPNOTSUPP; |
| 6869 | |
| 6870 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 6871 | !info->attrs[NL80211_ATTR_MAC]) |
| 6872 | return -EINVAL; |
| 6873 | |
| 6874 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 6875 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6876 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6877 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6878 | } |
| 6879 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6880 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 6881 | struct genl_info *info) |
| 6882 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6883 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6884 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6885 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6886 | struct sk_buff *msg; |
| 6887 | void *hdr; |
| 6888 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6889 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6890 | int err; |
| 6891 | |
| 6892 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6893 | !info->attrs[NL80211_ATTR_DURATION]) |
| 6894 | return -EINVAL; |
| 6895 | |
| 6896 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 6897 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 6898 | if (!rdev->ops->remain_on_channel || |
| 6899 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6900 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6901 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 6902 | /* |
| 6903 | * We should be on that channel for at least a minimum amount of |
| 6904 | * time (10ms) but no longer than the driver supports. |
| 6905 | */ |
| 6906 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 6907 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 6908 | return -EINVAL; |
| 6909 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6910 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6911 | if (err) |
| 6912 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6913 | |
| 6914 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6915 | if (!msg) |
| 6916 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6917 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6918 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6919 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 6920 | |
| 6921 | if (IS_ERR(hdr)) { |
| 6922 | err = PTR_ERR(hdr); |
| 6923 | goto free_msg; |
| 6924 | } |
| 6925 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6926 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 6927 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6928 | |
| 6929 | if (err) |
| 6930 | goto free_msg; |
| 6931 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6932 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6933 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6934 | |
| 6935 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6936 | |
| 6937 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6938 | |
| 6939 | nla_put_failure: |
| 6940 | err = -ENOBUFS; |
| 6941 | free_msg: |
| 6942 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6943 | return err; |
| 6944 | } |
| 6945 | |
| 6946 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 6947 | struct genl_info *info) |
| 6948 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 6950 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6951 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6952 | |
| 6953 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6954 | return -EINVAL; |
| 6955 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6956 | if (!rdev->ops->cancel_remain_on_channel) |
| 6957 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6958 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6959 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6960 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6961 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6962 | } |
| 6963 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6964 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6965 | u8 *rates, u8 rates_len) |
| 6966 | { |
| 6967 | u8 i; |
| 6968 | u32 mask = 0; |
| 6969 | |
| 6970 | for (i = 0; i < rates_len; i++) { |
| 6971 | int rate = (rates[i] & 0x7f) * 5; |
| 6972 | int ridx; |
| 6973 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 6974 | struct ieee80211_rate *srate = |
| 6975 | &sband->bitrates[ridx]; |
| 6976 | if (rate == srate->bitrate) { |
| 6977 | mask |= 1 << ridx; |
| 6978 | break; |
| 6979 | } |
| 6980 | } |
| 6981 | if (ridx == sband->n_bitrates) |
| 6982 | return 0; /* rate not found */ |
| 6983 | } |
| 6984 | |
| 6985 | return mask; |
| 6986 | } |
| 6987 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 6988 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 6989 | u8 *rates, u8 rates_len, |
| 6990 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 6991 | { |
| 6992 | u8 i; |
| 6993 | |
| 6994 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 6995 | |
| 6996 | for (i = 0; i < rates_len; i++) { |
| 6997 | int ridx, rbit; |
| 6998 | |
| 6999 | ridx = rates[i] / 8; |
| 7000 | rbit = BIT(rates[i] % 8); |
| 7001 | |
| 7002 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7003 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7004 | return false; |
| 7005 | |
| 7006 | /* check availability */ |
| 7007 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7008 | mcs[ridx] |= rbit; |
| 7009 | else |
| 7010 | return false; |
| 7011 | } |
| 7012 | |
| 7013 | return true; |
| 7014 | } |
| 7015 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7016 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7017 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7018 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7019 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 7020 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7021 | }; |
| 7022 | |
| 7023 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7024 | struct genl_info *info) |
| 7025 | { |
| 7026 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7028 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7029 | int rem, i; |
| 7030 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7031 | struct nlattr *tx_rates; |
| 7032 | struct ieee80211_supported_band *sband; |
| 7033 | |
| 7034 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 7035 | return -EINVAL; |
| 7036 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7037 | if (!rdev->ops->set_bitrate_mask) |
| 7038 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7039 | |
| 7040 | memset(&mask, 0, sizeof(mask)); |
| 7041 | /* Default to all rates enabled */ |
| 7042 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7043 | sband = rdev->wiphy.bands[i]; |
| 7044 | mask.control[i].legacy = |
| 7045 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7046 | if (sband) |
| 7047 | memcpy(mask.control[i].mcs, |
| 7048 | sband->ht_cap.mcs.rx_mask, |
| 7049 | sizeof(mask.control[i].mcs)); |
| 7050 | else |
| 7051 | memset(mask.control[i].mcs, 0, |
| 7052 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7053 | } |
| 7054 | |
| 7055 | /* |
| 7056 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7057 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7058 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7059 | 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] | 7060 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 7061 | { |
| 7062 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7063 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7064 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7065 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7066 | if (sband == NULL) |
| 7067 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7068 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7069 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7070 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7071 | mask.control[band].legacy = rateset_to_mask( |
| 7072 | sband, |
| 7073 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7074 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7075 | if ((mask.control[band].legacy == 0) && |
| 7076 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7077 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7078 | } |
| 7079 | if (tb[NL80211_TXRATE_MCS]) { |
| 7080 | if (!ht_rateset_to_mask( |
| 7081 | sband, |
| 7082 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 7083 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 7084 | mask.control[band].mcs)) |
| 7085 | return -EINVAL; |
| 7086 | } |
| 7087 | |
| 7088 | if (mask.control[band].legacy == 0) { |
| 7089 | /* don't allow empty legacy rates if HT |
| 7090 | * is not even supported. */ |
| 7091 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 7092 | return -EINVAL; |
| 7093 | |
| 7094 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 7095 | if (mask.control[band].mcs[i]) |
| 7096 | break; |
| 7097 | |
| 7098 | /* legacy and mcs rates may not be both empty */ |
| 7099 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7100 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7101 | } |
| 7102 | } |
| 7103 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7104 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7105 | } |
| 7106 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7107 | 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] | 7108 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7109 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7110 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7111 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7112 | |
| 7113 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7114 | return -EINVAL; |
| 7115 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7116 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7117 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7118 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7119 | switch (wdev->iftype) { |
| 7120 | case NL80211_IFTYPE_STATION: |
| 7121 | case NL80211_IFTYPE_ADHOC: |
| 7122 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7123 | case NL80211_IFTYPE_AP: |
| 7124 | case NL80211_IFTYPE_AP_VLAN: |
| 7125 | case NL80211_IFTYPE_MESH_POINT: |
| 7126 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7127 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7128 | break; |
| 7129 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7130 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7131 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7132 | |
| 7133 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7134 | if (!rdev->ops->mgmt_tx) |
| 7135 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7136 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7137 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7138 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7139 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7140 | } |
| 7141 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7142 | 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] | 7143 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7144 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7145 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7146 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7147 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7148 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7149 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7150 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7151 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7152 | bool offchan, no_cck, dont_wait_for_ack; |
| 7153 | |
| 7154 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7155 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7156 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7157 | return -EINVAL; |
| 7158 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7159 | if (!rdev->ops->mgmt_tx) |
| 7160 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7161 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7162 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7163 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7164 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7165 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7166 | case NL80211_IFTYPE_STATION: |
| 7167 | case NL80211_IFTYPE_ADHOC: |
| 7168 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7169 | case NL80211_IFTYPE_AP: |
| 7170 | case NL80211_IFTYPE_AP_VLAN: |
| 7171 | case NL80211_IFTYPE_MESH_POINT: |
| 7172 | case NL80211_IFTYPE_P2P_GO: |
| 7173 | break; |
| 7174 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7175 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7176 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7177 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7178 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7179 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7180 | return -EINVAL; |
| 7181 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7182 | |
| 7183 | /* |
| 7184 | * We should wait on the channel for at least a minimum amount |
| 7185 | * of time (10ms) but no longer than the driver supports. |
| 7186 | */ |
| 7187 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7188 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 7189 | return -EINVAL; |
| 7190 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7191 | } |
| 7192 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7193 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 7194 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7195 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 7196 | return -EINVAL; |
| 7197 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7198 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7199 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7200 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7201 | * the driver. The latter will use the current one |
| 7202 | */ |
| 7203 | chandef.chan = NULL; |
| 7204 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7205 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7206 | if (err) |
| 7207 | return err; |
| 7208 | } |
| 7209 | |
| 7210 | if (!chandef.chan && offchan) |
| 7211 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7212 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7213 | if (!dont_wait_for_ack) { |
| 7214 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7215 | if (!msg) |
| 7216 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7217 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7218 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7219 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7220 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7221 | if (IS_ERR(hdr)) { |
| 7222 | err = PTR_ERR(hdr); |
| 7223 | goto free_msg; |
| 7224 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7225 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7226 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7227 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, chandef.chan, offchan, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7228 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 7229 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7230 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7231 | if (err) |
| 7232 | goto free_msg; |
| 7233 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7234 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7235 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7236 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7237 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7238 | genlmsg_end(msg, hdr); |
| 7239 | return genlmsg_reply(msg, info); |
| 7240 | } |
| 7241 | |
| 7242 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7243 | |
| 7244 | nla_put_failure: |
| 7245 | err = -ENOBUFS; |
| 7246 | free_msg: |
| 7247 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7248 | return err; |
| 7249 | } |
| 7250 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7251 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7252 | { |
| 7253 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7254 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7255 | u64 cookie; |
| 7256 | |
| 7257 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7258 | return -EINVAL; |
| 7259 | |
| 7260 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7261 | return -EOPNOTSUPP; |
| 7262 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7263 | switch (wdev->iftype) { |
| 7264 | case NL80211_IFTYPE_STATION: |
| 7265 | case NL80211_IFTYPE_ADHOC: |
| 7266 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7267 | case NL80211_IFTYPE_AP: |
| 7268 | case NL80211_IFTYPE_AP_VLAN: |
| 7269 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7270 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7271 | break; |
| 7272 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7273 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7274 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7275 | |
| 7276 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7277 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7278 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7279 | } |
| 7280 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7281 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7282 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7284 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7285 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7286 | u8 ps_state; |
| 7287 | bool state; |
| 7288 | int err; |
| 7289 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7290 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7291 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7292 | |
| 7293 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7294 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7295 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7296 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7297 | |
| 7298 | wdev = dev->ieee80211_ptr; |
| 7299 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7300 | if (!rdev->ops->set_power_mgmt) |
| 7301 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7302 | |
| 7303 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7304 | |
| 7305 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7306 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7307 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7308 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7309 | if (!err) |
| 7310 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7311 | return err; |
| 7312 | } |
| 7313 | |
| 7314 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7315 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7317 | enum nl80211_ps_state ps_state; |
| 7318 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7319 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7320 | struct sk_buff *msg; |
| 7321 | void *hdr; |
| 7322 | int err; |
| 7323 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7324 | wdev = dev->ieee80211_ptr; |
| 7325 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7326 | if (!rdev->ops->set_power_mgmt) |
| 7327 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7328 | |
| 7329 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7330 | if (!msg) |
| 7331 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7332 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7333 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7334 | NL80211_CMD_GET_POWER_SAVE); |
| 7335 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7336 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7337 | goto free_msg; |
| 7338 | } |
| 7339 | |
| 7340 | if (wdev->ps) |
| 7341 | ps_state = NL80211_PS_ENABLED; |
| 7342 | else |
| 7343 | ps_state = NL80211_PS_DISABLED; |
| 7344 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7345 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 7346 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7347 | |
| 7348 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7349 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7350 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7351 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7352 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7353 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7354 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7355 | return err; |
| 7356 | } |
| 7357 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7358 | static struct nla_policy |
| 7359 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 7360 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 7361 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 7362 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7363 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 7364 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 7365 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7366 | }; |
| 7367 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7368 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7369 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7370 | { |
| 7371 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7372 | struct wireless_dev *wdev; |
| 7373 | struct net_device *dev = info->user_ptr[1]; |
| 7374 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 7375 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7376 | return -EINVAL; |
| 7377 | |
| 7378 | wdev = dev->ieee80211_ptr; |
| 7379 | |
| 7380 | if (!rdev->ops->set_cqm_txe_config) |
| 7381 | return -EOPNOTSUPP; |
| 7382 | |
| 7383 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 7384 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7385 | return -EOPNOTSUPP; |
| 7386 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7387 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7388 | } |
| 7389 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7390 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 7391 | s32 threshold, u32 hysteresis) |
| 7392 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7393 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7394 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7395 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7396 | |
| 7397 | if (threshold > 0) |
| 7398 | return -EINVAL; |
| 7399 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7400 | wdev = dev->ieee80211_ptr; |
| 7401 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7402 | if (!rdev->ops->set_cqm_rssi_config) |
| 7403 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7404 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7405 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7406 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7407 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7408 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7409 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7410 | } |
| 7411 | |
| 7412 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 7413 | { |
| 7414 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 7415 | struct nlattr *cqm; |
| 7416 | int err; |
| 7417 | |
| 7418 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 7419 | if (!cqm) { |
| 7420 | err = -EINVAL; |
| 7421 | goto out; |
| 7422 | } |
| 7423 | |
| 7424 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 7425 | nl80211_attr_cqm_policy); |
| 7426 | if (err) |
| 7427 | goto out; |
| 7428 | |
| 7429 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 7430 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 7431 | s32 threshold; |
| 7432 | u32 hysteresis; |
| 7433 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 7434 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 7435 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 7436 | } else if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 7437 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 7438 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 7439 | u32 rate, pkts, intvl; |
| 7440 | rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 7441 | pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 7442 | intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 7443 | err = nl80211_set_cqm_txe(info, rate, pkts, intvl); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7444 | } else |
| 7445 | err = -EINVAL; |
| 7446 | |
| 7447 | out: |
| 7448 | return err; |
| 7449 | } |
| 7450 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7451 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7452 | { |
| 7453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7454 | struct net_device *dev = info->user_ptr[1]; |
| 7455 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7456 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7457 | int err; |
| 7458 | |
| 7459 | /* start with default */ |
| 7460 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7461 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7462 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7463 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7464 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7465 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7466 | if (err) |
| 7467 | return err; |
| 7468 | } |
| 7469 | |
| 7470 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 7471 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 7472 | return -EINVAL; |
| 7473 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7474 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7475 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 7476 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 7477 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7478 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 7479 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7480 | return -EINVAL; |
| 7481 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 7482 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7483 | setup.beacon_interval = |
| 7484 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7485 | if (setup.beacon_interval < 10 || |
| 7486 | setup.beacon_interval > 10000) |
| 7487 | return -EINVAL; |
| 7488 | } |
| 7489 | |
| 7490 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 7491 | setup.dtim_period = |
| 7492 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 7493 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 7494 | return -EINVAL; |
| 7495 | } |
| 7496 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7497 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 7498 | /* parse additional setup parameters if given */ |
| 7499 | err = nl80211_parse_mesh_setup(info, &setup); |
| 7500 | if (err) |
| 7501 | return err; |
| 7502 | } |
| 7503 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 7504 | if (setup.user_mpm) |
| 7505 | cfg.auto_open_plinks = false; |
| 7506 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7507 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7508 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 7509 | if (err) |
| 7510 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7511 | } else { |
| 7512 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7513 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 7514 | } |
| 7515 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 7516 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7517 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7518 | int n_rates = |
| 7519 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7520 | struct ieee80211_supported_band *sband; |
| 7521 | |
| 7522 | if (!setup.chandef.chan) |
| 7523 | return -EINVAL; |
| 7524 | |
| 7525 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 7526 | |
| 7527 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7528 | &setup.basic_rates); |
| 7529 | if (err) |
| 7530 | return err; |
| 7531 | } |
| 7532 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7533 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7534 | } |
| 7535 | |
| 7536 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 7537 | { |
| 7538 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7539 | struct net_device *dev = info->user_ptr[1]; |
| 7540 | |
| 7541 | return cfg80211_leave_mesh(rdev, dev); |
| 7542 | } |
| 7543 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 7544 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7545 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 7546 | struct cfg80211_registered_device *rdev) |
| 7547 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7548 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7549 | struct nlattr *nl_pats, *nl_pat; |
| 7550 | int i, pat_len; |
| 7551 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7552 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7553 | return 0; |
| 7554 | |
| 7555 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 7556 | if (!nl_pats) |
| 7557 | return -ENOBUFS; |
| 7558 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7559 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7560 | nl_pat = nla_nest_start(msg, i + 1); |
| 7561 | if (!nl_pat) |
| 7562 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7563 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7564 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 7565 | DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7566 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7567 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7568 | pat_len, wowlan->patterns[i].pattern) || |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7569 | nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7570 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7571 | return -ENOBUFS; |
| 7572 | nla_nest_end(msg, nl_pat); |
| 7573 | } |
| 7574 | nla_nest_end(msg, nl_pats); |
| 7575 | |
| 7576 | return 0; |
| 7577 | } |
| 7578 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7579 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 7580 | struct cfg80211_wowlan_tcp *tcp) |
| 7581 | { |
| 7582 | struct nlattr *nl_tcp; |
| 7583 | |
| 7584 | if (!tcp) |
| 7585 | return 0; |
| 7586 | |
| 7587 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 7588 | if (!nl_tcp) |
| 7589 | return -ENOBUFS; |
| 7590 | |
| 7591 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 7592 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 7593 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 7594 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 7595 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 7596 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 7597 | tcp->payload_len, tcp->payload) || |
| 7598 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 7599 | tcp->data_interval) || |
| 7600 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 7601 | tcp->wake_len, tcp->wake_data) || |
| 7602 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 7603 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 7604 | return -ENOBUFS; |
| 7605 | |
| 7606 | if (tcp->payload_seq.len && |
| 7607 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 7608 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 7609 | return -ENOBUFS; |
| 7610 | |
| 7611 | if (tcp->payload_tok.len && |
| 7612 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 7613 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 7614 | &tcp->payload_tok)) |
| 7615 | return -ENOBUFS; |
| 7616 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 7617 | nla_nest_end(msg, nl_tcp); |
| 7618 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7619 | return 0; |
| 7620 | } |
| 7621 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7622 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7623 | { |
| 7624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7625 | struct sk_buff *msg; |
| 7626 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7627 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7628 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7629 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7630 | return -EOPNOTSUPP; |
| 7631 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7632 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7633 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7634 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 7635 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 7636 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 7637 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7641 | if (!msg) |
| 7642 | return -ENOMEM; |
| 7643 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7644 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7645 | NL80211_CMD_GET_WOWLAN); |
| 7646 | if (!hdr) |
| 7647 | goto nla_put_failure; |
| 7648 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7649 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7650 | struct nlattr *nl_wowlan; |
| 7651 | |
| 7652 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 7653 | if (!nl_wowlan) |
| 7654 | goto nla_put_failure; |
| 7655 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7656 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7657 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7658 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7659 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7660 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7661 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7662 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7663 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7664 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7665 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7666 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7667 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7668 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7669 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 7670 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7671 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7672 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 7673 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7674 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7675 | if (nl80211_send_wowlan_tcp(msg, |
| 7676 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7677 | goto nla_put_failure; |
| 7678 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7679 | nla_nest_end(msg, nl_wowlan); |
| 7680 | } |
| 7681 | |
| 7682 | genlmsg_end(msg, hdr); |
| 7683 | return genlmsg_reply(msg, info); |
| 7684 | |
| 7685 | nla_put_failure: |
| 7686 | nlmsg_free(msg); |
| 7687 | return -ENOBUFS; |
| 7688 | } |
| 7689 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7690 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 7691 | struct nlattr *attr, |
| 7692 | struct cfg80211_wowlan *trig) |
| 7693 | { |
| 7694 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 7695 | struct cfg80211_wowlan_tcp *cfg; |
| 7696 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 7697 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 7698 | u32 size; |
| 7699 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 7700 | int err, port; |
| 7701 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7702 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7703 | return -EINVAL; |
| 7704 | |
| 7705 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 7706 | nla_data(attr), nla_len(attr), |
| 7707 | nl80211_wowlan_tcp_policy); |
| 7708 | if (err) |
| 7709 | return err; |
| 7710 | |
| 7711 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 7712 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 7713 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 7714 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 7715 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 7716 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 7717 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 7718 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 7719 | return -EINVAL; |
| 7720 | |
| 7721 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7722 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7723 | return -EINVAL; |
| 7724 | |
| 7725 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7726 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 7727 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7728 | return -EINVAL; |
| 7729 | |
| 7730 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7731 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7732 | return -EINVAL; |
| 7733 | |
| 7734 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 7735 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 7736 | return -EINVAL; |
| 7737 | |
| 7738 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 7739 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7740 | |
| 7741 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 7742 | tokens_size = tokln - sizeof(*tok); |
| 7743 | |
| 7744 | if (!tok->len || tokens_size % tok->len) |
| 7745 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7746 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7747 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7748 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7749 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7750 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7751 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7752 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7753 | return -EINVAL; |
| 7754 | if (tok->offset + tok->len > data_size) |
| 7755 | return -EINVAL; |
| 7756 | } |
| 7757 | |
| 7758 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 7759 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7760 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7761 | return -EINVAL; |
| 7762 | if (seq->len == 0 || seq->len > 4) |
| 7763 | return -EINVAL; |
| 7764 | if (seq->len + seq->offset > data_size) |
| 7765 | return -EINVAL; |
| 7766 | } |
| 7767 | |
| 7768 | size = sizeof(*cfg); |
| 7769 | size += data_size; |
| 7770 | size += wake_size + wake_mask_size; |
| 7771 | size += tokens_size; |
| 7772 | |
| 7773 | cfg = kzalloc(size, GFP_KERNEL); |
| 7774 | if (!cfg) |
| 7775 | return -ENOMEM; |
| 7776 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 7777 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 7778 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 7779 | ETH_ALEN); |
| 7780 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 7781 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 7782 | else |
| 7783 | port = 0; |
| 7784 | #ifdef CONFIG_INET |
| 7785 | /* allocate a socket and port for it and use it */ |
| 7786 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 7787 | IPPROTO_TCP, &cfg->sock, 1); |
| 7788 | if (err) { |
| 7789 | kfree(cfg); |
| 7790 | return err; |
| 7791 | } |
| 7792 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 7793 | sock_release(cfg->sock); |
| 7794 | kfree(cfg); |
| 7795 | return -EADDRINUSE; |
| 7796 | } |
| 7797 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 7798 | #else |
| 7799 | if (!port) { |
| 7800 | kfree(cfg); |
| 7801 | return -EINVAL; |
| 7802 | } |
| 7803 | cfg->src_port = port; |
| 7804 | #endif |
| 7805 | |
| 7806 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 7807 | cfg->payload_len = data_size; |
| 7808 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 7809 | memcpy((void *)cfg->payload, |
| 7810 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 7811 | data_size); |
| 7812 | if (seq) |
| 7813 | cfg->payload_seq = *seq; |
| 7814 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 7815 | cfg->wake_len = wake_size; |
| 7816 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 7817 | memcpy((void *)cfg->wake_data, |
| 7818 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 7819 | wake_size); |
| 7820 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 7821 | data_size + wake_size; |
| 7822 | memcpy((void *)cfg->wake_mask, |
| 7823 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 7824 | wake_mask_size); |
| 7825 | if (tok) { |
| 7826 | cfg->tokens_size = tokens_size; |
| 7827 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 7828 | } |
| 7829 | |
| 7830 | trig->tcp = cfg; |
| 7831 | |
| 7832 | return 0; |
| 7833 | } |
| 7834 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7835 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 7836 | { |
| 7837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7838 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7839 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7840 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7841 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7842 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7843 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7844 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 7845 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7846 | return -EOPNOTSUPP; |
| 7847 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7848 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 7849 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7850 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7851 | goto set_wakeup; |
| 7852 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7853 | |
| 7854 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 7855 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7856 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 7857 | nl80211_wowlan_policy); |
| 7858 | if (err) |
| 7859 | return err; |
| 7860 | |
| 7861 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 7862 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 7863 | return -EINVAL; |
| 7864 | new_triggers.any = true; |
| 7865 | } |
| 7866 | |
| 7867 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 7868 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 7869 | return -EINVAL; |
| 7870 | new_triggers.disconnect = true; |
| 7871 | } |
| 7872 | |
| 7873 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 7874 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 7875 | return -EINVAL; |
| 7876 | new_triggers.magic_pkt = true; |
| 7877 | } |
| 7878 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 7879 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 7880 | return -EINVAL; |
| 7881 | |
| 7882 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 7883 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 7884 | return -EINVAL; |
| 7885 | new_triggers.gtk_rekey_failure = true; |
| 7886 | } |
| 7887 | |
| 7888 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 7889 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 7890 | return -EINVAL; |
| 7891 | new_triggers.eap_identity_req = true; |
| 7892 | } |
| 7893 | |
| 7894 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 7895 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 7896 | return -EINVAL; |
| 7897 | new_triggers.four_way_handshake = true; |
| 7898 | } |
| 7899 | |
| 7900 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 7901 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 7902 | return -EINVAL; |
| 7903 | new_triggers.rfkill_release = true; |
| 7904 | } |
| 7905 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7906 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 7907 | struct nlattr *pat; |
| 7908 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7909 | int rem, pat_len, mask_len, pkt_offset; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7910 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 7911 | |
| 7912 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7913 | rem) |
| 7914 | n_patterns++; |
| 7915 | if (n_patterns > wowlan->n_patterns) |
| 7916 | return -EINVAL; |
| 7917 | |
| 7918 | new_triggers.patterns = kcalloc(n_patterns, |
| 7919 | sizeof(new_triggers.patterns[0]), |
| 7920 | GFP_KERNEL); |
| 7921 | if (!new_triggers.patterns) |
| 7922 | return -ENOMEM; |
| 7923 | |
| 7924 | new_triggers.n_patterns = n_patterns; |
| 7925 | i = 0; |
| 7926 | |
| 7927 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 7928 | rem) { |
| 7929 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 7930 | nla_data(pat), nla_len(pat), NULL); |
| 7931 | err = -EINVAL; |
| 7932 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 7933 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 7934 | goto error; |
| 7935 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 7936 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 7937 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 7938 | mask_len) |
| 7939 | goto error; |
| 7940 | if (pat_len > wowlan->pattern_max_len || |
| 7941 | pat_len < wowlan->pattern_min_len) |
| 7942 | goto error; |
| 7943 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 7944 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) |
| 7945 | pkt_offset = 0; |
| 7946 | else |
| 7947 | pkt_offset = nla_get_u32( |
| 7948 | pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); |
| 7949 | if (pkt_offset > wowlan->max_pkt_offset) |
| 7950 | goto error; |
| 7951 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 7952 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7953 | new_triggers.patterns[i].mask = |
| 7954 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 7955 | if (!new_triggers.patterns[i].mask) { |
| 7956 | err = -ENOMEM; |
| 7957 | goto error; |
| 7958 | } |
| 7959 | new_triggers.patterns[i].pattern = |
| 7960 | new_triggers.patterns[i].mask + mask_len; |
| 7961 | memcpy(new_triggers.patterns[i].mask, |
| 7962 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 7963 | mask_len); |
| 7964 | new_triggers.patterns[i].pattern_len = pat_len; |
| 7965 | memcpy(new_triggers.patterns[i].pattern, |
| 7966 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 7967 | pat_len); |
| 7968 | i++; |
| 7969 | } |
| 7970 | } |
| 7971 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7972 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 7973 | err = nl80211_parse_wowlan_tcp( |
| 7974 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 7975 | &new_triggers); |
| 7976 | if (err) |
| 7977 | goto error; |
| 7978 | } |
| 7979 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7980 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 7981 | if (!ntrig) { |
| 7982 | err = -ENOMEM; |
| 7983 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7984 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7985 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7986 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7987 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 7988 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 7989 | if (rdev->ops->set_wakeup && |
| 7990 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 7991 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 7992 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7993 | return 0; |
| 7994 | error: |
| 7995 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 7996 | kfree(new_triggers.patterns[i].mask); |
| 7997 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 7998 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 7999 | sock_release(new_triggers.tcp->sock); |
| 8000 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8001 | return err; |
| 8002 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8003 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8004 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8005 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8006 | { |
| 8007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8008 | struct net_device *dev = info->user_ptr[1]; |
| 8009 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8010 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8011 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8012 | int err; |
| 8013 | |
| 8014 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8015 | return -EINVAL; |
| 8016 | |
| 8017 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8018 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8019 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8020 | nl80211_rekey_policy); |
| 8021 | if (err) |
| 8022 | return err; |
| 8023 | |
| 8024 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8025 | return -ERANGE; |
| 8026 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8027 | return -ERANGE; |
| 8028 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8029 | return -ERANGE; |
| 8030 | |
| 8031 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 8032 | NL80211_KEK_LEN); |
| 8033 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 8034 | NL80211_KCK_LEN); |
| 8035 | memcpy(rekey_data.replay_ctr, |
| 8036 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 8037 | NL80211_REPLAY_CTR_LEN); |
| 8038 | |
| 8039 | wdev_lock(wdev); |
| 8040 | if (!wdev->current_bss) { |
| 8041 | err = -ENOTCONN; |
| 8042 | goto out; |
| 8043 | } |
| 8044 | |
| 8045 | if (!rdev->ops->set_rekey_data) { |
| 8046 | err = -EOPNOTSUPP; |
| 8047 | goto out; |
| 8048 | } |
| 8049 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8050 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8051 | out: |
| 8052 | wdev_unlock(wdev); |
| 8053 | return err; |
| 8054 | } |
| 8055 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8056 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8057 | struct genl_info *info) |
| 8058 | { |
| 8059 | struct net_device *dev = info->user_ptr[1]; |
| 8060 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8061 | |
| 8062 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8063 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8064 | return -EINVAL; |
| 8065 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8066 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8067 | return -EBUSY; |
| 8068 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8069 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8070 | return 0; |
| 8071 | } |
| 8072 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8073 | static int nl80211_probe_client(struct sk_buff *skb, |
| 8074 | struct genl_info *info) |
| 8075 | { |
| 8076 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8077 | struct net_device *dev = info->user_ptr[1]; |
| 8078 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8079 | struct sk_buff *msg; |
| 8080 | void *hdr; |
| 8081 | const u8 *addr; |
| 8082 | u64 cookie; |
| 8083 | int err; |
| 8084 | |
| 8085 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8086 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8087 | return -EOPNOTSUPP; |
| 8088 | |
| 8089 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8090 | return -EINVAL; |
| 8091 | |
| 8092 | if (!rdev->ops->probe_client) |
| 8093 | return -EOPNOTSUPP; |
| 8094 | |
| 8095 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8096 | if (!msg) |
| 8097 | return -ENOMEM; |
| 8098 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8099 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8100 | NL80211_CMD_PROBE_CLIENT); |
| 8101 | |
| 8102 | if (IS_ERR(hdr)) { |
| 8103 | err = PTR_ERR(hdr); |
| 8104 | goto free_msg; |
| 8105 | } |
| 8106 | |
| 8107 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8108 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8109 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8110 | if (err) |
| 8111 | goto free_msg; |
| 8112 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8113 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8114 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8115 | |
| 8116 | genlmsg_end(msg, hdr); |
| 8117 | |
| 8118 | return genlmsg_reply(msg, info); |
| 8119 | |
| 8120 | nla_put_failure: |
| 8121 | err = -ENOBUFS; |
| 8122 | free_msg: |
| 8123 | nlmsg_free(msg); |
| 8124 | return err; |
| 8125 | } |
| 8126 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8127 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 8128 | { |
| 8129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8130 | struct cfg80211_beacon_registration *reg, *nreg; |
| 8131 | int rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8132 | |
| 8133 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 8134 | return -EOPNOTSUPP; |
| 8135 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8136 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 8137 | if (!nreg) |
| 8138 | return -ENOMEM; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8139 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8140 | /* First, check if already registered. */ |
| 8141 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 8142 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 8143 | if (reg->nlportid == info->snd_portid) { |
| 8144 | rv = -EALREADY; |
| 8145 | goto out_err; |
| 8146 | } |
| 8147 | } |
| 8148 | /* Add it to the list */ |
| 8149 | nreg->nlportid = info->snd_portid; |
| 8150 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 8151 | |
| 8152 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8153 | |
| 8154 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 8155 | out_err: |
| 8156 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 8157 | kfree(nreg); |
| 8158 | return rv; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8159 | } |
| 8160 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8161 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8162 | { |
| 8163 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8164 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8165 | int err; |
| 8166 | |
| 8167 | if (!rdev->ops->start_p2p_device) |
| 8168 | return -EOPNOTSUPP; |
| 8169 | |
| 8170 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8171 | return -EOPNOTSUPP; |
| 8172 | |
| 8173 | if (wdev->p2p_started) |
| 8174 | return 0; |
| 8175 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8176 | err = cfg80211_can_add_interface(rdev, wdev->iftype); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8177 | if (err) |
| 8178 | return err; |
| 8179 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 8180 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8181 | if (err) |
| 8182 | return err; |
| 8183 | |
| 8184 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8185 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8186 | |
| 8187 | return 0; |
| 8188 | } |
| 8189 | |
| 8190 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 8191 | { |
| 8192 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8193 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8194 | |
| 8195 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 8196 | return -EOPNOTSUPP; |
| 8197 | |
| 8198 | if (!rdev->ops->stop_p2p_device) |
| 8199 | return -EOPNOTSUPP; |
| 8200 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 8201 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8202 | |
| 8203 | return 0; |
| 8204 | } |
| 8205 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8206 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 8207 | struct genl_info *info) |
| 8208 | { |
| 8209 | void *hdr; |
| 8210 | struct sk_buff *msg; |
| 8211 | |
| 8212 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8213 | if (!msg) |
| 8214 | return -ENOMEM; |
| 8215 | |
| 8216 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8217 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 8218 | if (!hdr) |
| 8219 | goto nla_put_failure; |
| 8220 | |
| 8221 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 8222 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 8223 | goto nla_put_failure; |
| 8224 | |
| 8225 | genlmsg_end(msg, hdr); |
| 8226 | return genlmsg_reply(msg, info); |
| 8227 | |
| 8228 | nla_put_failure: |
| 8229 | kfree_skb(msg); |
| 8230 | return -ENOBUFS; |
| 8231 | } |
| 8232 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8233 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 8234 | { |
| 8235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8236 | struct cfg80211_update_ft_ies_params ft_params; |
| 8237 | struct net_device *dev = info->user_ptr[1]; |
| 8238 | |
| 8239 | if (!rdev->ops->update_ft_ies) |
| 8240 | return -EOPNOTSUPP; |
| 8241 | |
| 8242 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 8243 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8244 | return -EINVAL; |
| 8245 | |
| 8246 | memset(&ft_params, 0, sizeof(ft_params)); |
| 8247 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 8248 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8249 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8250 | |
| 8251 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 8252 | } |
| 8253 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8254 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 8255 | struct genl_info *info) |
| 8256 | { |
| 8257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8258 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8259 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 8260 | u16 duration; |
| 8261 | int ret; |
| 8262 | |
| 8263 | if (!rdev->ops->crit_proto_start) |
| 8264 | return -EOPNOTSUPP; |
| 8265 | |
| 8266 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 8267 | return -EINVAL; |
| 8268 | |
| 8269 | if (rdev->crit_proto_nlportid) |
| 8270 | return -EBUSY; |
| 8271 | |
| 8272 | /* determine protocol if provided */ |
| 8273 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 8274 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 8275 | |
| 8276 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 8277 | return -EINVAL; |
| 8278 | |
| 8279 | /* timeout must be provided */ |
| 8280 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 8281 | return -EINVAL; |
| 8282 | |
| 8283 | duration = |
| 8284 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 8285 | |
| 8286 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 8287 | return -ERANGE; |
| 8288 | |
| 8289 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 8290 | if (!ret) |
| 8291 | rdev->crit_proto_nlportid = info->snd_portid; |
| 8292 | |
| 8293 | return ret; |
| 8294 | } |
| 8295 | |
| 8296 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 8297 | struct genl_info *info) |
| 8298 | { |
| 8299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8300 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8301 | |
| 8302 | if (!rdev->ops->crit_proto_stop) |
| 8303 | return -EOPNOTSUPP; |
| 8304 | |
| 8305 | if (rdev->crit_proto_nlportid) { |
| 8306 | rdev->crit_proto_nlportid = 0; |
| 8307 | rdev_crit_proto_stop(rdev, wdev); |
| 8308 | } |
| 8309 | return 0; |
| 8310 | } |
| 8311 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8312 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 8313 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 8314 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8315 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 8316 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 8317 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8318 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8319 | /* 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] | 8320 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 8321 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8322 | |
| 8323 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8324 | struct genl_info *info) |
| 8325 | { |
| 8326 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8327 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8328 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8329 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 8330 | |
| 8331 | if (rtnl) |
| 8332 | rtnl_lock(); |
| 8333 | |
| 8334 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 8335 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8336 | if (IS_ERR(rdev)) { |
| 8337 | if (rtnl) |
| 8338 | rtnl_unlock(); |
| 8339 | return PTR_ERR(rdev); |
| 8340 | } |
| 8341 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8342 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 8343 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8344 | ASSERT_RTNL(); |
| 8345 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8346 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 8347 | info->attrs); |
| 8348 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8349 | if (rtnl) |
| 8350 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8351 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8352 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8353 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8354 | dev = wdev->netdev; |
| 8355 | rdev = wiphy_to_dev(wdev->wiphy); |
| 8356 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8357 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 8358 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8359 | if (rtnl) |
| 8360 | rtnl_unlock(); |
| 8361 | return -EINVAL; |
| 8362 | } |
| 8363 | |
| 8364 | info->user_ptr[1] = dev; |
| 8365 | } else { |
| 8366 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8367 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 8368 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8369 | if (dev) { |
| 8370 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 8371 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8372 | if (rtnl) |
| 8373 | rtnl_unlock(); |
| 8374 | return -ENETDOWN; |
| 8375 | } |
| 8376 | |
| 8377 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8378 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 8379 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8380 | if (rtnl) |
| 8381 | rtnl_unlock(); |
| 8382 | return -ENETDOWN; |
| 8383 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8384 | } |
| 8385 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8386 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8387 | } |
| 8388 | |
| 8389 | return 0; |
| 8390 | } |
| 8391 | |
| 8392 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 8393 | struct genl_info *info) |
| 8394 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 8395 | if (info->user_ptr[1]) { |
| 8396 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 8397 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8398 | |
| 8399 | if (wdev->netdev) |
| 8400 | dev_put(wdev->netdev); |
| 8401 | } else { |
| 8402 | dev_put(info->user_ptr[1]); |
| 8403 | } |
| 8404 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8405 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 8406 | rtnl_unlock(); |
| 8407 | } |
| 8408 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8409 | static struct genl_ops nl80211_ops[] = { |
| 8410 | { |
| 8411 | .cmd = NL80211_CMD_GET_WIPHY, |
| 8412 | .doit = nl80211_get_wiphy, |
| 8413 | .dumpit = nl80211_dump_wiphy, |
| 8414 | .policy = nl80211_policy, |
| 8415 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8416 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8417 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8418 | }, |
| 8419 | { |
| 8420 | .cmd = NL80211_CMD_SET_WIPHY, |
| 8421 | .doit = nl80211_set_wiphy, |
| 8422 | .policy = nl80211_policy, |
| 8423 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8424 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8425 | }, |
| 8426 | { |
| 8427 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 8428 | .doit = nl80211_get_interface, |
| 8429 | .dumpit = nl80211_dump_interface, |
| 8430 | .policy = nl80211_policy, |
| 8431 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8432 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8433 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8434 | }, |
| 8435 | { |
| 8436 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 8437 | .doit = nl80211_set_interface, |
| 8438 | .policy = nl80211_policy, |
| 8439 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8440 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8441 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8442 | }, |
| 8443 | { |
| 8444 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 8445 | .doit = nl80211_new_interface, |
| 8446 | .policy = nl80211_policy, |
| 8447 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8448 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8449 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8450 | }, |
| 8451 | { |
| 8452 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 8453 | .doit = nl80211_del_interface, |
| 8454 | .policy = nl80211_policy, |
| 8455 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 8456 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8457 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8458 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8459 | { |
| 8460 | .cmd = NL80211_CMD_GET_KEY, |
| 8461 | .doit = nl80211_get_key, |
| 8462 | .policy = nl80211_policy, |
| 8463 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8464 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8465 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8466 | }, |
| 8467 | { |
| 8468 | .cmd = NL80211_CMD_SET_KEY, |
| 8469 | .doit = nl80211_set_key, |
| 8470 | .policy = nl80211_policy, |
| 8471 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8472 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8473 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8474 | }, |
| 8475 | { |
| 8476 | .cmd = NL80211_CMD_NEW_KEY, |
| 8477 | .doit = nl80211_new_key, |
| 8478 | .policy = nl80211_policy, |
| 8479 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8481 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8482 | }, |
| 8483 | { |
| 8484 | .cmd = NL80211_CMD_DEL_KEY, |
| 8485 | .doit = nl80211_del_key, |
| 8486 | .policy = nl80211_policy, |
| 8487 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8488 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8489 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 8490 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8491 | { |
| 8492 | .cmd = NL80211_CMD_SET_BEACON, |
| 8493 | .policy = nl80211_policy, |
| 8494 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8495 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8496 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8497 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8498 | }, |
| 8499 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8500 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8501 | .policy = nl80211_policy, |
| 8502 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8503 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8504 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8505 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8506 | }, |
| 8507 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8508 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8509 | .policy = nl80211_policy, |
| 8510 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 8511 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8512 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8513 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 8514 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8515 | { |
| 8516 | .cmd = NL80211_CMD_GET_STATION, |
| 8517 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8518 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8519 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8520 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8521 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8522 | }, |
| 8523 | { |
| 8524 | .cmd = NL80211_CMD_SET_STATION, |
| 8525 | .doit = nl80211_set_station, |
| 8526 | .policy = nl80211_policy, |
| 8527 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8528 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8529 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8530 | }, |
| 8531 | { |
| 8532 | .cmd = NL80211_CMD_NEW_STATION, |
| 8533 | .doit = nl80211_new_station, |
| 8534 | .policy = nl80211_policy, |
| 8535 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8536 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8537 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8538 | }, |
| 8539 | { |
| 8540 | .cmd = NL80211_CMD_DEL_STATION, |
| 8541 | .doit = nl80211_del_station, |
| 8542 | .policy = nl80211_policy, |
| 8543 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8544 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8545 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 8546 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8547 | { |
| 8548 | .cmd = NL80211_CMD_GET_MPATH, |
| 8549 | .doit = nl80211_get_mpath, |
| 8550 | .dumpit = nl80211_dump_mpath, |
| 8551 | .policy = nl80211_policy, |
| 8552 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8553 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8554 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8555 | }, |
| 8556 | { |
| 8557 | .cmd = NL80211_CMD_SET_MPATH, |
| 8558 | .doit = nl80211_set_mpath, |
| 8559 | .policy = nl80211_policy, |
| 8560 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8561 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8562 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8563 | }, |
| 8564 | { |
| 8565 | .cmd = NL80211_CMD_NEW_MPATH, |
| 8566 | .doit = nl80211_new_mpath, |
| 8567 | .policy = nl80211_policy, |
| 8568 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8569 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8570 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8571 | }, |
| 8572 | { |
| 8573 | .cmd = NL80211_CMD_DEL_MPATH, |
| 8574 | .doit = nl80211_del_mpath, |
| 8575 | .policy = nl80211_policy, |
| 8576 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8577 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8578 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 8579 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8580 | { |
| 8581 | .cmd = NL80211_CMD_SET_BSS, |
| 8582 | .doit = nl80211_set_bss, |
| 8583 | .policy = nl80211_policy, |
| 8584 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8585 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8586 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 8587 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8588 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8589 | .cmd = NL80211_CMD_GET_REG, |
| 8590 | .doit = nl80211_get_reg, |
| 8591 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8592 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8593 | /* can be retrieved by unprivileged users */ |
| 8594 | }, |
| 8595 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8596 | .cmd = NL80211_CMD_SET_REG, |
| 8597 | .doit = nl80211_set_reg, |
| 8598 | .policy = nl80211_policy, |
| 8599 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8600 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8601 | }, |
| 8602 | { |
| 8603 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 8604 | .doit = nl80211_req_set_reg, |
| 8605 | .policy = nl80211_policy, |
| 8606 | .flags = GENL_ADMIN_PERM, |
| 8607 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8608 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8609 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 8610 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8611 | .policy = nl80211_policy, |
| 8612 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8613 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8614 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8615 | }, |
| 8616 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8617 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 8618 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8619 | .policy = nl80211_policy, |
| 8620 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8621 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8622 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 8623 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 8624 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8625 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 8626 | .doit = nl80211_trigger_scan, |
| 8627 | .policy = nl80211_policy, |
| 8628 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8629 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8630 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8631 | }, |
| 8632 | { |
| 8633 | .cmd = NL80211_CMD_GET_SCAN, |
| 8634 | .policy = nl80211_policy, |
| 8635 | .dumpit = nl80211_dump_scan, |
| 8636 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8637 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8638 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 8639 | .doit = nl80211_start_sched_scan, |
| 8640 | .policy = nl80211_policy, |
| 8641 | .flags = GENL_ADMIN_PERM, |
| 8642 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8643 | NL80211_FLAG_NEED_RTNL, |
| 8644 | }, |
| 8645 | { |
| 8646 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 8647 | .doit = nl80211_stop_sched_scan, |
| 8648 | .policy = nl80211_policy, |
| 8649 | .flags = GENL_ADMIN_PERM, |
| 8650 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8651 | NL80211_FLAG_NEED_RTNL, |
| 8652 | }, |
| 8653 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8654 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 8655 | .doit = nl80211_authenticate, |
| 8656 | .policy = nl80211_policy, |
| 8657 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8658 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8659 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8660 | }, |
| 8661 | { |
| 8662 | .cmd = NL80211_CMD_ASSOCIATE, |
| 8663 | .doit = nl80211_associate, |
| 8664 | .policy = nl80211_policy, |
| 8665 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8666 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8667 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8668 | }, |
| 8669 | { |
| 8670 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 8671 | .doit = nl80211_deauthenticate, |
| 8672 | .policy = nl80211_policy, |
| 8673 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8674 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8675 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8676 | }, |
| 8677 | { |
| 8678 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 8679 | .doit = nl80211_disassociate, |
| 8680 | .policy = nl80211_policy, |
| 8681 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8682 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8683 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8684 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8685 | { |
| 8686 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 8687 | .doit = nl80211_join_ibss, |
| 8688 | .policy = nl80211_policy, |
| 8689 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8690 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8691 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8692 | }, |
| 8693 | { |
| 8694 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 8695 | .doit = nl80211_leave_ibss, |
| 8696 | .policy = nl80211_policy, |
| 8697 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8698 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8699 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8700 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8701 | #ifdef CONFIG_NL80211_TESTMODE |
| 8702 | { |
| 8703 | .cmd = NL80211_CMD_TESTMODE, |
| 8704 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8705 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8706 | .policy = nl80211_policy, |
| 8707 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8708 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8709 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8710 | }, |
| 8711 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8712 | { |
| 8713 | .cmd = NL80211_CMD_CONNECT, |
| 8714 | .doit = nl80211_connect, |
| 8715 | .policy = nl80211_policy, |
| 8716 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8717 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8718 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8719 | }, |
| 8720 | { |
| 8721 | .cmd = NL80211_CMD_DISCONNECT, |
| 8722 | .doit = nl80211_disconnect, |
| 8723 | .policy = nl80211_policy, |
| 8724 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 8725 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8726 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8727 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8728 | { |
| 8729 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 8730 | .doit = nl80211_wiphy_netns, |
| 8731 | .policy = nl80211_policy, |
| 8732 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8733 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8734 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8735 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 8736 | { |
| 8737 | .cmd = NL80211_CMD_GET_SURVEY, |
| 8738 | .policy = nl80211_policy, |
| 8739 | .dumpit = nl80211_dump_survey, |
| 8740 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8741 | { |
| 8742 | .cmd = NL80211_CMD_SET_PMKSA, |
| 8743 | .doit = nl80211_setdel_pmksa, |
| 8744 | .policy = nl80211_policy, |
| 8745 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8746 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8747 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8748 | }, |
| 8749 | { |
| 8750 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 8751 | .doit = nl80211_setdel_pmksa, |
| 8752 | .policy = nl80211_policy, |
| 8753 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8754 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8755 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8756 | }, |
| 8757 | { |
| 8758 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 8759 | .doit = nl80211_flush_pmksa, |
| 8760 | .policy = nl80211_policy, |
| 8761 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8762 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8763 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8764 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8765 | { |
| 8766 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 8767 | .doit = nl80211_remain_on_channel, |
| 8768 | .policy = nl80211_policy, |
| 8769 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8770 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8771 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8772 | }, |
| 8773 | { |
| 8774 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 8775 | .doit = nl80211_cancel_remain_on_channel, |
| 8776 | .policy = nl80211_policy, |
| 8777 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8778 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8779 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8780 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8781 | { |
| 8782 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 8783 | .doit = nl80211_set_tx_bitrate_mask, |
| 8784 | .policy = nl80211_policy, |
| 8785 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8786 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8787 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8788 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8789 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8790 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 8791 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8792 | .policy = nl80211_policy, |
| 8793 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8794 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8795 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8796 | }, |
| 8797 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8798 | .cmd = NL80211_CMD_FRAME, |
| 8799 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8800 | .policy = nl80211_policy, |
| 8801 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8802 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8803 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8804 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8805 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8806 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 8807 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 8808 | .policy = nl80211_policy, |
| 8809 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8810 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8811 | NL80211_FLAG_NEED_RTNL, |
| 8812 | }, |
| 8813 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8814 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 8815 | .doit = nl80211_set_power_save, |
| 8816 | .policy = nl80211_policy, |
| 8817 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8818 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8819 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8820 | }, |
| 8821 | { |
| 8822 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 8823 | .doit = nl80211_get_power_save, |
| 8824 | .policy = nl80211_policy, |
| 8825 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8826 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8827 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8828 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8829 | { |
| 8830 | .cmd = NL80211_CMD_SET_CQM, |
| 8831 | .doit = nl80211_set_cqm, |
| 8832 | .policy = nl80211_policy, |
| 8833 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8834 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8835 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8836 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8837 | { |
| 8838 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 8839 | .doit = nl80211_set_channel, |
| 8840 | .policy = nl80211_policy, |
| 8841 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8842 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8843 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8844 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8845 | { |
| 8846 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 8847 | .doit = nl80211_set_wds_peer, |
| 8848 | .policy = nl80211_policy, |
| 8849 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 8850 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8851 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 8852 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8853 | { |
| 8854 | .cmd = NL80211_CMD_JOIN_MESH, |
| 8855 | .doit = nl80211_join_mesh, |
| 8856 | .policy = nl80211_policy, |
| 8857 | .flags = GENL_ADMIN_PERM, |
| 8858 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8859 | NL80211_FLAG_NEED_RTNL, |
| 8860 | }, |
| 8861 | { |
| 8862 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 8863 | .doit = nl80211_leave_mesh, |
| 8864 | .policy = nl80211_policy, |
| 8865 | .flags = GENL_ADMIN_PERM, |
| 8866 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8867 | NL80211_FLAG_NEED_RTNL, |
| 8868 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8869 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8870 | { |
| 8871 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 8872 | .doit = nl80211_get_wowlan, |
| 8873 | .policy = nl80211_policy, |
| 8874 | /* can be retrieved by unprivileged users */ |
| 8875 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8876 | NL80211_FLAG_NEED_RTNL, |
| 8877 | }, |
| 8878 | { |
| 8879 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 8880 | .doit = nl80211_set_wowlan, |
| 8881 | .policy = nl80211_policy, |
| 8882 | .flags = GENL_ADMIN_PERM, |
| 8883 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8884 | NL80211_FLAG_NEED_RTNL, |
| 8885 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8886 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8887 | { |
| 8888 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 8889 | .doit = nl80211_set_rekey_data, |
| 8890 | .policy = nl80211_policy, |
| 8891 | .flags = GENL_ADMIN_PERM, |
| 8892 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8893 | NL80211_FLAG_NEED_RTNL, |
| 8894 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8895 | { |
| 8896 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 8897 | .doit = nl80211_tdls_mgmt, |
| 8898 | .policy = nl80211_policy, |
| 8899 | .flags = GENL_ADMIN_PERM, |
| 8900 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8901 | NL80211_FLAG_NEED_RTNL, |
| 8902 | }, |
| 8903 | { |
| 8904 | .cmd = NL80211_CMD_TDLS_OPER, |
| 8905 | .doit = nl80211_tdls_oper, |
| 8906 | .policy = nl80211_policy, |
| 8907 | .flags = GENL_ADMIN_PERM, |
| 8908 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8909 | NL80211_FLAG_NEED_RTNL, |
| 8910 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8911 | { |
| 8912 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 8913 | .doit = nl80211_register_unexpected_frame, |
| 8914 | .policy = nl80211_policy, |
| 8915 | .flags = GENL_ADMIN_PERM, |
| 8916 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8917 | NL80211_FLAG_NEED_RTNL, |
| 8918 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8919 | { |
| 8920 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 8921 | .doit = nl80211_probe_client, |
| 8922 | .policy = nl80211_policy, |
| 8923 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 8924 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8925 | NL80211_FLAG_NEED_RTNL, |
| 8926 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8927 | { |
| 8928 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 8929 | .doit = nl80211_register_beacons, |
| 8930 | .policy = nl80211_policy, |
| 8931 | .flags = GENL_ADMIN_PERM, |
| 8932 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 8933 | NL80211_FLAG_NEED_RTNL, |
| 8934 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 8935 | { |
| 8936 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 8937 | .doit = nl80211_set_noack_map, |
| 8938 | .policy = nl80211_policy, |
| 8939 | .flags = GENL_ADMIN_PERM, |
| 8940 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8941 | NL80211_FLAG_NEED_RTNL, |
| 8942 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8943 | { |
| 8944 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 8945 | .doit = nl80211_start_p2p_device, |
| 8946 | .policy = nl80211_policy, |
| 8947 | .flags = GENL_ADMIN_PERM, |
| 8948 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 8949 | NL80211_FLAG_NEED_RTNL, |
| 8950 | }, |
| 8951 | { |
| 8952 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 8953 | .doit = nl80211_stop_p2p_device, |
| 8954 | .policy = nl80211_policy, |
| 8955 | .flags = GENL_ADMIN_PERM, |
| 8956 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 8957 | NL80211_FLAG_NEED_RTNL, |
| 8958 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8959 | { |
| 8960 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 8961 | .doit = nl80211_set_mcast_rate, |
| 8962 | .policy = nl80211_policy, |
| 8963 | .flags = GENL_ADMIN_PERM, |
| 8964 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8965 | NL80211_FLAG_NEED_RTNL, |
| 8966 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 8967 | { |
| 8968 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 8969 | .doit = nl80211_set_mac_acl, |
| 8970 | .policy = nl80211_policy, |
| 8971 | .flags = GENL_ADMIN_PERM, |
| 8972 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 8973 | NL80211_FLAG_NEED_RTNL, |
| 8974 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8975 | { |
| 8976 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 8977 | .doit = nl80211_start_radar_detection, |
| 8978 | .policy = nl80211_policy, |
| 8979 | .flags = GENL_ADMIN_PERM, |
| 8980 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8981 | NL80211_FLAG_NEED_RTNL, |
| 8982 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 8983 | { |
| 8984 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 8985 | .doit = nl80211_get_protocol_features, |
| 8986 | .policy = nl80211_policy, |
| 8987 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 8988 | { |
| 8989 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 8990 | .doit = nl80211_update_ft_ies, |
| 8991 | .policy = nl80211_policy, |
| 8992 | .flags = GENL_ADMIN_PERM, |
| 8993 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 8994 | NL80211_FLAG_NEED_RTNL, |
| 8995 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 8996 | { |
| 8997 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 8998 | .doit = nl80211_crit_protocol_start, |
| 8999 | .policy = nl80211_policy, |
| 9000 | .flags = GENL_ADMIN_PERM, |
| 9001 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9002 | NL80211_FLAG_NEED_RTNL, |
| 9003 | }, |
| 9004 | { |
| 9005 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 9006 | .doit = nl80211_crit_protocol_stop, |
| 9007 | .policy = nl80211_policy, |
| 9008 | .flags = GENL_ADMIN_PERM, |
| 9009 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 9010 | NL80211_FLAG_NEED_RTNL, |
| 9011 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9012 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9013 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9014 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 9015 | .name = "mlme", |
| 9016 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9017 | |
| 9018 | /* multicast groups */ |
| 9019 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 9020 | .name = "config", |
| 9021 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9022 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 9023 | .name = "scan", |
| 9024 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9025 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 9026 | .name = "regulatory", |
| 9027 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9028 | |
| 9029 | /* notification functions */ |
| 9030 | |
| 9031 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 9032 | { |
| 9033 | struct sk_buff *msg; |
| 9034 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9035 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9036 | if (!msg) |
| 9037 | return; |
| 9038 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9039 | if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, |
| 9040 | false, NULL, NULL, NULL) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9041 | nlmsg_free(msg); |
| 9042 | return; |
| 9043 | } |
| 9044 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9045 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9046 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9047 | } |
| 9048 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9049 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 9050 | struct cfg80211_registered_device *rdev) |
| 9051 | { |
| 9052 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 9053 | struct nlattr *nest; |
| 9054 | int i; |
| 9055 | |
| 9056 | if (WARN_ON(!req)) |
| 9057 | return 0; |
| 9058 | |
| 9059 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 9060 | if (!nest) |
| 9061 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9062 | for (i = 0; i < req->n_ssids; i++) { |
| 9063 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 9064 | goto nla_put_failure; |
| 9065 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9066 | nla_nest_end(msg, nest); |
| 9067 | |
| 9068 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9069 | if (!nest) |
| 9070 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9071 | for (i = 0; i < req->n_channels; i++) { |
| 9072 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9073 | goto nla_put_failure; |
| 9074 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9075 | nla_nest_end(msg, nest); |
| 9076 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9077 | if (req->ie && |
| 9078 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 9079 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9080 | |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9081 | if (req->flags) |
| 9082 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags); |
| 9083 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9084 | return 0; |
| 9085 | nla_put_failure: |
| 9086 | return -ENOBUFS; |
| 9087 | } |
| 9088 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9089 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 9090 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9091 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9092 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9093 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9094 | { |
| 9095 | void *hdr; |
| 9096 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9097 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9098 | if (!hdr) |
| 9099 | return -1; |
| 9100 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9101 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9102 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9103 | wdev->netdev->ifindex)) || |
| 9104 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9105 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9106 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 9107 | /* ignore errors and send incomplete event anyway */ |
| 9108 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9109 | |
| 9110 | return genlmsg_end(msg, hdr); |
| 9111 | |
| 9112 | nla_put_failure: |
| 9113 | genlmsg_cancel(msg, hdr); |
| 9114 | return -EMSGSIZE; |
| 9115 | } |
| 9116 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9117 | static int |
| 9118 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 9119 | struct cfg80211_registered_device *rdev, |
| 9120 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9121 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9122 | { |
| 9123 | void *hdr; |
| 9124 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9125 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9126 | if (!hdr) |
| 9127 | return -1; |
| 9128 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9129 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9130 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 9131 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9132 | |
| 9133 | return genlmsg_end(msg, hdr); |
| 9134 | |
| 9135 | nla_put_failure: |
| 9136 | genlmsg_cancel(msg, hdr); |
| 9137 | return -EMSGSIZE; |
| 9138 | } |
| 9139 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9140 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9141 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9142 | { |
| 9143 | struct sk_buff *msg; |
| 9144 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9145 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9146 | if (!msg) |
| 9147 | return; |
| 9148 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9149 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9150 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 9151 | nlmsg_free(msg); |
| 9152 | return; |
| 9153 | } |
| 9154 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9155 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9156 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9157 | } |
| 9158 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9159 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9160 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9161 | { |
| 9162 | struct sk_buff *msg; |
| 9163 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9164 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9165 | if (!msg) |
| 9166 | return; |
| 9167 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9168 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9169 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9170 | nlmsg_free(msg); |
| 9171 | return; |
| 9172 | } |
| 9173 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9174 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9175 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9176 | } |
| 9177 | |
| 9178 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9179 | struct wireless_dev *wdev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9180 | { |
| 9181 | struct sk_buff *msg; |
| 9182 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9183 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9184 | if (!msg) |
| 9185 | return; |
| 9186 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9187 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 9188 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9189 | nlmsg_free(msg); |
| 9190 | return; |
| 9191 | } |
| 9192 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9193 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9194 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9195 | } |
| 9196 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9197 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 9198 | struct net_device *netdev) |
| 9199 | { |
| 9200 | struct sk_buff *msg; |
| 9201 | |
| 9202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9203 | if (!msg) |
| 9204 | return; |
| 9205 | |
| 9206 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 9207 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 9208 | nlmsg_free(msg); |
| 9209 | return; |
| 9210 | } |
| 9211 | |
| 9212 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9213 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9214 | } |
| 9215 | |
| 9216 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 9217 | struct net_device *netdev, u32 cmd) |
| 9218 | { |
| 9219 | struct sk_buff *msg; |
| 9220 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9221 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9222 | if (!msg) |
| 9223 | return; |
| 9224 | |
| 9225 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 9226 | nlmsg_free(msg); |
| 9227 | return; |
| 9228 | } |
| 9229 | |
| 9230 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9231 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 9232 | } |
| 9233 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9234 | /* |
| 9235 | * This can happen on global regulatory changes or device specific settings |
| 9236 | * based on custom world regulatory domains. |
| 9237 | */ |
| 9238 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 9239 | { |
| 9240 | struct sk_buff *msg; |
| 9241 | void *hdr; |
| 9242 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9244 | if (!msg) |
| 9245 | return; |
| 9246 | |
| 9247 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 9248 | if (!hdr) { |
| 9249 | nlmsg_free(msg); |
| 9250 | return; |
| 9251 | } |
| 9252 | |
| 9253 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9254 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 9255 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9256 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9257 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 9258 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9259 | NL80211_REGDOM_TYPE_WORLD)) |
| 9260 | goto nla_put_failure; |
| 9261 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 9262 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9263 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 9264 | goto nla_put_failure; |
| 9265 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 9266 | request->intersect) { |
| 9267 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9268 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 9269 | goto nla_put_failure; |
| 9270 | } else { |
| 9271 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 9272 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 9273 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 9274 | request->alpha2)) |
| 9275 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9276 | } |
| 9277 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 9278 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9279 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 9280 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9281 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9282 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9283 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9284 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9285 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 9286 | GFP_ATOMIC); |
| 9287 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 9288 | |
| 9289 | return; |
| 9290 | |
| 9291 | nla_put_failure: |
| 9292 | genlmsg_cancel(msg, hdr); |
| 9293 | nlmsg_free(msg); |
| 9294 | } |
| 9295 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9296 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 9297 | struct net_device *netdev, |
| 9298 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9299 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9300 | { |
| 9301 | struct sk_buff *msg; |
| 9302 | void *hdr; |
| 9303 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9304 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9305 | if (!msg) |
| 9306 | return; |
| 9307 | |
| 9308 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9309 | if (!hdr) { |
| 9310 | nlmsg_free(msg); |
| 9311 | return; |
| 9312 | } |
| 9313 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9314 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9315 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9316 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9317 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9318 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9319 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9320 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9321 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9322 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9323 | return; |
| 9324 | |
| 9325 | nla_put_failure: |
| 9326 | genlmsg_cancel(msg, hdr); |
| 9327 | nlmsg_free(msg); |
| 9328 | } |
| 9329 | |
| 9330 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9331 | struct net_device *netdev, const u8 *buf, |
| 9332 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9333 | { |
| 9334 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9335 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9336 | } |
| 9337 | |
| 9338 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 9339 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9340 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9341 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9342 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 9343 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9344 | } |
| 9345 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9346 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9347 | struct net_device *netdev, const u8 *buf, |
| 9348 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9349 | { |
| 9350 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9351 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9352 | } |
| 9353 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 9354 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 9355 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9356 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9357 | { |
| 9358 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9359 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 9360 | } |
| 9361 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9362 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 9363 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9364 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9365 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9366 | struct wiphy *wiphy = wdev->wiphy; |
| 9367 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9368 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 9369 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9370 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9371 | if (WARN_ON(len < 2)) |
| 9372 | return; |
| 9373 | |
| 9374 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 9375 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 9376 | else |
| 9377 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 9378 | |
| 9379 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
| 9380 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9381 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 9382 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 9383 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 9384 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 9385 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9386 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9387 | { |
| 9388 | struct sk_buff *msg; |
| 9389 | void *hdr; |
| 9390 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9391 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9392 | if (!msg) |
| 9393 | return; |
| 9394 | |
| 9395 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9396 | if (!hdr) { |
| 9397 | nlmsg_free(msg); |
| 9398 | return; |
| 9399 | } |
| 9400 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9401 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9402 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9403 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 9404 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9405 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9406 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9407 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9408 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9409 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9410 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9411 | return; |
| 9412 | |
| 9413 | nla_put_failure: |
| 9414 | genlmsg_cancel(msg, hdr); |
| 9415 | nlmsg_free(msg); |
| 9416 | } |
| 9417 | |
| 9418 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9419 | struct net_device *netdev, const u8 *addr, |
| 9420 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9421 | { |
| 9422 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9423 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9424 | } |
| 9425 | |
| 9426 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9427 | struct net_device *netdev, const u8 *addr, |
| 9428 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9429 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9430 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 9431 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 9432 | } |
| 9433 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9434 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 9435 | struct net_device *netdev, const u8 *bssid, |
| 9436 | const u8 *req_ie, size_t req_ie_len, |
| 9437 | const u8 *resp_ie, size_t resp_ie_len, |
| 9438 | u16 status, gfp_t gfp) |
| 9439 | { |
| 9440 | struct sk_buff *msg; |
| 9441 | void *hdr; |
| 9442 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9443 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9444 | if (!msg) |
| 9445 | return; |
| 9446 | |
| 9447 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 9448 | if (!hdr) { |
| 9449 | nlmsg_free(msg); |
| 9450 | return; |
| 9451 | } |
| 9452 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9453 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9454 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9455 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 9456 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 9457 | (req_ie && |
| 9458 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9459 | (resp_ie && |
| 9460 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9461 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9462 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9463 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9464 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9465 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9466 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9467 | return; |
| 9468 | |
| 9469 | nla_put_failure: |
| 9470 | genlmsg_cancel(msg, hdr); |
| 9471 | nlmsg_free(msg); |
| 9472 | |
| 9473 | } |
| 9474 | |
| 9475 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 9476 | struct net_device *netdev, const u8 *bssid, |
| 9477 | const u8 *req_ie, size_t req_ie_len, |
| 9478 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 9479 | { |
| 9480 | struct sk_buff *msg; |
| 9481 | void *hdr; |
| 9482 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9483 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9484 | if (!msg) |
| 9485 | return; |
| 9486 | |
| 9487 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 9488 | if (!hdr) { |
| 9489 | nlmsg_free(msg); |
| 9490 | return; |
| 9491 | } |
| 9492 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9493 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9494 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9495 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 9496 | (req_ie && |
| 9497 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 9498 | (resp_ie && |
| 9499 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 9500 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9501 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9502 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9503 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9504 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9505 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9506 | return; |
| 9507 | |
| 9508 | nla_put_failure: |
| 9509 | genlmsg_cancel(msg, hdr); |
| 9510 | nlmsg_free(msg); |
| 9511 | |
| 9512 | } |
| 9513 | |
| 9514 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 9515 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 9516 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9517 | { |
| 9518 | struct sk_buff *msg; |
| 9519 | void *hdr; |
| 9520 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9521 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9522 | if (!msg) |
| 9523 | return; |
| 9524 | |
| 9525 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 9526 | if (!hdr) { |
| 9527 | nlmsg_free(msg); |
| 9528 | return; |
| 9529 | } |
| 9530 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9531 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9532 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9533 | (from_ap && reason && |
| 9534 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 9535 | (from_ap && |
| 9536 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 9537 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 9538 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9539 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9540 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9541 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9542 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9543 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9544 | return; |
| 9545 | |
| 9546 | nla_put_failure: |
| 9547 | genlmsg_cancel(msg, hdr); |
| 9548 | nlmsg_free(msg); |
| 9549 | |
| 9550 | } |
| 9551 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9552 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 9553 | struct net_device *netdev, const u8 *bssid, |
| 9554 | gfp_t gfp) |
| 9555 | { |
| 9556 | struct sk_buff *msg; |
| 9557 | void *hdr; |
| 9558 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9559 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9560 | if (!msg) |
| 9561 | return; |
| 9562 | |
| 9563 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 9564 | if (!hdr) { |
| 9565 | nlmsg_free(msg); |
| 9566 | return; |
| 9567 | } |
| 9568 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9569 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9570 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9571 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 9572 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9573 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9574 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9575 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9576 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9577 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9578 | return; |
| 9579 | |
| 9580 | nla_put_failure: |
| 9581 | genlmsg_cancel(msg, hdr); |
| 9582 | nlmsg_free(msg); |
| 9583 | } |
| 9584 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9585 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 9586 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9587 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9588 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9589 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9590 | struct sk_buff *msg; |
| 9591 | void *hdr; |
| 9592 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9593 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 9594 | return; |
| 9595 | |
| 9596 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 9597 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9598 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9599 | if (!msg) |
| 9600 | return; |
| 9601 | |
| 9602 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 9603 | if (!hdr) { |
| 9604 | nlmsg_free(msg); |
| 9605 | return; |
| 9606 | } |
| 9607 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9608 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9609 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9610 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9611 | (ie_len && ie && |
| 9612 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 9613 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9614 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9615 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9616 | |
| 9617 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9618 | nl80211_mlme_mcgrp.id, gfp); |
| 9619 | return; |
| 9620 | |
| 9621 | nla_put_failure: |
| 9622 | genlmsg_cancel(msg, hdr); |
| 9623 | nlmsg_free(msg); |
| 9624 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9625 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 9626 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9627 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 9628 | struct net_device *netdev, const u8 *addr, |
| 9629 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9630 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9631 | { |
| 9632 | struct sk_buff *msg; |
| 9633 | void *hdr; |
| 9634 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 9635 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9636 | if (!msg) |
| 9637 | return; |
| 9638 | |
| 9639 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 9640 | if (!hdr) { |
| 9641 | nlmsg_free(msg); |
| 9642 | return; |
| 9643 | } |
| 9644 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9645 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9646 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 9647 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 9648 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 9649 | (key_id != -1 && |
| 9650 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 9651 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 9652 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9653 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9654 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9655 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9656 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9657 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 9658 | return; |
| 9659 | |
| 9660 | nla_put_failure: |
| 9661 | genlmsg_cancel(msg, hdr); |
| 9662 | nlmsg_free(msg); |
| 9663 | } |
| 9664 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9665 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 9666 | struct ieee80211_channel *channel_before, |
| 9667 | struct ieee80211_channel *channel_after) |
| 9668 | { |
| 9669 | struct sk_buff *msg; |
| 9670 | void *hdr; |
| 9671 | struct nlattr *nl_freq; |
| 9672 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 9673 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9674 | if (!msg) |
| 9675 | return; |
| 9676 | |
| 9677 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 9678 | if (!hdr) { |
| 9679 | nlmsg_free(msg); |
| 9680 | return; |
| 9681 | } |
| 9682 | |
| 9683 | /* |
| 9684 | * Since we are applying the beacon hint to a wiphy we know its |
| 9685 | * wiphy_idx is valid |
| 9686 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9687 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 9688 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9689 | |
| 9690 | /* Before */ |
| 9691 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 9692 | if (!nl_freq) |
| 9693 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9694 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9695 | goto nla_put_failure; |
| 9696 | nla_nest_end(msg, nl_freq); |
| 9697 | |
| 9698 | /* After */ |
| 9699 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 9700 | if (!nl_freq) |
| 9701 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 9702 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9703 | goto nla_put_failure; |
| 9704 | nla_nest_end(msg, nl_freq); |
| 9705 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9706 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9707 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9708 | rcu_read_lock(); |
| 9709 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 9710 | GFP_ATOMIC); |
| 9711 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 9712 | |
| 9713 | return; |
| 9714 | |
| 9715 | nla_put_failure: |
| 9716 | genlmsg_cancel(msg, hdr); |
| 9717 | nlmsg_free(msg); |
| 9718 | } |
| 9719 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9720 | static void nl80211_send_remain_on_chan_event( |
| 9721 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9722 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9723 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9724 | unsigned int duration, gfp_t gfp) |
| 9725 | { |
| 9726 | struct sk_buff *msg; |
| 9727 | void *hdr; |
| 9728 | |
| 9729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9730 | if (!msg) |
| 9731 | return; |
| 9732 | |
| 9733 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 9734 | if (!hdr) { |
| 9735 | nlmsg_free(msg); |
| 9736 | return; |
| 9737 | } |
| 9738 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9739 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9740 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9741 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 9742 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9743 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9744 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 9745 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9746 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9747 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9748 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9749 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 9750 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 9751 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9752 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9753 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9754 | |
| 9755 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9756 | nl80211_mlme_mcgrp.id, gfp); |
| 9757 | return; |
| 9758 | |
| 9759 | nla_put_failure: |
| 9760 | genlmsg_cancel(msg, hdr); |
| 9761 | nlmsg_free(msg); |
| 9762 | } |
| 9763 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9764 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 9765 | struct ieee80211_channel *chan, |
| 9766 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9767 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9768 | struct wiphy *wiphy = wdev->wiphy; |
| 9769 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9770 | |
| 9771 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9772 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9773 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9774 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9775 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9776 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9777 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9778 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 9779 | struct ieee80211_channel *chan, |
| 9780 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9781 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9782 | struct wiphy *wiphy = wdev->wiphy; |
| 9783 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 9784 | |
| 9785 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9786 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 9787 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9788 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9789 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9790 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9791 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 9792 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9793 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9794 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9795 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9796 | struct sk_buff *msg; |
| 9797 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9798 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 9799 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9800 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9801 | if (!msg) |
| 9802 | return; |
| 9803 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 9804 | if (nl80211_send_station(msg, 0, 0, 0, |
| 9805 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9806 | nlmsg_free(msg); |
| 9807 | return; |
| 9808 | } |
| 9809 | |
| 9810 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9811 | nl80211_mlme_mcgrp.id, gfp); |
| 9812 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9813 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 9814 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9815 | 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] | 9816 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9817 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9818 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9819 | struct sk_buff *msg; |
| 9820 | void *hdr; |
| 9821 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9822 | trace_cfg80211_del_sta(dev, mac_addr); |
| 9823 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 9824 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9825 | if (!msg) |
| 9826 | return; |
| 9827 | |
| 9828 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 9829 | if (!hdr) { |
| 9830 | nlmsg_free(msg); |
| 9831 | return; |
| 9832 | } |
| 9833 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9834 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9835 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 9836 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9837 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9838 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9839 | |
| 9840 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9841 | nl80211_mlme_mcgrp.id, gfp); |
| 9842 | return; |
| 9843 | |
| 9844 | nla_put_failure: |
| 9845 | genlmsg_cancel(msg, hdr); |
| 9846 | nlmsg_free(msg); |
| 9847 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9848 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 9849 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9850 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 9851 | enum nl80211_connect_failed_reason reason, |
| 9852 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9853 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9854 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 9855 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9856 | struct sk_buff *msg; |
| 9857 | void *hdr; |
| 9858 | |
| 9859 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 9860 | if (!msg) |
| 9861 | return; |
| 9862 | |
| 9863 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 9864 | if (!hdr) { |
| 9865 | nlmsg_free(msg); |
| 9866 | return; |
| 9867 | } |
| 9868 | |
| 9869 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9870 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 9871 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 9872 | goto nla_put_failure; |
| 9873 | |
| 9874 | genlmsg_end(msg, hdr); |
| 9875 | |
| 9876 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 9877 | nl80211_mlme_mcgrp.id, gfp); |
| 9878 | return; |
| 9879 | |
| 9880 | nla_put_failure: |
| 9881 | genlmsg_cancel(msg, hdr); |
| 9882 | nlmsg_free(msg); |
| 9883 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9884 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 9885 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9886 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 9887 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9888 | { |
| 9889 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9890 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 9891 | struct sk_buff *msg; |
| 9892 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9893 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9894 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9895 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9896 | return false; |
| 9897 | |
| 9898 | msg = nlmsg_new(100, gfp); |
| 9899 | if (!msg) |
| 9900 | return true; |
| 9901 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9902 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9903 | if (!hdr) { |
| 9904 | nlmsg_free(msg); |
| 9905 | return true; |
| 9906 | } |
| 9907 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9908 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 9909 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 9910 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 9911 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9912 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 9913 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9914 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9915 | return true; |
| 9916 | |
| 9917 | nla_put_failure: |
| 9918 | genlmsg_cancel(msg, hdr); |
| 9919 | nlmsg_free(msg); |
| 9920 | return true; |
| 9921 | } |
| 9922 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9923 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 9924 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9925 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9926 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9927 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9928 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9929 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 9930 | |
| 9931 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9932 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 9933 | trace_cfg80211_return_bool(false); |
| 9934 | return false; |
| 9935 | } |
| 9936 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 9937 | addr, gfp); |
| 9938 | trace_cfg80211_return_bool(ret); |
| 9939 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9940 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 9941 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 9942 | |
| 9943 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 9944 | const u8 *addr, gfp_t gfp) |
| 9945 | { |
| 9946 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9947 | bool ret; |
| 9948 | |
| 9949 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 9950 | |
| 9951 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 9952 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 9953 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 9954 | trace_cfg80211_return_bool(false); |
| 9955 | return false; |
| 9956 | } |
| 9957 | ret = __nl80211_unexpected_frame(dev, |
| 9958 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 9959 | addr, gfp); |
| 9960 | trace_cfg80211_return_bool(ret); |
| 9961 | return ret; |
| 9962 | } |
| 9963 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 9964 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9965 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9966 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 9967 | int freq, int sig_dbm, |
| 9968 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9969 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9970 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9971 | struct sk_buff *msg; |
| 9972 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9973 | |
| 9974 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 9975 | if (!msg) |
| 9976 | return -ENOMEM; |
| 9977 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9978 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9979 | if (!hdr) { |
| 9980 | nlmsg_free(msg); |
| 9981 | return -ENOMEM; |
| 9982 | } |
| 9983 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9984 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9985 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 9986 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 9987 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9988 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 9989 | (sig_dbm && |
| 9990 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 9991 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 9992 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9993 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 9994 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9995 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9996 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9997 | |
| 9998 | nla_put_failure: |
| 9999 | genlmsg_cancel(msg, hdr); |
| 10000 | nlmsg_free(msg); |
| 10001 | return -ENOBUFS; |
| 10002 | } |
| 10003 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10004 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 10005 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10006 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10007 | struct wiphy *wiphy = wdev->wiphy; |
| 10008 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10009 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10010 | struct sk_buff *msg; |
| 10011 | void *hdr; |
| 10012 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10013 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 10014 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10015 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10016 | if (!msg) |
| 10017 | return; |
| 10018 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10019 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10020 | if (!hdr) { |
| 10021 | nlmsg_free(msg); |
| 10022 | return; |
| 10023 | } |
| 10024 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10025 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10026 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10027 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 10028 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10029 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 10030 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10031 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10032 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10033 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10034 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10035 | |
| 10036 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 10037 | return; |
| 10038 | |
| 10039 | nla_put_failure: |
| 10040 | genlmsg_cancel(msg, hdr); |
| 10041 | nlmsg_free(msg); |
| 10042 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10043 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10044 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10045 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 10046 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 10047 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10048 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10049 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10050 | struct wiphy *wiphy = wdev->wiphy; |
| 10051 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10052 | struct sk_buff *msg; |
| 10053 | struct nlattr *pinfoattr; |
| 10054 | void *hdr; |
| 10055 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10056 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 10057 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10058 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10059 | if (!msg) |
| 10060 | return; |
| 10061 | |
| 10062 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 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) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10069 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10070 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10071 | |
| 10072 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10073 | if (!pinfoattr) |
| 10074 | goto nla_put_failure; |
| 10075 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10076 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 10077 | rssi_event)) |
| 10078 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10079 | |
| 10080 | nla_nest_end(msg, pinfoattr); |
| 10081 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10082 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10083 | |
| 10084 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10085 | nl80211_mlme_mcgrp.id, gfp); |
| 10086 | return; |
| 10087 | |
| 10088 | nla_put_failure: |
| 10089 | genlmsg_cancel(msg, hdr); |
| 10090 | nlmsg_free(msg); |
| 10091 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10092 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10093 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10094 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 10095 | struct net_device *netdev, const u8 *bssid, |
| 10096 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10097 | { |
| 10098 | struct sk_buff *msg; |
| 10099 | struct nlattr *rekey_attr; |
| 10100 | void *hdr; |
| 10101 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10102 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10103 | if (!msg) |
| 10104 | return; |
| 10105 | |
| 10106 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 10107 | if (!hdr) { |
| 10108 | nlmsg_free(msg); |
| 10109 | return; |
| 10110 | } |
| 10111 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10112 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10113 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10114 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10115 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10116 | |
| 10117 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 10118 | if (!rekey_attr) |
| 10119 | goto nla_put_failure; |
| 10120 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10121 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 10122 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 10123 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10124 | |
| 10125 | nla_nest_end(msg, rekey_attr); |
| 10126 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10127 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10128 | |
| 10129 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10130 | nl80211_mlme_mcgrp.id, gfp); |
| 10131 | return; |
| 10132 | |
| 10133 | nla_put_failure: |
| 10134 | genlmsg_cancel(msg, hdr); |
| 10135 | nlmsg_free(msg); |
| 10136 | } |
| 10137 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10138 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 10139 | const u8 *replay_ctr, gfp_t gfp) |
| 10140 | { |
| 10141 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10142 | struct wiphy *wiphy = wdev->wiphy; |
| 10143 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10144 | |
| 10145 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 10146 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 10147 | } |
| 10148 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 10149 | |
| 10150 | static void |
| 10151 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 10152 | struct net_device *netdev, int index, |
| 10153 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10154 | { |
| 10155 | struct sk_buff *msg; |
| 10156 | struct nlattr *attr; |
| 10157 | void *hdr; |
| 10158 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10159 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10160 | if (!msg) |
| 10161 | return; |
| 10162 | |
| 10163 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 10164 | if (!hdr) { |
| 10165 | nlmsg_free(msg); |
| 10166 | return; |
| 10167 | } |
| 10168 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10169 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10170 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10171 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10172 | |
| 10173 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 10174 | if (!attr) |
| 10175 | goto nla_put_failure; |
| 10176 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10177 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 10178 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 10179 | (preauth && |
| 10180 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 10181 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10182 | |
| 10183 | nla_nest_end(msg, attr); |
| 10184 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10185 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 10186 | |
| 10187 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10188 | nl80211_mlme_mcgrp.id, gfp); |
| 10189 | return; |
| 10190 | |
| 10191 | nla_put_failure: |
| 10192 | genlmsg_cancel(msg, hdr); |
| 10193 | nlmsg_free(msg); |
| 10194 | } |
| 10195 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10196 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 10197 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 10198 | { |
| 10199 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10200 | struct wiphy *wiphy = wdev->wiphy; |
| 10201 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10202 | |
| 10203 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 10204 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 10205 | } |
| 10206 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 10207 | |
| 10208 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 10209 | struct net_device *netdev, |
| 10210 | struct cfg80211_chan_def *chandef, |
| 10211 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10212 | { |
| 10213 | struct sk_buff *msg; |
| 10214 | void *hdr; |
| 10215 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10217 | if (!msg) |
| 10218 | return; |
| 10219 | |
| 10220 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 10221 | if (!hdr) { |
| 10222 | nlmsg_free(msg); |
| 10223 | return; |
| 10224 | } |
| 10225 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10226 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10227 | goto nla_put_failure; |
| 10228 | |
| 10229 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 10230 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 10231 | |
| 10232 | genlmsg_end(msg, hdr); |
| 10233 | |
| 10234 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10235 | nl80211_mlme_mcgrp.id, gfp); |
| 10236 | return; |
| 10237 | |
| 10238 | nla_put_failure: |
| 10239 | genlmsg_cancel(msg, hdr); |
| 10240 | nlmsg_free(msg); |
| 10241 | } |
| 10242 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10243 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 10244 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10245 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10246 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10247 | struct wiphy *wiphy = wdev->wiphy; |
| 10248 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10249 | |
| 10250 | trace_cfg80211_ch_switch_notify(dev, chandef); |
| 10251 | |
| 10252 | wdev_lock(wdev); |
| 10253 | |
| 10254 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 10255 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) |
| 10256 | goto out; |
| 10257 | |
| 10258 | wdev->channel = chandef->chan; |
| 10259 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
| 10260 | out: |
| 10261 | wdev_unlock(wdev); |
| 10262 | return; |
| 10263 | } |
| 10264 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 10265 | |
| 10266 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 10267 | const u8 *peer, u32 num_packets, |
| 10268 | u32 rate, u32 intvl, gfp_t gfp) |
| 10269 | { |
| 10270 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10271 | struct wiphy *wiphy = wdev->wiphy; |
| 10272 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10273 | struct sk_buff *msg; |
| 10274 | struct nlattr *pinfoattr; |
| 10275 | void *hdr; |
| 10276 | |
| 10277 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 10278 | if (!msg) |
| 10279 | return; |
| 10280 | |
| 10281 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10282 | if (!hdr) { |
| 10283 | nlmsg_free(msg); |
| 10284 | return; |
| 10285 | } |
| 10286 | |
| 10287 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10288 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10289 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10290 | goto nla_put_failure; |
| 10291 | |
| 10292 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10293 | if (!pinfoattr) |
| 10294 | goto nla_put_failure; |
| 10295 | |
| 10296 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 10297 | goto nla_put_failure; |
| 10298 | |
| 10299 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 10300 | goto nla_put_failure; |
| 10301 | |
| 10302 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 10303 | goto nla_put_failure; |
| 10304 | |
| 10305 | nla_nest_end(msg, pinfoattr); |
| 10306 | |
| 10307 | genlmsg_end(msg, hdr); |
| 10308 | |
| 10309 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10310 | nl80211_mlme_mcgrp.id, gfp); |
| 10311 | return; |
| 10312 | |
| 10313 | nla_put_failure: |
| 10314 | genlmsg_cancel(msg, hdr); |
| 10315 | nlmsg_free(msg); |
| 10316 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10317 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 10318 | |
| 10319 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10320 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
| 10321 | struct cfg80211_chan_def *chandef, |
| 10322 | enum nl80211_radar_event event, |
| 10323 | struct net_device *netdev, gfp_t gfp) |
| 10324 | { |
| 10325 | struct sk_buff *msg; |
| 10326 | void *hdr; |
| 10327 | |
| 10328 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10329 | if (!msg) |
| 10330 | return; |
| 10331 | |
| 10332 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 10333 | if (!hdr) { |
| 10334 | nlmsg_free(msg); |
| 10335 | return; |
| 10336 | } |
| 10337 | |
| 10338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10339 | goto nla_put_failure; |
| 10340 | |
| 10341 | /* NOP and radar events don't need a netdev parameter */ |
| 10342 | if (netdev) { |
| 10343 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 10344 | |
| 10345 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10346 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10347 | goto nla_put_failure; |
| 10348 | } |
| 10349 | |
| 10350 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 10351 | goto nla_put_failure; |
| 10352 | |
| 10353 | if (nl80211_send_chandef(msg, chandef)) |
| 10354 | goto nla_put_failure; |
| 10355 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10356 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10357 | |
| 10358 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10359 | nl80211_mlme_mcgrp.id, gfp); |
| 10360 | return; |
| 10361 | |
| 10362 | nla_put_failure: |
| 10363 | genlmsg_cancel(msg, hdr); |
| 10364 | nlmsg_free(msg); |
| 10365 | } |
| 10366 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10367 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 10368 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10369 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10370 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10371 | struct wiphy *wiphy = wdev->wiphy; |
| 10372 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10373 | struct sk_buff *msg; |
| 10374 | struct nlattr *pinfoattr; |
| 10375 | void *hdr; |
| 10376 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10377 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 10378 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10379 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10380 | if (!msg) |
| 10381 | return; |
| 10382 | |
| 10383 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 10384 | if (!hdr) { |
| 10385 | nlmsg_free(msg); |
| 10386 | return; |
| 10387 | } |
| 10388 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10389 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10390 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10391 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 10392 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10393 | |
| 10394 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 10395 | if (!pinfoattr) |
| 10396 | goto nla_put_failure; |
| 10397 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10398 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 10399 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10400 | |
| 10401 | nla_nest_end(msg, pinfoattr); |
| 10402 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10403 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10404 | |
| 10405 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10406 | nl80211_mlme_mcgrp.id, gfp); |
| 10407 | return; |
| 10408 | |
| 10409 | nla_put_failure: |
| 10410 | genlmsg_cancel(msg, hdr); |
| 10411 | nlmsg_free(msg); |
| 10412 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10413 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 10414 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10415 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 10416 | u64 cookie, bool acked, gfp_t gfp) |
| 10417 | { |
| 10418 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10419 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10420 | struct sk_buff *msg; |
| 10421 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10422 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10423 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 10424 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10426 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10427 | if (!msg) |
| 10428 | return; |
| 10429 | |
| 10430 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 10431 | if (!hdr) { |
| 10432 | nlmsg_free(msg); |
| 10433 | return; |
| 10434 | } |
| 10435 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10436 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10437 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10438 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10439 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 10440 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 10441 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10442 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10443 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10444 | |
| 10445 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10446 | nl80211_mlme_mcgrp.id, gfp); |
| 10447 | return; |
| 10448 | |
| 10449 | nla_put_failure: |
| 10450 | genlmsg_cancel(msg, hdr); |
| 10451 | nlmsg_free(msg); |
| 10452 | } |
| 10453 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 10454 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10455 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 10456 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10457 | int freq, int sig_dbm) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10458 | { |
| 10459 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10460 | struct sk_buff *msg; |
| 10461 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10462 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10463 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 10464 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 10465 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10466 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10467 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10468 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 10469 | if (!msg) { |
| 10470 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10471 | return; |
| 10472 | } |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10473 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10474 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 10475 | if (!hdr) |
| 10476 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10477 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10478 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10479 | (freq && |
| 10480 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 10481 | (sig_dbm && |
| 10482 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 10483 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 10484 | goto nla_put_failure; |
| 10485 | |
| 10486 | genlmsg_end(msg, hdr); |
| 10487 | |
| 10488 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10489 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10490 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10491 | return; |
| 10492 | |
| 10493 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10494 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10495 | if (hdr) |
| 10496 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10497 | nlmsg_free(msg); |
| 10498 | } |
| 10499 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 10500 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10501 | #ifdef CONFIG_PM |
| 10502 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 10503 | struct cfg80211_wowlan_wakeup *wakeup, |
| 10504 | gfp_t gfp) |
| 10505 | { |
| 10506 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10507 | struct sk_buff *msg; |
| 10508 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10509 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10510 | |
| 10511 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 10512 | |
| 10513 | if (wakeup) |
| 10514 | size += wakeup->packet_present_len; |
| 10515 | |
| 10516 | msg = nlmsg_new(size, gfp); |
| 10517 | if (!msg) |
| 10518 | return; |
| 10519 | |
| 10520 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 10521 | if (!hdr) |
| 10522 | goto free_msg; |
| 10523 | |
| 10524 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10525 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10526 | goto free_msg; |
| 10527 | |
| 10528 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10529 | wdev->netdev->ifindex)) |
| 10530 | goto free_msg; |
| 10531 | |
| 10532 | if (wakeup) { |
| 10533 | struct nlattr *reasons; |
| 10534 | |
| 10535 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10536 | |
| 10537 | if (wakeup->disconnect && |
| 10538 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 10539 | goto free_msg; |
| 10540 | if (wakeup->magic_pkt && |
| 10541 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 10542 | goto free_msg; |
| 10543 | if (wakeup->gtk_rekey_failure && |
| 10544 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 10545 | goto free_msg; |
| 10546 | if (wakeup->eap_identity_req && |
| 10547 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 10548 | goto free_msg; |
| 10549 | if (wakeup->four_way_handshake && |
| 10550 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 10551 | goto free_msg; |
| 10552 | if (wakeup->rfkill_release && |
| 10553 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 10554 | goto free_msg; |
| 10555 | |
| 10556 | if (wakeup->pattern_idx >= 0 && |
| 10557 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 10558 | wakeup->pattern_idx)) |
| 10559 | goto free_msg; |
| 10560 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10561 | if (wakeup->tcp_match) |
| 10562 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH); |
| 10563 | |
| 10564 | if (wakeup->tcp_connlost) |
| 10565 | nla_put_flag(msg, |
| 10566 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST); |
| 10567 | |
| 10568 | if (wakeup->tcp_nomoretokens) |
| 10569 | nla_put_flag(msg, |
| 10570 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS); |
| 10571 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10572 | if (wakeup->packet) { |
| 10573 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 10574 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 10575 | |
| 10576 | if (!wakeup->packet_80211) { |
| 10577 | pkt_attr = |
| 10578 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 10579 | len_attr = |
| 10580 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 10581 | } |
| 10582 | |
| 10583 | if (wakeup->packet_len && |
| 10584 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 10585 | goto free_msg; |
| 10586 | |
| 10587 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 10588 | wakeup->packet)) |
| 10589 | goto free_msg; |
| 10590 | } |
| 10591 | |
| 10592 | nla_nest_end(msg, reasons); |
| 10593 | } |
| 10594 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10595 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 10596 | |
| 10597 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10598 | nl80211_mlme_mcgrp.id, gfp); |
| 10599 | return; |
| 10600 | |
| 10601 | free_msg: |
| 10602 | nlmsg_free(msg); |
| 10603 | } |
| 10604 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 10605 | #endif |
| 10606 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10607 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 10608 | enum nl80211_tdls_operation oper, |
| 10609 | u16 reason_code, gfp_t gfp) |
| 10610 | { |
| 10611 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10612 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 10613 | struct sk_buff *msg; |
| 10614 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10615 | |
| 10616 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 10617 | reason_code); |
| 10618 | |
| 10619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10620 | if (!msg) |
| 10621 | return; |
| 10622 | |
| 10623 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 10624 | if (!hdr) { |
| 10625 | nlmsg_free(msg); |
| 10626 | return; |
| 10627 | } |
| 10628 | |
| 10629 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10630 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10631 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 10632 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 10633 | (reason_code > 0 && |
| 10634 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 10635 | goto nla_put_failure; |
| 10636 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10637 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 10638 | |
| 10639 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10640 | nl80211_mlme_mcgrp.id, gfp); |
| 10641 | return; |
| 10642 | |
| 10643 | nla_put_failure: |
| 10644 | genlmsg_cancel(msg, hdr); |
| 10645 | nlmsg_free(msg); |
| 10646 | } |
| 10647 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 10648 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10649 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 10650 | unsigned long state, |
| 10651 | void *_notify) |
| 10652 | { |
| 10653 | struct netlink_notify *notify = _notify; |
| 10654 | struct cfg80211_registered_device *rdev; |
| 10655 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10656 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10657 | |
| 10658 | if (state != NETLINK_URELEASE) |
| 10659 | return NOTIFY_DONE; |
| 10660 | |
| 10661 | rcu_read_lock(); |
| 10662 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10663 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10664 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10665 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10666 | |
| 10667 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10668 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 10669 | list) { |
| 10670 | if (reg->nlportid == notify->portid) { |
| 10671 | list_del(®->list); |
| 10672 | kfree(reg); |
| 10673 | break; |
| 10674 | } |
| 10675 | } |
| 10676 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10677 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10678 | |
| 10679 | rcu_read_unlock(); |
| 10680 | |
| 10681 | return NOTIFY_DONE; |
| 10682 | } |
| 10683 | |
| 10684 | static struct notifier_block nl80211_netlink_notifier = { |
| 10685 | .notifier_call = nl80211_netlink_notify, |
| 10686 | }; |
| 10687 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10688 | void cfg80211_ft_event(struct net_device *netdev, |
| 10689 | struct cfg80211_ft_event_params *ft_event) |
| 10690 | { |
| 10691 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 10692 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 10693 | struct sk_buff *msg; |
| 10694 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10695 | |
| 10696 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 10697 | |
| 10698 | if (!ft_event->target_ap) |
| 10699 | return; |
| 10700 | |
| 10701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10702 | if (!msg) |
| 10703 | return; |
| 10704 | |
| 10705 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
| 10706 | if (!hdr) { |
| 10707 | nlmsg_free(msg); |
| 10708 | return; |
| 10709 | } |
| 10710 | |
| 10711 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 10712 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 10713 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap); |
| 10714 | if (ft_event->ies) |
| 10715 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies); |
| 10716 | if (ft_event->ric_ies) |
| 10717 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 10718 | ft_event->ric_ies); |
| 10719 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 10720 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10721 | |
| 10722 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 10723 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 10724 | } |
| 10725 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 10726 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10727 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 10728 | { |
| 10729 | struct cfg80211_registered_device *rdev; |
| 10730 | struct sk_buff *msg; |
| 10731 | void *hdr; |
| 10732 | u32 nlportid; |
| 10733 | |
| 10734 | rdev = wiphy_to_dev(wdev->wiphy); |
| 10735 | if (!rdev->crit_proto_nlportid) |
| 10736 | return; |
| 10737 | |
| 10738 | nlportid = rdev->crit_proto_nlportid; |
| 10739 | rdev->crit_proto_nlportid = 0; |
| 10740 | |
| 10741 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10742 | if (!msg) |
| 10743 | return; |
| 10744 | |
| 10745 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 10746 | if (!hdr) |
| 10747 | goto nla_put_failure; |
| 10748 | |
| 10749 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10750 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 10751 | goto nla_put_failure; |
| 10752 | |
| 10753 | genlmsg_end(msg, hdr); |
| 10754 | |
| 10755 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 10756 | return; |
| 10757 | |
| 10758 | nla_put_failure: |
| 10759 | if (hdr) |
| 10760 | genlmsg_cancel(msg, hdr); |
| 10761 | nlmsg_free(msg); |
| 10762 | |
| 10763 | } |
| 10764 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 10765 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10766 | /* initialisation/exit functions */ |
| 10767 | |
| 10768 | int nl80211_init(void) |
| 10769 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10770 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10771 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 10772 | err = genl_register_family_with_ops(&nl80211_fam, |
| 10773 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10774 | if (err) |
| 10775 | return err; |
| 10776 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10777 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 10778 | if (err) |
| 10779 | goto err_out; |
| 10780 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10781 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 10782 | if (err) |
| 10783 | goto err_out; |
| 10784 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10785 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 10786 | if (err) |
| 10787 | goto err_out; |
| 10788 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10789 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 10790 | if (err) |
| 10791 | goto err_out; |
| 10792 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10793 | #ifdef CONFIG_NL80211_TESTMODE |
| 10794 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 10795 | if (err) |
| 10796 | goto err_out; |
| 10797 | #endif |
| 10798 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10799 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 10800 | if (err) |
| 10801 | goto err_out; |
| 10802 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10803 | return 0; |
| 10804 | err_out: |
| 10805 | genl_unregister_family(&nl80211_fam); |
| 10806 | return err; |
| 10807 | } |
| 10808 | |
| 10809 | void nl80211_exit(void) |
| 10810 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10811 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10812 | genl_unregister_family(&nl80211_fam); |
| 10813 | } |