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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 26 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
| 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 49 | /* internal helper: get rdev and dev */ |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 50 | static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs, |
| 51 | struct cfg80211_registered_device **rdev, |
| 52 | struct net_device **dev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
| 54 | int ifindex; |
| 55 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 56 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 57 | return -EINVAL; |
| 58 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 59 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 60 | *dev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | if (!*dev) |
| 62 | return -ENODEV; |
| 63 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 64 | *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 65 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 67 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 73 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 74 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 75 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 76 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 77 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 78 | |
| 79 | assert_cfg80211_lock(); |
| 80 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 81 | if (!attrs[NL80211_ATTR_WIPHY] && |
| 82 | !attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 83 | return ERR_PTR(-EINVAL); |
| 84 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 85 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 86 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 87 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 88 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 89 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 90 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 91 | netdev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 92 | if (netdev) { |
| 93 | if (netdev->ieee80211_ptr) |
| 94 | tmp = wiphy_to_dev( |
| 95 | netdev->ieee80211_ptr->wiphy); |
| 96 | else |
| 97 | tmp = NULL; |
| 98 | |
| 99 | dev_put(netdev); |
| 100 | |
| 101 | /* not wireless device -- return error */ |
| 102 | if (!tmp) |
| 103 | return ERR_PTR(-EINVAL); |
| 104 | |
| 105 | /* mismatch -- return error */ |
| 106 | if (rdev && tmp != rdev) |
| 107 | return ERR_PTR(-EINVAL); |
| 108 | |
| 109 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 110 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 111 | } |
| 112 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 113 | if (!rdev) |
| 114 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 115 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 116 | if (netns != wiphy_net(&rdev->wiphy)) |
| 117 | return ERR_PTR(-ENODEV); |
| 118 | |
| 119 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /* |
| 123 | * This function returns a pointer to the driver |
| 124 | * that the genl_info item that is passed refers to. |
| 125 | * If successful, it returns non-NULL and also locks |
| 126 | * the driver's mutex! |
| 127 | * |
| 128 | * This means that you need to call cfg80211_unlock_rdev() |
| 129 | * before being allowed to acquire &cfg80211_mutex! |
| 130 | * |
| 131 | * This is necessary because we need to lock the global |
| 132 | * mutex to get an item off the list safely, and then |
| 133 | * we lock the rdev mutex so it doesn't go away under us. |
| 134 | * |
| 135 | * We don't want to keep cfg80211_mutex locked |
| 136 | * for all the time in order to allow requests on |
| 137 | * other interfaces to go through at the same time. |
| 138 | * |
| 139 | * The result of this can be a PTR_ERR and hence must |
| 140 | * be checked with IS_ERR() for errors. |
| 141 | */ |
| 142 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 143 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 144 | { |
| 145 | struct cfg80211_registered_device *rdev; |
| 146 | |
| 147 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 148 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 149 | |
| 150 | /* if it is not an error we grab the lock on |
| 151 | * it to assure it won't be going away while |
| 152 | * we operate on it */ |
| 153 | if (!IS_ERR(rdev)) |
| 154 | mutex_lock(&rdev->mtx); |
| 155 | |
| 156 | mutex_unlock(&cfg80211_mutex); |
| 157 | |
| 158 | return rdev; |
| 159 | } |
| 160 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 161 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 162 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 163 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 164 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 165 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 166 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 167 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 168 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 169 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 170 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 171 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 172 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 173 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 174 | |
| 175 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 176 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 177 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 178 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 179 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 180 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 181 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 182 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 183 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 184 | .len = WLAN_MAX_KEY_LEN }, |
| 185 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 186 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 187 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 188 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 189 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 190 | |
| 191 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 192 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 193 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 194 | .len = IEEE80211_MAX_DATA_LEN }, |
| 195 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 196 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 197 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 198 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 199 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 200 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 201 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 202 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 203 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 204 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 205 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 206 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 207 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 208 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 209 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 210 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 211 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 212 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 213 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 214 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 215 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 216 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 217 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 218 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 219 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 220 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 221 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 222 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 223 | |
| 224 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 226 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 227 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 228 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 229 | |
| 230 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 231 | .len = IEEE80211_MAX_SSID_LEN }, |
| 232 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 233 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 235 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 236 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 237 | [NL80211_ATTR_STA_FLAGS2] = { |
| 238 | .len = sizeof(struct nl80211_sta_flag_update), |
| 239 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 240 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 241 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 242 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 243 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 244 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 245 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 246 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 247 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 249 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 250 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 251 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 252 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 253 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 254 | .len = IEEE80211_MAX_DATA_LEN }, |
| 255 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 256 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 257 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 258 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 259 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 260 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 261 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 262 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 263 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 264 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 265 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 266 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 267 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 268 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 269 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 270 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 271 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 272 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 273 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 274 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 275 | .len = IEEE80211_MAX_DATA_LEN }, |
| 276 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 277 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 278 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 279 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 280 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 281 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 282 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 283 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 284 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 285 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 286 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 287 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 288 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 289 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 290 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 291 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 292 | .len = NL80211_HT_CAPABILITY_LEN |
| 293 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 294 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 295 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 296 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 297 | }; |
| 298 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 299 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 300 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 301 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 302 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 303 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 304 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 305 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 306 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 307 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 308 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 309 | }; |
| 310 | |
| 311 | /* policy for the key default flags */ |
| 312 | static const struct nla_policy |
| 313 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 314 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 315 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 316 | }; |
| 317 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 318 | /* policy for WoWLAN attributes */ |
| 319 | static const struct nla_policy |
| 320 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 321 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 322 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 323 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 324 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 325 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 326 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 327 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 328 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 329 | }; |
| 330 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 331 | /* policy for GTK rekey offload attributes */ |
| 332 | static const struct nla_policy |
| 333 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 334 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 335 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 336 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 337 | }; |
| 338 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 339 | static const struct nla_policy |
| 340 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 341 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 342 | .len = IEEE80211_MAX_SSID_LEN }, |
| 343 | }; |
| 344 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 345 | /* ifidx get helper */ |
| 346 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 347 | { |
| 348 | int res; |
| 349 | |
| 350 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 351 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 352 | nl80211_policy); |
| 353 | if (res) |
| 354 | return res; |
| 355 | |
| 356 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 357 | return -EINVAL; |
| 358 | |
| 359 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 360 | if (!res) |
| 361 | return -EINVAL; |
| 362 | return res; |
| 363 | } |
| 364 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 365 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 366 | struct netlink_callback *cb, |
| 367 | struct cfg80211_registered_device **rdev, |
| 368 | struct net_device **dev) |
| 369 | { |
| 370 | int ifidx = cb->args[0]; |
| 371 | int err; |
| 372 | |
| 373 | if (!ifidx) |
| 374 | ifidx = nl80211_get_ifidx(cb); |
| 375 | if (ifidx < 0) |
| 376 | return ifidx; |
| 377 | |
| 378 | cb->args[0] = ifidx; |
| 379 | |
| 380 | rtnl_lock(); |
| 381 | |
| 382 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 383 | if (!*dev) { |
| 384 | err = -ENODEV; |
| 385 | goto out_rtnl; |
| 386 | } |
| 387 | |
| 388 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 389 | if (IS_ERR(*rdev)) { |
| 390 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 391 | goto out_rtnl; |
| 392 | } |
| 393 | |
| 394 | return 0; |
| 395 | out_rtnl: |
| 396 | rtnl_unlock(); |
| 397 | return err; |
| 398 | } |
| 399 | |
| 400 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 401 | { |
| 402 | cfg80211_unlock_rdev(rdev); |
| 403 | rtnl_unlock(); |
| 404 | } |
| 405 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 406 | /* IE validation */ |
| 407 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 408 | { |
| 409 | const u8 *pos; |
| 410 | int len; |
| 411 | |
| 412 | if (!attr) |
| 413 | return true; |
| 414 | |
| 415 | pos = nla_data(attr); |
| 416 | len = nla_len(attr); |
| 417 | |
| 418 | while (len) { |
| 419 | u8 elemlen; |
| 420 | |
| 421 | if (len < 2) |
| 422 | return false; |
| 423 | len -= 2; |
| 424 | |
| 425 | elemlen = pos[1]; |
| 426 | if (elemlen > len) |
| 427 | return false; |
| 428 | |
| 429 | len -= elemlen; |
| 430 | pos += 2 + elemlen; |
| 431 | } |
| 432 | |
| 433 | return true; |
| 434 | } |
| 435 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 436 | /* message building helper */ |
| 437 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 438 | int flags, u8 cmd) |
| 439 | { |
| 440 | /* since there is no private header just add the generic one */ |
| 441 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 442 | } |
| 443 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 444 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 445 | struct ieee80211_channel *chan) |
| 446 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 447 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 448 | chan->center_freq)) |
| 449 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 450 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 451 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 452 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 453 | goto nla_put_failure; |
| 454 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 455 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 456 | goto nla_put_failure; |
| 457 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 458 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 459 | goto nla_put_failure; |
| 460 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 461 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 462 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 463 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 464 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 465 | DBM_TO_MBM(chan->max_power))) |
| 466 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 467 | |
| 468 | return 0; |
| 469 | |
| 470 | nla_put_failure: |
| 471 | return -ENOBUFS; |
| 472 | } |
| 473 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 474 | /* netlink command implementations */ |
| 475 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 476 | struct key_parse { |
| 477 | struct key_params p; |
| 478 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 479 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 480 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 481 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 482 | }; |
| 483 | |
| 484 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 485 | { |
| 486 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 487 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 488 | nl80211_key_policy); |
| 489 | if (err) |
| 490 | return err; |
| 491 | |
| 492 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 493 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 494 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 495 | if (k->def) { |
| 496 | k->def_uni = true; |
| 497 | k->def_multi = true; |
| 498 | } |
| 499 | if (k->defmgmt) |
| 500 | k->def_multi = true; |
| 501 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 502 | if (tb[NL80211_KEY_IDX]) |
| 503 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 504 | |
| 505 | if (tb[NL80211_KEY_DATA]) { |
| 506 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 507 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 508 | } |
| 509 | |
| 510 | if (tb[NL80211_KEY_SEQ]) { |
| 511 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 512 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 513 | } |
| 514 | |
| 515 | if (tb[NL80211_KEY_CIPHER]) |
| 516 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 517 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 518 | if (tb[NL80211_KEY_TYPE]) { |
| 519 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 520 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 521 | return -EINVAL; |
| 522 | } |
| 523 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 524 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 525 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 526 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 527 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 528 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 529 | if (err) |
| 530 | return err; |
| 531 | |
| 532 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 533 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 534 | } |
| 535 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 540 | { |
| 541 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 542 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 543 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 544 | } |
| 545 | |
| 546 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 547 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 548 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 549 | } |
| 550 | |
| 551 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 552 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 553 | |
| 554 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 555 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 556 | |
| 557 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 558 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 559 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 560 | if (k->def) { |
| 561 | k->def_uni = true; |
| 562 | k->def_multi = true; |
| 563 | } |
| 564 | if (k->defmgmt) |
| 565 | k->def_multi = true; |
| 566 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 567 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 568 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 569 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 570 | return -EINVAL; |
| 571 | } |
| 572 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 573 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 574 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 575 | int err = nla_parse_nested( |
| 576 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 577 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 578 | nl80211_key_default_policy); |
| 579 | if (err) |
| 580 | return err; |
| 581 | |
| 582 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 583 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 584 | } |
| 585 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 590 | { |
| 591 | int err; |
| 592 | |
| 593 | memset(k, 0, sizeof(*k)); |
| 594 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 595 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 596 | |
| 597 | if (info->attrs[NL80211_ATTR_KEY]) |
| 598 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 599 | else |
| 600 | err = nl80211_parse_key_old(info, k); |
| 601 | |
| 602 | if (err) |
| 603 | return err; |
| 604 | |
| 605 | if (k->def && k->defmgmt) |
| 606 | return -EINVAL; |
| 607 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 608 | if (k->defmgmt) { |
| 609 | if (k->def_uni || !k->def_multi) |
| 610 | return -EINVAL; |
| 611 | } |
| 612 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 613 | if (k->idx != -1) { |
| 614 | if (k->defmgmt) { |
| 615 | if (k->idx < 4 || k->idx > 5) |
| 616 | return -EINVAL; |
| 617 | } else if (k->def) { |
| 618 | if (k->idx < 0 || k->idx > 3) |
| 619 | return -EINVAL; |
| 620 | } else { |
| 621 | if (k->idx < 0 || k->idx > 5) |
| 622 | return -EINVAL; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 629 | static struct cfg80211_cached_keys * |
| 630 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 631 | struct nlattr *keys) |
| 632 | { |
| 633 | struct key_parse parse; |
| 634 | struct nlattr *key; |
| 635 | struct cfg80211_cached_keys *result; |
| 636 | int rem, err, def = 0; |
| 637 | |
| 638 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 639 | if (!result) |
| 640 | return ERR_PTR(-ENOMEM); |
| 641 | |
| 642 | result->def = -1; |
| 643 | result->defmgmt = -1; |
| 644 | |
| 645 | nla_for_each_nested(key, keys, rem) { |
| 646 | memset(&parse, 0, sizeof(parse)); |
| 647 | parse.idx = -1; |
| 648 | |
| 649 | err = nl80211_parse_key_new(key, &parse); |
| 650 | if (err) |
| 651 | goto error; |
| 652 | err = -EINVAL; |
| 653 | if (!parse.p.key) |
| 654 | goto error; |
| 655 | if (parse.idx < 0 || parse.idx > 4) |
| 656 | goto error; |
| 657 | if (parse.def) { |
| 658 | if (def) |
| 659 | goto error; |
| 660 | def = 1; |
| 661 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 662 | if (!parse.def_uni || !parse.def_multi) |
| 663 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 664 | } else if (parse.defmgmt) |
| 665 | goto error; |
| 666 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 667 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 668 | if (err) |
| 669 | goto error; |
| 670 | result->params[parse.idx].cipher = parse.p.cipher; |
| 671 | result->params[parse.idx].key_len = parse.p.key_len; |
| 672 | result->params[parse.idx].key = result->data[parse.idx]; |
| 673 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 674 | } |
| 675 | |
| 676 | return result; |
| 677 | error: |
| 678 | kfree(result); |
| 679 | return ERR_PTR(err); |
| 680 | } |
| 681 | |
| 682 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 683 | { |
| 684 | ASSERT_WDEV_LOCK(wdev); |
| 685 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 686 | switch (wdev->iftype) { |
| 687 | case NL80211_IFTYPE_AP: |
| 688 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 689 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 690 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 691 | break; |
| 692 | case NL80211_IFTYPE_ADHOC: |
| 693 | if (!wdev->current_bss) |
| 694 | return -ENOLINK; |
| 695 | break; |
| 696 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 697 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 698 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 699 | return -ENOLINK; |
| 700 | break; |
| 701 | default: |
| 702 | return -EINVAL; |
| 703 | } |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 708 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 709 | { |
| 710 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 711 | int i; |
| 712 | |
| 713 | if (!nl_modes) |
| 714 | goto nla_put_failure; |
| 715 | |
| 716 | i = 0; |
| 717 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 718 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 719 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 720 | ifmodes >>= 1; |
| 721 | i++; |
| 722 | } |
| 723 | |
| 724 | nla_nest_end(msg, nl_modes); |
| 725 | return 0; |
| 726 | |
| 727 | nla_put_failure: |
| 728 | return -ENOBUFS; |
| 729 | } |
| 730 | |
| 731 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 732 | struct sk_buff *msg) |
| 733 | { |
| 734 | struct nlattr *nl_combis; |
| 735 | int i, j; |
| 736 | |
| 737 | nl_combis = nla_nest_start(msg, |
| 738 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 739 | if (!nl_combis) |
| 740 | goto nla_put_failure; |
| 741 | |
| 742 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 743 | const struct ieee80211_iface_combination *c; |
| 744 | struct nlattr *nl_combi, *nl_limits; |
| 745 | |
| 746 | c = &wiphy->iface_combinations[i]; |
| 747 | |
| 748 | nl_combi = nla_nest_start(msg, i + 1); |
| 749 | if (!nl_combi) |
| 750 | goto nla_put_failure; |
| 751 | |
| 752 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 753 | if (!nl_limits) |
| 754 | goto nla_put_failure; |
| 755 | |
| 756 | for (j = 0; j < c->n_limits; j++) { |
| 757 | struct nlattr *nl_limit; |
| 758 | |
| 759 | nl_limit = nla_nest_start(msg, j + 1); |
| 760 | if (!nl_limit) |
| 761 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 762 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 763 | c->limits[j].max)) |
| 764 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 765 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 766 | c->limits[j].types)) |
| 767 | goto nla_put_failure; |
| 768 | nla_nest_end(msg, nl_limit); |
| 769 | } |
| 770 | |
| 771 | nla_nest_end(msg, nl_limits); |
| 772 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 773 | if (c->beacon_int_infra_match && |
| 774 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 775 | goto nla_put_failure; |
| 776 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 777 | c->num_different_channels) || |
| 778 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 779 | c->max_interfaces)) |
| 780 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 781 | |
| 782 | nla_nest_end(msg, nl_combi); |
| 783 | } |
| 784 | |
| 785 | nla_nest_end(msg, nl_combis); |
| 786 | |
| 787 | return 0; |
| 788 | nla_put_failure: |
| 789 | return -ENOBUFS; |
| 790 | } |
| 791 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 792 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 793 | struct cfg80211_registered_device *dev) |
| 794 | { |
| 795 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 796 | struct nlattr *nl_bands, *nl_band; |
| 797 | struct nlattr *nl_freqs, *nl_freq; |
| 798 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 799 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 800 | enum ieee80211_band band; |
| 801 | struct ieee80211_channel *chan; |
| 802 | struct ieee80211_rate *rate; |
| 803 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 804 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 805 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 806 | |
| 807 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 808 | if (!hdr) |
| 809 | return -1; |
| 810 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 812 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 813 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 814 | cfg80211_rdev_list_generation) || |
| 815 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 816 | dev->wiphy.retry_short) || |
| 817 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 818 | dev->wiphy.retry_long) || |
| 819 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 820 | dev->wiphy.frag_threshold) || |
| 821 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 822 | dev->wiphy.rts_threshold) || |
| 823 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 824 | dev->wiphy.coverage_class) || |
| 825 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 826 | dev->wiphy.max_scan_ssids) || |
| 827 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 828 | dev->wiphy.max_sched_scan_ssids) || |
| 829 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 830 | dev->wiphy.max_scan_ie_len) || |
| 831 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 832 | dev->wiphy.max_sched_scan_ie_len) || |
| 833 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 834 | dev->wiphy.max_match_sets)) |
| 835 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 836 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 837 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 838 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 839 | goto nla_put_failure; |
| 840 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 841 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 842 | goto nla_put_failure; |
| 843 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 844 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 845 | goto nla_put_failure; |
| 846 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 847 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 848 | goto nla_put_failure; |
| 849 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 850 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 851 | goto nla_put_failure; |
| 852 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 853 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 854 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 855 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 856 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 857 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 858 | dev->wiphy.cipher_suites)) |
| 859 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 860 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 861 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 862 | dev->wiphy.max_num_pmkids)) |
| 863 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 864 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 865 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 866 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 867 | goto nla_put_failure; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 869 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 870 | dev->wiphy.available_antennas_tx) || |
| 871 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 872 | dev->wiphy.available_antennas_rx)) |
| 873 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 874 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 875 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 876 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 877 | dev->wiphy.probe_resp_offload)) |
| 878 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 879 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 880 | if ((dev->wiphy.available_antennas_tx || |
| 881 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 882 | u32 tx_ant = 0, rx_ant = 0; |
| 883 | int res; |
| 884 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 885 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 886 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 887 | tx_ant) || |
| 888 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 889 | rx_ant)) |
| 890 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 894 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 895 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 896 | goto nla_put_failure; |
| 897 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 898 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 899 | if (!nl_bands) |
| 900 | goto nla_put_failure; |
| 901 | |
| 902 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 903 | if (!dev->wiphy.bands[band]) |
| 904 | continue; |
| 905 | |
| 906 | nl_band = nla_nest_start(msg, band); |
| 907 | if (!nl_band) |
| 908 | goto nla_put_failure; |
| 909 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 910 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 911 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 912 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 913 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 914 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 915 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 916 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 917 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 918 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 919 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 920 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 921 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 922 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 923 | /* add frequencies */ |
| 924 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 925 | if (!nl_freqs) |
| 926 | goto nla_put_failure; |
| 927 | |
| 928 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 929 | nl_freq = nla_nest_start(msg, i); |
| 930 | if (!nl_freq) |
| 931 | goto nla_put_failure; |
| 932 | |
| 933 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 934 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 935 | if (nl80211_msg_put_channel(msg, chan)) |
| 936 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 937 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 938 | nla_nest_end(msg, nl_freq); |
| 939 | } |
| 940 | |
| 941 | nla_nest_end(msg, nl_freqs); |
| 942 | |
| 943 | /* add bitrates */ |
| 944 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 945 | if (!nl_rates) |
| 946 | goto nla_put_failure; |
| 947 | |
| 948 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 949 | nl_rate = nla_nest_start(msg, i); |
| 950 | if (!nl_rate) |
| 951 | goto nla_put_failure; |
| 952 | |
| 953 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 954 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 955 | rate->bitrate)) |
| 956 | goto nla_put_failure; |
| 957 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 958 | nla_put_flag(msg, |
| 959 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 960 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 961 | |
| 962 | nla_nest_end(msg, nl_rate); |
| 963 | } |
| 964 | |
| 965 | nla_nest_end(msg, nl_rates); |
| 966 | |
| 967 | nla_nest_end(msg, nl_band); |
| 968 | } |
| 969 | nla_nest_end(msg, nl_bands); |
| 970 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 971 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 972 | if (!nl_cmds) |
| 973 | goto nla_put_failure; |
| 974 | |
| 975 | i = 0; |
| 976 | #define CMD(op, n) \ |
| 977 | do { \ |
| 978 | if (dev->ops->op) { \ |
| 979 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 980 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 981 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 982 | } \ |
| 983 | } while (0) |
| 984 | |
| 985 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 986 | CMD(change_virtual_intf, SET_INTERFACE); |
| 987 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 988 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 989 | CMD(add_station, NEW_STATION); |
| 990 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 991 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 992 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 993 | CMD(auth, AUTHENTICATE); |
| 994 | CMD(assoc, ASSOCIATE); |
| 995 | CMD(deauth, DEAUTHENTICATE); |
| 996 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 997 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 998 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 999 | CMD(set_pmksa, SET_PMKSA); |
| 1000 | CMD(del_pmksa, DEL_PMKSA); |
| 1001 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1002 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1003 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 1004 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1005 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1006 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 1007 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1008 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1009 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1010 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1011 | } |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1012 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1013 | dev->ops->join_mesh) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1014 | i++; |
| 1015 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1016 | goto nla_put_failure; |
| 1017 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1018 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 1019 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1020 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1021 | CMD(tdls_oper, TDLS_OPER); |
| 1022 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 1023 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1024 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 1025 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1026 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1027 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1028 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1029 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1030 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 1031 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1032 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 1033 | #ifdef CONFIG_NL80211_TESTMODE |
| 1034 | CMD(testmode_cmd, TESTMODE); |
| 1035 | #endif |
| 1036 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1037 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1038 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1039 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1040 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1041 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1042 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1043 | } |
| 1044 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 1045 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1046 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1047 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1048 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1051 | nla_nest_end(msg, nl_cmds); |
| 1052 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 1053 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1054 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 1055 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 1056 | dev->wiphy.max_remain_on_channel_duration)) |
| 1057 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 1058 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1059 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 1060 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1061 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 1062 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1063 | if (mgmt_stypes) { |
| 1064 | u16 stypes; |
| 1065 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1066 | enum nl80211_iftype ift; |
| 1067 | |
| 1068 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1069 | if (!nl_ifs) |
| 1070 | goto nla_put_failure; |
| 1071 | |
| 1072 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1073 | nl_ftypes = nla_nest_start(msg, ift); |
| 1074 | if (!nl_ftypes) |
| 1075 | goto nla_put_failure; |
| 1076 | i = 0; |
| 1077 | stypes = mgmt_stypes[ift].tx; |
| 1078 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1079 | if ((stypes & 1) && |
| 1080 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1081 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1082 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1083 | stypes >>= 1; |
| 1084 | i++; |
| 1085 | } |
| 1086 | nla_nest_end(msg, nl_ftypes); |
| 1087 | } |
| 1088 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1089 | nla_nest_end(msg, nl_ifs); |
| 1090 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1091 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1092 | if (!nl_ifs) |
| 1093 | goto nla_put_failure; |
| 1094 | |
| 1095 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1096 | nl_ftypes = nla_nest_start(msg, ift); |
| 1097 | if (!nl_ftypes) |
| 1098 | goto nla_put_failure; |
| 1099 | i = 0; |
| 1100 | stypes = mgmt_stypes[ift].rx; |
| 1101 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1102 | if ((stypes & 1) && |
| 1103 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1104 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1105 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1106 | stypes >>= 1; |
| 1107 | i++; |
| 1108 | } |
| 1109 | nla_nest_end(msg, nl_ftypes); |
| 1110 | } |
| 1111 | nla_nest_end(msg, nl_ifs); |
| 1112 | } |
| 1113 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1114 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1115 | struct nlattr *nl_wowlan; |
| 1116 | |
| 1117 | nl_wowlan = nla_nest_start(msg, |
| 1118 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1119 | if (!nl_wowlan) |
| 1120 | goto nla_put_failure; |
| 1121 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1122 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1123 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1124 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1125 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1126 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1127 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1128 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1129 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1130 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1131 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1132 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1133 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1134 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1135 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1136 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1137 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1138 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1139 | if (dev->wiphy.wowlan.n_patterns) { |
| 1140 | struct nl80211_wowlan_pattern_support pat = { |
| 1141 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1142 | .min_pattern_len = |
| 1143 | dev->wiphy.wowlan.pattern_min_len, |
| 1144 | .max_pattern_len = |
| 1145 | dev->wiphy.wowlan.pattern_max_len, |
| 1146 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1147 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1148 | sizeof(pat), &pat)) |
| 1149 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | nla_nest_end(msg, nl_wowlan); |
| 1153 | } |
| 1154 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1155 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1156 | dev->wiphy.software_iftypes)) |
| 1157 | goto nla_put_failure; |
| 1158 | |
| 1159 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1160 | goto nla_put_failure; |
| 1161 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1162 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1163 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1164 | dev->wiphy.ap_sme_capa)) |
| 1165 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1166 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1167 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1168 | dev->wiphy.features)) |
| 1169 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1170 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1171 | if (dev->wiphy.ht_capa_mod_mask && |
| 1172 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1173 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1174 | dev->wiphy.ht_capa_mod_mask)) |
| 1175 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1176 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1177 | return genlmsg_end(msg, hdr); |
| 1178 | |
| 1179 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1180 | genlmsg_cancel(msg, hdr); |
| 1181 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1185 | { |
| 1186 | int idx = 0; |
| 1187 | int start = cb->args[0]; |
| 1188 | struct cfg80211_registered_device *dev; |
| 1189 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1190 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1191 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1192 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1193 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1194 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1195 | continue; |
| 1196 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1197 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1198 | dev) < 0) { |
| 1199 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1200 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1201 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1202 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1203 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1204 | |
| 1205 | cb->args[0] = idx; |
| 1206 | |
| 1207 | return skb->len; |
| 1208 | } |
| 1209 | |
| 1210 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1211 | { |
| 1212 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1213 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1214 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1215 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1216 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1217 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1218 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1219 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1220 | nlmsg_free(msg); |
| 1221 | return -ENOBUFS; |
| 1222 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1223 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1224 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1225 | } |
| 1226 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1227 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1228 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1229 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1230 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1231 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1232 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1233 | }; |
| 1234 | |
| 1235 | static int parse_txq_params(struct nlattr *tb[], |
| 1236 | struct ieee80211_txq_params *txq_params) |
| 1237 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1238 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1239 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1240 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1241 | return -EINVAL; |
| 1242 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1243 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1244 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1245 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1246 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1247 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1248 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1249 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1250 | return -EINVAL; |
| 1251 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1252 | return 0; |
| 1253 | } |
| 1254 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1255 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1256 | { |
| 1257 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1258 | * You can only set the channel explicitly for WDS interfaces, |
| 1259 | * all others have their channel managed via their respective |
| 1260 | * "establish a connection" command (connect, join, ...) |
| 1261 | * |
| 1262 | * For AP/GO and mesh mode, the channel can be set with the |
| 1263 | * channel userspace API, but is only stored and passed to the |
| 1264 | * low-level driver when the AP starts or the mesh is joined. |
| 1265 | * This is for backward compatibility, userspace can also give |
| 1266 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1267 | * |
| 1268 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1269 | * whatever else is going on, so they have their own special |
| 1270 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1271 | */ |
| 1272 | return !wdev || |
| 1273 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1274 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1275 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1276 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1279 | static bool nl80211_valid_channel_type(struct genl_info *info, |
| 1280 | enum nl80211_channel_type *channel_type) |
| 1281 | { |
| 1282 | enum nl80211_channel_type tmp; |
| 1283 | |
| 1284 | if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) |
| 1285 | return false; |
| 1286 | |
| 1287 | tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1288 | if (tmp != NL80211_CHAN_NO_HT && |
| 1289 | tmp != NL80211_CHAN_HT20 && |
| 1290 | tmp != NL80211_CHAN_HT40PLUS && |
| 1291 | tmp != NL80211_CHAN_HT40MINUS) |
| 1292 | return false; |
| 1293 | |
| 1294 | if (channel_type) |
| 1295 | *channel_type = tmp; |
| 1296 | |
| 1297 | return true; |
| 1298 | } |
| 1299 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1300 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1301 | struct wireless_dev *wdev, |
| 1302 | struct genl_info *info) |
| 1303 | { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1304 | struct ieee80211_channel *channel; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1305 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1306 | u32 freq; |
| 1307 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1308 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
| 1309 | |
| 1310 | if (wdev) |
| 1311 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1312 | |
| 1313 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1314 | return -EINVAL; |
| 1315 | |
| 1316 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1317 | return -EOPNOTSUPP; |
| 1318 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1319 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 1320 | !nl80211_valid_channel_type(info, &channel_type)) |
| 1321 | return -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1322 | |
| 1323 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1324 | |
| 1325 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1326 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1327 | case NL80211_IFTYPE_AP: |
| 1328 | case NL80211_IFTYPE_P2P_GO: |
| 1329 | if (wdev->beacon_interval) { |
| 1330 | result = -EBUSY; |
| 1331 | break; |
| 1332 | } |
| 1333 | channel = rdev_freq_to_chan(rdev, freq, channel_type); |
| 1334 | if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy, |
| 1335 | channel, |
| 1336 | channel_type)) { |
| 1337 | result = -EINVAL; |
| 1338 | break; |
| 1339 | } |
| 1340 | wdev->preset_chan = channel; |
| 1341 | wdev->preset_chantype = channel_type; |
| 1342 | result = 0; |
| 1343 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1344 | case NL80211_IFTYPE_MESH_POINT: |
| 1345 | result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type); |
| 1346 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1347 | case NL80211_IFTYPE_MONITOR: |
| 1348 | result = cfg80211_set_monitor_channel(rdev, freq, channel_type); |
| 1349 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1350 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1351 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1352 | } |
| 1353 | mutex_unlock(&rdev->devlist_mtx); |
| 1354 | |
| 1355 | return result; |
| 1356 | } |
| 1357 | |
| 1358 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1359 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1360 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1361 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1362 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1363 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1364 | } |
| 1365 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1366 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1367 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1368 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1369 | struct net_device *dev = info->user_ptr[1]; |
| 1370 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1371 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1372 | |
| 1373 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1374 | return -EINVAL; |
| 1375 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1376 | if (netif_running(dev)) |
| 1377 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1378 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1379 | if (!rdev->ops->set_wds_peer) |
| 1380 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1381 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1382 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1383 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1384 | |
| 1385 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1386 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1390 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1391 | { |
| 1392 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1393 | struct net_device *netdev = NULL; |
| 1394 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1395 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1396 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1397 | u32 changed; |
| 1398 | u8 retry_short = 0, retry_long = 0; |
| 1399 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1400 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1401 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1402 | /* |
| 1403 | * Try to find the wiphy and netdev. Normally this |
| 1404 | * function shouldn't need the netdev, but this is |
| 1405 | * done for backward compatibility -- previously |
| 1406 | * setting the channel was done per wiphy, but now |
| 1407 | * it is per netdev. Previous userland like hostapd |
| 1408 | * also passed a netdev to set_wiphy, so that it is |
| 1409 | * possible to let that go to the right netdev! |
| 1410 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1411 | mutex_lock(&cfg80211_mutex); |
| 1412 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1413 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1414 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1415 | |
| 1416 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1417 | if (netdev && netdev->ieee80211_ptr) { |
| 1418 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1419 | mutex_lock(&rdev->mtx); |
| 1420 | } else |
| 1421 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1422 | } |
| 1423 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1424 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 1425 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 1426 | info->attrs); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1427 | if (IS_ERR(rdev)) { |
| 1428 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1429 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1430 | } |
| 1431 | wdev = NULL; |
| 1432 | netdev = NULL; |
| 1433 | result = 0; |
| 1434 | |
| 1435 | mutex_lock(&rdev->mtx); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1436 | } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1437 | wdev = netdev->ieee80211_ptr; |
| 1438 | else |
| 1439 | wdev = NULL; |
| 1440 | |
| 1441 | /* |
| 1442 | * end workaround code, by now the rdev is available |
| 1443 | * and locked, and wdev may or may not be NULL. |
| 1444 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1445 | |
| 1446 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1447 | result = cfg80211_dev_rename( |
| 1448 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1449 | |
| 1450 | mutex_unlock(&cfg80211_mutex); |
| 1451 | |
| 1452 | if (result) |
| 1453 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1454 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1455 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1456 | struct ieee80211_txq_params txq_params; |
| 1457 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1458 | |
| 1459 | if (!rdev->ops->set_txq_params) { |
| 1460 | result = -EOPNOTSUPP; |
| 1461 | goto bad_res; |
| 1462 | } |
| 1463 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1464 | if (!netdev) { |
| 1465 | result = -EINVAL; |
| 1466 | goto bad_res; |
| 1467 | } |
| 1468 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1469 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1470 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1471 | result = -EINVAL; |
| 1472 | goto bad_res; |
| 1473 | } |
| 1474 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1475 | if (!netif_running(netdev)) { |
| 1476 | result = -ENETDOWN; |
| 1477 | goto bad_res; |
| 1478 | } |
| 1479 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1480 | nla_for_each_nested(nl_txq_params, |
| 1481 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1482 | rem_txq_params) { |
| 1483 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1484 | nla_data(nl_txq_params), |
| 1485 | nla_len(nl_txq_params), |
| 1486 | txq_params_policy); |
| 1487 | result = parse_txq_params(tb, &txq_params); |
| 1488 | if (result) |
| 1489 | goto bad_res; |
| 1490 | |
| 1491 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1492 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1493 | &txq_params); |
| 1494 | if (result) |
| 1495 | goto bad_res; |
| 1496 | } |
| 1497 | } |
| 1498 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1499 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1500 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1501 | if (result) |
| 1502 | goto bad_res; |
| 1503 | } |
| 1504 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1505 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1506 | enum nl80211_tx_power_setting type; |
| 1507 | int idx, mbm = 0; |
| 1508 | |
| 1509 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1510 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1511 | goto bad_res; |
| 1512 | } |
| 1513 | |
| 1514 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1515 | type = nla_get_u32(info->attrs[idx]); |
| 1516 | |
| 1517 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1518 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1519 | result = -EINVAL; |
| 1520 | goto bad_res; |
| 1521 | } |
| 1522 | |
| 1523 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1524 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1525 | mbm = nla_get_u32(info->attrs[idx]); |
| 1526 | } |
| 1527 | |
| 1528 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1529 | if (result) |
| 1530 | goto bad_res; |
| 1531 | } |
| 1532 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1533 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1534 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1535 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1536 | if ((!rdev->wiphy.available_antennas_tx && |
| 1537 | !rdev->wiphy.available_antennas_rx) || |
| 1538 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1539 | result = -EOPNOTSUPP; |
| 1540 | goto bad_res; |
| 1541 | } |
| 1542 | |
| 1543 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1544 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1545 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1546 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1547 | * available antenna masks, except for the "all" mask */ |
| 1548 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1549 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1550 | result = -EINVAL; |
| 1551 | goto bad_res; |
| 1552 | } |
| 1553 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1554 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1555 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1556 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1557 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1558 | if (result) |
| 1559 | goto bad_res; |
| 1560 | } |
| 1561 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1562 | changed = 0; |
| 1563 | |
| 1564 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1565 | retry_short = nla_get_u8( |
| 1566 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1567 | if (retry_short == 0) { |
| 1568 | result = -EINVAL; |
| 1569 | goto bad_res; |
| 1570 | } |
| 1571 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1572 | } |
| 1573 | |
| 1574 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1575 | retry_long = nla_get_u8( |
| 1576 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1577 | if (retry_long == 0) { |
| 1578 | result = -EINVAL; |
| 1579 | goto bad_res; |
| 1580 | } |
| 1581 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1582 | } |
| 1583 | |
| 1584 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1585 | frag_threshold = nla_get_u32( |
| 1586 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1587 | if (frag_threshold < 256) { |
| 1588 | result = -EINVAL; |
| 1589 | goto bad_res; |
| 1590 | } |
| 1591 | if (frag_threshold != (u32) -1) { |
| 1592 | /* |
| 1593 | * Fragments (apart from the last one) are required to |
| 1594 | * have even length. Make the fragmentation code |
| 1595 | * simpler by stripping LSB should someone try to use |
| 1596 | * odd threshold value. |
| 1597 | */ |
| 1598 | frag_threshold &= ~0x1; |
| 1599 | } |
| 1600 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1601 | } |
| 1602 | |
| 1603 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1604 | rts_threshold = nla_get_u32( |
| 1605 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1606 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1607 | } |
| 1608 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1609 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1610 | coverage_class = nla_get_u8( |
| 1611 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1612 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1613 | } |
| 1614 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1615 | if (changed) { |
| 1616 | u8 old_retry_short, old_retry_long; |
| 1617 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1618 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1619 | |
| 1620 | if (!rdev->ops->set_wiphy_params) { |
| 1621 | result = -EOPNOTSUPP; |
| 1622 | goto bad_res; |
| 1623 | } |
| 1624 | |
| 1625 | old_retry_short = rdev->wiphy.retry_short; |
| 1626 | old_retry_long = rdev->wiphy.retry_long; |
| 1627 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1628 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1629 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1630 | |
| 1631 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1632 | rdev->wiphy.retry_short = retry_short; |
| 1633 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1634 | rdev->wiphy.retry_long = retry_long; |
| 1635 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1636 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1637 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1638 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1639 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1640 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1641 | |
| 1642 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1643 | if (result) { |
| 1644 | rdev->wiphy.retry_short = old_retry_short; |
| 1645 | rdev->wiphy.retry_long = old_retry_long; |
| 1646 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1647 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1648 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1649 | } |
| 1650 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1651 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1652 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1653 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1654 | if (netdev) |
| 1655 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1656 | return result; |
| 1657 | } |
| 1658 | |
| 1659 | |
| 1660 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1661 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1662 | struct net_device *dev) |
| 1663 | { |
| 1664 | void *hdr; |
| 1665 | |
| 1666 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1667 | if (!hdr) |
| 1668 | return -1; |
| 1669 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1670 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 1671 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1672 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) || |
| 1673 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1674 | dev->ieee80211_ptr->iftype) || |
| 1675 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1676 | rdev->devlist_generation ^ |
| 1677 | (cfg80211_rdev_list_generation << 2))) |
| 1678 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1679 | |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1680 | if (rdev->ops->get_channel) { |
| 1681 | struct ieee80211_channel *chan; |
| 1682 | enum nl80211_channel_type channel_type; |
| 1683 | |
| 1684 | chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type); |
John W. Linville | 59ef43e | 2012-04-18 14:17:13 -0400 | [diff] [blame] | 1685 | if (chan && |
| 1686 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1687 | chan->center_freq) || |
| 1688 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1689 | channel_type))) |
| 1690 | goto nla_put_failure; |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1691 | } |
| 1692 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1693 | return genlmsg_end(msg, hdr); |
| 1694 | |
| 1695 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1696 | genlmsg_cancel(msg, hdr); |
| 1697 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1701 | { |
| 1702 | int wp_idx = 0; |
| 1703 | int if_idx = 0; |
| 1704 | int wp_start = cb->args[0]; |
| 1705 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1706 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1707 | struct wireless_dev *wdev; |
| 1708 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1709 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1710 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1711 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1712 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1713 | if (wp_idx < wp_start) { |
| 1714 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1715 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1716 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1717 | if_idx = 0; |
| 1718 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1719 | mutex_lock(&rdev->devlist_mtx); |
| 1720 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1721 | if (if_idx < if_start) { |
| 1722 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1723 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1724 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1725 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1726 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1727 | rdev, wdev->netdev) < 0) { |
| 1728 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1729 | goto out; |
| 1730 | } |
| 1731 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1732 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1733 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1734 | |
| 1735 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1736 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1737 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1738 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1739 | |
| 1740 | cb->args[0] = wp_idx; |
| 1741 | cb->args[1] = if_idx; |
| 1742 | |
| 1743 | return skb->len; |
| 1744 | } |
| 1745 | |
| 1746 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1747 | { |
| 1748 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1749 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1750 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1751 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1752 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1753 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1754 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1755 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1756 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1757 | dev, netdev) < 0) { |
| 1758 | nlmsg_free(msg); |
| 1759 | return -ENOBUFS; |
| 1760 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1761 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1762 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1763 | } |
| 1764 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1765 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1766 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1767 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1768 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1769 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1770 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1771 | }; |
| 1772 | |
| 1773 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1774 | { |
| 1775 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1776 | int flag; |
| 1777 | |
| 1778 | *mntrflags = 0; |
| 1779 | |
| 1780 | if (!nla) |
| 1781 | return -EINVAL; |
| 1782 | |
| 1783 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1784 | nla, mntr_flags_policy)) |
| 1785 | return -EINVAL; |
| 1786 | |
| 1787 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1788 | if (flags[flag]) |
| 1789 | *mntrflags |= (1<<flag); |
| 1790 | |
| 1791 | return 0; |
| 1792 | } |
| 1793 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1794 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1795 | struct net_device *netdev, u8 use_4addr, |
| 1796 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1797 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1798 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1799 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1800 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1801 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1802 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1803 | |
| 1804 | switch (iftype) { |
| 1805 | case NL80211_IFTYPE_AP_VLAN: |
| 1806 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1807 | return 0; |
| 1808 | break; |
| 1809 | case NL80211_IFTYPE_STATION: |
| 1810 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1811 | return 0; |
| 1812 | break; |
| 1813 | default: |
| 1814 | break; |
| 1815 | } |
| 1816 | |
| 1817 | return -EOPNOTSUPP; |
| 1818 | } |
| 1819 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1820 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1823 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1824 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1825 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1826 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1827 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1828 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1829 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1830 | memset(¶ms, 0, sizeof(params)); |
| 1831 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1832 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1833 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1834 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1835 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1836 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1837 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1838 | if (ntype > NL80211_IFTYPE_MAX) |
| 1839 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1842 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1843 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1844 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1845 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1846 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1847 | if (netif_running(dev)) |
| 1848 | return -EBUSY; |
| 1849 | |
| 1850 | wdev_lock(wdev); |
| 1851 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1852 | IEEE80211_MAX_MESH_ID_LEN); |
| 1853 | wdev->mesh_id_up_len = |
| 1854 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1855 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1856 | wdev->mesh_id_up_len); |
| 1857 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1858 | } |
| 1859 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1860 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1861 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1862 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1863 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1864 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1865 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1866 | } else { |
| 1867 | params.use_4addr = -1; |
| 1868 | } |
| 1869 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1870 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1871 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1872 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1873 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1874 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1875 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1876 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1877 | |
| 1878 | flags = &_flags; |
| 1879 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1880 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1881 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1882 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1883 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1884 | else |
| 1885 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1886 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1887 | if (!err && params.use_4addr != -1) |
| 1888 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1889 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1890 | return err; |
| 1891 | } |
| 1892 | |
| 1893 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1894 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1896 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1897 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1898 | int err; |
| 1899 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1900 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1901 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1902 | memset(¶ms, 0, sizeof(params)); |
| 1903 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1904 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1905 | return -EINVAL; |
| 1906 | |
| 1907 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1908 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1909 | if (type > NL80211_IFTYPE_MAX) |
| 1910 | return -EINVAL; |
| 1911 | } |
| 1912 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1913 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1914 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1915 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1916 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1917 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1918 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1919 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1920 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1921 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1922 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1923 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1924 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1925 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1926 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1927 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1928 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1929 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1930 | if (IS_ERR(dev)) |
| 1931 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1932 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1933 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1934 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1935 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1936 | |
| 1937 | wdev_lock(wdev); |
| 1938 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1939 | IEEE80211_MAX_MESH_ID_LEN); |
| 1940 | wdev->mesh_id_up_len = |
| 1941 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1942 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1943 | wdev->mesh_id_up_len); |
| 1944 | wdev_unlock(wdev); |
| 1945 | } |
| 1946 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1947 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1951 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1953 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1954 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1955 | if (!rdev->ops->del_virtual_intf) |
| 1956 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1957 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1958 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1959 | } |
| 1960 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1961 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 1962 | { |
| 1963 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1964 | struct net_device *dev = info->user_ptr[1]; |
| 1965 | u16 noack_map; |
| 1966 | |
| 1967 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 1968 | return -EINVAL; |
| 1969 | |
| 1970 | if (!rdev->ops->set_noack_map) |
| 1971 | return -EOPNOTSUPP; |
| 1972 | |
| 1973 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 1974 | |
| 1975 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 1976 | } |
| 1977 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1978 | struct get_key_cookie { |
| 1979 | struct sk_buff *msg; |
| 1980 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1981 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1982 | }; |
| 1983 | |
| 1984 | static void get_key_callback(void *c, struct key_params *params) |
| 1985 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1986 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1987 | struct get_key_cookie *cookie = c; |
| 1988 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1989 | if ((params->key && |
| 1990 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1991 | params->key_len, params->key)) || |
| 1992 | (params->seq && |
| 1993 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1994 | params->seq_len, params->seq)) || |
| 1995 | (params->cipher && |
| 1996 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1997 | params->cipher))) |
| 1998 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1999 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2000 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2001 | if (!key) |
| 2002 | goto nla_put_failure; |
| 2003 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2004 | if ((params->key && |
| 2005 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2006 | params->key_len, params->key)) || |
| 2007 | (params->seq && |
| 2008 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2009 | params->seq_len, params->seq)) || |
| 2010 | (params->cipher && |
| 2011 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2012 | params->cipher))) |
| 2013 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2014 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2015 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2016 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2017 | |
| 2018 | nla_nest_end(cookie->msg, key); |
| 2019 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2020 | return; |
| 2021 | nla_put_failure: |
| 2022 | cookie->error = 1; |
| 2023 | } |
| 2024 | |
| 2025 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2028 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2029 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2030 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2031 | const u8 *mac_addr = NULL; |
| 2032 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2033 | struct get_key_cookie cookie = { |
| 2034 | .error = 0, |
| 2035 | }; |
| 2036 | void *hdr; |
| 2037 | struct sk_buff *msg; |
| 2038 | |
| 2039 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2040 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2041 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2042 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2043 | return -EINVAL; |
| 2044 | |
| 2045 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2046 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2047 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2048 | pairwise = !!mac_addr; |
| 2049 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2050 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2051 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2052 | return -EINVAL; |
| 2053 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2054 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2055 | return -EINVAL; |
| 2056 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2057 | } |
| 2058 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2059 | if (!rdev->ops->get_key) |
| 2060 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2061 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2062 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2063 | if (!msg) |
| 2064 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2065 | |
| 2066 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2067 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2068 | if (IS_ERR(hdr)) |
| 2069 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2070 | |
| 2071 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2072 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2073 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2074 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2075 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2076 | goto nla_put_failure; |
| 2077 | if (mac_addr && |
| 2078 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2079 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2080 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2081 | if (pairwise && mac_addr && |
| 2082 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2083 | return -ENOENT; |
| 2084 | |
| 2085 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 2086 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2087 | |
| 2088 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2089 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2090 | |
| 2091 | if (cookie.error) |
| 2092 | goto nla_put_failure; |
| 2093 | |
| 2094 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2095 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2096 | |
| 2097 | nla_put_failure: |
| 2098 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2099 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2100 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2101 | return err; |
| 2102 | } |
| 2103 | |
| 2104 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2105 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2107 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2108 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2109 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2110 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2111 | err = nl80211_parse_key(info, &key); |
| 2112 | if (err) |
| 2113 | return err; |
| 2114 | |
| 2115 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2116 | return -EINVAL; |
| 2117 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2118 | /* only support setting default key */ |
| 2119 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2120 | return -EINVAL; |
| 2121 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2122 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2123 | |
| 2124 | if (key.def) { |
| 2125 | if (!rdev->ops->set_default_key) { |
| 2126 | err = -EOPNOTSUPP; |
| 2127 | goto out; |
| 2128 | } |
| 2129 | |
| 2130 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2131 | if (err) |
| 2132 | goto out; |
| 2133 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2134 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 2135 | key.def_uni, key.def_multi); |
| 2136 | |
| 2137 | if (err) |
| 2138 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2139 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2140 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2141 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2142 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2143 | } else { |
| 2144 | if (key.def_uni || !key.def_multi) { |
| 2145 | err = -EINVAL; |
| 2146 | goto out; |
| 2147 | } |
| 2148 | |
| 2149 | if (!rdev->ops->set_default_mgmt_key) { |
| 2150 | err = -EOPNOTSUPP; |
| 2151 | goto out; |
| 2152 | } |
| 2153 | |
| 2154 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2155 | if (err) |
| 2156 | goto out; |
| 2157 | |
| 2158 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 2159 | dev, key.idx); |
| 2160 | if (err) |
| 2161 | goto out; |
| 2162 | |
| 2163 | #ifdef CONFIG_CFG80211_WEXT |
| 2164 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2165 | #endif |
| 2166 | } |
| 2167 | |
| 2168 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2169 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2170 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2171 | return err; |
| 2172 | } |
| 2173 | |
| 2174 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2175 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2177 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2178 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2179 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2180 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2181 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2182 | err = nl80211_parse_key(info, &key); |
| 2183 | if (err) |
| 2184 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2185 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2186 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2187 | return -EINVAL; |
| 2188 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2189 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2190 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2191 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2192 | if (key.type == -1) { |
| 2193 | if (mac_addr) |
| 2194 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2195 | else |
| 2196 | key.type = NL80211_KEYTYPE_GROUP; |
| 2197 | } |
| 2198 | |
| 2199 | /* for now */ |
| 2200 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2201 | key.type != NL80211_KEYTYPE_GROUP) |
| 2202 | return -EINVAL; |
| 2203 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2204 | if (!rdev->ops->add_key) |
| 2205 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2206 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2207 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2208 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2209 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2210 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2211 | |
| 2212 | wdev_lock(dev->ieee80211_ptr); |
| 2213 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2214 | if (!err) |
| 2215 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2216 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2217 | mac_addr, &key.p); |
| 2218 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2219 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2220 | return err; |
| 2221 | } |
| 2222 | |
| 2223 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2224 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2226 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2227 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2228 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2229 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2230 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2231 | err = nl80211_parse_key(info, &key); |
| 2232 | if (err) |
| 2233 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2234 | |
| 2235 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2236 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2237 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2238 | if (key.type == -1) { |
| 2239 | if (mac_addr) |
| 2240 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2241 | else |
| 2242 | key.type = NL80211_KEYTYPE_GROUP; |
| 2243 | } |
| 2244 | |
| 2245 | /* for now */ |
| 2246 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2247 | key.type != NL80211_KEYTYPE_GROUP) |
| 2248 | return -EINVAL; |
| 2249 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2250 | if (!rdev->ops->del_key) |
| 2251 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2252 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2253 | wdev_lock(dev->ieee80211_ptr); |
| 2254 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2255 | |
| 2256 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2257 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2258 | err = -ENOENT; |
| 2259 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2260 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2261 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2262 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2263 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2264 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2265 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2266 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2267 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2268 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2269 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2270 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2271 | } |
| 2272 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2273 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2274 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2275 | return err; |
| 2276 | } |
| 2277 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2278 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2279 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2280 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2281 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2282 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2283 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2284 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2285 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2286 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2287 | return -EINVAL; |
| 2288 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2289 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2290 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2291 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2292 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2293 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2294 | if (!bcn->head_len) |
| 2295 | return -EINVAL; |
| 2296 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2300 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2301 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2302 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2303 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2304 | } |
| 2305 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2306 | if (!haveinfo) |
| 2307 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2308 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2309 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2310 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2311 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2315 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2316 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2317 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2318 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2319 | } |
| 2320 | |
| 2321 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2322 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2323 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2324 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2325 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2326 | } |
| 2327 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2328 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2329 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2330 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2331 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2332 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2333 | } |
| 2334 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2335 | return 0; |
| 2336 | } |
| 2337 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame^] | 2338 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 2339 | struct cfg80211_ap_settings *params) |
| 2340 | { |
| 2341 | struct wireless_dev *wdev; |
| 2342 | bool ret = false; |
| 2343 | |
| 2344 | mutex_lock(&rdev->devlist_mtx); |
| 2345 | |
| 2346 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
| 2347 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 2348 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 2349 | continue; |
| 2350 | |
| 2351 | if (!wdev->preset_chan) |
| 2352 | continue; |
| 2353 | |
| 2354 | params->channel = wdev->preset_chan; |
| 2355 | params->channel_type = wdev->preset_chantype; |
| 2356 | ret = true; |
| 2357 | break; |
| 2358 | } |
| 2359 | |
| 2360 | mutex_unlock(&rdev->devlist_mtx); |
| 2361 | |
| 2362 | return ret; |
| 2363 | } |
| 2364 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2365 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2366 | { |
| 2367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2368 | struct net_device *dev = info->user_ptr[1]; |
| 2369 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2370 | struct cfg80211_ap_settings params; |
| 2371 | int err; |
| 2372 | |
| 2373 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2374 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2375 | return -EOPNOTSUPP; |
| 2376 | |
| 2377 | if (!rdev->ops->start_ap) |
| 2378 | return -EOPNOTSUPP; |
| 2379 | |
| 2380 | if (wdev->beacon_interval) |
| 2381 | return -EALREADY; |
| 2382 | |
| 2383 | memset(¶ms, 0, sizeof(params)); |
| 2384 | |
| 2385 | /* these are required for START_AP */ |
| 2386 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2387 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2388 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2389 | return -EINVAL; |
| 2390 | |
| 2391 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2392 | if (err) |
| 2393 | return err; |
| 2394 | |
| 2395 | params.beacon_interval = |
| 2396 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2397 | params.dtim_period = |
| 2398 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2399 | |
| 2400 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2401 | if (err) |
| 2402 | return err; |
| 2403 | |
| 2404 | /* |
| 2405 | * In theory, some of these attributes should be required here |
| 2406 | * but since they were not used when the command was originally |
| 2407 | * added, keep them optional for old user space programs to let |
| 2408 | * them continue to work with drivers that do not need the |
| 2409 | * additional information -- drivers must check! |
| 2410 | */ |
| 2411 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2412 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2413 | params.ssid_len = |
| 2414 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2415 | if (params.ssid_len == 0 || |
| 2416 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2417 | return -EINVAL; |
| 2418 | } |
| 2419 | |
| 2420 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2421 | params.hidden_ssid = nla_get_u32( |
| 2422 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2423 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2424 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2425 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2426 | return -EINVAL; |
| 2427 | } |
| 2428 | |
| 2429 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2430 | |
| 2431 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2432 | params.auth_type = nla_get_u32( |
| 2433 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2434 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2435 | return -EINVAL; |
| 2436 | } else |
| 2437 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2438 | |
| 2439 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2440 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2441 | if (err) |
| 2442 | return err; |
| 2443 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2444 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2445 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2446 | return -EOPNOTSUPP; |
| 2447 | params.inactivity_timeout = nla_get_u16( |
| 2448 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2449 | } |
| 2450 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2451 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2452 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 2453 | |
| 2454 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 2455 | !nl80211_valid_channel_type(info, &channel_type)) |
| 2456 | return -EINVAL; |
| 2457 | |
| 2458 | params.channel = rdev_freq_to_chan(rdev, |
| 2459 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 2460 | channel_type); |
| 2461 | if (!params.channel) |
| 2462 | return -EINVAL; |
| 2463 | params.channel_type = channel_type; |
| 2464 | } else if (wdev->preset_chan) { |
| 2465 | params.channel = wdev->preset_chan; |
| 2466 | params.channel_type = wdev->preset_chantype; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame^] | 2467 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2468 | return -EINVAL; |
| 2469 | |
| 2470 | if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel, |
| 2471 | params.channel_type)) |
| 2472 | return -EINVAL; |
| 2473 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2474 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame^] | 2475 | if (!err) { |
| 2476 | wdev->preset_chan = params.channel; |
| 2477 | wdev->preset_chantype = params.channel_type; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2478 | wdev->beacon_interval = params.beacon_interval; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame^] | 2479 | } |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2480 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2481 | } |
| 2482 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2483 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2484 | { |
| 2485 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2486 | struct net_device *dev = info->user_ptr[1]; |
| 2487 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2488 | struct cfg80211_beacon_data params; |
| 2489 | int err; |
| 2490 | |
| 2491 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2492 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2493 | return -EOPNOTSUPP; |
| 2494 | |
| 2495 | if (!rdev->ops->change_beacon) |
| 2496 | return -EOPNOTSUPP; |
| 2497 | |
| 2498 | if (!wdev->beacon_interval) |
| 2499 | return -EINVAL; |
| 2500 | |
| 2501 | err = nl80211_parse_beacon(info, ¶ms); |
| 2502 | if (err) |
| 2503 | return err; |
| 2504 | |
| 2505 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); |
| 2506 | } |
| 2507 | |
| 2508 | 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] | 2509 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2511 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2512 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2513 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2514 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2515 | if (!rdev->ops->stop_ap) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2516 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2517 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2518 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2519 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2520 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2521 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2522 | if (!wdev->beacon_interval) |
| 2523 | return -ENOENT; |
| 2524 | |
| 2525 | err = rdev->ops->stop_ap(&rdev->wiphy, dev); |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2526 | if (!err) |
| 2527 | wdev->beacon_interval = 0; |
| 2528 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2529 | } |
| 2530 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2531 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2532 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2533 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2534 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2535 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2536 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2537 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2538 | }; |
| 2539 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2540 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2541 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2542 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2543 | { |
| 2544 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2545 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2546 | int flag; |
| 2547 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2548 | /* |
| 2549 | * Try parsing the new attribute first so userspace |
| 2550 | * can specify both for older kernels. |
| 2551 | */ |
| 2552 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2553 | if (nla) { |
| 2554 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2555 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2556 | sta_flags = nla_data(nla); |
| 2557 | params->sta_flags_mask = sta_flags->mask; |
| 2558 | params->sta_flags_set = sta_flags->set; |
| 2559 | if ((params->sta_flags_mask | |
| 2560 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2561 | return -EINVAL; |
| 2562 | return 0; |
| 2563 | } |
| 2564 | |
| 2565 | /* if present, parse the old attribute */ |
| 2566 | |
| 2567 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2568 | if (!nla) |
| 2569 | return 0; |
| 2570 | |
| 2571 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2572 | nla, sta_flags_policy)) |
| 2573 | return -EINVAL; |
| 2574 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2575 | /* |
| 2576 | * Only allow certain flags for interface types so that |
| 2577 | * other attributes are silently ignored. Remember that |
| 2578 | * this is backward compatibility code with old userspace |
| 2579 | * and shouldn't be hit in other cases anyway. |
| 2580 | */ |
| 2581 | switch (iftype) { |
| 2582 | case NL80211_IFTYPE_AP: |
| 2583 | case NL80211_IFTYPE_AP_VLAN: |
| 2584 | case NL80211_IFTYPE_P2P_GO: |
| 2585 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2586 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2587 | BIT(NL80211_STA_FLAG_WME) | |
| 2588 | BIT(NL80211_STA_FLAG_MFP); |
| 2589 | break; |
| 2590 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2591 | case NL80211_IFTYPE_STATION: |
| 2592 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2593 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2594 | break; |
| 2595 | case NL80211_IFTYPE_MESH_POINT: |
| 2596 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2597 | BIT(NL80211_STA_FLAG_MFP) | |
| 2598 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2599 | default: |
| 2600 | return -EINVAL; |
| 2601 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2602 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2603 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2604 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2605 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2606 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2607 | /* no longer support new API additions in old API */ |
| 2608 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2609 | return -EINVAL; |
| 2610 | } |
| 2611 | } |
| 2612 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2613 | return 0; |
| 2614 | } |
| 2615 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2616 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2617 | int attr) |
| 2618 | { |
| 2619 | struct nlattr *rate; |
| 2620 | u16 bitrate; |
| 2621 | |
| 2622 | rate = nla_nest_start(msg, attr); |
| 2623 | if (!rate) |
| 2624 | goto nla_put_failure; |
| 2625 | |
| 2626 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2627 | bitrate = cfg80211_calculate_bitrate(info); |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2628 | if ((bitrate > 0 && |
| 2629 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) || |
| 2630 | ((info->flags & RATE_INFO_FLAGS_MCS) && |
| 2631 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || |
| 2632 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && |
| 2633 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || |
| 2634 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && |
| 2635 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) |
| 2636 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2637 | |
| 2638 | nla_nest_end(msg, rate); |
| 2639 | return true; |
| 2640 | |
| 2641 | nla_put_failure: |
| 2642 | return false; |
| 2643 | } |
| 2644 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2645 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2646 | int flags, |
| 2647 | struct cfg80211_registered_device *rdev, |
| 2648 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2649 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2650 | { |
| 2651 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2652 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2653 | |
| 2654 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2655 | if (!hdr) |
| 2656 | return -1; |
| 2657 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2658 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2659 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2660 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2661 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2662 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2663 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2664 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2665 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2666 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2667 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2668 | sinfo->connected_time)) |
| 2669 | goto nla_put_failure; |
| 2670 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2671 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2672 | sinfo->inactive_time)) |
| 2673 | goto nla_put_failure; |
| 2674 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2675 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2676 | sinfo->rx_bytes)) |
| 2677 | goto nla_put_failure; |
| 2678 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2679 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2680 | sinfo->tx_bytes)) |
| 2681 | goto nla_put_failure; |
| 2682 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2683 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2684 | goto nla_put_failure; |
| 2685 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2686 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2687 | goto nla_put_failure; |
| 2688 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2689 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2690 | sinfo->plink_state)) |
| 2691 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2692 | switch (rdev->wiphy.signal_type) { |
| 2693 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2694 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2695 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2696 | sinfo->signal)) |
| 2697 | goto nla_put_failure; |
| 2698 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2699 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2700 | sinfo->signal_avg)) |
| 2701 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2702 | break; |
| 2703 | default: |
| 2704 | break; |
| 2705 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2706 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2707 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2708 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2709 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2710 | } |
| 2711 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2712 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2713 | NL80211_STA_INFO_RX_BITRATE)) |
| 2714 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2715 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2716 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2717 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2718 | sinfo->rx_packets)) |
| 2719 | goto nla_put_failure; |
| 2720 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2721 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2722 | sinfo->tx_packets)) |
| 2723 | goto nla_put_failure; |
| 2724 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2725 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2726 | sinfo->tx_retries)) |
| 2727 | goto nla_put_failure; |
| 2728 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 2729 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2730 | sinfo->tx_failed)) |
| 2731 | goto nla_put_failure; |
| 2732 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 2733 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2734 | sinfo->beacon_loss_count)) |
| 2735 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2736 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2737 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2738 | if (!bss_param) |
| 2739 | goto nla_put_failure; |
| 2740 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2741 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 2742 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 2743 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 2744 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 2745 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 2746 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 2747 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2748 | sinfo->bss_param.dtim_period) || |
| 2749 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2750 | sinfo->bss_param.beacon_interval)) |
| 2751 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2752 | |
| 2753 | nla_nest_end(msg, bss_param); |
| 2754 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2755 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 2756 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2757 | sizeof(struct nl80211_sta_flag_update), |
| 2758 | &sinfo->sta_flags)) |
| 2759 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 2760 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 2761 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 2762 | sinfo->t_offset)) |
| 2763 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2764 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2765 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2766 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 2767 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2768 | sinfo->assoc_req_ies)) |
| 2769 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2770 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2771 | return genlmsg_end(msg, hdr); |
| 2772 | |
| 2773 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2774 | genlmsg_cancel(msg, hdr); |
| 2775 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2776 | } |
| 2777 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2778 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2779 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2780 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2781 | struct station_info sinfo; |
| 2782 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2783 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2784 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2785 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2786 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2787 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2788 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2789 | if (err) |
| 2790 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2791 | |
| 2792 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2793 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2794 | goto out_err; |
| 2795 | } |
| 2796 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2797 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2798 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2799 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2800 | mac_addr, &sinfo); |
| 2801 | if (err == -ENOENT) |
| 2802 | break; |
| 2803 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2804 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2805 | |
| 2806 | if (nl80211_send_station(skb, |
| 2807 | NETLINK_CB(cb->skb).pid, |
| 2808 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2809 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2810 | &sinfo) < 0) |
| 2811 | goto out; |
| 2812 | |
| 2813 | sta_idx++; |
| 2814 | } |
| 2815 | |
| 2816 | |
| 2817 | out: |
| 2818 | cb->args[1] = sta_idx; |
| 2819 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2820 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2821 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2822 | |
| 2823 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2824 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2825 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2826 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2827 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2829 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2830 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2831 | struct sk_buff *msg; |
| 2832 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2833 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2834 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2835 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2836 | |
| 2837 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2838 | return -EINVAL; |
| 2839 | |
| 2840 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2841 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2842 | if (!rdev->ops->get_station) |
| 2843 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2844 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2845 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2846 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2847 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2848 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2849 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2850 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2851 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2852 | |
| 2853 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2854 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2855 | nlmsg_free(msg); |
| 2856 | return -ENOBUFS; |
| 2857 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2859 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2863 | * 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] | 2864 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2865 | static struct net_device *get_vlan(struct genl_info *info, |
| 2866 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2867 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2868 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2869 | struct net_device *v; |
| 2870 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2871 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2872 | if (!vlanattr) |
| 2873 | return NULL; |
| 2874 | |
| 2875 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 2876 | if (!v) |
| 2877 | return ERR_PTR(-ENODEV); |
| 2878 | |
| 2879 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 2880 | ret = -EINVAL; |
| 2881 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2882 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2883 | |
| 2884 | if (!netif_running(v)) { |
| 2885 | ret = -ENETDOWN; |
| 2886 | goto error; |
| 2887 | } |
| 2888 | |
| 2889 | return v; |
| 2890 | error: |
| 2891 | dev_put(v); |
| 2892 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2896 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2898 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2899 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2900 | struct station_parameters params; |
| 2901 | u8 *mac_addr = NULL; |
| 2902 | |
| 2903 | memset(¶ms, 0, sizeof(params)); |
| 2904 | |
| 2905 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2906 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2907 | |
| 2908 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2909 | return -EINVAL; |
| 2910 | |
| 2911 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2912 | return -EINVAL; |
| 2913 | |
| 2914 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2915 | |
| 2916 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2917 | params.supported_rates = |
| 2918 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2919 | params.supported_rates_len = |
| 2920 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2921 | } |
| 2922 | |
| 2923 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2924 | params.listen_interval = |
| 2925 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2926 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2927 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2928 | params.ht_capa = |
| 2929 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2930 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2931 | if (!rdev->ops->change_station) |
| 2932 | return -EOPNOTSUPP; |
| 2933 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2934 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2935 | return -EINVAL; |
| 2936 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2937 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2938 | params.plink_action = |
| 2939 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2940 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2941 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2942 | params.plink_state = |
| 2943 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2944 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2945 | switch (dev->ieee80211_ptr->iftype) { |
| 2946 | case NL80211_IFTYPE_AP: |
| 2947 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2948 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2949 | /* disallow mesh-specific things */ |
| 2950 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2951 | return -EINVAL; |
| 2952 | |
| 2953 | /* TDLS can't be set, ... */ |
| 2954 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 2955 | return -EINVAL; |
| 2956 | /* |
| 2957 | * ... but don't bother the driver with it. This works around |
| 2958 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 2959 | * TLDS_PEER flag in the mask even for AP mode. |
| 2960 | */ |
| 2961 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2962 | |
| 2963 | /* accept only the listed bits */ |
| 2964 | if (params.sta_flags_mask & |
| 2965 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2966 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2967 | BIT(NL80211_STA_FLAG_WME) | |
| 2968 | BIT(NL80211_STA_FLAG_MFP))) |
| 2969 | return -EINVAL; |
| 2970 | |
| 2971 | /* must be last in here for error handling */ |
| 2972 | params.vlan = get_vlan(info, rdev); |
| 2973 | if (IS_ERR(params.vlan)) |
| 2974 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2975 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2976 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2977 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2978 | /* |
| 2979 | * Don't allow userspace to change the TDLS_PEER flag, |
| 2980 | * but silently ignore attempts to change it since we |
| 2981 | * don't have state here to verify that it doesn't try |
| 2982 | * to change the flag. |
| 2983 | */ |
| 2984 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 2985 | /* fall through */ |
| 2986 | case NL80211_IFTYPE_ADHOC: |
| 2987 | /* disallow things sta doesn't support */ |
| 2988 | if (params.plink_action) |
| 2989 | return -EINVAL; |
| 2990 | if (params.ht_capa) |
| 2991 | return -EINVAL; |
| 2992 | if (params.listen_interval >= 0) |
| 2993 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2994 | /* reject any changes other than AUTHORIZED */ |
| 2995 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2996 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2997 | break; |
| 2998 | case NL80211_IFTYPE_MESH_POINT: |
| 2999 | /* disallow things mesh doesn't support */ |
| 3000 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3001 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3002 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3003 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3004 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3005 | return -EINVAL; |
| 3006 | /* |
| 3007 | * No special handling for TDLS here -- the userspace |
| 3008 | * mesh code doesn't have this bug. |
| 3009 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3010 | if (params.sta_flags_mask & |
| 3011 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 3012 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3013 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3014 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 3015 | break; |
| 3016 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3017 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 3018 | } |
| 3019 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3020 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3021 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3022 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3023 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3024 | if (params.vlan) |
| 3025 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3026 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3027 | return err; |
| 3028 | } |
| 3029 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3030 | static struct nla_policy |
| 3031 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 3032 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 3033 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 3034 | }; |
| 3035 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3036 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 3037 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3039 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3040 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3041 | struct station_parameters params; |
| 3042 | u8 *mac_addr = NULL; |
| 3043 | |
| 3044 | memset(¶ms, 0, sizeof(params)); |
| 3045 | |
| 3046 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3047 | return -EINVAL; |
| 3048 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3049 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 3050 | return -EINVAL; |
| 3051 | |
| 3052 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 3053 | return -EINVAL; |
| 3054 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3055 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 3056 | return -EINVAL; |
| 3057 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3058 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3059 | params.supported_rates = |
| 3060 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3061 | params.supported_rates_len = |
| 3062 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 3063 | params.listen_interval = |
| 3064 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3065 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 3066 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 3067 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 3068 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 3069 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 3070 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 3071 | params.ht_capa = |
| 3072 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3073 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 3074 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 3075 | params.plink_action = |
| 3076 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 3077 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3078 | if (!rdev->ops->add_station) |
| 3079 | return -EOPNOTSUPP; |
| 3080 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3081 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3082 | return -EINVAL; |
| 3083 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3084 | switch (dev->ieee80211_ptr->iftype) { |
| 3085 | case NL80211_IFTYPE_AP: |
| 3086 | case NL80211_IFTYPE_AP_VLAN: |
| 3087 | case NL80211_IFTYPE_P2P_GO: |
| 3088 | /* parse WME attributes if sta is WME capable */ |
| 3089 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 3090 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 3091 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 3092 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 3093 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3094 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3095 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 3096 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 3097 | nl80211_sta_wme_policy); |
| 3098 | if (err) |
| 3099 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3100 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3101 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 3102 | params.uapsd_queues = |
| 3103 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 3104 | if (params.uapsd_queues & |
| 3105 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 3106 | return -EINVAL; |
| 3107 | |
| 3108 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 3109 | params.max_sp = |
| 3110 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 3111 | |
| 3112 | if (params.max_sp & |
| 3113 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 3114 | return -EINVAL; |
| 3115 | |
| 3116 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 3117 | } |
| 3118 | /* TDLS peers cannot be added */ |
| 3119 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3120 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3121 | /* but don't bother the driver with it */ |
| 3122 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3123 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3124 | /* must be last in here for error handling */ |
| 3125 | params.vlan = get_vlan(info, rdev); |
| 3126 | if (IS_ERR(params.vlan)) |
| 3127 | return PTR_ERR(params.vlan); |
| 3128 | break; |
| 3129 | case NL80211_IFTYPE_MESH_POINT: |
| 3130 | /* TDLS peers cannot be added */ |
| 3131 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3132 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3133 | break; |
| 3134 | case NL80211_IFTYPE_STATION: |
| 3135 | /* Only TDLS peers can be added */ |
| 3136 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3137 | return -EINVAL; |
| 3138 | /* Can only add if TDLS ... */ |
| 3139 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3140 | return -EOPNOTSUPP; |
| 3141 | /* ... with external setup is supported */ |
| 3142 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3143 | return -EOPNOTSUPP; |
| 3144 | break; |
| 3145 | default: |
| 3146 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3147 | } |
| 3148 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3149 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3150 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3151 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3152 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3153 | if (params.vlan) |
| 3154 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3155 | return err; |
| 3156 | } |
| 3157 | |
| 3158 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3159 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3161 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3162 | u8 *mac_addr = NULL; |
| 3163 | |
| 3164 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3165 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3166 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3167 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3168 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3169 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3170 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3171 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3172 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3173 | if (!rdev->ops->del_station) |
| 3174 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3175 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3176 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3177 | } |
| 3178 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3179 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 3180 | int flags, struct net_device *dev, |
| 3181 | u8 *dst, u8 *next_hop, |
| 3182 | struct mpath_info *pinfo) |
| 3183 | { |
| 3184 | void *hdr; |
| 3185 | struct nlattr *pinfoattr; |
| 3186 | |
| 3187 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 3188 | if (!hdr) |
| 3189 | return -1; |
| 3190 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3191 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3192 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3193 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3194 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3195 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3196 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3197 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3198 | if (!pinfoattr) |
| 3199 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3200 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3201 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3202 | pinfo->frame_qlen)) |
| 3203 | goto nla_put_failure; |
| 3204 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3205 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3206 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3207 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3208 | pinfo->metric)) || |
| 3209 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3210 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3211 | pinfo->exptime)) || |
| 3212 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3213 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3214 | pinfo->flags)) || |
| 3215 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3216 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3217 | pinfo->discovery_timeout)) || |
| 3218 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3219 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3220 | pinfo->discovery_retries))) |
| 3221 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3222 | |
| 3223 | nla_nest_end(msg, pinfoattr); |
| 3224 | |
| 3225 | return genlmsg_end(msg, hdr); |
| 3226 | |
| 3227 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3228 | genlmsg_cancel(msg, hdr); |
| 3229 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3233 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3234 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3235 | struct mpath_info pinfo; |
| 3236 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3237 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3238 | u8 dst[ETH_ALEN]; |
| 3239 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3240 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3241 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3242 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3243 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3244 | if (err) |
| 3245 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3246 | |
| 3247 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3248 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3249 | goto out_err; |
| 3250 | } |
| 3251 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3252 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3253 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3254 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3255 | } |
| 3256 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3257 | while (1) { |
| 3258 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 3259 | dst, next_hop, &pinfo); |
| 3260 | if (err == -ENOENT) |
| 3261 | break; |
| 3262 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3263 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3264 | |
| 3265 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 3266 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3267 | netdev, dst, next_hop, |
| 3268 | &pinfo) < 0) |
| 3269 | goto out; |
| 3270 | |
| 3271 | path_idx++; |
| 3272 | } |
| 3273 | |
| 3274 | |
| 3275 | out: |
| 3276 | cb->args[1] = path_idx; |
| 3277 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3278 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3279 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3280 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3284 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3286 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3287 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3288 | struct mpath_info pinfo; |
| 3289 | struct sk_buff *msg; |
| 3290 | u8 *dst = NULL; |
| 3291 | u8 next_hop[ETH_ALEN]; |
| 3292 | |
| 3293 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3294 | |
| 3295 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3296 | return -EINVAL; |
| 3297 | |
| 3298 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3299 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3300 | if (!rdev->ops->get_mpath) |
| 3301 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3303 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3304 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3305 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3306 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3307 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3308 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3309 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3310 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3311 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3312 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3313 | |
| 3314 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3315 | dev, dst, next_hop, &pinfo) < 0) { |
| 3316 | nlmsg_free(msg); |
| 3317 | return -ENOBUFS; |
| 3318 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3319 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3320 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3324 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3325 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3326 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3327 | u8 *dst = NULL; |
| 3328 | u8 *next_hop = NULL; |
| 3329 | |
| 3330 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3331 | return -EINVAL; |
| 3332 | |
| 3333 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3334 | return -EINVAL; |
| 3335 | |
| 3336 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3337 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3339 | if (!rdev->ops->change_mpath) |
| 3340 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3341 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3342 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3343 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3344 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3345 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3346 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3347 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3348 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3349 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3351 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3352 | u8 *dst = NULL; |
| 3353 | u8 *next_hop = NULL; |
| 3354 | |
| 3355 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3356 | return -EINVAL; |
| 3357 | |
| 3358 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3359 | return -EINVAL; |
| 3360 | |
| 3361 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3362 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3363 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3364 | if (!rdev->ops->add_mpath) |
| 3365 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3366 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3367 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3368 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3369 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3370 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3374 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3375 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3376 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3377 | u8 *dst = NULL; |
| 3378 | |
| 3379 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3380 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3381 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3382 | if (!rdev->ops->del_mpath) |
| 3383 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3384 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3385 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3386 | } |
| 3387 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3388 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3389 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3391 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3392 | struct bss_parameters params; |
| 3393 | |
| 3394 | memset(¶ms, 0, sizeof(params)); |
| 3395 | /* default to not changing parameters */ |
| 3396 | params.use_cts_prot = -1; |
| 3397 | params.use_short_preamble = -1; |
| 3398 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3399 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3400 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3401 | |
| 3402 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3403 | params.use_cts_prot = |
| 3404 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3405 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3406 | params.use_short_preamble = |
| 3407 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3408 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3409 | params.use_short_slot_time = |
| 3410 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3411 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3412 | params.basic_rates = |
| 3413 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3414 | params.basic_rates_len = |
| 3415 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3416 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3417 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3418 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3419 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3420 | params.ht_opmode = |
| 3421 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3422 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3423 | if (!rdev->ops->change_bss) |
| 3424 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3425 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3426 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3427 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3428 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3429 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3430 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3431 | } |
| 3432 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3433 | 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] | 3434 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3435 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3436 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3437 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3438 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3439 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3440 | }; |
| 3441 | |
| 3442 | static int parse_reg_rule(struct nlattr *tb[], |
| 3443 | struct ieee80211_reg_rule *reg_rule) |
| 3444 | { |
| 3445 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3446 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3447 | |
| 3448 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3449 | return -EINVAL; |
| 3450 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3451 | return -EINVAL; |
| 3452 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3453 | return -EINVAL; |
| 3454 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3455 | return -EINVAL; |
| 3456 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3457 | return -EINVAL; |
| 3458 | |
| 3459 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3460 | |
| 3461 | freq_range->start_freq_khz = |
| 3462 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3463 | freq_range->end_freq_khz = |
| 3464 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3465 | freq_range->max_bandwidth_khz = |
| 3466 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3467 | |
| 3468 | power_rule->max_eirp = |
| 3469 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3470 | |
| 3471 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3472 | power_rule->max_antenna_gain = |
| 3473 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3474 | |
| 3475 | return 0; |
| 3476 | } |
| 3477 | |
| 3478 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3479 | { |
| 3480 | int r; |
| 3481 | char *data = NULL; |
| 3482 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3483 | /* |
| 3484 | * You should only get this when cfg80211 hasn't yet initialized |
| 3485 | * completely when built-in to the kernel right between the time |
| 3486 | * window between nl80211_init() and regulatory_init(), if that is |
| 3487 | * even possible. |
| 3488 | */ |
| 3489 | mutex_lock(&cfg80211_mutex); |
| 3490 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3491 | mutex_unlock(&cfg80211_mutex); |
| 3492 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3493 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3494 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3495 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3496 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3497 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3498 | |
| 3499 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3500 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3501 | r = regulatory_hint_user(data); |
| 3502 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3503 | return r; |
| 3504 | } |
| 3505 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3506 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3507 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3508 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3509 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3510 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3511 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3512 | struct mesh_config cur_params; |
| 3513 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3514 | void *hdr; |
| 3515 | struct nlattr *pinfoattr; |
| 3516 | struct sk_buff *msg; |
| 3517 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3518 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3519 | return -EOPNOTSUPP; |
| 3520 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3521 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3522 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3523 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3524 | wdev_lock(wdev); |
| 3525 | /* If not connected, get default parameters */ |
| 3526 | if (!wdev->mesh_id_len) |
| 3527 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3528 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3529 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3530 | &cur_params); |
| 3531 | wdev_unlock(wdev); |
| 3532 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3533 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3534 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3535 | |
| 3536 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3537 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3538 | if (!msg) |
| 3539 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3540 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3541 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3542 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3543 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3544 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3545 | if (!pinfoattr) |
| 3546 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3547 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3548 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3549 | cur_params.dot11MeshRetryTimeout) || |
| 3550 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3551 | cur_params.dot11MeshConfirmTimeout) || |
| 3552 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3553 | cur_params.dot11MeshHoldingTimeout) || |
| 3554 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3555 | cur_params.dot11MeshMaxPeerLinks) || |
| 3556 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3557 | cur_params.dot11MeshMaxRetries) || |
| 3558 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3559 | cur_params.dot11MeshTTL) || |
| 3560 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3561 | cur_params.element_ttl) || |
| 3562 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3563 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3564 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3565 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3566 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3567 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3568 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3569 | cur_params.path_refresh_time) || |
| 3570 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3571 | cur_params.min_discovery_timeout) || |
| 3572 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3573 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3574 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3575 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3576 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3577 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3578 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3579 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3580 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3581 | cur_params.dot11MeshHWMPRootMode) || |
| 3582 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3583 | cur_params.dot11MeshHWMPRannInterval) || |
| 3584 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3585 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3586 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3587 | cur_params.dot11MeshForwarding) || |
| 3588 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3589 | cur_params.rssi_threshold) || |
| 3590 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3591 | cur_params.ht_opmode) || |
| 3592 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3593 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 3594 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3595 | cur_params.dot11MeshHWMProotInterval) || |
| 3596 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3597 | cur_params.dot11MeshHWMPconfirmationInterval)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3598 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3599 | nla_nest_end(msg, pinfoattr); |
| 3600 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3601 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3602 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3603 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3604 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3605 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3606 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3607 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3610 | 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] | 3611 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3612 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3613 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3614 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3615 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3616 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3617 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3618 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3619 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3620 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3621 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3622 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3623 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3624 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3625 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3626 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3627 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3628 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3629 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3630 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3631 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 3632 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3633 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 3634 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3635 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3636 | }; |
| 3637 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3638 | static const struct nla_policy |
| 3639 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3640 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3641 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3642 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3643 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3644 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3645 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3646 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3647 | }; |
| 3648 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3649 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3650 | struct mesh_config *cfg, |
| 3651 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3652 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3653 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3654 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3655 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3656 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3657 | do {\ |
| 3658 | if (table[attr_num]) {\ |
| 3659 | cfg->param = nla_fn(table[attr_num]); \ |
| 3660 | mask |= (1 << (attr_num - 1)); \ |
| 3661 | } \ |
| 3662 | } while (0);\ |
| 3663 | |
| 3664 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3665 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3666 | return -EINVAL; |
| 3667 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3668 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3669 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3670 | return -EINVAL; |
| 3671 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3672 | /* This makes sure that there aren't more than 32 mesh config |
| 3673 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3674 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3675 | |
| 3676 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3677 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3678 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3679 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3680 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3681 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3682 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3683 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3684 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3685 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3686 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3687 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3688 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3689 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3690 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 3691 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3693 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3694 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3695 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 3696 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3697 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3698 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3699 | nla_get_u8); |
| 3700 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, |
| 3701 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3702 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3703 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3704 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3705 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3706 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3707 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3708 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3710 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3711 | nla_get_u16); |
| 3712 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, |
| 3713 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3714 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3715 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3716 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3717 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3718 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3719 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3720 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3721 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3722 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
| 3723 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3724 | nla_get_u16); |
| 3725 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 3726 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 3727 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 3728 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3729 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3730 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3731 | dot11MeshGateAnnouncementProtocol, mask, |
| 3732 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3733 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3734 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3735 | mask, NL80211_MESHCONF_FORWARDING, |
| 3736 | nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3737 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3738 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 3739 | nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3740 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 3741 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 3742 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 3743 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
| 3744 | mask, |
| 3745 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 3746 | nla_get_u32); |
| 3747 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, |
| 3748 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 3749 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 3750 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3751 | dot11MeshHWMPconfirmationInterval, mask, |
| 3752 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 3753 | nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3754 | if (mask_out) |
| 3755 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3756 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3757 | return 0; |
| 3758 | |
| 3759 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3760 | } |
| 3761 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3762 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3763 | struct mesh_setup *setup) |
| 3764 | { |
| 3765 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3766 | |
| 3767 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3768 | return -EINVAL; |
| 3769 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3770 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3771 | nl80211_mesh_setup_params_policy)) |
| 3772 | return -EINVAL; |
| 3773 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3774 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 3775 | setup->sync_method = |
| 3776 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 3777 | IEEE80211_SYNC_METHOD_VENDOR : |
| 3778 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 3779 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3780 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3781 | setup->path_sel_proto = |
| 3782 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3783 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3784 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3785 | |
| 3786 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3787 | setup->path_metric = |
| 3788 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3789 | IEEE80211_PATH_METRIC_VENDOR : |
| 3790 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3791 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3792 | |
| 3793 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3794 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3795 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3796 | if (!is_valid_ie_attr(ieattr)) |
| 3797 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3798 | setup->ie = nla_data(ieattr); |
| 3799 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3800 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3801 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3802 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3803 | |
| 3804 | return 0; |
| 3805 | } |
| 3806 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3807 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3808 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3809 | { |
| 3810 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3811 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3812 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3813 | struct mesh_config cfg; |
| 3814 | u32 mask; |
| 3815 | int err; |
| 3816 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3817 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3818 | return -EOPNOTSUPP; |
| 3819 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3820 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3821 | return -EOPNOTSUPP; |
| 3822 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3823 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3824 | if (err) |
| 3825 | return err; |
| 3826 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3827 | wdev_lock(wdev); |
| 3828 | if (!wdev->mesh_id_len) |
| 3829 | err = -ENOLINK; |
| 3830 | |
| 3831 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3832 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3833 | mask, &cfg); |
| 3834 | |
| 3835 | wdev_unlock(wdev); |
| 3836 | |
| 3837 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3838 | } |
| 3839 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3840 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3841 | { |
| 3842 | struct sk_buff *msg; |
| 3843 | void *hdr = NULL; |
| 3844 | struct nlattr *nl_reg_rules; |
| 3845 | unsigned int i; |
| 3846 | int err = -EINVAL; |
| 3847 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3848 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3849 | |
| 3850 | if (!cfg80211_regdomain) |
| 3851 | goto out; |
| 3852 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3853 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3854 | if (!msg) { |
| 3855 | err = -ENOBUFS; |
| 3856 | goto out; |
| 3857 | } |
| 3858 | |
| 3859 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3860 | NL80211_CMD_GET_REG); |
| 3861 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3862 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3863 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3864 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 3865 | cfg80211_regdomain->alpha2) || |
| 3866 | (cfg80211_regdomain->dfs_region && |
| 3867 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 3868 | cfg80211_regdomain->dfs_region))) |
| 3869 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3870 | |
| 3871 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3872 | if (!nl_reg_rules) |
| 3873 | goto nla_put_failure; |
| 3874 | |
| 3875 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3876 | struct nlattr *nl_reg_rule; |
| 3877 | const struct ieee80211_reg_rule *reg_rule; |
| 3878 | const struct ieee80211_freq_range *freq_range; |
| 3879 | const struct ieee80211_power_rule *power_rule; |
| 3880 | |
| 3881 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3882 | freq_range = ®_rule->freq_range; |
| 3883 | power_rule = ®_rule->power_rule; |
| 3884 | |
| 3885 | nl_reg_rule = nla_nest_start(msg, i); |
| 3886 | if (!nl_reg_rule) |
| 3887 | goto nla_put_failure; |
| 3888 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3889 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3890 | reg_rule->flags) || |
| 3891 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3892 | freq_range->start_freq_khz) || |
| 3893 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3894 | freq_range->end_freq_khz) || |
| 3895 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3896 | freq_range->max_bandwidth_khz) || |
| 3897 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3898 | power_rule->max_antenna_gain) || |
| 3899 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3900 | power_rule->max_eirp)) |
| 3901 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3902 | |
| 3903 | nla_nest_end(msg, nl_reg_rule); |
| 3904 | } |
| 3905 | |
| 3906 | nla_nest_end(msg, nl_reg_rules); |
| 3907 | |
| 3908 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3909 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3910 | goto out; |
| 3911 | |
| 3912 | nla_put_failure: |
| 3913 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3914 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3915 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3916 | err = -EMSGSIZE; |
| 3917 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3918 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3919 | return err; |
| 3920 | } |
| 3921 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3922 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3923 | { |
| 3924 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3925 | struct nlattr *nl_reg_rule; |
| 3926 | char *alpha2 = NULL; |
| 3927 | int rem_reg_rules = 0, r = 0; |
| 3928 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3929 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3930 | struct ieee80211_regdomain *rd = NULL; |
| 3931 | |
| 3932 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3933 | return -EINVAL; |
| 3934 | |
| 3935 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3936 | return -EINVAL; |
| 3937 | |
| 3938 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3939 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3940 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 3941 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 3942 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3943 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3944 | rem_reg_rules) { |
| 3945 | num_rules++; |
| 3946 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3947 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3950 | mutex_lock(&cfg80211_mutex); |
| 3951 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3952 | if (!reg_is_valid_request(alpha2)) { |
| 3953 | r = -EINVAL; |
| 3954 | goto bad_reg; |
| 3955 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3956 | |
| 3957 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3958 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3959 | |
| 3960 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3961 | if (!rd) { |
| 3962 | r = -ENOMEM; |
| 3963 | goto bad_reg; |
| 3964 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3965 | |
| 3966 | rd->n_reg_rules = num_rules; |
| 3967 | rd->alpha2[0] = alpha2[0]; |
| 3968 | rd->alpha2[1] = alpha2[1]; |
| 3969 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3970 | /* |
| 3971 | * Disable DFS master mode if the DFS region was |
| 3972 | * not supported or known on this kernel. |
| 3973 | */ |
| 3974 | if (reg_supported_dfs_region(dfs_region)) |
| 3975 | rd->dfs_region = dfs_region; |
| 3976 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3977 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3978 | rem_reg_rules) { |
| 3979 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3980 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3981 | reg_rule_policy); |
| 3982 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3983 | if (r) |
| 3984 | goto bad_reg; |
| 3985 | |
| 3986 | rule_idx++; |
| 3987 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3988 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3989 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3990 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3991 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
| 3994 | BUG_ON(rule_idx != num_rules); |
| 3995 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3996 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3997 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3998 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3999 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4000 | return r; |
| 4001 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 4002 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 4003 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4004 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 4005 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4008 | static int validate_scan_freqs(struct nlattr *freqs) |
| 4009 | { |
| 4010 | struct nlattr *attr1, *attr2; |
| 4011 | int n_channels = 0, tmp1, tmp2; |
| 4012 | |
| 4013 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 4014 | n_channels++; |
| 4015 | /* |
| 4016 | * Some hardware has a limited channel list for |
| 4017 | * scanning, and it is pretty much nonsensical |
| 4018 | * to scan for a channel twice, so disallow that |
| 4019 | * and don't require drivers to check that the |
| 4020 | * channel list they get isn't longer than what |
| 4021 | * they can scan, as long as they can scan all |
| 4022 | * the channels they registered at once. |
| 4023 | */ |
| 4024 | nla_for_each_nested(attr2, freqs, tmp2) |
| 4025 | if (attr1 != attr2 && |
| 4026 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 4027 | return 0; |
| 4028 | } |
| 4029 | |
| 4030 | return n_channels; |
| 4031 | } |
| 4032 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4033 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 4034 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4036 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4037 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4038 | struct nlattr *attr; |
| 4039 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4040 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4041 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4042 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4043 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4044 | return -EINVAL; |
| 4045 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4046 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4047 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4048 | if (!rdev->ops->scan) |
| 4049 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4050 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4051 | if (rdev->scan_req) |
| 4052 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4053 | |
| 4054 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4055 | n_channels = validate_scan_freqs( |
| 4056 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4057 | if (!n_channels) |
| 4058 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4059 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4060 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 4061 | n_channels = 0; |
| 4062 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4063 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4064 | if (wiphy->bands[band]) |
| 4065 | n_channels += wiphy->bands[band]->n_channels; |
| 4066 | } |
| 4067 | |
| 4068 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4069 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 4070 | n_ssids++; |
| 4071 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4072 | if (n_ssids > wiphy->max_scan_ssids) |
| 4073 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4074 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4075 | if (info->attrs[NL80211_ATTR_IE]) |
| 4076 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4077 | else |
| 4078 | ie_len = 0; |
| 4079 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4080 | if (ie_len > wiphy->max_scan_ie_len) |
| 4081 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 4082 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4083 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4084 | + sizeof(*request->ssids) * n_ssids |
| 4085 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4086 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4087 | if (!request) |
| 4088 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4089 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4090 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 4091 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4092 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4093 | if (ie_len) { |
| 4094 | if (request->ssids) |
| 4095 | request->ie = (void *)(request->ssids + n_ssids); |
| 4096 | else |
| 4097 | request->ie = (void *)(request->channels + n_channels); |
| 4098 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4099 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4100 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4101 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4102 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4103 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4104 | struct ieee80211_channel *chan; |
| 4105 | |
| 4106 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4107 | |
| 4108 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4109 | err = -EINVAL; |
| 4110 | goto out_free; |
| 4111 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4112 | |
| 4113 | /* ignore disabled channels */ |
| 4114 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4115 | continue; |
| 4116 | |
| 4117 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4118 | i++; |
| 4119 | } |
| 4120 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4121 | enum ieee80211_band band; |
| 4122 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4123 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4124 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4125 | int j; |
| 4126 | if (!wiphy->bands[band]) |
| 4127 | continue; |
| 4128 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4129 | struct ieee80211_channel *chan; |
| 4130 | |
| 4131 | chan = &wiphy->bands[band]->channels[j]; |
| 4132 | |
| 4133 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4134 | continue; |
| 4135 | |
| 4136 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4137 | i++; |
| 4138 | } |
| 4139 | } |
| 4140 | } |
| 4141 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 4142 | if (!i) { |
| 4143 | err = -EINVAL; |
| 4144 | goto out_free; |
| 4145 | } |
| 4146 | |
| 4147 | request->n_channels = i; |
| 4148 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4149 | i = 0; |
| 4150 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4151 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4152 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4153 | err = -EINVAL; |
| 4154 | goto out_free; |
| 4155 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4156 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4157 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4158 | i++; |
| 4159 | } |
| 4160 | } |
| 4161 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4162 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4163 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4164 | memcpy((void *)request->ie, |
| 4165 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4166 | request->ie_len); |
| 4167 | } |
| 4168 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4169 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4170 | if (wiphy->bands[i]) |
| 4171 | request->rates[i] = |
| 4172 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4173 | |
| 4174 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4175 | nla_for_each_nested(attr, |
| 4176 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4177 | tmp) { |
| 4178 | enum ieee80211_band band = nla_type(attr); |
| 4179 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4180 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4181 | err = -EINVAL; |
| 4182 | goto out_free; |
| 4183 | } |
| 4184 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4185 | nla_data(attr), |
| 4186 | nla_len(attr), |
| 4187 | &request->rates[band]); |
| 4188 | if (err) |
| 4189 | goto out_free; |
| 4190 | } |
| 4191 | } |
| 4192 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4193 | request->no_cck = |
| 4194 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4195 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4196 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4197 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4198 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4199 | rdev->scan_req = request; |
| 4200 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4201 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4202 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4203 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4204 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4205 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4206 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4207 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4208 | kfree(request); |
| 4209 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4210 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4211 | return err; |
| 4212 | } |
| 4213 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4214 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4215 | struct genl_info *info) |
| 4216 | { |
| 4217 | struct cfg80211_sched_scan_request *request; |
| 4218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4219 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4220 | struct nlattr *attr; |
| 4221 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4222 | 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] | 4223 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4224 | enum ieee80211_band band; |
| 4225 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4226 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4227 | |
| 4228 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4229 | !rdev->ops->sched_scan_start) |
| 4230 | return -EOPNOTSUPP; |
| 4231 | |
| 4232 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4233 | return -EINVAL; |
| 4234 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4235 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4236 | return -EINVAL; |
| 4237 | |
| 4238 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4239 | if (interval == 0) |
| 4240 | return -EINVAL; |
| 4241 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4242 | wiphy = &rdev->wiphy; |
| 4243 | |
| 4244 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4245 | n_channels = validate_scan_freqs( |
| 4246 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4247 | if (!n_channels) |
| 4248 | return -EINVAL; |
| 4249 | } else { |
| 4250 | n_channels = 0; |
| 4251 | |
| 4252 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4253 | if (wiphy->bands[band]) |
| 4254 | n_channels += wiphy->bands[band]->n_channels; |
| 4255 | } |
| 4256 | |
| 4257 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4258 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4259 | tmp) |
| 4260 | n_ssids++; |
| 4261 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4262 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4263 | return -EINVAL; |
| 4264 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4265 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4266 | nla_for_each_nested(attr, |
| 4267 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4268 | tmp) |
| 4269 | n_match_sets++; |
| 4270 | |
| 4271 | if (n_match_sets > wiphy->max_match_sets) |
| 4272 | return -EINVAL; |
| 4273 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4274 | if (info->attrs[NL80211_ATTR_IE]) |
| 4275 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4276 | else |
| 4277 | ie_len = 0; |
| 4278 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4279 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4280 | return -EINVAL; |
| 4281 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4282 | mutex_lock(&rdev->sched_scan_mtx); |
| 4283 | |
| 4284 | if (rdev->sched_scan_req) { |
| 4285 | err = -EINPROGRESS; |
| 4286 | goto out; |
| 4287 | } |
| 4288 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4289 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4290 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4291 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4292 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4293 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4294 | if (!request) { |
| 4295 | err = -ENOMEM; |
| 4296 | goto out; |
| 4297 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4298 | |
| 4299 | if (n_ssids) |
| 4300 | request->ssids = (void *)&request->channels[n_channels]; |
| 4301 | request->n_ssids = n_ssids; |
| 4302 | if (ie_len) { |
| 4303 | if (request->ssids) |
| 4304 | request->ie = (void *)(request->ssids + n_ssids); |
| 4305 | else |
| 4306 | request->ie = (void *)(request->channels + n_channels); |
| 4307 | } |
| 4308 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4309 | if (n_match_sets) { |
| 4310 | if (request->ie) |
| 4311 | request->match_sets = (void *)(request->ie + ie_len); |
| 4312 | else if (request->ssids) |
| 4313 | request->match_sets = |
| 4314 | (void *)(request->ssids + n_ssids); |
| 4315 | else |
| 4316 | request->match_sets = |
| 4317 | (void *)(request->channels + n_channels); |
| 4318 | } |
| 4319 | request->n_match_sets = n_match_sets; |
| 4320 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4321 | i = 0; |
| 4322 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4323 | /* user specified, bail out if channel not found */ |
| 4324 | nla_for_each_nested(attr, |
| 4325 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4326 | tmp) { |
| 4327 | struct ieee80211_channel *chan; |
| 4328 | |
| 4329 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4330 | |
| 4331 | if (!chan) { |
| 4332 | err = -EINVAL; |
| 4333 | goto out_free; |
| 4334 | } |
| 4335 | |
| 4336 | /* ignore disabled channels */ |
| 4337 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4338 | continue; |
| 4339 | |
| 4340 | request->channels[i] = chan; |
| 4341 | i++; |
| 4342 | } |
| 4343 | } else { |
| 4344 | /* all channels */ |
| 4345 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4346 | int j; |
| 4347 | if (!wiphy->bands[band]) |
| 4348 | continue; |
| 4349 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4350 | struct ieee80211_channel *chan; |
| 4351 | |
| 4352 | chan = &wiphy->bands[band]->channels[j]; |
| 4353 | |
| 4354 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4355 | continue; |
| 4356 | |
| 4357 | request->channels[i] = chan; |
| 4358 | i++; |
| 4359 | } |
| 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | if (!i) { |
| 4364 | err = -EINVAL; |
| 4365 | goto out_free; |
| 4366 | } |
| 4367 | |
| 4368 | request->n_channels = i; |
| 4369 | |
| 4370 | i = 0; |
| 4371 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4372 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4373 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4374 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4375 | err = -EINVAL; |
| 4376 | goto out_free; |
| 4377 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4378 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4379 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4380 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4381 | i++; |
| 4382 | } |
| 4383 | } |
| 4384 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4385 | i = 0; |
| 4386 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4387 | nla_for_each_nested(attr, |
| 4388 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4389 | tmp) { |
| 4390 | struct nlattr *ssid; |
| 4391 | |
| 4392 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4393 | nla_data(attr), nla_len(attr), |
| 4394 | nl80211_match_policy); |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 4395 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4396 | if (ssid) { |
| 4397 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4398 | err = -EINVAL; |
| 4399 | goto out_free; |
| 4400 | } |
| 4401 | memcpy(request->match_sets[i].ssid.ssid, |
| 4402 | nla_data(ssid), nla_len(ssid)); |
| 4403 | request->match_sets[i].ssid.ssid_len = |
| 4404 | nla_len(ssid); |
| 4405 | } |
| 4406 | i++; |
| 4407 | } |
| 4408 | } |
| 4409 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4410 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4411 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4412 | memcpy((void *)request->ie, |
| 4413 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4414 | request->ie_len); |
| 4415 | } |
| 4416 | |
| 4417 | request->dev = dev; |
| 4418 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4419 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4420 | |
| 4421 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 4422 | if (!err) { |
| 4423 | rdev->sched_scan_req = request; |
| 4424 | nl80211_send_sched_scan(rdev, dev, |
| 4425 | NL80211_CMD_START_SCHED_SCAN); |
| 4426 | goto out; |
| 4427 | } |
| 4428 | |
| 4429 | out_free: |
| 4430 | kfree(request); |
| 4431 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4432 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4433 | return err; |
| 4434 | } |
| 4435 | |
| 4436 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4437 | struct genl_info *info) |
| 4438 | { |
| 4439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4440 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4441 | |
| 4442 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4443 | !rdev->ops->sched_scan_stop) |
| 4444 | return -EOPNOTSUPP; |
| 4445 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4446 | mutex_lock(&rdev->sched_scan_mtx); |
| 4447 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4448 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4449 | |
| 4450 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4451 | } |
| 4452 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4453 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4454 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4455 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4456 | struct wireless_dev *wdev, |
| 4457 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4458 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4459 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4460 | void *hdr; |
| 4461 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4462 | |
| 4463 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4464 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4465 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4466 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4467 | if (!hdr) |
| 4468 | return -1; |
| 4469 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4470 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4471 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4472 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4473 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4474 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4475 | |
| 4476 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4477 | if (!bss) |
| 4478 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4479 | if ((!is_zero_ether_addr(res->bssid) && |
| 4480 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4481 | (res->information_elements && res->len_information_elements && |
| 4482 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4483 | res->len_information_elements, |
| 4484 | res->information_elements)) || |
| 4485 | (res->beacon_ies && res->len_beacon_ies && |
| 4486 | res->beacon_ies != res->information_elements && |
| 4487 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4488 | res->len_beacon_ies, res->beacon_ies))) |
| 4489 | goto nla_put_failure; |
| 4490 | if (res->tsf && |
| 4491 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4492 | goto nla_put_failure; |
| 4493 | if (res->beacon_interval && |
| 4494 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4495 | goto nla_put_failure; |
| 4496 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4497 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4498 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4499 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4500 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4501 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4502 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4503 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4504 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4505 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4506 | break; |
| 4507 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4508 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4509 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4510 | break; |
| 4511 | default: |
| 4512 | break; |
| 4513 | } |
| 4514 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4515 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4516 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4517 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4518 | if (intbss == wdev->current_bss && |
| 4519 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4520 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4521 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4522 | break; |
| 4523 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4524 | if (intbss == wdev->current_bss && |
| 4525 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4526 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4527 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4528 | break; |
| 4529 | default: |
| 4530 | break; |
| 4531 | } |
| 4532 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4533 | nla_nest_end(msg, bss); |
| 4534 | |
| 4535 | return genlmsg_end(msg, hdr); |
| 4536 | |
| 4537 | nla_put_failure: |
| 4538 | genlmsg_cancel(msg, hdr); |
| 4539 | return -EMSGSIZE; |
| 4540 | } |
| 4541 | |
| 4542 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4543 | struct netlink_callback *cb) |
| 4544 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4545 | struct cfg80211_registered_device *rdev; |
| 4546 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4547 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4548 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4549 | int start = cb->args[1], idx = 0; |
| 4550 | int err; |
| 4551 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4552 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4553 | if (err) |
| 4554 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4555 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4556 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4557 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4558 | wdev_lock(wdev); |
| 4559 | spin_lock_bh(&rdev->bss_lock); |
| 4560 | cfg80211_bss_expire(rdev); |
| 4561 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4562 | cb->seq = rdev->bss_generation; |
| 4563 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4564 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4565 | if (++idx <= start) |
| 4566 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4567 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4568 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4569 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4570 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4571 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4572 | } |
| 4573 | } |
| 4574 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4575 | spin_unlock_bh(&rdev->bss_lock); |
| 4576 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4577 | |
| 4578 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4579 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4580 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4581 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4582 | } |
| 4583 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4584 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4585 | int flags, struct net_device *dev, |
| 4586 | struct survey_info *survey) |
| 4587 | { |
| 4588 | void *hdr; |
| 4589 | struct nlattr *infoattr; |
| 4590 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4591 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4592 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4593 | if (!hdr) |
| 4594 | return -ENOMEM; |
| 4595 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4596 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4597 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4598 | |
| 4599 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4600 | if (!infoattr) |
| 4601 | goto nla_put_failure; |
| 4602 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4603 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4604 | survey->channel->center_freq)) |
| 4605 | goto nla_put_failure; |
| 4606 | |
| 4607 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4608 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4609 | goto nla_put_failure; |
| 4610 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4611 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4612 | goto nla_put_failure; |
| 4613 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4614 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4615 | survey->channel_time)) |
| 4616 | goto nla_put_failure; |
| 4617 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4618 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4619 | survey->channel_time_busy)) |
| 4620 | goto nla_put_failure; |
| 4621 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4622 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4623 | survey->channel_time_ext_busy)) |
| 4624 | goto nla_put_failure; |
| 4625 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4626 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4627 | survey->channel_time_rx)) |
| 4628 | goto nla_put_failure; |
| 4629 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4630 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4631 | survey->channel_time_tx)) |
| 4632 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4633 | |
| 4634 | nla_nest_end(msg, infoattr); |
| 4635 | |
| 4636 | return genlmsg_end(msg, hdr); |
| 4637 | |
| 4638 | nla_put_failure: |
| 4639 | genlmsg_cancel(msg, hdr); |
| 4640 | return -EMSGSIZE; |
| 4641 | } |
| 4642 | |
| 4643 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4644 | struct netlink_callback *cb) |
| 4645 | { |
| 4646 | struct survey_info survey; |
| 4647 | struct cfg80211_registered_device *dev; |
| 4648 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4649 | int survey_idx = cb->args[1]; |
| 4650 | int res; |
| 4651 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4652 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4653 | if (res) |
| 4654 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4655 | |
| 4656 | if (!dev->ops->dump_survey) { |
| 4657 | res = -EOPNOTSUPP; |
| 4658 | goto out_err; |
| 4659 | } |
| 4660 | |
| 4661 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4662 | struct ieee80211_channel *chan; |
| 4663 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4664 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4665 | &survey); |
| 4666 | if (res == -ENOENT) |
| 4667 | break; |
| 4668 | if (res) |
| 4669 | goto out_err; |
| 4670 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4671 | /* Survey without a channel doesn't make sense */ |
| 4672 | if (!survey.channel) { |
| 4673 | res = -EINVAL; |
| 4674 | goto out; |
| 4675 | } |
| 4676 | |
| 4677 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4678 | survey.channel->center_freq); |
| 4679 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4680 | survey_idx++; |
| 4681 | continue; |
| 4682 | } |
| 4683 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4684 | if (nl80211_send_survey(skb, |
| 4685 | NETLINK_CB(cb->skb).pid, |
| 4686 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4687 | netdev, |
| 4688 | &survey) < 0) |
| 4689 | goto out; |
| 4690 | survey_idx++; |
| 4691 | } |
| 4692 | |
| 4693 | out: |
| 4694 | cb->args[1] = survey_idx; |
| 4695 | res = skb->len; |
| 4696 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4697 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4698 | return res; |
| 4699 | } |
| 4700 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4701 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4702 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4703 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4704 | } |
| 4705 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4706 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4707 | { |
| 4708 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4709 | NL80211_WPA_VERSION_2)); |
| 4710 | } |
| 4711 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4712 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4713 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4714 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4715 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4716 | struct ieee80211_channel *chan; |
| 4717 | const u8 *bssid, *ssid, *ie = NULL; |
| 4718 | int err, ssid_len, ie_len = 0; |
| 4719 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4720 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4721 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4722 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4723 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4724 | return -EINVAL; |
| 4725 | |
| 4726 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4727 | return -EINVAL; |
| 4728 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4729 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4730 | return -EINVAL; |
| 4731 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4732 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4733 | return -EINVAL; |
| 4734 | |
| 4735 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4736 | return -EINVAL; |
| 4737 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4738 | err = nl80211_parse_key(info, &key); |
| 4739 | if (err) |
| 4740 | return err; |
| 4741 | |
| 4742 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4743 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4744 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4745 | if (!key.p.key || !key.p.key_len) |
| 4746 | return -EINVAL; |
| 4747 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4748 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4749 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4750 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4751 | return -EINVAL; |
| 4752 | if (key.idx > 4) |
| 4753 | return -EINVAL; |
| 4754 | } else { |
| 4755 | key.p.key_len = 0; |
| 4756 | key.p.key = NULL; |
| 4757 | } |
| 4758 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4759 | if (key.idx >= 0) { |
| 4760 | int i; |
| 4761 | bool ok = false; |
| 4762 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4763 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4764 | ok = true; |
| 4765 | break; |
| 4766 | } |
| 4767 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4768 | if (!ok) |
| 4769 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4770 | } |
| 4771 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4772 | if (!rdev->ops->auth) |
| 4773 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4774 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4775 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4776 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4777 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4778 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4779 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4780 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4781 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4782 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4783 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4784 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4785 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4786 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4787 | |
| 4788 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4789 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4790 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4791 | } |
| 4792 | |
| 4793 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4794 | if (!nl80211_valid_auth_type(auth_type)) |
| 4795 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4796 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4797 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4798 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4799 | /* |
| 4800 | * Since we no longer track auth state, ignore |
| 4801 | * requests to only change local state. |
| 4802 | */ |
| 4803 | if (local_state_change) |
| 4804 | return 0; |
| 4805 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4806 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4807 | ssid, ssid_len, ie, ie_len, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4808 | key.p.key, key.p.key_len, key.idx); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4809 | } |
| 4810 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4811 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4812 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4813 | struct cfg80211_crypto_settings *settings, |
| 4814 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4815 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4816 | memset(settings, 0, sizeof(*settings)); |
| 4817 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4818 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4819 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4820 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4821 | u16 proto; |
| 4822 | proto = nla_get_u16( |
| 4823 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4824 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4825 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4826 | proto != ETH_P_PAE) |
| 4827 | return -EINVAL; |
| 4828 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4829 | settings->control_port_no_encrypt = true; |
| 4830 | } else |
| 4831 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4832 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4833 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4834 | void *data; |
| 4835 | int len, i; |
| 4836 | |
| 4837 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4838 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4839 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4840 | |
| 4841 | if (len % sizeof(u32)) |
| 4842 | return -EINVAL; |
| 4843 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4844 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4845 | return -EINVAL; |
| 4846 | |
| 4847 | memcpy(settings->ciphers_pairwise, data, len); |
| 4848 | |
| 4849 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4850 | if (!cfg80211_supported_cipher_suite( |
| 4851 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4852 | settings->ciphers_pairwise[i])) |
| 4853 | return -EINVAL; |
| 4854 | } |
| 4855 | |
| 4856 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4857 | settings->cipher_group = |
| 4858 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4859 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4860 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4861 | return -EINVAL; |
| 4862 | } |
| 4863 | |
| 4864 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4865 | settings->wpa_versions = |
| 4866 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4867 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4868 | return -EINVAL; |
| 4869 | } |
| 4870 | |
| 4871 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4872 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4873 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4874 | |
| 4875 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4876 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4877 | settings->n_akm_suites = len / sizeof(u32); |
| 4878 | |
| 4879 | if (len % sizeof(u32)) |
| 4880 | return -EINVAL; |
| 4881 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4882 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4883 | return -EINVAL; |
| 4884 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4885 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4886 | } |
| 4887 | |
| 4888 | return 0; |
| 4889 | } |
| 4890 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4891 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4892 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4894 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4895 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4896 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4897 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4898 | int err, ssid_len, ie_len = 0; |
| 4899 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4900 | u32 flags = 0; |
| 4901 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 4902 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4903 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4904 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4905 | return -EINVAL; |
| 4906 | |
| 4907 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4908 | !info->attrs[NL80211_ATTR_SSID] || |
| 4909 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4910 | return -EINVAL; |
| 4911 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4912 | if (!rdev->ops->assoc) |
| 4913 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4914 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4915 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4916 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4917 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4918 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4919 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4920 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4921 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4922 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4923 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4924 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4925 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4926 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4927 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4928 | |
| 4929 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4930 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4931 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4932 | } |
| 4933 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4934 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4935 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4936 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4937 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4938 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4939 | else if (mfp != NL80211_MFP_NO) |
| 4940 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4941 | } |
| 4942 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4943 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4944 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4945 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4946 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 4947 | flags |= ASSOC_REQ_DISABLE_HT; |
| 4948 | |
| 4949 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 4950 | ht_capa_mask = |
| 4951 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 4952 | |
| 4953 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 4954 | if (!ht_capa_mask) |
| 4955 | return -EINVAL; |
| 4956 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4957 | } |
| 4958 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4959 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4960 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4961 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4962 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4963 | &crypto, flags, ht_capa, |
| 4964 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4965 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4966 | return err; |
| 4967 | } |
| 4968 | |
| 4969 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4970 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4972 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4973 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4974 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4975 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4976 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4977 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4978 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4979 | return -EINVAL; |
| 4980 | |
| 4981 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4982 | return -EINVAL; |
| 4983 | |
| 4984 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4985 | return -EINVAL; |
| 4986 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4987 | if (!rdev->ops->deauth) |
| 4988 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4989 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4990 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4991 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4992 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4993 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4994 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4995 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4996 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4997 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4998 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4999 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5000 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5001 | |
| 5002 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5003 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5004 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5005 | } |
| 5006 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5007 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5008 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5009 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5010 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5011 | } |
| 5012 | |
| 5013 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 5014 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5015 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5016 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5017 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5018 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5019 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5020 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5021 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5022 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5023 | return -EINVAL; |
| 5024 | |
| 5025 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5026 | return -EINVAL; |
| 5027 | |
| 5028 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5029 | return -EINVAL; |
| 5030 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5031 | if (!rdev->ops->disassoc) |
| 5032 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5033 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5034 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5035 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5036 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5037 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5038 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5039 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5040 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5041 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5042 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5043 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 5044 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5045 | |
| 5046 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 5047 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5048 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5049 | } |
| 5050 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 5051 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 5052 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5053 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 5054 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5055 | } |
| 5056 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5057 | static bool |
| 5058 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 5059 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 5060 | int rateval) |
| 5061 | { |
| 5062 | struct wiphy *wiphy = &rdev->wiphy; |
| 5063 | bool found = false; |
| 5064 | int band, i; |
| 5065 | |
| 5066 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5067 | struct ieee80211_supported_band *sband; |
| 5068 | |
| 5069 | sband = wiphy->bands[band]; |
| 5070 | if (!sband) |
| 5071 | continue; |
| 5072 | |
| 5073 | for (i = 0; i < sband->n_bitrates; i++) { |
| 5074 | if (sband->bitrates[i].bitrate == rateval) { |
| 5075 | mcast_rate[band] = i + 1; |
| 5076 | found = true; |
| 5077 | break; |
| 5078 | } |
| 5079 | } |
| 5080 | } |
| 5081 | |
| 5082 | return found; |
| 5083 | } |
| 5084 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5085 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5086 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5087 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5088 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5089 | struct cfg80211_ibss_params ibss; |
| 5090 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5091 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5092 | int err; |
| 5093 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5094 | memset(&ibss, 0, sizeof(ibss)); |
| 5095 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5096 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5097 | return -EINVAL; |
| 5098 | |
| 5099 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5100 | !info->attrs[NL80211_ATTR_SSID] || |
| 5101 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5102 | return -EINVAL; |
| 5103 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 5104 | ibss.beacon_interval = 100; |
| 5105 | |
| 5106 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 5107 | ibss.beacon_interval = |
| 5108 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5109 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 5110 | return -EINVAL; |
| 5111 | } |
| 5112 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5113 | if (!rdev->ops->join_ibss) |
| 5114 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5115 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5116 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5117 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5118 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5119 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5120 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5121 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5122 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 5123 | |
| 5124 | if (!is_valid_ether_addr(ibss.bssid)) |
| 5125 | return -EINVAL; |
| 5126 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5127 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5128 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5129 | |
| 5130 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5131 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5132 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5133 | } |
| 5134 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5135 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5136 | enum nl80211_channel_type channel_type; |
| 5137 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5138 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5139 | return -EINVAL; |
| 5140 | |
| 5141 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5142 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 5143 | return -EINVAL; |
| 5144 | |
| 5145 | ibss.channel_type = channel_type; |
| 5146 | } else { |
| 5147 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 5148 | } |
| 5149 | |
| 5150 | ibss.channel = rdev_freq_to_chan(rdev, |
| 5151 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 5152 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5153 | if (!ibss.channel || |
| 5154 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5155 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5156 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5157 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5158 | /* Both channels should be able to initiate communication */ |
| 5159 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 5160 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 5161 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 5162 | ibss.channel_type)) |
| 5163 | return -EINVAL; |
| 5164 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5165 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5166 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5167 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5168 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5169 | u8 *rates = |
| 5170 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5171 | int n_rates = |
| 5172 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5173 | struct ieee80211_supported_band *sband = |
| 5174 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5175 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5176 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5177 | &ibss.basic_rates); |
| 5178 | if (err) |
| 5179 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5180 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5181 | |
| 5182 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5183 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5184 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5185 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5186 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5187 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5188 | connkeys = nl80211_parse_connkeys(rdev, |
| 5189 | info->attrs[NL80211_ATTR_KEYS]); |
| 5190 | if (IS_ERR(connkeys)) |
| 5191 | return PTR_ERR(connkeys); |
| 5192 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5193 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5194 | ibss.control_port = |
| 5195 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5196 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5197 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5198 | if (err) |
| 5199 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5200 | return err; |
| 5201 | } |
| 5202 | |
| 5203 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5204 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5206 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5207 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5208 | if (!rdev->ops->leave_ibss) |
| 5209 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5210 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5211 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5212 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5213 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5214 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5215 | } |
| 5216 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5217 | #ifdef CONFIG_NL80211_TESTMODE |
| 5218 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5219 | .name = "testmode", |
| 5220 | }; |
| 5221 | |
| 5222 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5223 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5225 | int err; |
| 5226 | |
| 5227 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5228 | return -EINVAL; |
| 5229 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5230 | err = -EOPNOTSUPP; |
| 5231 | if (rdev->ops->testmode_cmd) { |
| 5232 | rdev->testmode_info = info; |
| 5233 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 5234 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5235 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5236 | rdev->testmode_info = NULL; |
| 5237 | } |
| 5238 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5239 | return err; |
| 5240 | } |
| 5241 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5242 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5243 | struct netlink_callback *cb) |
| 5244 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5245 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5246 | int err; |
| 5247 | long phy_idx; |
| 5248 | void *data = NULL; |
| 5249 | int data_len = 0; |
| 5250 | |
| 5251 | if (cb->args[0]) { |
| 5252 | /* |
| 5253 | * 0 is a valid index, but not valid for args[0], |
| 5254 | * so we need to offset by 1. |
| 5255 | */ |
| 5256 | phy_idx = cb->args[0] - 1; |
| 5257 | } else { |
| 5258 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5259 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5260 | nl80211_policy); |
| 5261 | if (err) |
| 5262 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5263 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5264 | mutex_lock(&cfg80211_mutex); |
| 5265 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 5266 | nl80211_fam.attrbuf); |
| 5267 | if (IS_ERR(rdev)) { |
| 5268 | mutex_unlock(&cfg80211_mutex); |
| 5269 | return PTR_ERR(rdev); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5270 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 5271 | phy_idx = rdev->wiphy_idx; |
| 5272 | rdev = NULL; |
| 5273 | mutex_unlock(&cfg80211_mutex); |
| 5274 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5275 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5276 | cb->args[1] = |
| 5277 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5278 | } |
| 5279 | |
| 5280 | if (cb->args[1]) { |
| 5281 | data = nla_data((void *)cb->args[1]); |
| 5282 | data_len = nla_len((void *)cb->args[1]); |
| 5283 | } |
| 5284 | |
| 5285 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5286 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5287 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5288 | mutex_unlock(&cfg80211_mutex); |
| 5289 | return -ENOENT; |
| 5290 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5291 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5292 | mutex_unlock(&cfg80211_mutex); |
| 5293 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5294 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5295 | err = -EOPNOTSUPP; |
| 5296 | goto out_err; |
| 5297 | } |
| 5298 | |
| 5299 | while (1) { |
| 5300 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 5301 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5302 | NL80211_CMD_TESTMODE); |
| 5303 | struct nlattr *tmdata; |
| 5304 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5305 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5306 | genlmsg_cancel(skb, hdr); |
| 5307 | break; |
| 5308 | } |
| 5309 | |
| 5310 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5311 | if (!tmdata) { |
| 5312 | genlmsg_cancel(skb, hdr); |
| 5313 | break; |
| 5314 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5315 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
| 5316 | data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5317 | nla_nest_end(skb, tmdata); |
| 5318 | |
| 5319 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5320 | genlmsg_cancel(skb, hdr); |
| 5321 | break; |
| 5322 | } else if (err) { |
| 5323 | genlmsg_cancel(skb, hdr); |
| 5324 | goto out_err; |
| 5325 | } |
| 5326 | |
| 5327 | genlmsg_end(skb, hdr); |
| 5328 | } |
| 5329 | |
| 5330 | err = skb->len; |
| 5331 | /* see above */ |
| 5332 | cb->args[0] = phy_idx + 1; |
| 5333 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5334 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5335 | return err; |
| 5336 | } |
| 5337 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5338 | static struct sk_buff * |
| 5339 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 5340 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 5341 | { |
| 5342 | struct sk_buff *skb; |
| 5343 | void *hdr; |
| 5344 | struct nlattr *data; |
| 5345 | |
| 5346 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5347 | if (!skb) |
| 5348 | return NULL; |
| 5349 | |
| 5350 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 5351 | if (!hdr) { |
| 5352 | kfree_skb(skb); |
| 5353 | return NULL; |
| 5354 | } |
| 5355 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5356 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5357 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5358 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5359 | |
| 5360 | ((void **)skb->cb)[0] = rdev; |
| 5361 | ((void **)skb->cb)[1] = hdr; |
| 5362 | ((void **)skb->cb)[2] = data; |
| 5363 | |
| 5364 | return skb; |
| 5365 | |
| 5366 | nla_put_failure: |
| 5367 | kfree_skb(skb); |
| 5368 | return NULL; |
| 5369 | } |
| 5370 | |
| 5371 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5372 | int approxlen) |
| 5373 | { |
| 5374 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5375 | |
| 5376 | if (WARN_ON(!rdev->testmode_info)) |
| 5377 | return NULL; |
| 5378 | |
| 5379 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 5380 | rdev->testmode_info->snd_pid, |
| 5381 | rdev->testmode_info->snd_seq, |
| 5382 | GFP_KERNEL); |
| 5383 | } |
| 5384 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5385 | |
| 5386 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5387 | { |
| 5388 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5389 | void *hdr = ((void **)skb->cb)[1]; |
| 5390 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5391 | |
| 5392 | if (WARN_ON(!rdev->testmode_info)) { |
| 5393 | kfree_skb(skb); |
| 5394 | return -EINVAL; |
| 5395 | } |
| 5396 | |
| 5397 | nla_nest_end(skb, data); |
| 5398 | genlmsg_end(skb, hdr); |
| 5399 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5400 | } |
| 5401 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5402 | |
| 5403 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5404 | int approxlen, gfp_t gfp) |
| 5405 | { |
| 5406 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5407 | |
| 5408 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5409 | } |
| 5410 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5411 | |
| 5412 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5413 | { |
| 5414 | void *hdr = ((void **)skb->cb)[1]; |
| 5415 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5416 | |
| 5417 | nla_nest_end(skb, data); |
| 5418 | genlmsg_end(skb, hdr); |
| 5419 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5420 | } |
| 5421 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5422 | #endif |
| 5423 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5424 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5425 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5426 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5427 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5428 | struct cfg80211_connect_params connect; |
| 5429 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5430 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5431 | int err; |
| 5432 | |
| 5433 | memset(&connect, 0, sizeof(connect)); |
| 5434 | |
| 5435 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5436 | return -EINVAL; |
| 5437 | |
| 5438 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5439 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5440 | return -EINVAL; |
| 5441 | |
| 5442 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5443 | connect.auth_type = |
| 5444 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 5445 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 5446 | return -EINVAL; |
| 5447 | } else |
| 5448 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5449 | |
| 5450 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5451 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5452 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5453 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5454 | if (err) |
| 5455 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5456 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5457 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5458 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5459 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5460 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5461 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5462 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5463 | connect.bg_scan_period = -1; |
| 5464 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5465 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5466 | connect.bg_scan_period = |
| 5467 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5468 | } |
| 5469 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5470 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5471 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5472 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5473 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5474 | |
| 5475 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5476 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5477 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5478 | } |
| 5479 | |
| 5480 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5481 | connect.channel = |
| 5482 | ieee80211_get_channel(wiphy, |
| 5483 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5484 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5485 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5486 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5487 | } |
| 5488 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5489 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5490 | connkeys = nl80211_parse_connkeys(rdev, |
| 5491 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5492 | if (IS_ERR(connkeys)) |
| 5493 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5494 | } |
| 5495 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5496 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5497 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5498 | |
| 5499 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5500 | memcpy(&connect.ht_capa_mask, |
| 5501 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5502 | sizeof(connect.ht_capa_mask)); |
| 5503 | |
| 5504 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5505 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5506 | return -EINVAL; |
| 5507 | memcpy(&connect.ht_capa, |
| 5508 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5509 | sizeof(connect.ht_capa)); |
| 5510 | } |
| 5511 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5512 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5513 | if (err) |
| 5514 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5515 | return err; |
| 5516 | } |
| 5517 | |
| 5518 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5519 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5520 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5521 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5522 | u16 reason; |
| 5523 | |
| 5524 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5525 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5526 | else |
| 5527 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5528 | |
| 5529 | if (reason == 0) |
| 5530 | return -EINVAL; |
| 5531 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5532 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5533 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5534 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5535 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5536 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5537 | } |
| 5538 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5539 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5540 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5542 | struct net *net; |
| 5543 | int err; |
| 5544 | u32 pid; |
| 5545 | |
| 5546 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5547 | return -EINVAL; |
| 5548 | |
| 5549 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5550 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5551 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5552 | if (IS_ERR(net)) |
| 5553 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5554 | |
| 5555 | err = 0; |
| 5556 | |
| 5557 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5558 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5559 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5560 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5561 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5562 | return err; |
| 5563 | } |
| 5564 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5565 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5566 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5567 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5568 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5569 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5570 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5571 | struct cfg80211_pmksa pmksa; |
| 5572 | |
| 5573 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5574 | |
| 5575 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5576 | return -EINVAL; |
| 5577 | |
| 5578 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5579 | return -EINVAL; |
| 5580 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5581 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5582 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5583 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5584 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5585 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5586 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5587 | |
| 5588 | switch (info->genlhdr->cmd) { |
| 5589 | case NL80211_CMD_SET_PMKSA: |
| 5590 | rdev_ops = rdev->ops->set_pmksa; |
| 5591 | break; |
| 5592 | case NL80211_CMD_DEL_PMKSA: |
| 5593 | rdev_ops = rdev->ops->del_pmksa; |
| 5594 | break; |
| 5595 | default: |
| 5596 | WARN_ON(1); |
| 5597 | break; |
| 5598 | } |
| 5599 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5600 | if (!rdev_ops) |
| 5601 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5602 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5603 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5604 | } |
| 5605 | |
| 5606 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5607 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5609 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5610 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5611 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5612 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5613 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5614 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5615 | if (!rdev->ops->flush_pmksa) |
| 5616 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5617 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5618 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5619 | } |
| 5620 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5621 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5622 | { |
| 5623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5624 | struct net_device *dev = info->user_ptr[1]; |
| 5625 | u8 action_code, dialog_token; |
| 5626 | u16 status_code; |
| 5627 | u8 *peer; |
| 5628 | |
| 5629 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5630 | !rdev->ops->tdls_mgmt) |
| 5631 | return -EOPNOTSUPP; |
| 5632 | |
| 5633 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5634 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5635 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5636 | !info->attrs[NL80211_ATTR_IE] || |
| 5637 | !info->attrs[NL80211_ATTR_MAC]) |
| 5638 | return -EINVAL; |
| 5639 | |
| 5640 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5641 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5642 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5643 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5644 | |
| 5645 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5646 | dialog_token, status_code, |
| 5647 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5648 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5649 | } |
| 5650 | |
| 5651 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5652 | { |
| 5653 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5654 | struct net_device *dev = info->user_ptr[1]; |
| 5655 | enum nl80211_tdls_operation operation; |
| 5656 | u8 *peer; |
| 5657 | |
| 5658 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5659 | !rdev->ops->tdls_oper) |
| 5660 | return -EOPNOTSUPP; |
| 5661 | |
| 5662 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5663 | !info->attrs[NL80211_ATTR_MAC]) |
| 5664 | return -EINVAL; |
| 5665 | |
| 5666 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5667 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5668 | |
| 5669 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5670 | } |
| 5671 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5672 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5673 | struct genl_info *info) |
| 5674 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5676 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5677 | struct ieee80211_channel *chan; |
| 5678 | struct sk_buff *msg; |
| 5679 | void *hdr; |
| 5680 | u64 cookie; |
| 5681 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5682 | u32 freq, duration; |
| 5683 | int err; |
| 5684 | |
| 5685 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5686 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5687 | return -EINVAL; |
| 5688 | |
| 5689 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5690 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5691 | if (!rdev->ops->remain_on_channel || |
| 5692 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5693 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5694 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 5695 | /* |
| 5696 | * We should be on that channel for at least a minimum amount of |
| 5697 | * time (10ms) but no longer than the driver supports. |
| 5698 | */ |
| 5699 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 5700 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 5701 | return -EINVAL; |
| 5702 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5703 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 5704 | !nl80211_valid_channel_type(info, &channel_type)) |
| 5705 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5706 | |
| 5707 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5708 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5709 | if (chan == NULL) |
| 5710 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5711 | |
| 5712 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5713 | if (!msg) |
| 5714 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5715 | |
| 5716 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5717 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5718 | |
| 5719 | if (IS_ERR(hdr)) { |
| 5720 | err = PTR_ERR(hdr); |
| 5721 | goto free_msg; |
| 5722 | } |
| 5723 | |
| 5724 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5725 | channel_type, duration, &cookie); |
| 5726 | |
| 5727 | if (err) |
| 5728 | goto free_msg; |
| 5729 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5730 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 5731 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5732 | |
| 5733 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5734 | |
| 5735 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5736 | |
| 5737 | nla_put_failure: |
| 5738 | err = -ENOBUFS; |
| 5739 | free_msg: |
| 5740 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5741 | return err; |
| 5742 | } |
| 5743 | |
| 5744 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5745 | struct genl_info *info) |
| 5746 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5747 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5748 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5749 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5750 | |
| 5751 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5752 | return -EINVAL; |
| 5753 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5754 | if (!rdev->ops->cancel_remain_on_channel) |
| 5755 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5756 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5757 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5759 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5760 | } |
| 5761 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5762 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5763 | u8 *rates, u8 rates_len) |
| 5764 | { |
| 5765 | u8 i; |
| 5766 | u32 mask = 0; |
| 5767 | |
| 5768 | for (i = 0; i < rates_len; i++) { |
| 5769 | int rate = (rates[i] & 0x7f) * 5; |
| 5770 | int ridx; |
| 5771 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5772 | struct ieee80211_rate *srate = |
| 5773 | &sband->bitrates[ridx]; |
| 5774 | if (rate == srate->bitrate) { |
| 5775 | mask |= 1 << ridx; |
| 5776 | break; |
| 5777 | } |
| 5778 | } |
| 5779 | if (ridx == sband->n_bitrates) |
| 5780 | return 0; /* rate not found */ |
| 5781 | } |
| 5782 | |
| 5783 | return mask; |
| 5784 | } |
| 5785 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5786 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5787 | u8 *rates, u8 rates_len, |
| 5788 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 5789 | { |
| 5790 | u8 i; |
| 5791 | |
| 5792 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 5793 | |
| 5794 | for (i = 0; i < rates_len; i++) { |
| 5795 | int ridx, rbit; |
| 5796 | |
| 5797 | ridx = rates[i] / 8; |
| 5798 | rbit = BIT(rates[i] % 8); |
| 5799 | |
| 5800 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 5801 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5802 | return false; |
| 5803 | |
| 5804 | /* check availability */ |
| 5805 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 5806 | mcs[ridx] |= rbit; |
| 5807 | else |
| 5808 | return false; |
| 5809 | } |
| 5810 | |
| 5811 | return true; |
| 5812 | } |
| 5813 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5814 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5815 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5816 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5817 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 5818 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5819 | }; |
| 5820 | |
| 5821 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5822 | struct genl_info *info) |
| 5823 | { |
| 5824 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5825 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5826 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5827 | int rem, i; |
| 5828 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5829 | struct nlattr *tx_rates; |
| 5830 | struct ieee80211_supported_band *sband; |
| 5831 | |
| 5832 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5833 | return -EINVAL; |
| 5834 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5835 | if (!rdev->ops->set_bitrate_mask) |
| 5836 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5837 | |
| 5838 | memset(&mask, 0, sizeof(mask)); |
| 5839 | /* Default to all rates enabled */ |
| 5840 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5841 | sband = rdev->wiphy.bands[i]; |
| 5842 | mask.control[i].legacy = |
| 5843 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5844 | if (sband) |
| 5845 | memcpy(mask.control[i].mcs, |
| 5846 | sband->ht_cap.mcs.rx_mask, |
| 5847 | sizeof(mask.control[i].mcs)); |
| 5848 | else |
| 5849 | memset(mask.control[i].mcs, 0, |
| 5850 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5851 | } |
| 5852 | |
| 5853 | /* |
| 5854 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5855 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5856 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5857 | 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] | 5858 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5859 | { |
| 5860 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5861 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5862 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5863 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5864 | if (sband == NULL) |
| 5865 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5866 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5867 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5868 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5869 | mask.control[band].legacy = rateset_to_mask( |
| 5870 | sband, |
| 5871 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5872 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 5873 | if ((mask.control[band].legacy == 0) && |
| 5874 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 5875 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5876 | } |
| 5877 | if (tb[NL80211_TXRATE_MCS]) { |
| 5878 | if (!ht_rateset_to_mask( |
| 5879 | sband, |
| 5880 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 5881 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 5882 | mask.control[band].mcs)) |
| 5883 | return -EINVAL; |
| 5884 | } |
| 5885 | |
| 5886 | if (mask.control[band].legacy == 0) { |
| 5887 | /* don't allow empty legacy rates if HT |
| 5888 | * is not even supported. */ |
| 5889 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 5890 | return -EINVAL; |
| 5891 | |
| 5892 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5893 | if (mask.control[band].mcs[i]) |
| 5894 | break; |
| 5895 | |
| 5896 | /* legacy and mcs rates may not be both empty */ |
| 5897 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5898 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5899 | } |
| 5900 | } |
| 5901 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5902 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5903 | } |
| 5904 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5905 | 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] | 5906 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5908 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5909 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5910 | |
| 5911 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5912 | return -EINVAL; |
| 5913 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5914 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5915 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5916 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5918 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5919 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5920 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5921 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5922 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5923 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5924 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5925 | |
| 5926 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5927 | if (!rdev->ops->mgmt_tx) |
| 5928 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5929 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5930 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5931 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5932 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5933 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5934 | } |
| 5935 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5936 | 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] | 5937 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5939 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5940 | struct ieee80211_channel *chan; |
| 5941 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5942 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5943 | u32 freq; |
| 5944 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 5945 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5946 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5947 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5948 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5949 | bool offchan, no_cck, dont_wait_for_ack; |
| 5950 | |
| 5951 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5952 | |
| 5953 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5954 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5955 | return -EINVAL; |
| 5956 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5957 | if (!rdev->ops->mgmt_tx) |
| 5958 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5959 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5960 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5961 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5962 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5963 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5964 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5965 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5966 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5967 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5968 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5969 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5970 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5971 | return -EINVAL; |
| 5972 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 5973 | |
| 5974 | /* |
| 5975 | * We should wait on the channel for at least a minimum amount |
| 5976 | * of time (10ms) but no longer than the driver supports. |
| 5977 | */ |
| 5978 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 5979 | wait > rdev->wiphy.max_remain_on_channel_duration) |
| 5980 | return -EINVAL; |
| 5981 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5982 | } |
| 5983 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5984 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5985 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5986 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5987 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5988 | } |
| 5989 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5990 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5991 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5992 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 5993 | return -EINVAL; |
| 5994 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5995 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5996 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5997 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5998 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5999 | if (chan == NULL) |
| 6000 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6001 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6002 | if (!dont_wait_for_ack) { |
| 6003 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6004 | if (!msg) |
| 6005 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6006 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6007 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6008 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6009 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6010 | if (IS_ERR(hdr)) { |
| 6011 | err = PTR_ERR(hdr); |
| 6012 | goto free_msg; |
| 6013 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6014 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6015 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6016 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 6017 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6018 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 6019 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6020 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6021 | if (err) |
| 6022 | goto free_msg; |
| 6023 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6024 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6025 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6026 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6027 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 6028 | genlmsg_end(msg, hdr); |
| 6029 | return genlmsg_reply(msg, info); |
| 6030 | } |
| 6031 | |
| 6032 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6033 | |
| 6034 | nla_put_failure: |
| 6035 | err = -ENOBUFS; |
| 6036 | free_msg: |
| 6037 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6038 | return err; |
| 6039 | } |
| 6040 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6041 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 6042 | { |
| 6043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6044 | struct net_device *dev = info->user_ptr[1]; |
| 6045 | u64 cookie; |
| 6046 | |
| 6047 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 6048 | return -EINVAL; |
| 6049 | |
| 6050 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 6051 | return -EOPNOTSUPP; |
| 6052 | |
| 6053 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 6054 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6055 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 6056 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 6057 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 6058 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6059 | return -EOPNOTSUPP; |
| 6060 | |
| 6061 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 6062 | |
| 6063 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 6064 | } |
| 6065 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6066 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6067 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6068 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6069 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6070 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6071 | u8 ps_state; |
| 6072 | bool state; |
| 6073 | int err; |
| 6074 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6075 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 6076 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6077 | |
| 6078 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 6079 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6080 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 6081 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6082 | |
| 6083 | wdev = dev->ieee80211_ptr; |
| 6084 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6085 | if (!rdev->ops->set_power_mgmt) |
| 6086 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6087 | |
| 6088 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 6089 | |
| 6090 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6091 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6092 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6093 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 6094 | wdev->ps_timeout); |
| 6095 | if (!err) |
| 6096 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6097 | return err; |
| 6098 | } |
| 6099 | |
| 6100 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 6101 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6102 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6103 | enum nl80211_ps_state ps_state; |
| 6104 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6105 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6106 | struct sk_buff *msg; |
| 6107 | void *hdr; |
| 6108 | int err; |
| 6109 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6110 | wdev = dev->ieee80211_ptr; |
| 6111 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6112 | if (!rdev->ops->set_power_mgmt) |
| 6113 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6114 | |
| 6115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6116 | if (!msg) |
| 6117 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6118 | |
| 6119 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6120 | NL80211_CMD_GET_POWER_SAVE); |
| 6121 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6122 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6123 | goto free_msg; |
| 6124 | } |
| 6125 | |
| 6126 | if (wdev->ps) |
| 6127 | ps_state = NL80211_PS_ENABLED; |
| 6128 | else |
| 6129 | ps_state = NL80211_PS_DISABLED; |
| 6130 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6131 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 6132 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6133 | |
| 6134 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6135 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6136 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6137 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6138 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6139 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6140 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6141 | return err; |
| 6142 | } |
| 6143 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6144 | static struct nla_policy |
| 6145 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 6146 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 6147 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 6148 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 6149 | }; |
| 6150 | |
| 6151 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 6152 | s32 threshold, u32 hysteresis) |
| 6153 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6155 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6156 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6157 | |
| 6158 | if (threshold > 0) |
| 6159 | return -EINVAL; |
| 6160 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6161 | wdev = dev->ieee80211_ptr; |
| 6162 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6163 | if (!rdev->ops->set_cqm_rssi_config) |
| 6164 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6165 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6166 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6167 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6168 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6169 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6170 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 6171 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6175 | { |
| 6176 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6177 | struct nlattr *cqm; |
| 6178 | int err; |
| 6179 | |
| 6180 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6181 | if (!cqm) { |
| 6182 | err = -EINVAL; |
| 6183 | goto out; |
| 6184 | } |
| 6185 | |
| 6186 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6187 | nl80211_attr_cqm_policy); |
| 6188 | if (err) |
| 6189 | goto out; |
| 6190 | |
| 6191 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6192 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6193 | s32 threshold; |
| 6194 | u32 hysteresis; |
| 6195 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6196 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6197 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 6198 | } else |
| 6199 | err = -EINVAL; |
| 6200 | |
| 6201 | out: |
| 6202 | return err; |
| 6203 | } |
| 6204 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6205 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6206 | { |
| 6207 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6208 | struct net_device *dev = info->user_ptr[1]; |
| 6209 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6210 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6211 | int err; |
| 6212 | |
| 6213 | /* start with default */ |
| 6214 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6215 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6216 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6217 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6218 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6219 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6220 | if (err) |
| 6221 | return err; |
| 6222 | } |
| 6223 | |
| 6224 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6225 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6226 | return -EINVAL; |
| 6227 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6228 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6229 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6230 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6231 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6232 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6233 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6234 | return -EINVAL; |
| 6235 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6236 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6237 | /* parse additional setup parameters if given */ |
| 6238 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6239 | if (err) |
| 6240 | return err; |
| 6241 | } |
| 6242 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 6243 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 6244 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 6245 | |
| 6246 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 6247 | !nl80211_valid_channel_type(info, &channel_type)) |
| 6248 | return -EINVAL; |
| 6249 | |
| 6250 | setup.channel = rdev_freq_to_chan(rdev, |
| 6251 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 6252 | channel_type); |
| 6253 | if (!setup.channel) |
| 6254 | return -EINVAL; |
| 6255 | setup.channel_type = channel_type; |
| 6256 | } else { |
| 6257 | /* cfg80211_join_mesh() will sort it out */ |
| 6258 | setup.channel = NULL; |
| 6259 | } |
| 6260 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6261 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6262 | } |
| 6263 | |
| 6264 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6265 | { |
| 6266 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6267 | struct net_device *dev = info->user_ptr[1]; |
| 6268 | |
| 6269 | return cfg80211_leave_mesh(rdev, dev); |
| 6270 | } |
| 6271 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6272 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6273 | { |
| 6274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6275 | struct sk_buff *msg; |
| 6276 | void *hdr; |
| 6277 | |
| 6278 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6279 | return -EOPNOTSUPP; |
| 6280 | |
| 6281 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6282 | if (!msg) |
| 6283 | return -ENOMEM; |
| 6284 | |
| 6285 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6286 | NL80211_CMD_GET_WOWLAN); |
| 6287 | if (!hdr) |
| 6288 | goto nla_put_failure; |
| 6289 | |
| 6290 | if (rdev->wowlan) { |
| 6291 | struct nlattr *nl_wowlan; |
| 6292 | |
| 6293 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6294 | if (!nl_wowlan) |
| 6295 | goto nla_put_failure; |
| 6296 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6297 | if ((rdev->wowlan->any && |
| 6298 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6299 | (rdev->wowlan->disconnect && |
| 6300 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6301 | (rdev->wowlan->magic_pkt && |
| 6302 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6303 | (rdev->wowlan->gtk_rekey_failure && |
| 6304 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6305 | (rdev->wowlan->eap_identity_req && |
| 6306 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6307 | (rdev->wowlan->four_way_handshake && |
| 6308 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6309 | (rdev->wowlan->rfkill_release && |
| 6310 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6311 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6312 | if (rdev->wowlan->n_patterns) { |
| 6313 | struct nlattr *nl_pats, *nl_pat; |
| 6314 | int i, pat_len; |
| 6315 | |
| 6316 | nl_pats = nla_nest_start(msg, |
| 6317 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6318 | if (!nl_pats) |
| 6319 | goto nla_put_failure; |
| 6320 | |
| 6321 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6322 | nl_pat = nla_nest_start(msg, i + 1); |
| 6323 | if (!nl_pat) |
| 6324 | goto nla_put_failure; |
| 6325 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6326 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6327 | DIV_ROUND_UP(pat_len, 8), |
| 6328 | rdev->wowlan->patterns[i].mask) || |
| 6329 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6330 | pat_len, |
| 6331 | rdev->wowlan->patterns[i].pattern)) |
| 6332 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6333 | nla_nest_end(msg, nl_pat); |
| 6334 | } |
| 6335 | nla_nest_end(msg, nl_pats); |
| 6336 | } |
| 6337 | |
| 6338 | nla_nest_end(msg, nl_wowlan); |
| 6339 | } |
| 6340 | |
| 6341 | genlmsg_end(msg, hdr); |
| 6342 | return genlmsg_reply(msg, info); |
| 6343 | |
| 6344 | nla_put_failure: |
| 6345 | nlmsg_free(msg); |
| 6346 | return -ENOBUFS; |
| 6347 | } |
| 6348 | |
| 6349 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6350 | { |
| 6351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6352 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 6353 | struct cfg80211_wowlan no_triggers = {}; |
| 6354 | struct cfg80211_wowlan new_triggers = {}; |
| 6355 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6356 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6357 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6358 | |
| 6359 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6360 | return -EOPNOTSUPP; |
| 6361 | |
| 6362 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 6363 | goto no_triggers; |
| 6364 | |
| 6365 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6366 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6367 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6368 | nl80211_wowlan_policy); |
| 6369 | if (err) |
| 6370 | return err; |
| 6371 | |
| 6372 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6373 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6374 | return -EINVAL; |
| 6375 | new_triggers.any = true; |
| 6376 | } |
| 6377 | |
| 6378 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6379 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6380 | return -EINVAL; |
| 6381 | new_triggers.disconnect = true; |
| 6382 | } |
| 6383 | |
| 6384 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6385 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6386 | return -EINVAL; |
| 6387 | new_triggers.magic_pkt = true; |
| 6388 | } |
| 6389 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6390 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6391 | return -EINVAL; |
| 6392 | |
| 6393 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6394 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6395 | return -EINVAL; |
| 6396 | new_triggers.gtk_rekey_failure = true; |
| 6397 | } |
| 6398 | |
| 6399 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6400 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6401 | return -EINVAL; |
| 6402 | new_triggers.eap_identity_req = true; |
| 6403 | } |
| 6404 | |
| 6405 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6406 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6407 | return -EINVAL; |
| 6408 | new_triggers.four_way_handshake = true; |
| 6409 | } |
| 6410 | |
| 6411 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6412 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6413 | return -EINVAL; |
| 6414 | new_triggers.rfkill_release = true; |
| 6415 | } |
| 6416 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6417 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6418 | struct nlattr *pat; |
| 6419 | int n_patterns = 0; |
| 6420 | int rem, pat_len, mask_len; |
| 6421 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6422 | |
| 6423 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6424 | rem) |
| 6425 | n_patterns++; |
| 6426 | if (n_patterns > wowlan->n_patterns) |
| 6427 | return -EINVAL; |
| 6428 | |
| 6429 | new_triggers.patterns = kcalloc(n_patterns, |
| 6430 | sizeof(new_triggers.patterns[0]), |
| 6431 | GFP_KERNEL); |
| 6432 | if (!new_triggers.patterns) |
| 6433 | return -ENOMEM; |
| 6434 | |
| 6435 | new_triggers.n_patterns = n_patterns; |
| 6436 | i = 0; |
| 6437 | |
| 6438 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6439 | rem) { |
| 6440 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6441 | nla_data(pat), nla_len(pat), NULL); |
| 6442 | err = -EINVAL; |
| 6443 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6444 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6445 | goto error; |
| 6446 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6447 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6448 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6449 | mask_len) |
| 6450 | goto error; |
| 6451 | if (pat_len > wowlan->pattern_max_len || |
| 6452 | pat_len < wowlan->pattern_min_len) |
| 6453 | goto error; |
| 6454 | |
| 6455 | new_triggers.patterns[i].mask = |
| 6456 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6457 | if (!new_triggers.patterns[i].mask) { |
| 6458 | err = -ENOMEM; |
| 6459 | goto error; |
| 6460 | } |
| 6461 | new_triggers.patterns[i].pattern = |
| 6462 | new_triggers.patterns[i].mask + mask_len; |
| 6463 | memcpy(new_triggers.patterns[i].mask, |
| 6464 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6465 | mask_len); |
| 6466 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6467 | memcpy(new_triggers.patterns[i].pattern, |
| 6468 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6469 | pat_len); |
| 6470 | i++; |
| 6471 | } |
| 6472 | } |
| 6473 | |
| 6474 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 6475 | struct cfg80211_wowlan *ntrig; |
| 6476 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 6477 | GFP_KERNEL); |
| 6478 | if (!ntrig) { |
| 6479 | err = -ENOMEM; |
| 6480 | goto error; |
| 6481 | } |
| 6482 | cfg80211_rdev_free_wowlan(rdev); |
| 6483 | rdev->wowlan = ntrig; |
| 6484 | } else { |
| 6485 | no_triggers: |
| 6486 | cfg80211_rdev_free_wowlan(rdev); |
| 6487 | rdev->wowlan = NULL; |
| 6488 | } |
| 6489 | |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6490 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
| 6491 | rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan); |
| 6492 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6493 | return 0; |
| 6494 | error: |
| 6495 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6496 | kfree(new_triggers.patterns[i].mask); |
| 6497 | kfree(new_triggers.patterns); |
| 6498 | return err; |
| 6499 | } |
| 6500 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6501 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6502 | { |
| 6503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6504 | struct net_device *dev = info->user_ptr[1]; |
| 6505 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6506 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6507 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6508 | int err; |
| 6509 | |
| 6510 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6511 | return -EINVAL; |
| 6512 | |
| 6513 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6514 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6515 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6516 | nl80211_rekey_policy); |
| 6517 | if (err) |
| 6518 | return err; |
| 6519 | |
| 6520 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6521 | return -ERANGE; |
| 6522 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6523 | return -ERANGE; |
| 6524 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6525 | return -ERANGE; |
| 6526 | |
| 6527 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6528 | NL80211_KEK_LEN); |
| 6529 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6530 | NL80211_KCK_LEN); |
| 6531 | memcpy(rekey_data.replay_ctr, |
| 6532 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6533 | NL80211_REPLAY_CTR_LEN); |
| 6534 | |
| 6535 | wdev_lock(wdev); |
| 6536 | if (!wdev->current_bss) { |
| 6537 | err = -ENOTCONN; |
| 6538 | goto out; |
| 6539 | } |
| 6540 | |
| 6541 | if (!rdev->ops->set_rekey_data) { |
| 6542 | err = -EOPNOTSUPP; |
| 6543 | goto out; |
| 6544 | } |
| 6545 | |
| 6546 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 6547 | out: |
| 6548 | wdev_unlock(wdev); |
| 6549 | return err; |
| 6550 | } |
| 6551 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6552 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6553 | struct genl_info *info) |
| 6554 | { |
| 6555 | struct net_device *dev = info->user_ptr[1]; |
| 6556 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6557 | |
| 6558 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6559 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6560 | return -EINVAL; |
| 6561 | |
| 6562 | if (wdev->ap_unexpected_nlpid) |
| 6563 | return -EBUSY; |
| 6564 | |
| 6565 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 6566 | return 0; |
| 6567 | } |
| 6568 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6569 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6570 | struct genl_info *info) |
| 6571 | { |
| 6572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6573 | struct net_device *dev = info->user_ptr[1]; |
| 6574 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6575 | struct sk_buff *msg; |
| 6576 | void *hdr; |
| 6577 | const u8 *addr; |
| 6578 | u64 cookie; |
| 6579 | int err; |
| 6580 | |
| 6581 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6582 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6583 | return -EOPNOTSUPP; |
| 6584 | |
| 6585 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6586 | return -EINVAL; |
| 6587 | |
| 6588 | if (!rdev->ops->probe_client) |
| 6589 | return -EOPNOTSUPP; |
| 6590 | |
| 6591 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6592 | if (!msg) |
| 6593 | return -ENOMEM; |
| 6594 | |
| 6595 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6596 | NL80211_CMD_PROBE_CLIENT); |
| 6597 | |
| 6598 | if (IS_ERR(hdr)) { |
| 6599 | err = PTR_ERR(hdr); |
| 6600 | goto free_msg; |
| 6601 | } |
| 6602 | |
| 6603 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6604 | |
| 6605 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6606 | if (err) |
| 6607 | goto free_msg; |
| 6608 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6609 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6610 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6611 | |
| 6612 | genlmsg_end(msg, hdr); |
| 6613 | |
| 6614 | return genlmsg_reply(msg, info); |
| 6615 | |
| 6616 | nla_put_failure: |
| 6617 | err = -ENOBUFS; |
| 6618 | free_msg: |
| 6619 | nlmsg_free(msg); |
| 6620 | return err; |
| 6621 | } |
| 6622 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6623 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6624 | { |
| 6625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6626 | |
| 6627 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6628 | return -EOPNOTSUPP; |
| 6629 | |
| 6630 | if (rdev->ap_beacons_nlpid) |
| 6631 | return -EBUSY; |
| 6632 | |
| 6633 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 6634 | |
| 6635 | return 0; |
| 6636 | } |
| 6637 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6638 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6639 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6640 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6641 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6642 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6643 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6644 | |
| 6645 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6646 | struct genl_info *info) |
| 6647 | { |
| 6648 | struct cfg80211_registered_device *rdev; |
| 6649 | struct net_device *dev; |
| 6650 | int err; |
| 6651 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6652 | |
| 6653 | if (rtnl) |
| 6654 | rtnl_lock(); |
| 6655 | |
| 6656 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 6657 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6658 | if (IS_ERR(rdev)) { |
| 6659 | if (rtnl) |
| 6660 | rtnl_unlock(); |
| 6661 | return PTR_ERR(rdev); |
| 6662 | } |
| 6663 | info->user_ptr[0] = rdev; |
| 6664 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6665 | err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs, |
| 6666 | &rdev, &dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6667 | if (err) { |
| 6668 | if (rtnl) |
| 6669 | rtnl_unlock(); |
| 6670 | return err; |
| 6671 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6672 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 6673 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 6674 | cfg80211_unlock_rdev(rdev); |
| 6675 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6676 | if (rtnl) |
| 6677 | rtnl_unlock(); |
| 6678 | return -ENETDOWN; |
| 6679 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6680 | info->user_ptr[0] = rdev; |
| 6681 | info->user_ptr[1] = dev; |
| 6682 | } |
| 6683 | |
| 6684 | return 0; |
| 6685 | } |
| 6686 | |
| 6687 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6688 | struct genl_info *info) |
| 6689 | { |
| 6690 | if (info->user_ptr[0]) |
| 6691 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 6692 | if (info->user_ptr[1]) |
| 6693 | dev_put(info->user_ptr[1]); |
| 6694 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6695 | rtnl_unlock(); |
| 6696 | } |
| 6697 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6698 | static struct genl_ops nl80211_ops[] = { |
| 6699 | { |
| 6700 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6701 | .doit = nl80211_get_wiphy, |
| 6702 | .dumpit = nl80211_dump_wiphy, |
| 6703 | .policy = nl80211_policy, |
| 6704 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6705 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6706 | }, |
| 6707 | { |
| 6708 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6709 | .doit = nl80211_set_wiphy, |
| 6710 | .policy = nl80211_policy, |
| 6711 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6712 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6713 | }, |
| 6714 | { |
| 6715 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6716 | .doit = nl80211_get_interface, |
| 6717 | .dumpit = nl80211_dump_interface, |
| 6718 | .policy = nl80211_policy, |
| 6719 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6720 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6721 | }, |
| 6722 | { |
| 6723 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6724 | .doit = nl80211_set_interface, |
| 6725 | .policy = nl80211_policy, |
| 6726 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6727 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6728 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6729 | }, |
| 6730 | { |
| 6731 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6732 | .doit = nl80211_new_interface, |
| 6733 | .policy = nl80211_policy, |
| 6734 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6735 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6736 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6737 | }, |
| 6738 | { |
| 6739 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6740 | .doit = nl80211_del_interface, |
| 6741 | .policy = nl80211_policy, |
| 6742 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6743 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6744 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6745 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6746 | { |
| 6747 | .cmd = NL80211_CMD_GET_KEY, |
| 6748 | .doit = nl80211_get_key, |
| 6749 | .policy = nl80211_policy, |
| 6750 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6751 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6752 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6753 | }, |
| 6754 | { |
| 6755 | .cmd = NL80211_CMD_SET_KEY, |
| 6756 | .doit = nl80211_set_key, |
| 6757 | .policy = nl80211_policy, |
| 6758 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6759 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6760 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6761 | }, |
| 6762 | { |
| 6763 | .cmd = NL80211_CMD_NEW_KEY, |
| 6764 | .doit = nl80211_new_key, |
| 6765 | .policy = nl80211_policy, |
| 6766 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6767 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6768 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6769 | }, |
| 6770 | { |
| 6771 | .cmd = NL80211_CMD_DEL_KEY, |
| 6772 | .doit = nl80211_del_key, |
| 6773 | .policy = nl80211_policy, |
| 6774 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6775 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6776 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6777 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6778 | { |
| 6779 | .cmd = NL80211_CMD_SET_BEACON, |
| 6780 | .policy = nl80211_policy, |
| 6781 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6782 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6783 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6784 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6785 | }, |
| 6786 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6787 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6788 | .policy = nl80211_policy, |
| 6789 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6790 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6792 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6793 | }, |
| 6794 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6795 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6796 | .policy = nl80211_policy, |
| 6797 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6798 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6799 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6800 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6801 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6802 | { |
| 6803 | .cmd = NL80211_CMD_GET_STATION, |
| 6804 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6805 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6806 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6807 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6808 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6809 | }, |
| 6810 | { |
| 6811 | .cmd = NL80211_CMD_SET_STATION, |
| 6812 | .doit = nl80211_set_station, |
| 6813 | .policy = nl80211_policy, |
| 6814 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6815 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6816 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6817 | }, |
| 6818 | { |
| 6819 | .cmd = NL80211_CMD_NEW_STATION, |
| 6820 | .doit = nl80211_new_station, |
| 6821 | .policy = nl80211_policy, |
| 6822 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6823 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6824 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6825 | }, |
| 6826 | { |
| 6827 | .cmd = NL80211_CMD_DEL_STATION, |
| 6828 | .doit = nl80211_del_station, |
| 6829 | .policy = nl80211_policy, |
| 6830 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6831 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6832 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6833 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6834 | { |
| 6835 | .cmd = NL80211_CMD_GET_MPATH, |
| 6836 | .doit = nl80211_get_mpath, |
| 6837 | .dumpit = nl80211_dump_mpath, |
| 6838 | .policy = nl80211_policy, |
| 6839 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6840 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6841 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6842 | }, |
| 6843 | { |
| 6844 | .cmd = NL80211_CMD_SET_MPATH, |
| 6845 | .doit = nl80211_set_mpath, |
| 6846 | .policy = nl80211_policy, |
| 6847 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6848 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6849 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6850 | }, |
| 6851 | { |
| 6852 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6853 | .doit = nl80211_new_mpath, |
| 6854 | .policy = nl80211_policy, |
| 6855 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6856 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6857 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6858 | }, |
| 6859 | { |
| 6860 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6861 | .doit = nl80211_del_mpath, |
| 6862 | .policy = nl80211_policy, |
| 6863 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6864 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6865 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6866 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6867 | { |
| 6868 | .cmd = NL80211_CMD_SET_BSS, |
| 6869 | .doit = nl80211_set_bss, |
| 6870 | .policy = nl80211_policy, |
| 6871 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6872 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6873 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6874 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6875 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6876 | .cmd = NL80211_CMD_GET_REG, |
| 6877 | .doit = nl80211_get_reg, |
| 6878 | .policy = nl80211_policy, |
| 6879 | /* can be retrieved by unprivileged users */ |
| 6880 | }, |
| 6881 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6882 | .cmd = NL80211_CMD_SET_REG, |
| 6883 | .doit = nl80211_set_reg, |
| 6884 | .policy = nl80211_policy, |
| 6885 | .flags = GENL_ADMIN_PERM, |
| 6886 | }, |
| 6887 | { |
| 6888 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6889 | .doit = nl80211_req_set_reg, |
| 6890 | .policy = nl80211_policy, |
| 6891 | .flags = GENL_ADMIN_PERM, |
| 6892 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6893 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6894 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6895 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6896 | .policy = nl80211_policy, |
| 6897 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6898 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6899 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6900 | }, |
| 6901 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6902 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6903 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6904 | .policy = nl80211_policy, |
| 6905 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6906 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6907 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6908 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6909 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6910 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6911 | .doit = nl80211_trigger_scan, |
| 6912 | .policy = nl80211_policy, |
| 6913 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6914 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6915 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6916 | }, |
| 6917 | { |
| 6918 | .cmd = NL80211_CMD_GET_SCAN, |
| 6919 | .policy = nl80211_policy, |
| 6920 | .dumpit = nl80211_dump_scan, |
| 6921 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6922 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6923 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6924 | .doit = nl80211_start_sched_scan, |
| 6925 | .policy = nl80211_policy, |
| 6926 | .flags = GENL_ADMIN_PERM, |
| 6927 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6928 | NL80211_FLAG_NEED_RTNL, |
| 6929 | }, |
| 6930 | { |
| 6931 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6932 | .doit = nl80211_stop_sched_scan, |
| 6933 | .policy = nl80211_policy, |
| 6934 | .flags = GENL_ADMIN_PERM, |
| 6935 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6936 | NL80211_FLAG_NEED_RTNL, |
| 6937 | }, |
| 6938 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6939 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6940 | .doit = nl80211_authenticate, |
| 6941 | .policy = nl80211_policy, |
| 6942 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6943 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6944 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6945 | }, |
| 6946 | { |
| 6947 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6948 | .doit = nl80211_associate, |
| 6949 | .policy = nl80211_policy, |
| 6950 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6951 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6952 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6953 | }, |
| 6954 | { |
| 6955 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6956 | .doit = nl80211_deauthenticate, |
| 6957 | .policy = nl80211_policy, |
| 6958 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6959 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6960 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6961 | }, |
| 6962 | { |
| 6963 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6964 | .doit = nl80211_disassociate, |
| 6965 | .policy = nl80211_policy, |
| 6966 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6967 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6968 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6969 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6970 | { |
| 6971 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6972 | .doit = nl80211_join_ibss, |
| 6973 | .policy = nl80211_policy, |
| 6974 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6975 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6976 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6977 | }, |
| 6978 | { |
| 6979 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6980 | .doit = nl80211_leave_ibss, |
| 6981 | .policy = nl80211_policy, |
| 6982 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6983 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6984 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6985 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6986 | #ifdef CONFIG_NL80211_TESTMODE |
| 6987 | { |
| 6988 | .cmd = NL80211_CMD_TESTMODE, |
| 6989 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6990 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6991 | .policy = nl80211_policy, |
| 6992 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6993 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6994 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6995 | }, |
| 6996 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6997 | { |
| 6998 | .cmd = NL80211_CMD_CONNECT, |
| 6999 | .doit = nl80211_connect, |
| 7000 | .policy = nl80211_policy, |
| 7001 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7002 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7003 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7004 | }, |
| 7005 | { |
| 7006 | .cmd = NL80211_CMD_DISCONNECT, |
| 7007 | .doit = nl80211_disconnect, |
| 7008 | .policy = nl80211_policy, |
| 7009 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7010 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7011 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7012 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7013 | { |
| 7014 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 7015 | .doit = nl80211_wiphy_netns, |
| 7016 | .policy = nl80211_policy, |
| 7017 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7018 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7019 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7020 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7021 | { |
| 7022 | .cmd = NL80211_CMD_GET_SURVEY, |
| 7023 | .policy = nl80211_policy, |
| 7024 | .dumpit = nl80211_dump_survey, |
| 7025 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7026 | { |
| 7027 | .cmd = NL80211_CMD_SET_PMKSA, |
| 7028 | .doit = nl80211_setdel_pmksa, |
| 7029 | .policy = nl80211_policy, |
| 7030 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7031 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7032 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7033 | }, |
| 7034 | { |
| 7035 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 7036 | .doit = nl80211_setdel_pmksa, |
| 7037 | .policy = nl80211_policy, |
| 7038 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7039 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7040 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7041 | }, |
| 7042 | { |
| 7043 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 7044 | .doit = nl80211_flush_pmksa, |
| 7045 | .policy = nl80211_policy, |
| 7046 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7047 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7048 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7049 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7050 | { |
| 7051 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7052 | .doit = nl80211_remain_on_channel, |
| 7053 | .policy = nl80211_policy, |
| 7054 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7055 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7056 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7057 | }, |
| 7058 | { |
| 7059 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7060 | .doit = nl80211_cancel_remain_on_channel, |
| 7061 | .policy = nl80211_policy, |
| 7062 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7063 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7064 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7065 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7066 | { |
| 7067 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 7068 | .doit = nl80211_set_tx_bitrate_mask, |
| 7069 | .policy = nl80211_policy, |
| 7070 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7071 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7072 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7073 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7074 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7075 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 7076 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7077 | .policy = nl80211_policy, |
| 7078 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7079 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7080 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7081 | }, |
| 7082 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7083 | .cmd = NL80211_CMD_FRAME, |
| 7084 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7085 | .policy = nl80211_policy, |
| 7086 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 7087 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7088 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7089 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7090 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7091 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 7092 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 7093 | .policy = nl80211_policy, |
| 7094 | .flags = GENL_ADMIN_PERM, |
| 7095 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7096 | NL80211_FLAG_NEED_RTNL, |
| 7097 | }, |
| 7098 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7099 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 7100 | .doit = nl80211_set_power_save, |
| 7101 | .policy = nl80211_policy, |
| 7102 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7103 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7104 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7105 | }, |
| 7106 | { |
| 7107 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 7108 | .doit = nl80211_get_power_save, |
| 7109 | .policy = nl80211_policy, |
| 7110 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7111 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7112 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7113 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7114 | { |
| 7115 | .cmd = NL80211_CMD_SET_CQM, |
| 7116 | .doit = nl80211_set_cqm, |
| 7117 | .policy = nl80211_policy, |
| 7118 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7119 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7120 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7121 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7122 | { |
| 7123 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 7124 | .doit = nl80211_set_channel, |
| 7125 | .policy = nl80211_policy, |
| 7126 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7127 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7128 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7129 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7130 | { |
| 7131 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 7132 | .doit = nl80211_set_wds_peer, |
| 7133 | .policy = nl80211_policy, |
| 7134 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 7135 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7136 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 7137 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7138 | { |
| 7139 | .cmd = NL80211_CMD_JOIN_MESH, |
| 7140 | .doit = nl80211_join_mesh, |
| 7141 | .policy = nl80211_policy, |
| 7142 | .flags = GENL_ADMIN_PERM, |
| 7143 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7144 | NL80211_FLAG_NEED_RTNL, |
| 7145 | }, |
| 7146 | { |
| 7147 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 7148 | .doit = nl80211_leave_mesh, |
| 7149 | .policy = nl80211_policy, |
| 7150 | .flags = GENL_ADMIN_PERM, |
| 7151 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7152 | NL80211_FLAG_NEED_RTNL, |
| 7153 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 7154 | { |
| 7155 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 7156 | .doit = nl80211_get_wowlan, |
| 7157 | .policy = nl80211_policy, |
| 7158 | /* can be retrieved by unprivileged users */ |
| 7159 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7160 | NL80211_FLAG_NEED_RTNL, |
| 7161 | }, |
| 7162 | { |
| 7163 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 7164 | .doit = nl80211_set_wowlan, |
| 7165 | .policy = nl80211_policy, |
| 7166 | .flags = GENL_ADMIN_PERM, |
| 7167 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7168 | NL80211_FLAG_NEED_RTNL, |
| 7169 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7170 | { |
| 7171 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 7172 | .doit = nl80211_set_rekey_data, |
| 7173 | .policy = nl80211_policy, |
| 7174 | .flags = GENL_ADMIN_PERM, |
| 7175 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7176 | NL80211_FLAG_NEED_RTNL, |
| 7177 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7178 | { |
| 7179 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7180 | .doit = nl80211_tdls_mgmt, |
| 7181 | .policy = nl80211_policy, |
| 7182 | .flags = GENL_ADMIN_PERM, |
| 7183 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7184 | NL80211_FLAG_NEED_RTNL, |
| 7185 | }, |
| 7186 | { |
| 7187 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7188 | .doit = nl80211_tdls_oper, |
| 7189 | .policy = nl80211_policy, |
| 7190 | .flags = GENL_ADMIN_PERM, |
| 7191 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7192 | NL80211_FLAG_NEED_RTNL, |
| 7193 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7194 | { |
| 7195 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7196 | .doit = nl80211_register_unexpected_frame, |
| 7197 | .policy = nl80211_policy, |
| 7198 | .flags = GENL_ADMIN_PERM, |
| 7199 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7200 | NL80211_FLAG_NEED_RTNL, |
| 7201 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7202 | { |
| 7203 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7204 | .doit = nl80211_probe_client, |
| 7205 | .policy = nl80211_policy, |
| 7206 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7207 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7208 | NL80211_FLAG_NEED_RTNL, |
| 7209 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7210 | { |
| 7211 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7212 | .doit = nl80211_register_beacons, |
| 7213 | .policy = nl80211_policy, |
| 7214 | .flags = GENL_ADMIN_PERM, |
| 7215 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7216 | NL80211_FLAG_NEED_RTNL, |
| 7217 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7218 | { |
| 7219 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7220 | .doit = nl80211_set_noack_map, |
| 7221 | .policy = nl80211_policy, |
| 7222 | .flags = GENL_ADMIN_PERM, |
| 7223 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7224 | NL80211_FLAG_NEED_RTNL, |
| 7225 | }, |
| 7226 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7227 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7228 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7229 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7230 | .name = "mlme", |
| 7231 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7232 | |
| 7233 | /* multicast groups */ |
| 7234 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7235 | .name = "config", |
| 7236 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7237 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7238 | .name = "scan", |
| 7239 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7240 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7241 | .name = "regulatory", |
| 7242 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7243 | |
| 7244 | /* notification functions */ |
| 7245 | |
| 7246 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7247 | { |
| 7248 | struct sk_buff *msg; |
| 7249 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7250 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7251 | if (!msg) |
| 7252 | return; |
| 7253 | |
| 7254 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7255 | nlmsg_free(msg); |
| 7256 | return; |
| 7257 | } |
| 7258 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7259 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7260 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7261 | } |
| 7262 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7263 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7264 | struct cfg80211_registered_device *rdev) |
| 7265 | { |
| 7266 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7267 | struct nlattr *nest; |
| 7268 | int i; |
| 7269 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7270 | ASSERT_RDEV_LOCK(rdev); |
| 7271 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7272 | if (WARN_ON(!req)) |
| 7273 | return 0; |
| 7274 | |
| 7275 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7276 | if (!nest) |
| 7277 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7278 | for (i = 0; i < req->n_ssids; i++) { |
| 7279 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7280 | goto nla_put_failure; |
| 7281 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7282 | nla_nest_end(msg, nest); |
| 7283 | |
| 7284 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7285 | if (!nest) |
| 7286 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7287 | for (i = 0; i < req->n_channels; i++) { |
| 7288 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7289 | goto nla_put_failure; |
| 7290 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7291 | nla_nest_end(msg, nest); |
| 7292 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7293 | if (req->ie && |
| 7294 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7295 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7296 | |
| 7297 | return 0; |
| 7298 | nla_put_failure: |
| 7299 | return -ENOBUFS; |
| 7300 | } |
| 7301 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7302 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7303 | struct cfg80211_registered_device *rdev, |
| 7304 | struct net_device *netdev, |
| 7305 | u32 pid, u32 seq, int flags, |
| 7306 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7307 | { |
| 7308 | void *hdr; |
| 7309 | |
| 7310 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 7311 | if (!hdr) |
| 7312 | return -1; |
| 7313 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7314 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7315 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7316 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7317 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7318 | /* ignore errors and send incomplete event anyway */ |
| 7319 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7320 | |
| 7321 | return genlmsg_end(msg, hdr); |
| 7322 | |
| 7323 | nla_put_failure: |
| 7324 | genlmsg_cancel(msg, hdr); |
| 7325 | return -EMSGSIZE; |
| 7326 | } |
| 7327 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7328 | static int |
| 7329 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7330 | struct cfg80211_registered_device *rdev, |
| 7331 | struct net_device *netdev, |
| 7332 | u32 pid, u32 seq, int flags, u32 cmd) |
| 7333 | { |
| 7334 | void *hdr; |
| 7335 | |
| 7336 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 7337 | if (!hdr) |
| 7338 | return -1; |
| 7339 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7340 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7341 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7342 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7343 | |
| 7344 | return genlmsg_end(msg, hdr); |
| 7345 | |
| 7346 | nla_put_failure: |
| 7347 | genlmsg_cancel(msg, hdr); |
| 7348 | return -EMSGSIZE; |
| 7349 | } |
| 7350 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7351 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 7352 | struct net_device *netdev) |
| 7353 | { |
| 7354 | struct sk_buff *msg; |
| 7355 | |
| 7356 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7357 | if (!msg) |
| 7358 | return; |
| 7359 | |
| 7360 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7361 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7362 | nlmsg_free(msg); |
| 7363 | return; |
| 7364 | } |
| 7365 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7366 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7367 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7368 | } |
| 7369 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7370 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 7371 | struct net_device *netdev) |
| 7372 | { |
| 7373 | struct sk_buff *msg; |
| 7374 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7375 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7376 | if (!msg) |
| 7377 | return; |
| 7378 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7379 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7380 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7381 | nlmsg_free(msg); |
| 7382 | return; |
| 7383 | } |
| 7384 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7385 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7386 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7387 | } |
| 7388 | |
| 7389 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 7390 | struct net_device *netdev) |
| 7391 | { |
| 7392 | struct sk_buff *msg; |
| 7393 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7394 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7395 | if (!msg) |
| 7396 | return; |
| 7397 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7398 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7399 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7400 | nlmsg_free(msg); |
| 7401 | return; |
| 7402 | } |
| 7403 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7404 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7405 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7406 | } |
| 7407 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7408 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7409 | struct net_device *netdev) |
| 7410 | { |
| 7411 | struct sk_buff *msg; |
| 7412 | |
| 7413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7414 | if (!msg) |
| 7415 | return; |
| 7416 | |
| 7417 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7418 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7419 | nlmsg_free(msg); |
| 7420 | return; |
| 7421 | } |
| 7422 | |
| 7423 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7424 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7425 | } |
| 7426 | |
| 7427 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7428 | struct net_device *netdev, u32 cmd) |
| 7429 | { |
| 7430 | struct sk_buff *msg; |
| 7431 | |
| 7432 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7433 | if (!msg) |
| 7434 | return; |
| 7435 | |
| 7436 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7437 | nlmsg_free(msg); |
| 7438 | return; |
| 7439 | } |
| 7440 | |
| 7441 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7442 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7443 | } |
| 7444 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7445 | /* |
| 7446 | * This can happen on global regulatory changes or device specific settings |
| 7447 | * based on custom world regulatory domains. |
| 7448 | */ |
| 7449 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7450 | { |
| 7451 | struct sk_buff *msg; |
| 7452 | void *hdr; |
| 7453 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7454 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7455 | if (!msg) |
| 7456 | return; |
| 7457 | |
| 7458 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7459 | if (!hdr) { |
| 7460 | nlmsg_free(msg); |
| 7461 | return; |
| 7462 | } |
| 7463 | |
| 7464 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7465 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 7466 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7467 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7468 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 7469 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7470 | NL80211_REGDOM_TYPE_WORLD)) |
| 7471 | goto nla_put_failure; |
| 7472 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 7473 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7474 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 7475 | goto nla_put_failure; |
| 7476 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7477 | request->intersect) { |
| 7478 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7479 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 7480 | goto nla_put_failure; |
| 7481 | } else { |
| 7482 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7483 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 7484 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 7485 | request->alpha2)) |
| 7486 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7487 | } |
| 7488 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7489 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 7490 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 7491 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7492 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7493 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7494 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7495 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7496 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7497 | GFP_ATOMIC); |
| 7498 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7499 | |
| 7500 | return; |
| 7501 | |
| 7502 | nla_put_failure: |
| 7503 | genlmsg_cancel(msg, hdr); |
| 7504 | nlmsg_free(msg); |
| 7505 | } |
| 7506 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7507 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7508 | struct net_device *netdev, |
| 7509 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7510 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7511 | { |
| 7512 | struct sk_buff *msg; |
| 7513 | void *hdr; |
| 7514 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7515 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7516 | if (!msg) |
| 7517 | return; |
| 7518 | |
| 7519 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7520 | if (!hdr) { |
| 7521 | nlmsg_free(msg); |
| 7522 | return; |
| 7523 | } |
| 7524 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7525 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7526 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7527 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 7528 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7529 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7530 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7531 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7532 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7533 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7534 | return; |
| 7535 | |
| 7536 | nla_put_failure: |
| 7537 | genlmsg_cancel(msg, hdr); |
| 7538 | nlmsg_free(msg); |
| 7539 | } |
| 7540 | |
| 7541 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7542 | struct net_device *netdev, const u8 *buf, |
| 7543 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7544 | { |
| 7545 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7546 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7547 | } |
| 7548 | |
| 7549 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 7550 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7551 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7552 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7553 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7554 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7555 | } |
| 7556 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7557 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7558 | struct net_device *netdev, const u8 *buf, |
| 7559 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7560 | { |
| 7561 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7562 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7563 | } |
| 7564 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7565 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 7566 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7567 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7568 | { |
| 7569 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7570 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7571 | } |
| 7572 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7573 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7574 | struct net_device *netdev, const u8 *buf, |
| 7575 | size_t len, gfp_t gfp) |
| 7576 | { |
| 7577 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7578 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7579 | } |
| 7580 | |
| 7581 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7582 | struct net_device *netdev, const u8 *buf, |
| 7583 | size_t len, gfp_t gfp) |
| 7584 | { |
| 7585 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7586 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7587 | } |
| 7588 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7589 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7590 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7591 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7592 | { |
| 7593 | struct sk_buff *msg; |
| 7594 | void *hdr; |
| 7595 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7596 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7597 | if (!msg) |
| 7598 | return; |
| 7599 | |
| 7600 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7601 | if (!hdr) { |
| 7602 | nlmsg_free(msg); |
| 7603 | return; |
| 7604 | } |
| 7605 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7606 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7607 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7608 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 7609 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 7610 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7611 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7612 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7613 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7614 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7615 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7616 | return; |
| 7617 | |
| 7618 | nla_put_failure: |
| 7619 | genlmsg_cancel(msg, hdr); |
| 7620 | nlmsg_free(msg); |
| 7621 | } |
| 7622 | |
| 7623 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7624 | struct net_device *netdev, const u8 *addr, |
| 7625 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7626 | { |
| 7627 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7628 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7629 | } |
| 7630 | |
| 7631 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7632 | struct net_device *netdev, const u8 *addr, |
| 7633 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7634 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7635 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 7636 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7637 | } |
| 7638 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7639 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 7640 | struct net_device *netdev, const u8 *bssid, |
| 7641 | const u8 *req_ie, size_t req_ie_len, |
| 7642 | const u8 *resp_ie, size_t resp_ie_len, |
| 7643 | u16 status, gfp_t gfp) |
| 7644 | { |
| 7645 | struct sk_buff *msg; |
| 7646 | void *hdr; |
| 7647 | |
| 7648 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7649 | if (!msg) |
| 7650 | return; |
| 7651 | |
| 7652 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 7653 | if (!hdr) { |
| 7654 | nlmsg_free(msg); |
| 7655 | return; |
| 7656 | } |
| 7657 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7658 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7659 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7660 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 7661 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 7662 | (req_ie && |
| 7663 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 7664 | (resp_ie && |
| 7665 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 7666 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7667 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7668 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7669 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7670 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7671 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7672 | return; |
| 7673 | |
| 7674 | nla_put_failure: |
| 7675 | genlmsg_cancel(msg, hdr); |
| 7676 | nlmsg_free(msg); |
| 7677 | |
| 7678 | } |
| 7679 | |
| 7680 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 7681 | struct net_device *netdev, const u8 *bssid, |
| 7682 | const u8 *req_ie, size_t req_ie_len, |
| 7683 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 7684 | { |
| 7685 | struct sk_buff *msg; |
| 7686 | void *hdr; |
| 7687 | |
| 7688 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7689 | if (!msg) |
| 7690 | return; |
| 7691 | |
| 7692 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 7693 | if (!hdr) { |
| 7694 | nlmsg_free(msg); |
| 7695 | return; |
| 7696 | } |
| 7697 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7698 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7699 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7700 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 7701 | (req_ie && |
| 7702 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 7703 | (resp_ie && |
| 7704 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 7705 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7706 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7707 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7708 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7709 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7710 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7711 | return; |
| 7712 | |
| 7713 | nla_put_failure: |
| 7714 | genlmsg_cancel(msg, hdr); |
| 7715 | nlmsg_free(msg); |
| 7716 | |
| 7717 | } |
| 7718 | |
| 7719 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 7720 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7721 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7722 | { |
| 7723 | struct sk_buff *msg; |
| 7724 | void *hdr; |
| 7725 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7726 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7727 | if (!msg) |
| 7728 | return; |
| 7729 | |
| 7730 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7731 | if (!hdr) { |
| 7732 | nlmsg_free(msg); |
| 7733 | return; |
| 7734 | } |
| 7735 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7736 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7737 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7738 | (from_ap && reason && |
| 7739 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 7740 | (from_ap && |
| 7741 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 7742 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 7743 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7744 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7745 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7746 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7747 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7748 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7749 | return; |
| 7750 | |
| 7751 | nla_put_failure: |
| 7752 | genlmsg_cancel(msg, hdr); |
| 7753 | nlmsg_free(msg); |
| 7754 | |
| 7755 | } |
| 7756 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7757 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7758 | struct net_device *netdev, const u8 *bssid, |
| 7759 | gfp_t gfp) |
| 7760 | { |
| 7761 | struct sk_buff *msg; |
| 7762 | void *hdr; |
| 7763 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7764 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7765 | if (!msg) |
| 7766 | return; |
| 7767 | |
| 7768 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7769 | if (!hdr) { |
| 7770 | nlmsg_free(msg); |
| 7771 | return; |
| 7772 | } |
| 7773 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7774 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7775 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7776 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 7777 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7778 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7779 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7780 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7781 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7782 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7783 | return; |
| 7784 | |
| 7785 | nla_put_failure: |
| 7786 | genlmsg_cancel(msg, hdr); |
| 7787 | nlmsg_free(msg); |
| 7788 | } |
| 7789 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7790 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7791 | struct net_device *netdev, |
| 7792 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7793 | gfp_t gfp) |
| 7794 | { |
| 7795 | struct sk_buff *msg; |
| 7796 | void *hdr; |
| 7797 | |
| 7798 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7799 | if (!msg) |
| 7800 | return; |
| 7801 | |
| 7802 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7803 | if (!hdr) { |
| 7804 | nlmsg_free(msg); |
| 7805 | return; |
| 7806 | } |
| 7807 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7808 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7809 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7810 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 7811 | (ie_len && ie && |
| 7812 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 7813 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7814 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7815 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7816 | |
| 7817 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7818 | nl80211_mlme_mcgrp.id, gfp); |
| 7819 | return; |
| 7820 | |
| 7821 | nla_put_failure: |
| 7822 | genlmsg_cancel(msg, hdr); |
| 7823 | nlmsg_free(msg); |
| 7824 | } |
| 7825 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7826 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7827 | struct net_device *netdev, const u8 *addr, |
| 7828 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7829 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7830 | { |
| 7831 | struct sk_buff *msg; |
| 7832 | void *hdr; |
| 7833 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7834 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7835 | if (!msg) |
| 7836 | return; |
| 7837 | |
| 7838 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7839 | if (!hdr) { |
| 7840 | nlmsg_free(msg); |
| 7841 | return; |
| 7842 | } |
| 7843 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7844 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7845 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7846 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 7847 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 7848 | (key_id != -1 && |
| 7849 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 7850 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 7851 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7852 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7853 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7854 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7855 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7856 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7857 | return; |
| 7858 | |
| 7859 | nla_put_failure: |
| 7860 | genlmsg_cancel(msg, hdr); |
| 7861 | nlmsg_free(msg); |
| 7862 | } |
| 7863 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7864 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7865 | struct ieee80211_channel *channel_before, |
| 7866 | struct ieee80211_channel *channel_after) |
| 7867 | { |
| 7868 | struct sk_buff *msg; |
| 7869 | void *hdr; |
| 7870 | struct nlattr *nl_freq; |
| 7871 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7873 | if (!msg) |
| 7874 | return; |
| 7875 | |
| 7876 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7877 | if (!hdr) { |
| 7878 | nlmsg_free(msg); |
| 7879 | return; |
| 7880 | } |
| 7881 | |
| 7882 | /* |
| 7883 | * Since we are applying the beacon hint to a wiphy we know its |
| 7884 | * wiphy_idx is valid |
| 7885 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7886 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7887 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7888 | |
| 7889 | /* Before */ |
| 7890 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7891 | if (!nl_freq) |
| 7892 | goto nla_put_failure; |
| 7893 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7894 | goto nla_put_failure; |
| 7895 | nla_nest_end(msg, nl_freq); |
| 7896 | |
| 7897 | /* After */ |
| 7898 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7899 | if (!nl_freq) |
| 7900 | goto nla_put_failure; |
| 7901 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7902 | goto nla_put_failure; |
| 7903 | nla_nest_end(msg, nl_freq); |
| 7904 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7905 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7906 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7907 | rcu_read_lock(); |
| 7908 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7909 | GFP_ATOMIC); |
| 7910 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7911 | |
| 7912 | return; |
| 7913 | |
| 7914 | nla_put_failure: |
| 7915 | genlmsg_cancel(msg, hdr); |
| 7916 | nlmsg_free(msg); |
| 7917 | } |
| 7918 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7919 | static void nl80211_send_remain_on_chan_event( |
| 7920 | int cmd, struct cfg80211_registered_device *rdev, |
| 7921 | struct net_device *netdev, u64 cookie, |
| 7922 | struct ieee80211_channel *chan, |
| 7923 | enum nl80211_channel_type channel_type, |
| 7924 | unsigned int duration, gfp_t gfp) |
| 7925 | { |
| 7926 | struct sk_buff *msg; |
| 7927 | void *hdr; |
| 7928 | |
| 7929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7930 | if (!msg) |
| 7931 | return; |
| 7932 | |
| 7933 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7934 | if (!hdr) { |
| 7935 | nlmsg_free(msg); |
| 7936 | return; |
| 7937 | } |
| 7938 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7939 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7940 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7941 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
| 7942 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) || |
| 7943 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7944 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7945 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7946 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 7947 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 7948 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7949 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7950 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7951 | |
| 7952 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7953 | nl80211_mlme_mcgrp.id, gfp); |
| 7954 | return; |
| 7955 | |
| 7956 | nla_put_failure: |
| 7957 | genlmsg_cancel(msg, hdr); |
| 7958 | nlmsg_free(msg); |
| 7959 | } |
| 7960 | |
| 7961 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7962 | struct net_device *netdev, u64 cookie, |
| 7963 | struct ieee80211_channel *chan, |
| 7964 | enum nl80211_channel_type channel_type, |
| 7965 | unsigned int duration, gfp_t gfp) |
| 7966 | { |
| 7967 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7968 | rdev, netdev, cookie, chan, |
| 7969 | channel_type, duration, gfp); |
| 7970 | } |
| 7971 | |
| 7972 | void nl80211_send_remain_on_channel_cancel( |
| 7973 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7974 | u64 cookie, struct ieee80211_channel *chan, |
| 7975 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7976 | { |
| 7977 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7978 | rdev, netdev, cookie, chan, |
| 7979 | channel_type, 0, gfp); |
| 7980 | } |
| 7981 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7982 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7983 | struct net_device *dev, const u8 *mac_addr, |
| 7984 | struct station_info *sinfo, gfp_t gfp) |
| 7985 | { |
| 7986 | struct sk_buff *msg; |
| 7987 | |
| 7988 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7989 | if (!msg) |
| 7990 | return; |
| 7991 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 7992 | if (nl80211_send_station(msg, 0, 0, 0, |
| 7993 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7994 | nlmsg_free(msg); |
| 7995 | return; |
| 7996 | } |
| 7997 | |
| 7998 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7999 | nl80211_mlme_mcgrp.id, gfp); |
| 8000 | } |
| 8001 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8002 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 8003 | struct net_device *dev, const u8 *mac_addr, |
| 8004 | gfp_t gfp) |
| 8005 | { |
| 8006 | struct sk_buff *msg; |
| 8007 | void *hdr; |
| 8008 | |
| 8009 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8010 | if (!msg) |
| 8011 | return; |
| 8012 | |
| 8013 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 8014 | if (!hdr) { |
| 8015 | nlmsg_free(msg); |
| 8016 | return; |
| 8017 | } |
| 8018 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8019 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8020 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 8021 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8022 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8023 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 8024 | |
| 8025 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8026 | nl80211_mlme_mcgrp.id, gfp); |
| 8027 | return; |
| 8028 | |
| 8029 | nla_put_failure: |
| 8030 | genlmsg_cancel(msg, hdr); |
| 8031 | nlmsg_free(msg); |
| 8032 | } |
| 8033 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8034 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 8035 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8036 | { |
| 8037 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8038 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8039 | struct sk_buff *msg; |
| 8040 | void *hdr; |
| 8041 | int err; |
| 8042 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 8043 | |
| 8044 | if (!nlpid) |
| 8045 | return false; |
| 8046 | |
| 8047 | msg = nlmsg_new(100, gfp); |
| 8048 | if (!msg) |
| 8049 | return true; |
| 8050 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8051 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8052 | if (!hdr) { |
| 8053 | nlmsg_free(msg); |
| 8054 | return true; |
| 8055 | } |
| 8056 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8057 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8058 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8059 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 8060 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8061 | |
| 8062 | err = genlmsg_end(msg, hdr); |
| 8063 | if (err < 0) { |
| 8064 | nlmsg_free(msg); |
| 8065 | return true; |
| 8066 | } |
| 8067 | |
| 8068 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 8069 | return true; |
| 8070 | |
| 8071 | nla_put_failure: |
| 8072 | genlmsg_cancel(msg, hdr); |
| 8073 | nlmsg_free(msg); |
| 8074 | return true; |
| 8075 | } |
| 8076 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 8077 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 8078 | { |
| 8079 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 8080 | addr, gfp); |
| 8081 | } |
| 8082 | |
| 8083 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 8084 | const u8 *addr, gfp_t gfp) |
| 8085 | { |
| 8086 | return __nl80211_unexpected_frame(dev, |
| 8087 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 8088 | addr, gfp); |
| 8089 | } |
| 8090 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8091 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 8092 | struct net_device *netdev, u32 nlpid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8093 | int freq, int sig_dbm, |
| 8094 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8095 | { |
| 8096 | struct sk_buff *msg; |
| 8097 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8098 | |
| 8099 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8100 | if (!msg) |
| 8101 | return -ENOMEM; |
| 8102 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8103 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8104 | if (!hdr) { |
| 8105 | nlmsg_free(msg); |
| 8106 | return -ENOMEM; |
| 8107 | } |
| 8108 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8109 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8110 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8111 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8112 | (sig_dbm && |
| 8113 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8114 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 8115 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8116 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8117 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8118 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8119 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8120 | |
| 8121 | nla_put_failure: |
| 8122 | genlmsg_cancel(msg, hdr); |
| 8123 | nlmsg_free(msg); |
| 8124 | return -ENOBUFS; |
| 8125 | } |
| 8126 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8127 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 8128 | struct net_device *netdev, u64 cookie, |
| 8129 | const u8 *buf, size_t len, bool ack, |
| 8130 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8131 | { |
| 8132 | struct sk_buff *msg; |
| 8133 | void *hdr; |
| 8134 | |
| 8135 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 8136 | if (!msg) |
| 8137 | return; |
| 8138 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8139 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8140 | if (!hdr) { |
| 8141 | nlmsg_free(msg); |
| 8142 | return; |
| 8143 | } |
| 8144 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8145 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8146 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8147 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 8148 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8149 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8150 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8151 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8152 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8153 | |
| 8154 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 8155 | return; |
| 8156 | |
| 8157 | nla_put_failure: |
| 8158 | genlmsg_cancel(msg, hdr); |
| 8159 | nlmsg_free(msg); |
| 8160 | } |
| 8161 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8162 | void |
| 8163 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 8164 | struct net_device *netdev, |
| 8165 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 8166 | gfp_t gfp) |
| 8167 | { |
| 8168 | struct sk_buff *msg; |
| 8169 | struct nlattr *pinfoattr; |
| 8170 | void *hdr; |
| 8171 | |
| 8172 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8173 | if (!msg) |
| 8174 | return; |
| 8175 | |
| 8176 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8177 | if (!hdr) { |
| 8178 | nlmsg_free(msg); |
| 8179 | return; |
| 8180 | } |
| 8181 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8182 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8183 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8184 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8185 | |
| 8186 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8187 | if (!pinfoattr) |
| 8188 | goto nla_put_failure; |
| 8189 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8190 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8191 | rssi_event)) |
| 8192 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8193 | |
| 8194 | nla_nest_end(msg, pinfoattr); |
| 8195 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8196 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8197 | |
| 8198 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8199 | nl80211_mlme_mcgrp.id, gfp); |
| 8200 | return; |
| 8201 | |
| 8202 | nla_put_failure: |
| 8203 | genlmsg_cancel(msg, hdr); |
| 8204 | nlmsg_free(msg); |
| 8205 | } |
| 8206 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8207 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8208 | struct net_device *netdev, const u8 *bssid, |
| 8209 | const u8 *replay_ctr, gfp_t gfp) |
| 8210 | { |
| 8211 | struct sk_buff *msg; |
| 8212 | struct nlattr *rekey_attr; |
| 8213 | void *hdr; |
| 8214 | |
| 8215 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8216 | if (!msg) |
| 8217 | return; |
| 8218 | |
| 8219 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8220 | if (!hdr) { |
| 8221 | nlmsg_free(msg); |
| 8222 | return; |
| 8223 | } |
| 8224 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8225 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8226 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8227 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8228 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8229 | |
| 8230 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8231 | if (!rekey_attr) |
| 8232 | goto nla_put_failure; |
| 8233 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8234 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8235 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8236 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8237 | |
| 8238 | nla_nest_end(msg, rekey_attr); |
| 8239 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8240 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8241 | |
| 8242 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8243 | nl80211_mlme_mcgrp.id, gfp); |
| 8244 | return; |
| 8245 | |
| 8246 | nla_put_failure: |
| 8247 | genlmsg_cancel(msg, hdr); |
| 8248 | nlmsg_free(msg); |
| 8249 | } |
| 8250 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8251 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8252 | struct net_device *netdev, int index, |
| 8253 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8254 | { |
| 8255 | struct sk_buff *msg; |
| 8256 | struct nlattr *attr; |
| 8257 | void *hdr; |
| 8258 | |
| 8259 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8260 | if (!msg) |
| 8261 | return; |
| 8262 | |
| 8263 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8264 | if (!hdr) { |
| 8265 | nlmsg_free(msg); |
| 8266 | return; |
| 8267 | } |
| 8268 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8269 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8270 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8271 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8272 | |
| 8273 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8274 | if (!attr) |
| 8275 | goto nla_put_failure; |
| 8276 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8277 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8278 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8279 | (preauth && |
| 8280 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8281 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8282 | |
| 8283 | nla_nest_end(msg, attr); |
| 8284 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8285 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8286 | |
| 8287 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8288 | nl80211_mlme_mcgrp.id, gfp); |
| 8289 | return; |
| 8290 | |
| 8291 | nla_put_failure: |
| 8292 | genlmsg_cancel(msg, hdr); |
| 8293 | nlmsg_free(msg); |
| 8294 | } |
| 8295 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8296 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 8297 | struct net_device *netdev, int freq, |
| 8298 | enum nl80211_channel_type type, gfp_t gfp) |
| 8299 | { |
| 8300 | struct sk_buff *msg; |
| 8301 | void *hdr; |
| 8302 | |
| 8303 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8304 | if (!msg) |
| 8305 | return; |
| 8306 | |
| 8307 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8308 | if (!hdr) { |
| 8309 | nlmsg_free(msg); |
| 8310 | return; |
| 8311 | } |
| 8312 | |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8313 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8314 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8315 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type)) |
| 8316 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8317 | |
| 8318 | genlmsg_end(msg, hdr); |
| 8319 | |
| 8320 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8321 | nl80211_mlme_mcgrp.id, gfp); |
| 8322 | return; |
| 8323 | |
| 8324 | nla_put_failure: |
| 8325 | genlmsg_cancel(msg, hdr); |
| 8326 | nlmsg_free(msg); |
| 8327 | } |
| 8328 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8329 | void |
| 8330 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8331 | struct net_device *netdev, const u8 *peer, |
| 8332 | u32 num_packets, gfp_t gfp) |
| 8333 | { |
| 8334 | struct sk_buff *msg; |
| 8335 | struct nlattr *pinfoattr; |
| 8336 | void *hdr; |
| 8337 | |
| 8338 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8339 | if (!msg) |
| 8340 | return; |
| 8341 | |
| 8342 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8343 | if (!hdr) { |
| 8344 | nlmsg_free(msg); |
| 8345 | return; |
| 8346 | } |
| 8347 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8348 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8349 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8350 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8351 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8352 | |
| 8353 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8354 | if (!pinfoattr) |
| 8355 | goto nla_put_failure; |
| 8356 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8357 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 8358 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8359 | |
| 8360 | nla_nest_end(msg, pinfoattr); |
| 8361 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8362 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8363 | |
| 8364 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8365 | nl80211_mlme_mcgrp.id, gfp); |
| 8366 | return; |
| 8367 | |
| 8368 | nla_put_failure: |
| 8369 | genlmsg_cancel(msg, hdr); |
| 8370 | nlmsg_free(msg); |
| 8371 | } |
| 8372 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8373 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 8374 | u64 cookie, bool acked, gfp_t gfp) |
| 8375 | { |
| 8376 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8377 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8378 | struct sk_buff *msg; |
| 8379 | void *hdr; |
| 8380 | int err; |
| 8381 | |
| 8382 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8383 | if (!msg) |
| 8384 | return; |
| 8385 | |
| 8386 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 8387 | if (!hdr) { |
| 8388 | nlmsg_free(msg); |
| 8389 | return; |
| 8390 | } |
| 8391 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8392 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8393 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8394 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8395 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8396 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8397 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8398 | |
| 8399 | err = genlmsg_end(msg, hdr); |
| 8400 | if (err < 0) { |
| 8401 | nlmsg_free(msg); |
| 8402 | return; |
| 8403 | } |
| 8404 | |
| 8405 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8406 | nl80211_mlme_mcgrp.id, gfp); |
| 8407 | return; |
| 8408 | |
| 8409 | nla_put_failure: |
| 8410 | genlmsg_cancel(msg, hdr); |
| 8411 | nlmsg_free(msg); |
| 8412 | } |
| 8413 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 8414 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8415 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 8416 | const u8 *frame, size_t len, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8417 | int freq, int sig_dbm, gfp_t gfp) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8418 | { |
| 8419 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 8420 | struct sk_buff *msg; |
| 8421 | void *hdr; |
| 8422 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 8423 | |
| 8424 | if (!nlpid) |
| 8425 | return; |
| 8426 | |
| 8427 | msg = nlmsg_new(len + 100, gfp); |
| 8428 | if (!msg) |
| 8429 | return; |
| 8430 | |
| 8431 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 8432 | if (!hdr) { |
| 8433 | nlmsg_free(msg); |
| 8434 | return; |
| 8435 | } |
| 8436 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8437 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8438 | (freq && |
| 8439 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 8440 | (sig_dbm && |
| 8441 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8442 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 8443 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8444 | |
| 8445 | genlmsg_end(msg, hdr); |
| 8446 | |
| 8447 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 8448 | return; |
| 8449 | |
| 8450 | nla_put_failure: |
| 8451 | genlmsg_cancel(msg, hdr); |
| 8452 | nlmsg_free(msg); |
| 8453 | } |
| 8454 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 8455 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8456 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 8457 | unsigned long state, |
| 8458 | void *_notify) |
| 8459 | { |
| 8460 | struct netlink_notify *notify = _notify; |
| 8461 | struct cfg80211_registered_device *rdev; |
| 8462 | struct wireless_dev *wdev; |
| 8463 | |
| 8464 | if (state != NETLINK_URELEASE) |
| 8465 | return NOTIFY_DONE; |
| 8466 | |
| 8467 | rcu_read_lock(); |
| 8468 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8469 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8470 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8471 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8472 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 8473 | rdev->ap_beacons_nlpid = 0; |
| 8474 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8475 | |
| 8476 | rcu_read_unlock(); |
| 8477 | |
| 8478 | return NOTIFY_DONE; |
| 8479 | } |
| 8480 | |
| 8481 | static struct notifier_block nl80211_netlink_notifier = { |
| 8482 | .notifier_call = nl80211_netlink_notify, |
| 8483 | }; |
| 8484 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8485 | /* initialisation/exit functions */ |
| 8486 | |
| 8487 | int nl80211_init(void) |
| 8488 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8489 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8490 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8491 | err = genl_register_family_with_ops(&nl80211_fam, |
| 8492 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8493 | if (err) |
| 8494 | return err; |
| 8495 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8496 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 8497 | if (err) |
| 8498 | goto err_out; |
| 8499 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8500 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 8501 | if (err) |
| 8502 | goto err_out; |
| 8503 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8504 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 8505 | if (err) |
| 8506 | goto err_out; |
| 8507 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8508 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 8509 | if (err) |
| 8510 | goto err_out; |
| 8511 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8512 | #ifdef CONFIG_NL80211_TESTMODE |
| 8513 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 8514 | if (err) |
| 8515 | goto err_out; |
| 8516 | #endif |
| 8517 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8518 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 8519 | if (err) |
| 8520 | goto err_out; |
| 8521 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8522 | return 0; |
| 8523 | err_out: |
| 8524 | genl_unregister_family(&nl80211_fam); |
| 8525 | return err; |
| 8526 | } |
| 8527 | |
| 8528 | void nl80211_exit(void) |
| 8529 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8530 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8531 | genl_unregister_family(&nl80211_fam); |
| 8532 | } |