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 | |
| 26 | /* the netlink family */ |
| 27 | static struct genl_family nl80211_fam = { |
| 28 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 29 | .name = "nl80211", /* have users key off the name instead */ |
| 30 | .hdrsize = 0, /* no private header */ |
| 31 | .version = 1, /* no particular meaning now */ |
| 32 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 33 | .netnsok = true, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 34 | }; |
| 35 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 36 | /* internal helper: get rdev and dev */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 37 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 38 | struct cfg80211_registered_device **rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 39 | struct net_device **dev) |
| 40 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 41 | struct nlattr **attrs = info->attrs; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 42 | int ifindex; |
| 43 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 44 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 45 | return -EINVAL; |
| 46 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 47 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 48 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 49 | if (!*dev) |
| 50 | return -ENODEV; |
| 51 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 52 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 53 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 54 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 55 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 62 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 63 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 64 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 65 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 66 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 67 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 68 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 69 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 70 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 71 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 72 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 73 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 74 | |
| 75 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 76 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 77 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 78 | |
| 79 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 80 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 81 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 82 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 83 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 84 | .len = WLAN_MAX_KEY_LEN }, |
| 85 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 86 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 87 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 88 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 89 | |
| 90 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 91 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 92 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 93 | .len = IEEE80211_MAX_DATA_LEN }, |
| 94 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 95 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 96 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 97 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 98 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 99 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 100 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 101 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 102 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 103 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 104 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 105 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 106 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 107 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 108 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 109 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 110 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 111 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 112 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 113 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 114 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 115 | .len = NL80211_MAX_SUPP_RATES }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 116 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 117 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
| 118 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 119 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 120 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 121 | |
| 122 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 123 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 124 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 125 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 126 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 127 | |
| 128 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 129 | .len = IEEE80211_MAX_SSID_LEN }, |
| 130 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 131 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 132 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 133 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 134 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 135 | [NL80211_ATTR_STA_FLAGS2] = { |
| 136 | .len = sizeof(struct nl80211_sta_flag_update), |
| 137 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 138 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 139 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 140 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 141 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 142 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 143 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 144 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 145 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 146 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 147 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 148 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 149 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 150 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 151 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 152 | .len = IEEE80211_MAX_DATA_LEN }, |
| 153 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 154 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 155 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 156 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 157 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 158 | |
| 159 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 160 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 161 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 162 | }; |
| 163 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 164 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 165 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 166 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 167 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 168 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 169 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 170 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 171 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
| 172 | }; |
| 173 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 174 | /* ifidx get helper */ |
| 175 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 176 | { |
| 177 | int res; |
| 178 | |
| 179 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 180 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 181 | nl80211_policy); |
| 182 | if (res) |
| 183 | return res; |
| 184 | |
| 185 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 186 | return -EINVAL; |
| 187 | |
| 188 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 189 | if (!res) |
| 190 | return -EINVAL; |
| 191 | return res; |
| 192 | } |
| 193 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 194 | /* IE validation */ |
| 195 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 196 | { |
| 197 | const u8 *pos; |
| 198 | int len; |
| 199 | |
| 200 | if (!attr) |
| 201 | return true; |
| 202 | |
| 203 | pos = nla_data(attr); |
| 204 | len = nla_len(attr); |
| 205 | |
| 206 | while (len) { |
| 207 | u8 elemlen; |
| 208 | |
| 209 | if (len < 2) |
| 210 | return false; |
| 211 | len -= 2; |
| 212 | |
| 213 | elemlen = pos[1]; |
| 214 | if (elemlen > len) |
| 215 | return false; |
| 216 | |
| 217 | len -= elemlen; |
| 218 | pos += 2 + elemlen; |
| 219 | } |
| 220 | |
| 221 | return true; |
| 222 | } |
| 223 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 224 | /* message building helper */ |
| 225 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 226 | int flags, u8 cmd) |
| 227 | { |
| 228 | /* since there is no private header just add the generic one */ |
| 229 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 230 | } |
| 231 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 232 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 233 | struct ieee80211_channel *chan) |
| 234 | { |
| 235 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 236 | chan->center_freq); |
| 237 | |
| 238 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 239 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 240 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 241 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 242 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 243 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 244 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 245 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 246 | |
| 247 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 248 | DBM_TO_MBM(chan->max_power)); |
| 249 | |
| 250 | return 0; |
| 251 | |
| 252 | nla_put_failure: |
| 253 | return -ENOBUFS; |
| 254 | } |
| 255 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 256 | /* netlink command implementations */ |
| 257 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 258 | struct key_parse { |
| 259 | struct key_params p; |
| 260 | int idx; |
| 261 | bool def, defmgmt; |
| 262 | }; |
| 263 | |
| 264 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 265 | { |
| 266 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 267 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 268 | nl80211_key_policy); |
| 269 | if (err) |
| 270 | return err; |
| 271 | |
| 272 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 273 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 274 | |
| 275 | if (tb[NL80211_KEY_IDX]) |
| 276 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 277 | |
| 278 | if (tb[NL80211_KEY_DATA]) { |
| 279 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 280 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 281 | } |
| 282 | |
| 283 | if (tb[NL80211_KEY_SEQ]) { |
| 284 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 285 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 286 | } |
| 287 | |
| 288 | if (tb[NL80211_KEY_CIPHER]) |
| 289 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 295 | { |
| 296 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 297 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 298 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 299 | } |
| 300 | |
| 301 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 302 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 303 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 304 | } |
| 305 | |
| 306 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 307 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 308 | |
| 309 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 310 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 311 | |
| 312 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 313 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 319 | { |
| 320 | int err; |
| 321 | |
| 322 | memset(k, 0, sizeof(*k)); |
| 323 | k->idx = -1; |
| 324 | |
| 325 | if (info->attrs[NL80211_ATTR_KEY]) |
| 326 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 327 | else |
| 328 | err = nl80211_parse_key_old(info, k); |
| 329 | |
| 330 | if (err) |
| 331 | return err; |
| 332 | |
| 333 | if (k->def && k->defmgmt) |
| 334 | return -EINVAL; |
| 335 | |
| 336 | if (k->idx != -1) { |
| 337 | if (k->defmgmt) { |
| 338 | if (k->idx < 4 || k->idx > 5) |
| 339 | return -EINVAL; |
| 340 | } else if (k->def) { |
| 341 | if (k->idx < 0 || k->idx > 3) |
| 342 | return -EINVAL; |
| 343 | } else { |
| 344 | if (k->idx < 0 || k->idx > 5) |
| 345 | return -EINVAL; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 352 | static struct cfg80211_cached_keys * |
| 353 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 354 | struct nlattr *keys) |
| 355 | { |
| 356 | struct key_parse parse; |
| 357 | struct nlattr *key; |
| 358 | struct cfg80211_cached_keys *result; |
| 359 | int rem, err, def = 0; |
| 360 | |
| 361 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 362 | if (!result) |
| 363 | return ERR_PTR(-ENOMEM); |
| 364 | |
| 365 | result->def = -1; |
| 366 | result->defmgmt = -1; |
| 367 | |
| 368 | nla_for_each_nested(key, keys, rem) { |
| 369 | memset(&parse, 0, sizeof(parse)); |
| 370 | parse.idx = -1; |
| 371 | |
| 372 | err = nl80211_parse_key_new(key, &parse); |
| 373 | if (err) |
| 374 | goto error; |
| 375 | err = -EINVAL; |
| 376 | if (!parse.p.key) |
| 377 | goto error; |
| 378 | if (parse.idx < 0 || parse.idx > 4) |
| 379 | goto error; |
| 380 | if (parse.def) { |
| 381 | if (def) |
| 382 | goto error; |
| 383 | def = 1; |
| 384 | result->def = parse.idx; |
| 385 | } else if (parse.defmgmt) |
| 386 | goto error; |
| 387 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
| 388 | parse.idx, NULL); |
| 389 | if (err) |
| 390 | goto error; |
| 391 | result->params[parse.idx].cipher = parse.p.cipher; |
| 392 | result->params[parse.idx].key_len = parse.p.key_len; |
| 393 | result->params[parse.idx].key = result->data[parse.idx]; |
| 394 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 395 | } |
| 396 | |
| 397 | return result; |
| 398 | error: |
| 399 | kfree(result); |
| 400 | return ERR_PTR(err); |
| 401 | } |
| 402 | |
| 403 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 404 | { |
| 405 | ASSERT_WDEV_LOCK(wdev); |
| 406 | |
| 407 | if (!netif_running(wdev->netdev)) |
| 408 | return -ENETDOWN; |
| 409 | |
| 410 | switch (wdev->iftype) { |
| 411 | case NL80211_IFTYPE_AP: |
| 412 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 413 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 414 | break; |
| 415 | case NL80211_IFTYPE_ADHOC: |
| 416 | if (!wdev->current_bss) |
| 417 | return -ENOLINK; |
| 418 | break; |
| 419 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 420 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 421 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 422 | return -ENOLINK; |
| 423 | break; |
| 424 | default: |
| 425 | return -EINVAL; |
| 426 | } |
| 427 | |
| 428 | return 0; |
| 429 | } |
| 430 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 431 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 432 | struct cfg80211_registered_device *dev) |
| 433 | { |
| 434 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 435 | struct nlattr *nl_bands, *nl_band; |
| 436 | struct nlattr *nl_freqs, *nl_freq; |
| 437 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 438 | struct nlattr *nl_modes; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 439 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 440 | enum ieee80211_band band; |
| 441 | struct ieee80211_channel *chan; |
| 442 | struct ieee80211_rate *rate; |
| 443 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 444 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 445 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 446 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 447 | |
| 448 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 449 | if (!hdr) |
| 450 | return -1; |
| 451 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 452 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 453 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 454 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 455 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 456 | cfg80211_rdev_list_generation); |
| 457 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 458 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 459 | dev->wiphy.retry_short); |
| 460 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 461 | dev->wiphy.retry_long); |
| 462 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 463 | dev->wiphy.frag_threshold); |
| 464 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 465 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 466 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 467 | dev->wiphy.coverage_class); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 468 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 469 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 470 | dev->wiphy.max_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 471 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 472 | dev->wiphy.max_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 473 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 474 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 475 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 476 | dev->wiphy.cipher_suites); |
| 477 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 478 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 479 | dev->wiphy.max_num_pmkids); |
| 480 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 481 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 482 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 483 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 484 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 485 | if (!nl_modes) |
| 486 | goto nla_put_failure; |
| 487 | |
| 488 | i = 0; |
| 489 | while (ifmodes) { |
| 490 | if (ifmodes & 1) |
| 491 | NLA_PUT_FLAG(msg, i); |
| 492 | ifmodes >>= 1; |
| 493 | i++; |
| 494 | } |
| 495 | |
| 496 | nla_nest_end(msg, nl_modes); |
| 497 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 498 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 499 | if (!nl_bands) |
| 500 | goto nla_put_failure; |
| 501 | |
| 502 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 503 | if (!dev->wiphy.bands[band]) |
| 504 | continue; |
| 505 | |
| 506 | nl_band = nla_nest_start(msg, band); |
| 507 | if (!nl_band) |
| 508 | goto nla_put_failure; |
| 509 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 510 | /* add HT info */ |
| 511 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 512 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 513 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 514 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 515 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 516 | dev->wiphy.bands[band]->ht_cap.cap); |
| 517 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 518 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 519 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 520 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 521 | } |
| 522 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 523 | /* add frequencies */ |
| 524 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 525 | if (!nl_freqs) |
| 526 | goto nla_put_failure; |
| 527 | |
| 528 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 529 | nl_freq = nla_nest_start(msg, i); |
| 530 | if (!nl_freq) |
| 531 | goto nla_put_failure; |
| 532 | |
| 533 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 534 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 535 | if (nl80211_msg_put_channel(msg, chan)) |
| 536 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 537 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 538 | nla_nest_end(msg, nl_freq); |
| 539 | } |
| 540 | |
| 541 | nla_nest_end(msg, nl_freqs); |
| 542 | |
| 543 | /* add bitrates */ |
| 544 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 545 | if (!nl_rates) |
| 546 | goto nla_put_failure; |
| 547 | |
| 548 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 549 | nl_rate = nla_nest_start(msg, i); |
| 550 | if (!nl_rate) |
| 551 | goto nla_put_failure; |
| 552 | |
| 553 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 554 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 555 | rate->bitrate); |
| 556 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 557 | NLA_PUT_FLAG(msg, |
| 558 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 559 | |
| 560 | nla_nest_end(msg, nl_rate); |
| 561 | } |
| 562 | |
| 563 | nla_nest_end(msg, nl_rates); |
| 564 | |
| 565 | nla_nest_end(msg, nl_band); |
| 566 | } |
| 567 | nla_nest_end(msg, nl_bands); |
| 568 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 569 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 570 | if (!nl_cmds) |
| 571 | goto nla_put_failure; |
| 572 | |
| 573 | i = 0; |
| 574 | #define CMD(op, n) \ |
| 575 | do { \ |
| 576 | if (dev->ops->op) { \ |
| 577 | i++; \ |
| 578 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 579 | } \ |
| 580 | } while (0) |
| 581 | |
| 582 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 583 | CMD(change_virtual_intf, SET_INTERFACE); |
| 584 | CMD(add_key, NEW_KEY); |
| 585 | CMD(add_beacon, NEW_BEACON); |
| 586 | CMD(add_station, NEW_STATION); |
| 587 | CMD(add_mpath, NEW_MPATH); |
| 588 | CMD(set_mesh_params, SET_MESH_PARAMS); |
| 589 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 590 | CMD(auth, AUTHENTICATE); |
| 591 | CMD(assoc, ASSOCIATE); |
| 592 | CMD(deauth, DEAUTHENTICATE); |
| 593 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 594 | CMD(join_ibss, JOIN_IBSS); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 595 | CMD(set_pmksa, SET_PMKSA); |
| 596 | CMD(del_pmksa, DEL_PMKSA); |
| 597 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 598 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 599 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 600 | CMD(mgmt_tx, FRAME); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 601 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 602 | i++; |
| 603 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 604 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 605 | CMD(set_channel, SET_CHANNEL); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 606 | |
| 607 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 608 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 609 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 610 | i++; |
| 611 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 612 | } |
| 613 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 614 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 615 | i++; |
| 616 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 617 | } |
| 618 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 619 | nla_nest_end(msg, nl_cmds); |
| 620 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 621 | if (mgmt_stypes) { |
| 622 | u16 stypes; |
| 623 | struct nlattr *nl_ftypes, *nl_ifs; |
| 624 | enum nl80211_iftype ift; |
| 625 | |
| 626 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 627 | if (!nl_ifs) |
| 628 | goto nla_put_failure; |
| 629 | |
| 630 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 631 | nl_ftypes = nla_nest_start(msg, ift); |
| 632 | if (!nl_ftypes) |
| 633 | goto nla_put_failure; |
| 634 | i = 0; |
| 635 | stypes = mgmt_stypes[ift].tx; |
| 636 | while (stypes) { |
| 637 | if (stypes & 1) |
| 638 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 639 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 640 | stypes >>= 1; |
| 641 | i++; |
| 642 | } |
| 643 | nla_nest_end(msg, nl_ftypes); |
| 644 | } |
| 645 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 646 | nla_nest_end(msg, nl_ifs); |
| 647 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 648 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 649 | if (!nl_ifs) |
| 650 | goto nla_put_failure; |
| 651 | |
| 652 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 653 | nl_ftypes = nla_nest_start(msg, ift); |
| 654 | if (!nl_ftypes) |
| 655 | goto nla_put_failure; |
| 656 | i = 0; |
| 657 | stypes = mgmt_stypes[ift].rx; |
| 658 | while (stypes) { |
| 659 | if (stypes & 1) |
| 660 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 661 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 662 | stypes >>= 1; |
| 663 | i++; |
| 664 | } |
| 665 | nla_nest_end(msg, nl_ftypes); |
| 666 | } |
| 667 | nla_nest_end(msg, nl_ifs); |
| 668 | } |
| 669 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 670 | return genlmsg_end(msg, hdr); |
| 671 | |
| 672 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 673 | genlmsg_cancel(msg, hdr); |
| 674 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 678 | { |
| 679 | int idx = 0; |
| 680 | int start = cb->args[0]; |
| 681 | struct cfg80211_registered_device *dev; |
| 682 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 683 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 684 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 685 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 686 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 687 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 688 | continue; |
| 689 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 690 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 691 | dev) < 0) { |
| 692 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 693 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 694 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 695 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 696 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 697 | |
| 698 | cb->args[0] = idx; |
| 699 | |
| 700 | return skb->len; |
| 701 | } |
| 702 | |
| 703 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 704 | { |
| 705 | struct sk_buff *msg; |
| 706 | struct cfg80211_registered_device *dev; |
| 707 | |
| 708 | dev = cfg80211_get_dev_from_info(info); |
| 709 | if (IS_ERR(dev)) |
| 710 | return PTR_ERR(dev); |
| 711 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 712 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 713 | if (!msg) |
| 714 | goto out_err; |
| 715 | |
| 716 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) |
| 717 | goto out_free; |
| 718 | |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 719 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 720 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 721 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 722 | |
| 723 | out_free: |
| 724 | nlmsg_free(msg); |
| 725 | out_err: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 726 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 727 | return -ENOBUFS; |
| 728 | } |
| 729 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 730 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 731 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 732 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 733 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 734 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 735 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 736 | }; |
| 737 | |
| 738 | static int parse_txq_params(struct nlattr *tb[], |
| 739 | struct ieee80211_txq_params *txq_params) |
| 740 | { |
| 741 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 742 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 743 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 744 | return -EINVAL; |
| 745 | |
| 746 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 747 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 748 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 749 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 750 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 755 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 756 | { |
| 757 | /* |
| 758 | * You can only set the channel explicitly for AP, mesh |
| 759 | * and WDS type interfaces; all others have their channel |
| 760 | * managed via their respective "establish a connection" |
| 761 | * command (connect, join, ...) |
| 762 | * |
| 763 | * Monitors are special as they are normally slaved to |
| 764 | * whatever else is going on, so they behave as though |
| 765 | * you tried setting the wiphy channel itself. |
| 766 | */ |
| 767 | return !wdev || |
| 768 | wdev->iftype == NL80211_IFTYPE_AP || |
| 769 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 770 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 771 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 772 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 776 | struct wireless_dev *wdev, |
| 777 | struct genl_info *info) |
| 778 | { |
| 779 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 780 | u32 freq; |
| 781 | int result; |
| 782 | |
| 783 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 784 | return -EINVAL; |
| 785 | |
| 786 | if (!nl80211_can_set_dev_channel(wdev)) |
| 787 | return -EOPNOTSUPP; |
| 788 | |
| 789 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 790 | channel_type = nla_get_u32(info->attrs[ |
| 791 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 792 | if (channel_type != NL80211_CHAN_NO_HT && |
| 793 | channel_type != NL80211_CHAN_HT20 && |
| 794 | channel_type != NL80211_CHAN_HT40PLUS && |
| 795 | channel_type != NL80211_CHAN_HT40MINUS) |
| 796 | return -EINVAL; |
| 797 | } |
| 798 | |
| 799 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 800 | |
| 801 | mutex_lock(&rdev->devlist_mtx); |
| 802 | if (wdev) { |
| 803 | wdev_lock(wdev); |
| 804 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 805 | wdev_unlock(wdev); |
| 806 | } else { |
| 807 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 808 | } |
| 809 | mutex_unlock(&rdev->devlist_mtx); |
| 810 | |
| 811 | return result; |
| 812 | } |
| 813 | |
| 814 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 815 | { |
| 816 | struct cfg80211_registered_device *rdev; |
| 817 | struct net_device *netdev; |
| 818 | int result; |
| 819 | |
| 820 | rtnl_lock(); |
| 821 | |
| 822 | result = get_rdev_dev_by_info_ifindex(info, &rdev, &netdev); |
| 823 | if (result) |
| 824 | goto unlock; |
| 825 | |
| 826 | result = __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
| 827 | |
| 828 | unlock: |
| 829 | rtnl_unlock(); |
| 830 | |
| 831 | return result; |
| 832 | } |
| 833 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 834 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 835 | { |
| 836 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 837 | struct net_device *netdev = NULL; |
| 838 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 839 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 840 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 841 | u32 changed; |
| 842 | u8 retry_short = 0, retry_long = 0; |
| 843 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 844 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 845 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 846 | rtnl_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 847 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 848 | /* |
| 849 | * Try to find the wiphy and netdev. Normally this |
| 850 | * function shouldn't need the netdev, but this is |
| 851 | * done for backward compatibility -- previously |
| 852 | * setting the channel was done per wiphy, but now |
| 853 | * it is per netdev. Previous userland like hostapd |
| 854 | * also passed a netdev to set_wiphy, so that it is |
| 855 | * possible to let that go to the right netdev! |
| 856 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 857 | mutex_lock(&cfg80211_mutex); |
| 858 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 859 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 860 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 861 | |
| 862 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 863 | if (netdev && netdev->ieee80211_ptr) { |
| 864 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 865 | mutex_lock(&rdev->mtx); |
| 866 | } else |
| 867 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 868 | } |
| 869 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 870 | if (!netdev) { |
| 871 | rdev = __cfg80211_rdev_from_info(info); |
| 872 | if (IS_ERR(rdev)) { |
| 873 | mutex_unlock(&cfg80211_mutex); |
| 874 | result = PTR_ERR(rdev); |
| 875 | goto unlock; |
| 876 | } |
| 877 | wdev = NULL; |
| 878 | netdev = NULL; |
| 879 | result = 0; |
| 880 | |
| 881 | mutex_lock(&rdev->mtx); |
| 882 | } else if (netif_running(netdev) && |
| 883 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 884 | wdev = netdev->ieee80211_ptr; |
| 885 | else |
| 886 | wdev = NULL; |
| 887 | |
| 888 | /* |
| 889 | * end workaround code, by now the rdev is available |
| 890 | * and locked, and wdev may or may not be NULL. |
| 891 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 892 | |
| 893 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 894 | result = cfg80211_dev_rename( |
| 895 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 896 | |
| 897 | mutex_unlock(&cfg80211_mutex); |
| 898 | |
| 899 | if (result) |
| 900 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 901 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 902 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 903 | struct ieee80211_txq_params txq_params; |
| 904 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 905 | |
| 906 | if (!rdev->ops->set_txq_params) { |
| 907 | result = -EOPNOTSUPP; |
| 908 | goto bad_res; |
| 909 | } |
| 910 | |
| 911 | nla_for_each_nested(nl_txq_params, |
| 912 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 913 | rem_txq_params) { |
| 914 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 915 | nla_data(nl_txq_params), |
| 916 | nla_len(nl_txq_params), |
| 917 | txq_params_policy); |
| 918 | result = parse_txq_params(tb, &txq_params); |
| 919 | if (result) |
| 920 | goto bad_res; |
| 921 | |
| 922 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 923 | &txq_params); |
| 924 | if (result) |
| 925 | goto bad_res; |
| 926 | } |
| 927 | } |
| 928 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 929 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 930 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 931 | if (result) |
| 932 | goto bad_res; |
| 933 | } |
| 934 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 935 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 936 | enum nl80211_tx_power_setting type; |
| 937 | int idx, mbm = 0; |
| 938 | |
| 939 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 940 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 941 | goto bad_res; |
| 942 | } |
| 943 | |
| 944 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 945 | type = nla_get_u32(info->attrs[idx]); |
| 946 | |
| 947 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 948 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 949 | result = -EINVAL; |
| 950 | goto bad_res; |
| 951 | } |
| 952 | |
| 953 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 954 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 955 | mbm = nla_get_u32(info->attrs[idx]); |
| 956 | } |
| 957 | |
| 958 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 959 | if (result) |
| 960 | goto bad_res; |
| 961 | } |
| 962 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 963 | changed = 0; |
| 964 | |
| 965 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 966 | retry_short = nla_get_u8( |
| 967 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 968 | if (retry_short == 0) { |
| 969 | result = -EINVAL; |
| 970 | goto bad_res; |
| 971 | } |
| 972 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 973 | } |
| 974 | |
| 975 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 976 | retry_long = nla_get_u8( |
| 977 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 978 | if (retry_long == 0) { |
| 979 | result = -EINVAL; |
| 980 | goto bad_res; |
| 981 | } |
| 982 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 983 | } |
| 984 | |
| 985 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 986 | frag_threshold = nla_get_u32( |
| 987 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 988 | if (frag_threshold < 256) { |
| 989 | result = -EINVAL; |
| 990 | goto bad_res; |
| 991 | } |
| 992 | if (frag_threshold != (u32) -1) { |
| 993 | /* |
| 994 | * Fragments (apart from the last one) are required to |
| 995 | * have even length. Make the fragmentation code |
| 996 | * simpler by stripping LSB should someone try to use |
| 997 | * odd threshold value. |
| 998 | */ |
| 999 | frag_threshold &= ~0x1; |
| 1000 | } |
| 1001 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1002 | } |
| 1003 | |
| 1004 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1005 | rts_threshold = nla_get_u32( |
| 1006 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1007 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1008 | } |
| 1009 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1010 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1011 | coverage_class = nla_get_u8( |
| 1012 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1013 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1014 | } |
| 1015 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1016 | if (changed) { |
| 1017 | u8 old_retry_short, old_retry_long; |
| 1018 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1019 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1020 | |
| 1021 | if (!rdev->ops->set_wiphy_params) { |
| 1022 | result = -EOPNOTSUPP; |
| 1023 | goto bad_res; |
| 1024 | } |
| 1025 | |
| 1026 | old_retry_short = rdev->wiphy.retry_short; |
| 1027 | old_retry_long = rdev->wiphy.retry_long; |
| 1028 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1029 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1030 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1031 | |
| 1032 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1033 | rdev->wiphy.retry_short = retry_short; |
| 1034 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1035 | rdev->wiphy.retry_long = retry_long; |
| 1036 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1037 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1038 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1039 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1040 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1041 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1042 | |
| 1043 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1044 | if (result) { |
| 1045 | rdev->wiphy.retry_short = old_retry_short; |
| 1046 | rdev->wiphy.retry_long = old_retry_long; |
| 1047 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1048 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1049 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1050 | } |
| 1051 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1052 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1053 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1054 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1055 | if (netdev) |
| 1056 | dev_put(netdev); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1057 | unlock: |
| 1058 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1059 | return result; |
| 1060 | } |
| 1061 | |
| 1062 | |
| 1063 | 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] | 1064 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1065 | struct net_device *dev) |
| 1066 | { |
| 1067 | void *hdr; |
| 1068 | |
| 1069 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1070 | if (!hdr) |
| 1071 | return -1; |
| 1072 | |
| 1073 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1074 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1075 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1076 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1077 | |
| 1078 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1079 | rdev->devlist_generation ^ |
| 1080 | (cfg80211_rdev_list_generation << 2)); |
| 1081 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1082 | return genlmsg_end(msg, hdr); |
| 1083 | |
| 1084 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1085 | genlmsg_cancel(msg, hdr); |
| 1086 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1090 | { |
| 1091 | int wp_idx = 0; |
| 1092 | int if_idx = 0; |
| 1093 | int wp_start = cb->args[0]; |
| 1094 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1095 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1096 | struct wireless_dev *wdev; |
| 1097 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1098 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1099 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1100 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1101 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1102 | if (wp_idx < wp_start) { |
| 1103 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1104 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1105 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1106 | if_idx = 0; |
| 1107 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1108 | mutex_lock(&rdev->devlist_mtx); |
| 1109 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1110 | if (if_idx < if_start) { |
| 1111 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1112 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1113 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1114 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1115 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1116 | rdev, wdev->netdev) < 0) { |
| 1117 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1118 | goto out; |
| 1119 | } |
| 1120 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1121 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1122 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1123 | |
| 1124 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1125 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1126 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1127 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1128 | |
| 1129 | cb->args[0] = wp_idx; |
| 1130 | cb->args[1] = if_idx; |
| 1131 | |
| 1132 | return skb->len; |
| 1133 | } |
| 1134 | |
| 1135 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1136 | { |
| 1137 | struct sk_buff *msg; |
| 1138 | struct cfg80211_registered_device *dev; |
| 1139 | struct net_device *netdev; |
| 1140 | int err; |
| 1141 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1142 | err = get_rdev_dev_by_info_ifindex(info, &dev, &netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1143 | if (err) |
| 1144 | return err; |
| 1145 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1147 | if (!msg) |
| 1148 | goto out_err; |
| 1149 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1150 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
| 1151 | dev, netdev) < 0) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1152 | goto out_free; |
| 1153 | |
| 1154 | dev_put(netdev); |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 1155 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1156 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1157 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1158 | |
| 1159 | out_free: |
| 1160 | nlmsg_free(msg); |
| 1161 | out_err: |
| 1162 | dev_put(netdev); |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 1163 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1164 | return -ENOBUFS; |
| 1165 | } |
| 1166 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1167 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1168 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1169 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1170 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1171 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1172 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1173 | }; |
| 1174 | |
| 1175 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1176 | { |
| 1177 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1178 | int flag; |
| 1179 | |
| 1180 | *mntrflags = 0; |
| 1181 | |
| 1182 | if (!nla) |
| 1183 | return -EINVAL; |
| 1184 | |
| 1185 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1186 | nla, mntr_flags_policy)) |
| 1187 | return -EINVAL; |
| 1188 | |
| 1189 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1190 | if (flags[flag]) |
| 1191 | *mntrflags |= (1<<flag); |
| 1192 | |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1196 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1197 | struct net_device *netdev, u8 use_4addr, |
| 1198 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1199 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1200 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1201 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1202 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1203 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1204 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1205 | |
| 1206 | switch (iftype) { |
| 1207 | case NL80211_IFTYPE_AP_VLAN: |
| 1208 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1209 | return 0; |
| 1210 | break; |
| 1211 | case NL80211_IFTYPE_STATION: |
| 1212 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1213 | return 0; |
| 1214 | break; |
| 1215 | default: |
| 1216 | break; |
| 1217 | } |
| 1218 | |
| 1219 | return -EOPNOTSUPP; |
| 1220 | } |
| 1221 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1222 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1223 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1224 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1225 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1226 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1227 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1228 | struct net_device *dev; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1229 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1230 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1231 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1232 | memset(¶ms, 0, sizeof(params)); |
| 1233 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1234 | rtnl_lock(); |
| 1235 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1236 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1237 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1238 | goto unlock_rtnl; |
| 1239 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1240 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1241 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1242 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1243 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1244 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1245 | change = true; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1246 | if (ntype > NL80211_IFTYPE_MAX) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1247 | err = -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1248 | goto unlock; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1249 | } |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1250 | } |
| 1251 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1252 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1253 | if (ntype != NL80211_IFTYPE_MESH_POINT) { |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1254 | err = -EINVAL; |
| 1255 | goto unlock; |
| 1256 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1257 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1258 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1259 | change = true; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1260 | } |
| 1261 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1262 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1263 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1264 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1265 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1266 | if (err) |
| 1267 | goto unlock; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1268 | } else { |
| 1269 | params.use_4addr = -1; |
| 1270 | } |
| 1271 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1272 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1273 | if (ntype != NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1274 | err = -EINVAL; |
| 1275 | goto unlock; |
| 1276 | } |
| 1277 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1278 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1279 | if (err) |
| 1280 | goto unlock; |
| 1281 | |
| 1282 | flags = &_flags; |
| 1283 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1284 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1285 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1286 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1287 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1288 | else |
| 1289 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1290 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1291 | if (!err && params.use_4addr != -1) |
| 1292 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1293 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1294 | unlock: |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1295 | dev_put(dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1296 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1297 | unlock_rtnl: |
| 1298 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1299 | return err; |
| 1300 | } |
| 1301 | |
| 1302 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1303 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1304 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1305 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1306 | int err; |
| 1307 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1308 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1309 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1310 | memset(¶ms, 0, sizeof(params)); |
| 1311 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1312 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1313 | return -EINVAL; |
| 1314 | |
| 1315 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1316 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1317 | if (type > NL80211_IFTYPE_MAX) |
| 1318 | return -EINVAL; |
| 1319 | } |
| 1320 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1321 | rtnl_lock(); |
| 1322 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1323 | rdev = cfg80211_get_dev_from_info(info); |
| 1324 | if (IS_ERR(rdev)) { |
| 1325 | err = PTR_ERR(rdev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1326 | goto unlock_rtnl; |
| 1327 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1328 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1329 | if (!rdev->ops->add_virtual_intf || |
| 1330 | !(rdev->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1331 | err = -EOPNOTSUPP; |
| 1332 | goto unlock; |
| 1333 | } |
| 1334 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1335 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1336 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1337 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1338 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1339 | } |
| 1340 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1341 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1342 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1343 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1344 | if (err) |
| 1345 | goto unlock; |
| 1346 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1347 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1348 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1349 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1350 | &flags); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1351 | err = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1352 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1353 | type, err ? NULL : &flags, ¶ms); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1354 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1355 | unlock: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1356 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1357 | unlock_rtnl: |
| 1358 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1359 | return err; |
| 1360 | } |
| 1361 | |
| 1362 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1363 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1364 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1365 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1366 | struct net_device *dev; |
| 1367 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1368 | rtnl_lock(); |
| 1369 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1370 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1371 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1372 | goto unlock_rtnl; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1373 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1374 | if (!rdev->ops->del_virtual_intf) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1375 | err = -EOPNOTSUPP; |
| 1376 | goto out; |
| 1377 | } |
| 1378 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1379 | err = rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1380 | |
| 1381 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1382 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1383 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1384 | unlock_rtnl: |
| 1385 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1386 | return err; |
| 1387 | } |
| 1388 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1389 | struct get_key_cookie { |
| 1390 | struct sk_buff *msg; |
| 1391 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1392 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1393 | }; |
| 1394 | |
| 1395 | static void get_key_callback(void *c, struct key_params *params) |
| 1396 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1397 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1398 | struct get_key_cookie *cookie = c; |
| 1399 | |
| 1400 | if (params->key) |
| 1401 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1402 | params->key_len, params->key); |
| 1403 | |
| 1404 | if (params->seq) |
| 1405 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1406 | params->seq_len, params->seq); |
| 1407 | |
| 1408 | if (params->cipher) |
| 1409 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1410 | params->cipher); |
| 1411 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1412 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1413 | if (!key) |
| 1414 | goto nla_put_failure; |
| 1415 | |
| 1416 | if (params->key) |
| 1417 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1418 | params->key_len, params->key); |
| 1419 | |
| 1420 | if (params->seq) |
| 1421 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1422 | params->seq_len, params->seq); |
| 1423 | |
| 1424 | if (params->cipher) |
| 1425 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1426 | params->cipher); |
| 1427 | |
| 1428 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1429 | |
| 1430 | nla_nest_end(cookie->msg, key); |
| 1431 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1432 | return; |
| 1433 | nla_put_failure: |
| 1434 | cookie->error = 1; |
| 1435 | } |
| 1436 | |
| 1437 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1438 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1439 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1440 | int err; |
| 1441 | struct net_device *dev; |
| 1442 | u8 key_idx = 0; |
| 1443 | u8 *mac_addr = NULL; |
| 1444 | struct get_key_cookie cookie = { |
| 1445 | .error = 0, |
| 1446 | }; |
| 1447 | void *hdr; |
| 1448 | struct sk_buff *msg; |
| 1449 | |
| 1450 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1451 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1452 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1453 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1454 | return -EINVAL; |
| 1455 | |
| 1456 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1457 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1458 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1459 | rtnl_lock(); |
| 1460 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1461 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1462 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1463 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1464 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1465 | if (!rdev->ops->get_key) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1466 | err = -EOPNOTSUPP; |
| 1467 | goto out; |
| 1468 | } |
| 1469 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1470 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1471 | if (!msg) { |
| 1472 | err = -ENOMEM; |
| 1473 | goto out; |
| 1474 | } |
| 1475 | |
| 1476 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1477 | NL80211_CMD_NEW_KEY); |
| 1478 | |
| 1479 | if (IS_ERR(hdr)) { |
| 1480 | err = PTR_ERR(hdr); |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1481 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1485 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1486 | |
| 1487 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1488 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1489 | if (mac_addr) |
| 1490 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1491 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1492 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, mac_addr, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1493 | &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1494 | |
| 1495 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1496 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1497 | |
| 1498 | if (cookie.error) |
| 1499 | goto nla_put_failure; |
| 1500 | |
| 1501 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1502 | err = genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1503 | goto out; |
| 1504 | |
| 1505 | nla_put_failure: |
| 1506 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1507 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1508 | nlmsg_free(msg); |
| 1509 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1510 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1511 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1512 | unlock_rtnl: |
| 1513 | rtnl_unlock(); |
| 1514 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1515 | return err; |
| 1516 | } |
| 1517 | |
| 1518 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1519 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1520 | struct cfg80211_registered_device *rdev; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1521 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1522 | int err; |
| 1523 | struct net_device *dev; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1524 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, |
| 1525 | u8 key_index); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1526 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1527 | err = nl80211_parse_key(info, &key); |
| 1528 | if (err) |
| 1529 | return err; |
| 1530 | |
| 1531 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1532 | return -EINVAL; |
| 1533 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1534 | /* only support setting default key */ |
| 1535 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1536 | return -EINVAL; |
| 1537 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1538 | rtnl_lock(); |
| 1539 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1540 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1541 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1542 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1543 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1544 | if (key.def) |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1545 | func = rdev->ops->set_default_key; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1546 | else |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1547 | func = rdev->ops->set_default_mgmt_key; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1548 | |
| 1549 | if (!func) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1550 | err = -EOPNOTSUPP; |
| 1551 | goto out; |
| 1552 | } |
| 1553 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1554 | wdev_lock(dev->ieee80211_ptr); |
| 1555 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1556 | if (!err) |
| 1557 | err = func(&rdev->wiphy, dev, key.idx); |
| 1558 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1559 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1560 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1561 | if (func == rdev->ops->set_default_key) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1562 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1563 | else |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1564 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1565 | } |
| 1566 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1567 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1568 | |
| 1569 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1570 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1571 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1572 | |
| 1573 | unlock_rtnl: |
| 1574 | rtnl_unlock(); |
| 1575 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1576 | return err; |
| 1577 | } |
| 1578 | |
| 1579 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1580 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1581 | struct cfg80211_registered_device *rdev; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1582 | int err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1583 | struct net_device *dev; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1584 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1585 | u8 *mac_addr = NULL; |
| 1586 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1587 | err = nl80211_parse_key(info, &key); |
| 1588 | if (err) |
| 1589 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1590 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1591 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1592 | return -EINVAL; |
| 1593 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1594 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1595 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1596 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1597 | rtnl_lock(); |
| 1598 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1599 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1600 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1601 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1602 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1603 | if (!rdev->ops->add_key) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1604 | err = -EOPNOTSUPP; |
| 1605 | goto out; |
| 1606 | } |
| 1607 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1608 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, mac_addr)) { |
| 1609 | err = -EINVAL; |
| 1610 | goto out; |
| 1611 | } |
| 1612 | |
| 1613 | wdev_lock(dev->ieee80211_ptr); |
| 1614 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1615 | if (!err) |
| 1616 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
| 1617 | mac_addr, &key.p); |
| 1618 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1619 | |
| 1620 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1621 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1622 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1623 | unlock_rtnl: |
| 1624 | rtnl_unlock(); |
| 1625 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1626 | return err; |
| 1627 | } |
| 1628 | |
| 1629 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1630 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1631 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1632 | int err; |
| 1633 | struct net_device *dev; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1634 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1635 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1636 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1637 | err = nl80211_parse_key(info, &key); |
| 1638 | if (err) |
| 1639 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1640 | |
| 1641 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1642 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1643 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1644 | rtnl_lock(); |
| 1645 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1646 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1647 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1648 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1649 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1650 | if (!rdev->ops->del_key) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1651 | err = -EOPNOTSUPP; |
| 1652 | goto out; |
| 1653 | } |
| 1654 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1655 | wdev_lock(dev->ieee80211_ptr); |
| 1656 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1657 | if (!err) |
| 1658 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1659 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1660 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1661 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1662 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1663 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1664 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1665 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1666 | } |
| 1667 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1668 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1669 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1670 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1671 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1672 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1673 | |
| 1674 | unlock_rtnl: |
| 1675 | rtnl_unlock(); |
| 1676 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1677 | return err; |
| 1678 | } |
| 1679 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1680 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1681 | { |
| 1682 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1683 | struct beacon_parameters *info); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1684 | struct cfg80211_registered_device *rdev; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1685 | int err; |
| 1686 | struct net_device *dev; |
| 1687 | struct beacon_parameters params; |
| 1688 | int haveinfo = 0; |
| 1689 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1690 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1691 | return -EINVAL; |
| 1692 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1693 | rtnl_lock(); |
| 1694 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1695 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1696 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1697 | goto unlock_rtnl; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1698 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 1699 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1700 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1701 | err = -EOPNOTSUPP; |
| 1702 | goto out; |
| 1703 | } |
| 1704 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1705 | switch (info->genlhdr->cmd) { |
| 1706 | case NL80211_CMD_NEW_BEACON: |
| 1707 | /* these are required for NEW_BEACON */ |
| 1708 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 1709 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 1710 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1711 | err = -EINVAL; |
| 1712 | goto out; |
| 1713 | } |
| 1714 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1715 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1716 | break; |
| 1717 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1718 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1719 | break; |
| 1720 | default: |
| 1721 | WARN_ON(1); |
| 1722 | err = -EOPNOTSUPP; |
| 1723 | goto out; |
| 1724 | } |
| 1725 | |
| 1726 | if (!call) { |
| 1727 | err = -EOPNOTSUPP; |
| 1728 | goto out; |
| 1729 | } |
| 1730 | |
| 1731 | memset(¶ms, 0, sizeof(params)); |
| 1732 | |
| 1733 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 1734 | params.interval = |
| 1735 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1736 | haveinfo = 1; |
| 1737 | } |
| 1738 | |
| 1739 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 1740 | params.dtim_period = |
| 1741 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1742 | haveinfo = 1; |
| 1743 | } |
| 1744 | |
| 1745 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1746 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1747 | params.head_len = |
| 1748 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1749 | haveinfo = 1; |
| 1750 | } |
| 1751 | |
| 1752 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 1753 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1754 | params.tail_len = |
| 1755 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1756 | haveinfo = 1; |
| 1757 | } |
| 1758 | |
| 1759 | if (!haveinfo) { |
| 1760 | err = -EINVAL; |
| 1761 | goto out; |
| 1762 | } |
| 1763 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1764 | err = call(&rdev->wiphy, dev, ¶ms); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1765 | |
| 1766 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1767 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1768 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1769 | unlock_rtnl: |
| 1770 | rtnl_unlock(); |
| 1771 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1772 | return err; |
| 1773 | } |
| 1774 | |
| 1775 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1776 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1777 | struct cfg80211_registered_device *rdev; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1778 | int err; |
| 1779 | struct net_device *dev; |
| 1780 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1781 | rtnl_lock(); |
| 1782 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1783 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1784 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1785 | goto unlock_rtnl; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1786 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1787 | if (!rdev->ops->del_beacon) { |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1788 | err = -EOPNOTSUPP; |
| 1789 | goto out; |
| 1790 | } |
| 1791 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 1792 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1793 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1794 | err = -EOPNOTSUPP; |
| 1795 | goto out; |
| 1796 | } |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1797 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1798 | |
| 1799 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1800 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1801 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1802 | unlock_rtnl: |
| 1803 | rtnl_unlock(); |
| 1804 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1805 | return err; |
| 1806 | } |
| 1807 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1808 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 1809 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 1810 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 1811 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 1812 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1813 | }; |
| 1814 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1815 | static int parse_station_flags(struct genl_info *info, |
| 1816 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1817 | { |
| 1818 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1819 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1820 | int flag; |
| 1821 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1822 | /* |
| 1823 | * Try parsing the new attribute first so userspace |
| 1824 | * can specify both for older kernels. |
| 1825 | */ |
| 1826 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 1827 | if (nla) { |
| 1828 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1829 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1830 | sta_flags = nla_data(nla); |
| 1831 | params->sta_flags_mask = sta_flags->mask; |
| 1832 | params->sta_flags_set = sta_flags->set; |
| 1833 | if ((params->sta_flags_mask | |
| 1834 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 1835 | return -EINVAL; |
| 1836 | return 0; |
| 1837 | } |
| 1838 | |
| 1839 | /* if present, parse the old attribute */ |
| 1840 | |
| 1841 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1842 | if (!nla) |
| 1843 | return 0; |
| 1844 | |
| 1845 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 1846 | nla, sta_flags_policy)) |
| 1847 | return -EINVAL; |
| 1848 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1849 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 1850 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1851 | |
| 1852 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 1853 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1854 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1855 | |
| 1856 | return 0; |
| 1857 | } |
| 1858 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1859 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 1860 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 1861 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1862 | { |
| 1863 | void *hdr; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1864 | struct nlattr *sinfoattr, *txrate; |
| 1865 | u16 bitrate; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1866 | |
| 1867 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1868 | if (!hdr) |
| 1869 | return -1; |
| 1870 | |
| 1871 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1872 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1873 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1874 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 1875 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1876 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 1877 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1878 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1879 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 1880 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 1881 | sinfo->inactive_time); |
| 1882 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 1883 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 1884 | sinfo->rx_bytes); |
| 1885 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 1886 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 1887 | sinfo->tx_bytes); |
| 1888 | if (sinfo->filled & STATION_INFO_LLID) |
| 1889 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 1890 | sinfo->llid); |
| 1891 | if (sinfo->filled & STATION_INFO_PLID) |
| 1892 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 1893 | sinfo->plid); |
| 1894 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 1895 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 1896 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1897 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 1898 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 1899 | sinfo->signal); |
| 1900 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
| 1901 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); |
| 1902 | if (!txrate) |
| 1903 | goto nla_put_failure; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1904 | |
John W. Linville | 254416a | 2009-12-09 16:43:52 -0500 | [diff] [blame] | 1905 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 1906 | bitrate = cfg80211_calculate_bitrate(&sinfo->txrate); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1907 | if (bitrate > 0) |
| 1908 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 1909 | |
| 1910 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
| 1911 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, |
| 1912 | sinfo->txrate.mcs); |
| 1913 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 1914 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 1915 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1916 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 1917 | |
| 1918 | nla_nest_end(msg, txrate); |
| 1919 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 1920 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 1921 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 1922 | sinfo->rx_packets); |
| 1923 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 1924 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 1925 | sinfo->tx_packets); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1926 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1927 | |
| 1928 | return genlmsg_end(msg, hdr); |
| 1929 | |
| 1930 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1931 | genlmsg_cancel(msg, hdr); |
| 1932 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1933 | } |
| 1934 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1935 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1936 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1937 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1938 | struct station_info sinfo; |
| 1939 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1940 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1941 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1942 | int ifidx = cb->args[0]; |
| 1943 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1944 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1945 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 1946 | if (!ifidx) |
| 1947 | ifidx = nl80211_get_ifidx(cb); |
| 1948 | if (ifidx < 0) |
| 1949 | return ifidx; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1950 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1951 | rtnl_lock(); |
| 1952 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1953 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1954 | if (!netdev) { |
| 1955 | err = -ENODEV; |
| 1956 | goto out_rtnl; |
| 1957 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1958 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1959 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1960 | if (IS_ERR(dev)) { |
| 1961 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1962 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1966 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1967 | goto out_err; |
| 1968 | } |
| 1969 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1970 | while (1) { |
| 1971 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 1972 | mac_addr, &sinfo); |
| 1973 | if (err == -ENOENT) |
| 1974 | break; |
| 1975 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1976 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1977 | |
| 1978 | if (nl80211_send_station(skb, |
| 1979 | NETLINK_CB(cb->skb).pid, |
| 1980 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1981 | netdev, mac_addr, |
| 1982 | &sinfo) < 0) |
| 1983 | goto out; |
| 1984 | |
| 1985 | sta_idx++; |
| 1986 | } |
| 1987 | |
| 1988 | |
| 1989 | out: |
| 1990 | cb->args[1] = sta_idx; |
| 1991 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1992 | out_err: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 1993 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1994 | out_rtnl: |
| 1995 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1996 | |
| 1997 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1998 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1999 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2000 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2001 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2002 | struct cfg80211_registered_device *rdev; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2003 | int err; |
| 2004 | struct net_device *dev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2005 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2006 | struct sk_buff *msg; |
| 2007 | u8 *mac_addr = NULL; |
| 2008 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2009 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2010 | |
| 2011 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2012 | return -EINVAL; |
| 2013 | |
| 2014 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2015 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2016 | rtnl_lock(); |
| 2017 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2018 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2019 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2020 | goto out_rtnl; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2021 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2022 | if (!rdev->ops->get_station) { |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2023 | err = -EOPNOTSUPP; |
| 2024 | goto out; |
| 2025 | } |
| 2026 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2027 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2028 | if (err) |
| 2029 | goto out; |
| 2030 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2031 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2032 | if (!msg) |
| 2033 | goto out; |
| 2034 | |
| 2035 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2036 | dev, mac_addr, &sinfo) < 0) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2037 | goto out_free; |
| 2038 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2039 | err = genlmsg_reply(msg, info); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2040 | goto out; |
| 2041 | |
| 2042 | out_free: |
| 2043 | nlmsg_free(msg); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2044 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2045 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2046 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2047 | out_rtnl: |
| 2048 | rtnl_unlock(); |
| 2049 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2050 | return err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2054 | * 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] | 2055 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2056 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2057 | struct cfg80211_registered_device *rdev, |
| 2058 | struct net_device **vlan) |
| 2059 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2060 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2061 | *vlan = NULL; |
| 2062 | |
| 2063 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2064 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2065 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2066 | if (!*vlan) |
| 2067 | return -ENODEV; |
| 2068 | if (!(*vlan)->ieee80211_ptr) |
| 2069 | return -EINVAL; |
| 2070 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2071 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2072 | if (!netif_running(*vlan)) |
| 2073 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2074 | } |
| 2075 | return 0; |
| 2076 | } |
| 2077 | |
| 2078 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2079 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2080 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2081 | int err; |
| 2082 | struct net_device *dev; |
| 2083 | struct station_parameters params; |
| 2084 | u8 *mac_addr = NULL; |
| 2085 | |
| 2086 | memset(¶ms, 0, sizeof(params)); |
| 2087 | |
| 2088 | params.listen_interval = -1; |
| 2089 | |
| 2090 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2091 | return -EINVAL; |
| 2092 | |
| 2093 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2094 | return -EINVAL; |
| 2095 | |
| 2096 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2097 | |
| 2098 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2099 | params.supported_rates = |
| 2100 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2101 | params.supported_rates_len = |
| 2102 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2103 | } |
| 2104 | |
| 2105 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2106 | params.listen_interval = |
| 2107 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2108 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2109 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2110 | params.ht_capa = |
| 2111 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2112 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2113 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2114 | return -EINVAL; |
| 2115 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2116 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2117 | params.plink_action = |
| 2118 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2119 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2120 | rtnl_lock(); |
| 2121 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2122 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2123 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2124 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2125 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2126 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2127 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2128 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2129 | |
| 2130 | /* validate settings */ |
| 2131 | err = 0; |
| 2132 | |
| 2133 | switch (dev->ieee80211_ptr->iftype) { |
| 2134 | case NL80211_IFTYPE_AP: |
| 2135 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 2136 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2137 | /* disallow mesh-specific things */ |
| 2138 | if (params.plink_action) |
| 2139 | err = -EINVAL; |
| 2140 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 2141 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2142 | case NL80211_IFTYPE_STATION: |
| 2143 | /* disallow everything but AUTHORIZED flag */ |
| 2144 | if (params.plink_action) |
| 2145 | err = -EINVAL; |
| 2146 | if (params.vlan) |
| 2147 | err = -EINVAL; |
| 2148 | if (params.supported_rates) |
| 2149 | err = -EINVAL; |
| 2150 | if (params.ht_capa) |
| 2151 | err = -EINVAL; |
| 2152 | if (params.listen_interval >= 0) |
| 2153 | err = -EINVAL; |
| 2154 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2155 | err = -EINVAL; |
| 2156 | break; |
| 2157 | case NL80211_IFTYPE_MESH_POINT: |
| 2158 | /* disallow things mesh doesn't support */ |
| 2159 | if (params.vlan) |
| 2160 | err = -EINVAL; |
| 2161 | if (params.ht_capa) |
| 2162 | err = -EINVAL; |
| 2163 | if (params.listen_interval >= 0) |
| 2164 | err = -EINVAL; |
| 2165 | if (params.supported_rates) |
| 2166 | err = -EINVAL; |
| 2167 | if (params.sta_flags_mask) |
| 2168 | err = -EINVAL; |
| 2169 | break; |
| 2170 | default: |
| 2171 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2172 | } |
| 2173 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2174 | if (err) |
| 2175 | goto out; |
| 2176 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2177 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2178 | err = -EOPNOTSUPP; |
| 2179 | goto out; |
| 2180 | } |
| 2181 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2182 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2183 | |
| 2184 | out: |
| 2185 | if (params.vlan) |
| 2186 | dev_put(params.vlan); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2187 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2188 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2189 | out_rtnl: |
| 2190 | rtnl_unlock(); |
| 2191 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2192 | return err; |
| 2193 | } |
| 2194 | |
| 2195 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2196 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2197 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2198 | int err; |
| 2199 | struct net_device *dev; |
| 2200 | struct station_parameters params; |
| 2201 | u8 *mac_addr = NULL; |
| 2202 | |
| 2203 | memset(¶ms, 0, sizeof(params)); |
| 2204 | |
| 2205 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2206 | return -EINVAL; |
| 2207 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2208 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2209 | return -EINVAL; |
| 2210 | |
| 2211 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2212 | return -EINVAL; |
| 2213 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2214 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2215 | return -EINVAL; |
| 2216 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2217 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2218 | params.supported_rates = |
| 2219 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2220 | params.supported_rates_len = |
| 2221 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2222 | params.listen_interval = |
| 2223 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2224 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2225 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2226 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2227 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2228 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2229 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2230 | params.ht_capa = |
| 2231 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2232 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2233 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2234 | return -EINVAL; |
| 2235 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2236 | rtnl_lock(); |
| 2237 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2238 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2239 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2240 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2241 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2242 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 2243 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 2244 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2245 | err = -EINVAL; |
| 2246 | goto out; |
| 2247 | } |
| 2248 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2249 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2250 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2251 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2252 | |
| 2253 | /* validate settings */ |
| 2254 | err = 0; |
| 2255 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2256 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2257 | err = -EOPNOTSUPP; |
| 2258 | goto out; |
| 2259 | } |
| 2260 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2261 | if (!netif_running(dev)) { |
| 2262 | err = -ENETDOWN; |
| 2263 | goto out; |
| 2264 | } |
| 2265 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2266 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2267 | |
| 2268 | out: |
| 2269 | if (params.vlan) |
| 2270 | dev_put(params.vlan); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2271 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2272 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2273 | out_rtnl: |
| 2274 | rtnl_unlock(); |
| 2275 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2276 | return err; |
| 2277 | } |
| 2278 | |
| 2279 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2280 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2281 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2282 | int err; |
| 2283 | struct net_device *dev; |
| 2284 | u8 *mac_addr = NULL; |
| 2285 | |
| 2286 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2287 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2288 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2289 | rtnl_lock(); |
| 2290 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2291 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2292 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2293 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2294 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2295 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2296 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 2297 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 2298 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2299 | err = -EINVAL; |
| 2300 | goto out; |
| 2301 | } |
| 2302 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2303 | if (!rdev->ops->del_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2304 | err = -EOPNOTSUPP; |
| 2305 | goto out; |
| 2306 | } |
| 2307 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2308 | err = rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2309 | |
| 2310 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2311 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2312 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2313 | out_rtnl: |
| 2314 | rtnl_unlock(); |
| 2315 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2316 | return err; |
| 2317 | } |
| 2318 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2319 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2320 | int flags, struct net_device *dev, |
| 2321 | u8 *dst, u8 *next_hop, |
| 2322 | struct mpath_info *pinfo) |
| 2323 | { |
| 2324 | void *hdr; |
| 2325 | struct nlattr *pinfoattr; |
| 2326 | |
| 2327 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2328 | if (!hdr) |
| 2329 | return -1; |
| 2330 | |
| 2331 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2332 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2333 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2334 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2335 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2336 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2337 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2338 | if (!pinfoattr) |
| 2339 | goto nla_put_failure; |
| 2340 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2341 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2342 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2343 | if (pinfo->filled & MPATH_INFO_SN) |
| 2344 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2345 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2346 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2347 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2348 | pinfo->metric); |
| 2349 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2350 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2351 | pinfo->exptime); |
| 2352 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2353 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2354 | pinfo->flags); |
| 2355 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2356 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2357 | pinfo->discovery_timeout); |
| 2358 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2359 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2360 | pinfo->discovery_retries); |
| 2361 | |
| 2362 | nla_nest_end(msg, pinfoattr); |
| 2363 | |
| 2364 | return genlmsg_end(msg, hdr); |
| 2365 | |
| 2366 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2367 | genlmsg_cancel(msg, hdr); |
| 2368 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2372 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2373 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2374 | struct mpath_info pinfo; |
| 2375 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2376 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2377 | u8 dst[ETH_ALEN]; |
| 2378 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2379 | int ifidx = cb->args[0]; |
| 2380 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2381 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2382 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 2383 | if (!ifidx) |
| 2384 | ifidx = nl80211_get_ifidx(cb); |
| 2385 | if (ifidx < 0) |
| 2386 | return ifidx; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2387 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2388 | rtnl_lock(); |
| 2389 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2390 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2391 | if (!netdev) { |
| 2392 | err = -ENODEV; |
| 2393 | goto out_rtnl; |
| 2394 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2395 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2396 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2397 | if (IS_ERR(dev)) { |
| 2398 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2399 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2403 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2404 | goto out_err; |
| 2405 | } |
| 2406 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2407 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2408 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2409 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2410 | } |
| 2411 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2412 | while (1) { |
| 2413 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2414 | dst, next_hop, &pinfo); |
| 2415 | if (err == -ENOENT) |
| 2416 | break; |
| 2417 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2418 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2419 | |
| 2420 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2421 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2422 | netdev, dst, next_hop, |
| 2423 | &pinfo) < 0) |
| 2424 | goto out; |
| 2425 | |
| 2426 | path_idx++; |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | out: |
| 2431 | cb->args[1] = path_idx; |
| 2432 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2433 | out_err: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 2434 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2435 | out_rtnl: |
| 2436 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2437 | |
| 2438 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2442 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2443 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2444 | int err; |
| 2445 | struct net_device *dev; |
| 2446 | struct mpath_info pinfo; |
| 2447 | struct sk_buff *msg; |
| 2448 | u8 *dst = NULL; |
| 2449 | u8 next_hop[ETH_ALEN]; |
| 2450 | |
| 2451 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2452 | |
| 2453 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2454 | return -EINVAL; |
| 2455 | |
| 2456 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2457 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2458 | rtnl_lock(); |
| 2459 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2460 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2461 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2462 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2463 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2464 | if (!rdev->ops->get_mpath) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2465 | err = -EOPNOTSUPP; |
| 2466 | goto out; |
| 2467 | } |
| 2468 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2469 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2470 | err = -EOPNOTSUPP; |
| 2471 | goto out; |
| 2472 | } |
| 2473 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2474 | 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] | 2475 | if (err) |
| 2476 | goto out; |
| 2477 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2479 | if (!msg) |
| 2480 | goto out; |
| 2481 | |
| 2482 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
| 2483 | dev, dst, next_hop, &pinfo) < 0) |
| 2484 | goto out_free; |
| 2485 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2486 | err = genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2487 | goto out; |
| 2488 | |
| 2489 | out_free: |
| 2490 | nlmsg_free(msg); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2491 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2492 | cfg80211_unlock_rdev(rdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2493 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2494 | out_rtnl: |
| 2495 | rtnl_unlock(); |
| 2496 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2497 | return err; |
| 2498 | } |
| 2499 | |
| 2500 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2501 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2502 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2503 | int err; |
| 2504 | struct net_device *dev; |
| 2505 | u8 *dst = NULL; |
| 2506 | u8 *next_hop = NULL; |
| 2507 | |
| 2508 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2509 | return -EINVAL; |
| 2510 | |
| 2511 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2512 | return -EINVAL; |
| 2513 | |
| 2514 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2515 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2516 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2517 | rtnl_lock(); |
| 2518 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2519 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2520 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2521 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2522 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2523 | if (!rdev->ops->change_mpath) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2524 | err = -EOPNOTSUPP; |
| 2525 | goto out; |
| 2526 | } |
| 2527 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2528 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2529 | err = -EOPNOTSUPP; |
| 2530 | goto out; |
| 2531 | } |
| 2532 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2533 | if (!netif_running(dev)) { |
| 2534 | err = -ENETDOWN; |
| 2535 | goto out; |
| 2536 | } |
| 2537 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2538 | err = rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2539 | |
| 2540 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2541 | cfg80211_unlock_rdev(rdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2542 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2543 | out_rtnl: |
| 2544 | rtnl_unlock(); |
| 2545 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2546 | return err; |
| 2547 | } |
| 2548 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2549 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2550 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2551 | int err; |
| 2552 | struct net_device *dev; |
| 2553 | u8 *dst = NULL; |
| 2554 | u8 *next_hop = NULL; |
| 2555 | |
| 2556 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2557 | return -EINVAL; |
| 2558 | |
| 2559 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2560 | return -EINVAL; |
| 2561 | |
| 2562 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2563 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2564 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2565 | rtnl_lock(); |
| 2566 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2567 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2568 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2569 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2570 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2571 | if (!rdev->ops->add_mpath) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2572 | err = -EOPNOTSUPP; |
| 2573 | goto out; |
| 2574 | } |
| 2575 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2576 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2577 | err = -EOPNOTSUPP; |
| 2578 | goto out; |
| 2579 | } |
| 2580 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2581 | if (!netif_running(dev)) { |
| 2582 | err = -ENETDOWN; |
| 2583 | goto out; |
| 2584 | } |
| 2585 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2586 | err = rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2587 | |
| 2588 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2589 | cfg80211_unlock_rdev(rdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2590 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2591 | out_rtnl: |
| 2592 | rtnl_unlock(); |
| 2593 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2594 | return err; |
| 2595 | } |
| 2596 | |
| 2597 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2598 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2599 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2600 | int err; |
| 2601 | struct net_device *dev; |
| 2602 | u8 *dst = NULL; |
| 2603 | |
| 2604 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2605 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2606 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2607 | rtnl_lock(); |
| 2608 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2609 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2610 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2611 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2612 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2613 | if (!rdev->ops->del_mpath) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2614 | err = -EOPNOTSUPP; |
| 2615 | goto out; |
| 2616 | } |
| 2617 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2618 | err = rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2619 | |
| 2620 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2621 | cfg80211_unlock_rdev(rdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2622 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2623 | out_rtnl: |
| 2624 | rtnl_unlock(); |
| 2625 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2626 | return err; |
| 2627 | } |
| 2628 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2629 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2630 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2631 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2632 | int err; |
| 2633 | struct net_device *dev; |
| 2634 | struct bss_parameters params; |
| 2635 | |
| 2636 | memset(¶ms, 0, sizeof(params)); |
| 2637 | /* default to not changing parameters */ |
| 2638 | params.use_cts_prot = -1; |
| 2639 | params.use_short_preamble = -1; |
| 2640 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2641 | params.ap_isolate = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2642 | |
| 2643 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2644 | params.use_cts_prot = |
| 2645 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2646 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2647 | params.use_short_preamble = |
| 2648 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2649 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2650 | params.use_short_slot_time = |
| 2651 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2652 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2653 | params.basic_rates = |
| 2654 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2655 | params.basic_rates_len = |
| 2656 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2657 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2658 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2659 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2660 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2661 | rtnl_lock(); |
| 2662 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2663 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2664 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2665 | goto out_rtnl; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2666 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2667 | if (!rdev->ops->change_bss) { |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2668 | err = -EOPNOTSUPP; |
| 2669 | goto out; |
| 2670 | } |
| 2671 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 2672 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2673 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2674 | err = -EOPNOTSUPP; |
| 2675 | goto out; |
| 2676 | } |
| 2677 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2678 | err = rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2679 | |
| 2680 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2681 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2682 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2683 | out_rtnl: |
| 2684 | rtnl_unlock(); |
| 2685 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2686 | return err; |
| 2687 | } |
| 2688 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2689 | 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] | 2690 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2691 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2692 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2693 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2694 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2695 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2696 | }; |
| 2697 | |
| 2698 | static int parse_reg_rule(struct nlattr *tb[], |
| 2699 | struct ieee80211_reg_rule *reg_rule) |
| 2700 | { |
| 2701 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2702 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2703 | |
| 2704 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2705 | return -EINVAL; |
| 2706 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2707 | return -EINVAL; |
| 2708 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2709 | return -EINVAL; |
| 2710 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2711 | return -EINVAL; |
| 2712 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2713 | return -EINVAL; |
| 2714 | |
| 2715 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2716 | |
| 2717 | freq_range->start_freq_khz = |
| 2718 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2719 | freq_range->end_freq_khz = |
| 2720 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2721 | freq_range->max_bandwidth_khz = |
| 2722 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2723 | |
| 2724 | power_rule->max_eirp = |
| 2725 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2726 | |
| 2727 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2728 | power_rule->max_antenna_gain = |
| 2729 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2730 | |
| 2731 | return 0; |
| 2732 | } |
| 2733 | |
| 2734 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2735 | { |
| 2736 | int r; |
| 2737 | char *data = NULL; |
| 2738 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2739 | /* |
| 2740 | * You should only get this when cfg80211 hasn't yet initialized |
| 2741 | * completely when built-in to the kernel right between the time |
| 2742 | * window between nl80211_init() and regulatory_init(), if that is |
| 2743 | * even possible. |
| 2744 | */ |
| 2745 | mutex_lock(&cfg80211_mutex); |
| 2746 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2747 | mutex_unlock(&cfg80211_mutex); |
| 2748 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2749 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2750 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2751 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2752 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2753 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2754 | |
| 2755 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2756 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2757 | r = regulatory_hint_user(data); |
| 2758 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2759 | return r; |
| 2760 | } |
| 2761 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2762 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
| 2763 | struct genl_info *info) |
| 2764 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2765 | struct cfg80211_registered_device *rdev; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2766 | struct mesh_config cur_params; |
| 2767 | int err; |
| 2768 | struct net_device *dev; |
| 2769 | void *hdr; |
| 2770 | struct nlattr *pinfoattr; |
| 2771 | struct sk_buff *msg; |
| 2772 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2773 | rtnl_lock(); |
| 2774 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2775 | /* Look up our device */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2776 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2777 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2778 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2779 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2780 | if (!rdev->ops->get_mesh_params) { |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2781 | err = -EOPNOTSUPP; |
| 2782 | goto out; |
| 2783 | } |
| 2784 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2785 | /* Get the mesh params */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2786 | err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2787 | if (err) |
| 2788 | goto out; |
| 2789 | |
| 2790 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2791 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2792 | if (!msg) { |
| 2793 | err = -ENOBUFS; |
| 2794 | goto out; |
| 2795 | } |
| 2796 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2797 | NL80211_CMD_GET_MESH_PARAMS); |
| 2798 | if (!hdr) |
| 2799 | goto nla_put_failure; |
| 2800 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); |
| 2801 | if (!pinfoattr) |
| 2802 | goto nla_put_failure; |
| 2803 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2804 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2805 | cur_params.dot11MeshRetryTimeout); |
| 2806 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2807 | cur_params.dot11MeshConfirmTimeout); |
| 2808 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2809 | cur_params.dot11MeshHoldingTimeout); |
| 2810 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2811 | cur_params.dot11MeshMaxPeerLinks); |
| 2812 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2813 | cur_params.dot11MeshMaxRetries); |
| 2814 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2815 | cur_params.dot11MeshTTL); |
| 2816 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2817 | cur_params.auto_open_plinks); |
| 2818 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2819 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2820 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2821 | cur_params.path_refresh_time); |
| 2822 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2823 | cur_params.min_discovery_timeout); |
| 2824 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2825 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2826 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2827 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2828 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2829 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2830 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2831 | cur_params.dot11MeshHWMPRootMode); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2832 | nla_nest_end(msg, pinfoattr); |
| 2833 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2834 | err = genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2835 | goto out; |
| 2836 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2837 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2838 | genlmsg_cancel(msg, hdr); |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 2839 | nlmsg_free(msg); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2840 | err = -EMSGSIZE; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2841 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2842 | /* Cleanup */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2843 | cfg80211_unlock_rdev(rdev); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2844 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2845 | out_rtnl: |
| 2846 | rtnl_unlock(); |
| 2847 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2848 | return err; |
| 2849 | } |
| 2850 | |
| 2851 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2852 | do {\ |
| 2853 | if (table[attr_num]) {\ |
| 2854 | cfg.param = nla_fn(table[attr_num]); \ |
| 2855 | mask |= (1 << (attr_num - 1)); \ |
| 2856 | } \ |
| 2857 | } while (0);\ |
| 2858 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2859 | 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] | 2860 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2861 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2862 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2863 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2864 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2865 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
| 2866 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2867 | |
| 2868 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2869 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2870 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2871 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2872 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2873 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2874 | }; |
| 2875 | |
| 2876 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) |
| 2877 | { |
| 2878 | int err; |
| 2879 | u32 mask; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2880 | struct cfg80211_registered_device *rdev; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2881 | struct net_device *dev; |
| 2882 | struct mesh_config cfg; |
| 2883 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
| 2884 | struct nlattr *parent_attr; |
| 2885 | |
| 2886 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; |
| 2887 | if (!parent_attr) |
| 2888 | return -EINVAL; |
| 2889 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
| 2890 | parent_attr, nl80211_meshconf_params_policy)) |
| 2891 | return -EINVAL; |
| 2892 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2893 | rtnl_lock(); |
| 2894 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2895 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2896 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2897 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2898 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2899 | if (!rdev->ops->set_mesh_params) { |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2900 | err = -EOPNOTSUPP; |
| 2901 | goto out; |
| 2902 | } |
| 2903 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2904 | /* This makes sure that there aren't more than 32 mesh config |
| 2905 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2906 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2907 | |
| 2908 | /* Fill in the params struct */ |
| 2909 | mask = 0; |
| 2910 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2911 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2912 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2913 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2914 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2915 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2916 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2917 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2918 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2919 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2920 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2921 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
| 2922 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2923 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2924 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2925 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2926 | nla_get_u8); |
| 2927 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2928 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2929 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2930 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2931 | nla_get_u16); |
| 2932 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2933 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2934 | nla_get_u32); |
| 2935 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2936 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2937 | nla_get_u16); |
| 2938 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2939 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2940 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2941 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 2942 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2943 | dot11MeshHWMPRootMode, mask, |
| 2944 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 2945 | nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2946 | |
| 2947 | /* Apply changes */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2948 | err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2949 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2950 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2951 | /* cleanup */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2952 | cfg80211_unlock_rdev(rdev); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2953 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2954 | out_rtnl: |
| 2955 | rtnl_unlock(); |
| 2956 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2957 | return err; |
| 2958 | } |
| 2959 | |
| 2960 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2961 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2962 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 2963 | { |
| 2964 | struct sk_buff *msg; |
| 2965 | void *hdr = NULL; |
| 2966 | struct nlattr *nl_reg_rules; |
| 2967 | unsigned int i; |
| 2968 | int err = -EINVAL; |
| 2969 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2970 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2971 | |
| 2972 | if (!cfg80211_regdomain) |
| 2973 | goto out; |
| 2974 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2975 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2976 | if (!msg) { |
| 2977 | err = -ENOBUFS; |
| 2978 | goto out; |
| 2979 | } |
| 2980 | |
| 2981 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2982 | NL80211_CMD_GET_REG); |
| 2983 | if (!hdr) |
| 2984 | goto nla_put_failure; |
| 2985 | |
| 2986 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 2987 | cfg80211_regdomain->alpha2); |
| 2988 | |
| 2989 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 2990 | if (!nl_reg_rules) |
| 2991 | goto nla_put_failure; |
| 2992 | |
| 2993 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 2994 | struct nlattr *nl_reg_rule; |
| 2995 | const struct ieee80211_reg_rule *reg_rule; |
| 2996 | const struct ieee80211_freq_range *freq_range; |
| 2997 | const struct ieee80211_power_rule *power_rule; |
| 2998 | |
| 2999 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3000 | freq_range = ®_rule->freq_range; |
| 3001 | power_rule = ®_rule->power_rule; |
| 3002 | |
| 3003 | nl_reg_rule = nla_nest_start(msg, i); |
| 3004 | if (!nl_reg_rule) |
| 3005 | goto nla_put_failure; |
| 3006 | |
| 3007 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3008 | reg_rule->flags); |
| 3009 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3010 | freq_range->start_freq_khz); |
| 3011 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3012 | freq_range->end_freq_khz); |
| 3013 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3014 | freq_range->max_bandwidth_khz); |
| 3015 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3016 | power_rule->max_antenna_gain); |
| 3017 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3018 | power_rule->max_eirp); |
| 3019 | |
| 3020 | nla_nest_end(msg, nl_reg_rule); |
| 3021 | } |
| 3022 | |
| 3023 | nla_nest_end(msg, nl_reg_rules); |
| 3024 | |
| 3025 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3026 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3027 | goto out; |
| 3028 | |
| 3029 | nla_put_failure: |
| 3030 | genlmsg_cancel(msg, hdr); |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3031 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3032 | err = -EMSGSIZE; |
| 3033 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3034 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3035 | return err; |
| 3036 | } |
| 3037 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3038 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3039 | { |
| 3040 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3041 | struct nlattr *nl_reg_rule; |
| 3042 | char *alpha2 = NULL; |
| 3043 | int rem_reg_rules = 0, r = 0; |
| 3044 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3045 | struct ieee80211_regdomain *rd = NULL; |
| 3046 | |
| 3047 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3048 | return -EINVAL; |
| 3049 | |
| 3050 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3051 | return -EINVAL; |
| 3052 | |
| 3053 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3054 | |
| 3055 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3056 | rem_reg_rules) { |
| 3057 | num_rules++; |
| 3058 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3059 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3062 | mutex_lock(&cfg80211_mutex); |
| 3063 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3064 | if (!reg_is_valid_request(alpha2)) { |
| 3065 | r = -EINVAL; |
| 3066 | goto bad_reg; |
| 3067 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3068 | |
| 3069 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3070 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3071 | |
| 3072 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3073 | if (!rd) { |
| 3074 | r = -ENOMEM; |
| 3075 | goto bad_reg; |
| 3076 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3077 | |
| 3078 | rd->n_reg_rules = num_rules; |
| 3079 | rd->alpha2[0] = alpha2[0]; |
| 3080 | rd->alpha2[1] = alpha2[1]; |
| 3081 | |
| 3082 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3083 | rem_reg_rules) { |
| 3084 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3085 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3086 | reg_rule_policy); |
| 3087 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3088 | if (r) |
| 3089 | goto bad_reg; |
| 3090 | |
| 3091 | rule_idx++; |
| 3092 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3093 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3094 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3095 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3096 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | BUG_ON(rule_idx != num_rules); |
| 3100 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3101 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3102 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3103 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3104 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3105 | return r; |
| 3106 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3107 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3108 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3109 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3110 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3111 | } |
| 3112 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3113 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3114 | { |
| 3115 | struct nlattr *attr1, *attr2; |
| 3116 | int n_channels = 0, tmp1, tmp2; |
| 3117 | |
| 3118 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3119 | n_channels++; |
| 3120 | /* |
| 3121 | * Some hardware has a limited channel list for |
| 3122 | * scanning, and it is pretty much nonsensical |
| 3123 | * to scan for a channel twice, so disallow that |
| 3124 | * and don't require drivers to check that the |
| 3125 | * channel list they get isn't longer than what |
| 3126 | * they can scan, as long as they can scan all |
| 3127 | * the channels they registered at once. |
| 3128 | */ |
| 3129 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3130 | if (attr1 != attr2 && |
| 3131 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3132 | return 0; |
| 3133 | } |
| 3134 | |
| 3135 | return n_channels; |
| 3136 | } |
| 3137 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3138 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3139 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3140 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3141 | struct net_device *dev; |
| 3142 | struct cfg80211_scan_request *request; |
| 3143 | struct cfg80211_ssid *ssid; |
| 3144 | struct ieee80211_channel *channel; |
| 3145 | struct nlattr *attr; |
| 3146 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3147 | int err, tmp, n_ssids = 0, n_channels, i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3148 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3149 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3150 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3151 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3152 | return -EINVAL; |
| 3153 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3154 | rtnl_lock(); |
| 3155 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3156 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3157 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3158 | goto out_rtnl; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3159 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3160 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3161 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3162 | if (!rdev->ops->scan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3163 | err = -EOPNOTSUPP; |
| 3164 | goto out; |
| 3165 | } |
| 3166 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3167 | if (!netif_running(dev)) { |
| 3168 | err = -ENETDOWN; |
| 3169 | goto out; |
| 3170 | } |
| 3171 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3172 | if (rdev->scan_req) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3173 | err = -EBUSY; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3174 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3178 | n_channels = validate_scan_freqs( |
| 3179 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3180 | if (!n_channels) { |
| 3181 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3182 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3183 | } |
| 3184 | } else { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3185 | n_channels = 0; |
| 3186 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3187 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3188 | if (wiphy->bands[band]) |
| 3189 | n_channels += wiphy->bands[band]->n_channels; |
| 3190 | } |
| 3191 | |
| 3192 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3193 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3194 | n_ssids++; |
| 3195 | |
| 3196 | if (n_ssids > wiphy->max_scan_ssids) { |
| 3197 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3198 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3199 | } |
| 3200 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3201 | if (info->attrs[NL80211_ATTR_IE]) |
| 3202 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3203 | else |
| 3204 | ie_len = 0; |
| 3205 | |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3206 | if (ie_len > wiphy->max_scan_ie_len) { |
| 3207 | err = -EINVAL; |
| 3208 | goto out; |
| 3209 | } |
| 3210 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3211 | request = kzalloc(sizeof(*request) |
| 3212 | + sizeof(*ssid) * n_ssids |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3213 | + sizeof(channel) * n_channels |
| 3214 | + ie_len, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3215 | if (!request) { |
| 3216 | err = -ENOMEM; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3217 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3218 | } |
| 3219 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3220 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3221 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3222 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3223 | if (ie_len) { |
| 3224 | if (request->ssids) |
| 3225 | request->ie = (void *)(request->ssids + n_ssids); |
| 3226 | else |
| 3227 | request->ie = (void *)(request->channels + n_channels); |
| 3228 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3229 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3230 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3231 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3232 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3233 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3234 | struct ieee80211_channel *chan; |
| 3235 | |
| 3236 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3237 | |
| 3238 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3239 | err = -EINVAL; |
| 3240 | goto out_free; |
| 3241 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3242 | |
| 3243 | /* ignore disabled channels */ |
| 3244 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3245 | continue; |
| 3246 | |
| 3247 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3248 | i++; |
| 3249 | } |
| 3250 | } else { |
| 3251 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3252 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3253 | int j; |
| 3254 | if (!wiphy->bands[band]) |
| 3255 | continue; |
| 3256 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3257 | struct ieee80211_channel *chan; |
| 3258 | |
| 3259 | chan = &wiphy->bands[band]->channels[j]; |
| 3260 | |
| 3261 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3262 | continue; |
| 3263 | |
| 3264 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3265 | i++; |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3270 | if (!i) { |
| 3271 | err = -EINVAL; |
| 3272 | goto out_free; |
| 3273 | } |
| 3274 | |
| 3275 | request->n_channels = i; |
| 3276 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3277 | i = 0; |
| 3278 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3279 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 3280 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 3281 | err = -EINVAL; |
| 3282 | goto out_free; |
| 3283 | } |
| 3284 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 3285 | request->ssids[i].ssid_len = nla_len(attr); |
| 3286 | i++; |
| 3287 | } |
| 3288 | } |
| 3289 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3290 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3291 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3292 | memcpy((void *)request->ie, |
| 3293 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3294 | request->ie_len); |
| 3295 | } |
| 3296 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3297 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3298 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3299 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3300 | rdev->scan_req = request; |
| 3301 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3302 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3303 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3304 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3305 | dev_hold(dev); |
| 3306 | } |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 3307 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3308 | out_free: |
| 3309 | if (err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3310 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3311 | kfree(request); |
| 3312 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3313 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3314 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3315 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3316 | out_rtnl: |
| 3317 | rtnl_unlock(); |
| 3318 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3319 | return err; |
| 3320 | } |
| 3321 | |
| 3322 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 3323 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3324 | struct wireless_dev *wdev, |
| 3325 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3326 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3327 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3328 | void *hdr; |
| 3329 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3330 | int i; |
| 3331 | |
| 3332 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3333 | |
| 3334 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3335 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3336 | if (!hdr) |
| 3337 | return -1; |
| 3338 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3339 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3340 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3341 | |
| 3342 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3343 | if (!bss) |
| 3344 | goto nla_put_failure; |
| 3345 | if (!is_zero_ether_addr(res->bssid)) |
| 3346 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3347 | if (res->information_elements && res->len_information_elements) |
| 3348 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3349 | res->len_information_elements, |
| 3350 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3351 | if (res->beacon_ies && res->len_beacon_ies && |
| 3352 | res->beacon_ies != res->information_elements) |
| 3353 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3354 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3355 | if (res->tsf) |
| 3356 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3357 | if (res->beacon_interval) |
| 3358 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3359 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3360 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3361 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3362 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3363 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3364 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3365 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3366 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3367 | break; |
| 3368 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3369 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3370 | break; |
| 3371 | default: |
| 3372 | break; |
| 3373 | } |
| 3374 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3375 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 3376 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3377 | case NL80211_IFTYPE_STATION: |
| 3378 | if (intbss == wdev->current_bss) |
| 3379 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3380 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3381 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3382 | if (intbss != wdev->auth_bsses[i]) |
| 3383 | continue; |
| 3384 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3385 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3386 | break; |
| 3387 | } |
| 3388 | break; |
| 3389 | case NL80211_IFTYPE_ADHOC: |
| 3390 | if (intbss == wdev->current_bss) |
| 3391 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3392 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3393 | break; |
| 3394 | default: |
| 3395 | break; |
| 3396 | } |
| 3397 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3398 | nla_nest_end(msg, bss); |
| 3399 | |
| 3400 | return genlmsg_end(msg, hdr); |
| 3401 | |
| 3402 | nla_put_failure: |
| 3403 | genlmsg_cancel(msg, hdr); |
| 3404 | return -EMSGSIZE; |
| 3405 | } |
| 3406 | |
| 3407 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3408 | struct netlink_callback *cb) |
| 3409 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3410 | struct cfg80211_registered_device *rdev; |
| 3411 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3412 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3413 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3414 | int ifidx = cb->args[0]; |
| 3415 | int start = cb->args[1], idx = 0; |
| 3416 | int err; |
| 3417 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 3418 | if (!ifidx) |
| 3419 | ifidx = nl80211_get_ifidx(cb); |
| 3420 | if (ifidx < 0) |
| 3421 | return ifidx; |
| 3422 | cb->args[0] = ifidx; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3423 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3424 | dev = dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3425 | if (!dev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3426 | return -ENODEV; |
| 3427 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3428 | rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3429 | if (IS_ERR(rdev)) { |
| 3430 | err = PTR_ERR(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3431 | goto out_put_netdev; |
| 3432 | } |
| 3433 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3434 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3435 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3436 | wdev_lock(wdev); |
| 3437 | spin_lock_bh(&rdev->bss_lock); |
| 3438 | cfg80211_bss_expire(rdev); |
| 3439 | |
| 3440 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3441 | if (++idx <= start) |
| 3442 | continue; |
| 3443 | if (nl80211_send_bss(skb, |
| 3444 | NETLINK_CB(cb->skb).pid, |
| 3445 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3446 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3447 | idx--; |
| 3448 | goto out; |
| 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | out: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3453 | spin_unlock_bh(&rdev->bss_lock); |
| 3454 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3455 | |
| 3456 | cb->args[1] = idx; |
| 3457 | err = skb->len; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3458 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3459 | out_put_netdev: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3460 | dev_put(dev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3461 | |
| 3462 | return err; |
| 3463 | } |
| 3464 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 3465 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 3466 | int flags, struct net_device *dev, |
| 3467 | struct survey_info *survey) |
| 3468 | { |
| 3469 | void *hdr; |
| 3470 | struct nlattr *infoattr; |
| 3471 | |
| 3472 | /* Survey without a channel doesn't make sense */ |
| 3473 | if (!survey->channel) |
| 3474 | return -EINVAL; |
| 3475 | |
| 3476 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3477 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 3478 | if (!hdr) |
| 3479 | return -ENOMEM; |
| 3480 | |
| 3481 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3482 | |
| 3483 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 3484 | if (!infoattr) |
| 3485 | goto nla_put_failure; |
| 3486 | |
| 3487 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 3488 | survey->channel->center_freq); |
| 3489 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 3490 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 3491 | survey->noise); |
| 3492 | |
| 3493 | nla_nest_end(msg, infoattr); |
| 3494 | |
| 3495 | return genlmsg_end(msg, hdr); |
| 3496 | |
| 3497 | nla_put_failure: |
| 3498 | genlmsg_cancel(msg, hdr); |
| 3499 | return -EMSGSIZE; |
| 3500 | } |
| 3501 | |
| 3502 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 3503 | struct netlink_callback *cb) |
| 3504 | { |
| 3505 | struct survey_info survey; |
| 3506 | struct cfg80211_registered_device *dev; |
| 3507 | struct net_device *netdev; |
| 3508 | int ifidx = cb->args[0]; |
| 3509 | int survey_idx = cb->args[1]; |
| 3510 | int res; |
| 3511 | |
| 3512 | if (!ifidx) |
| 3513 | ifidx = nl80211_get_ifidx(cb); |
| 3514 | if (ifidx < 0) |
| 3515 | return ifidx; |
| 3516 | cb->args[0] = ifidx; |
| 3517 | |
| 3518 | rtnl_lock(); |
| 3519 | |
| 3520 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 3521 | if (!netdev) { |
| 3522 | res = -ENODEV; |
| 3523 | goto out_rtnl; |
| 3524 | } |
| 3525 | |
| 3526 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
| 3527 | if (IS_ERR(dev)) { |
| 3528 | res = PTR_ERR(dev); |
| 3529 | goto out_rtnl; |
| 3530 | } |
| 3531 | |
| 3532 | if (!dev->ops->dump_survey) { |
| 3533 | res = -EOPNOTSUPP; |
| 3534 | goto out_err; |
| 3535 | } |
| 3536 | |
| 3537 | while (1) { |
| 3538 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 3539 | &survey); |
| 3540 | if (res == -ENOENT) |
| 3541 | break; |
| 3542 | if (res) |
| 3543 | goto out_err; |
| 3544 | |
| 3545 | if (nl80211_send_survey(skb, |
| 3546 | NETLINK_CB(cb->skb).pid, |
| 3547 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3548 | netdev, |
| 3549 | &survey) < 0) |
| 3550 | goto out; |
| 3551 | survey_idx++; |
| 3552 | } |
| 3553 | |
| 3554 | out: |
| 3555 | cb->args[1] = survey_idx; |
| 3556 | res = skb->len; |
| 3557 | out_err: |
| 3558 | cfg80211_unlock_rdev(dev); |
| 3559 | out_rtnl: |
| 3560 | rtnl_unlock(); |
| 3561 | |
| 3562 | return res; |
| 3563 | } |
| 3564 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3565 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3566 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3567 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3568 | } |
| 3569 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3570 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3571 | { |
| 3572 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3573 | NL80211_WPA_VERSION_2)); |
| 3574 | } |
| 3575 | |
| 3576 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3577 | { |
| 3578 | return akm == WLAN_AKM_SUITE_8021X || |
| 3579 | akm == WLAN_AKM_SUITE_PSK; |
| 3580 | } |
| 3581 | |
| 3582 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3583 | { |
| 3584 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3585 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3586 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3587 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3588 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3589 | } |
| 3590 | |
| 3591 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3592 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3593 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3594 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3595 | struct net_device *dev; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3596 | struct ieee80211_channel *chan; |
| 3597 | const u8 *bssid, *ssid, *ie = NULL; |
| 3598 | int err, ssid_len, ie_len = 0; |
| 3599 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3600 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3601 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3602 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3603 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3604 | return -EINVAL; |
| 3605 | |
| 3606 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3607 | return -EINVAL; |
| 3608 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3609 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3610 | return -EINVAL; |
| 3611 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3612 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3613 | return -EINVAL; |
| 3614 | |
| 3615 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3616 | return -EINVAL; |
| 3617 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3618 | err = nl80211_parse_key(info, &key); |
| 3619 | if (err) |
| 3620 | return err; |
| 3621 | |
| 3622 | if (key.idx >= 0) { |
| 3623 | if (!key.p.key || !key.p.key_len) |
| 3624 | return -EINVAL; |
| 3625 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3626 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3627 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3628 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3629 | return -EINVAL; |
| 3630 | if (key.idx > 4) |
| 3631 | return -EINVAL; |
| 3632 | } else { |
| 3633 | key.p.key_len = 0; |
| 3634 | key.p.key = NULL; |
| 3635 | } |
| 3636 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3637 | rtnl_lock(); |
| 3638 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3639 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3640 | if (err) |
| 3641 | goto unlock_rtnl; |
| 3642 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 3643 | if (key.idx >= 0) { |
| 3644 | int i; |
| 3645 | bool ok = false; |
| 3646 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 3647 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 3648 | ok = true; |
| 3649 | break; |
| 3650 | } |
| 3651 | } |
| 3652 | if (!ok) { |
| 3653 | err = -EINVAL; |
| 3654 | goto out; |
| 3655 | } |
| 3656 | } |
| 3657 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3658 | if (!rdev->ops->auth) { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3659 | err = -EOPNOTSUPP; |
| 3660 | goto out; |
| 3661 | } |
| 3662 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 3663 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 3664 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3665 | err = -EOPNOTSUPP; |
| 3666 | goto out; |
| 3667 | } |
| 3668 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3669 | if (!netif_running(dev)) { |
| 3670 | err = -ENETDOWN; |
| 3671 | goto out; |
| 3672 | } |
| 3673 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3674 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3675 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3676 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3677 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3678 | err = -EINVAL; |
| 3679 | goto out; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3680 | } |
| 3681 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3682 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3683 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3684 | |
| 3685 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3686 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3687 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3688 | } |
| 3689 | |
| 3690 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 3691 | if (!nl80211_valid_auth_type(auth_type)) { |
| 3692 | err = -EINVAL; |
| 3693 | goto out; |
| 3694 | } |
| 3695 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3696 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3697 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3698 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3699 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3700 | key.p.key, key.p.key_len, key.idx, |
| 3701 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3702 | |
| 3703 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3704 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3705 | dev_put(dev); |
| 3706 | unlock_rtnl: |
| 3707 | rtnl_unlock(); |
| 3708 | return err; |
| 3709 | } |
| 3710 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3711 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 3712 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3713 | struct cfg80211_crypto_settings *settings, |
| 3714 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3715 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 3716 | memset(settings, 0, sizeof(*settings)); |
| 3717 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3718 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 3719 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3720 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 3721 | u16 proto; |
| 3722 | proto = nla_get_u16( |
| 3723 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 3724 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 3725 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 3726 | proto != ETH_P_PAE) |
| 3727 | return -EINVAL; |
| 3728 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 3729 | settings->control_port_no_encrypt = true; |
| 3730 | } else |
| 3731 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 3732 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3733 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 3734 | void *data; |
| 3735 | int len, i; |
| 3736 | |
| 3737 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3738 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3739 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 3740 | |
| 3741 | if (len % sizeof(u32)) |
| 3742 | return -EINVAL; |
| 3743 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3744 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3745 | return -EINVAL; |
| 3746 | |
| 3747 | memcpy(settings->ciphers_pairwise, data, len); |
| 3748 | |
| 3749 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3750 | if (!nl80211_valid_cipher_suite( |
| 3751 | settings->ciphers_pairwise[i])) |
| 3752 | return -EINVAL; |
| 3753 | } |
| 3754 | |
| 3755 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 3756 | settings->cipher_group = |
| 3757 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 3758 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 3759 | return -EINVAL; |
| 3760 | } |
| 3761 | |
| 3762 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 3763 | settings->wpa_versions = |
| 3764 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 3765 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 3766 | return -EINVAL; |
| 3767 | } |
| 3768 | |
| 3769 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 3770 | void *data; |
| 3771 | int len, i; |
| 3772 | |
| 3773 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3774 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3775 | settings->n_akm_suites = len / sizeof(u32); |
| 3776 | |
| 3777 | if (len % sizeof(u32)) |
| 3778 | return -EINVAL; |
| 3779 | |
| 3780 | memcpy(settings->akm_suites, data, len); |
| 3781 | |
| 3782 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3783 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 3784 | return -EINVAL; |
| 3785 | } |
| 3786 | |
| 3787 | return 0; |
| 3788 | } |
| 3789 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3790 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 3791 | { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3792 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3793 | struct net_device *dev; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3794 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3795 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3796 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3797 | int err, ssid_len, ie_len = 0; |
| 3798 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3799 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3800 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3801 | return -EINVAL; |
| 3802 | |
| 3803 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3804 | !info->attrs[NL80211_ATTR_SSID] || |
| 3805 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3806 | return -EINVAL; |
| 3807 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3808 | rtnl_lock(); |
| 3809 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3810 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3811 | if (err) |
| 3812 | goto unlock_rtnl; |
| 3813 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3814 | if (!rdev->ops->assoc) { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3815 | err = -EOPNOTSUPP; |
| 3816 | goto out; |
| 3817 | } |
| 3818 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 3819 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 3820 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3821 | err = -EOPNOTSUPP; |
| 3822 | goto out; |
| 3823 | } |
| 3824 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3825 | if (!netif_running(dev)) { |
| 3826 | err = -ENETDOWN; |
| 3827 | goto out; |
| 3828 | } |
| 3829 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3830 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3831 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3832 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 3833 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3834 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { |
| 3835 | err = -EINVAL; |
| 3836 | goto out; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3837 | } |
| 3838 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3839 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3840 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3841 | |
| 3842 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3843 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3844 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3845 | } |
| 3846 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3847 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3848 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3849 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3850 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3851 | use_mfp = true; |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3852 | else if (mfp != NL80211_MFP_NO) { |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3853 | err = -EINVAL; |
| 3854 | goto out; |
| 3855 | } |
| 3856 | } |
| 3857 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3858 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 3859 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 3860 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 3861 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3862 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3863 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 3864 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3865 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3866 | |
| 3867 | out: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 3868 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3869 | dev_put(dev); |
| 3870 | unlock_rtnl: |
| 3871 | rtnl_unlock(); |
| 3872 | return err; |
| 3873 | } |
| 3874 | |
| 3875 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 3876 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3877 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3878 | struct net_device *dev; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3879 | const u8 *ie = NULL, *bssid; |
| 3880 | int err, ie_len = 0; |
| 3881 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3882 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3883 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3884 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3885 | return -EINVAL; |
| 3886 | |
| 3887 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3888 | return -EINVAL; |
| 3889 | |
| 3890 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3891 | return -EINVAL; |
| 3892 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3893 | rtnl_lock(); |
| 3894 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3895 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3896 | if (err) |
| 3897 | goto unlock_rtnl; |
| 3898 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3899 | if (!rdev->ops->deauth) { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3900 | err = -EOPNOTSUPP; |
| 3901 | goto out; |
| 3902 | } |
| 3903 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 3904 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 3905 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3906 | err = -EOPNOTSUPP; |
| 3907 | goto out; |
| 3908 | } |
| 3909 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3910 | if (!netif_running(dev)) { |
| 3911 | err = -ENETDOWN; |
| 3912 | goto out; |
| 3913 | } |
| 3914 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3915 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3916 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3917 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3918 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3919 | /* Reason Code 0 is reserved */ |
| 3920 | err = -EINVAL; |
| 3921 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3922 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3923 | |
| 3924 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3925 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3926 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3927 | } |
| 3928 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3929 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3930 | |
| 3931 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 3932 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3933 | |
| 3934 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3935 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3936 | dev_put(dev); |
| 3937 | unlock_rtnl: |
| 3938 | rtnl_unlock(); |
| 3939 | return err; |
| 3940 | } |
| 3941 | |
| 3942 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 3943 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3944 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3945 | struct net_device *dev; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3946 | const u8 *ie = NULL, *bssid; |
| 3947 | int err, ie_len = 0; |
| 3948 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3949 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3950 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3951 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3952 | return -EINVAL; |
| 3953 | |
| 3954 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3955 | return -EINVAL; |
| 3956 | |
| 3957 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3958 | return -EINVAL; |
| 3959 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3960 | rtnl_lock(); |
| 3961 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3962 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3963 | if (err) |
| 3964 | goto unlock_rtnl; |
| 3965 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3966 | if (!rdev->ops->disassoc) { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3967 | err = -EOPNOTSUPP; |
| 3968 | goto out; |
| 3969 | } |
| 3970 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 3971 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 3972 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3973 | err = -EOPNOTSUPP; |
| 3974 | goto out; |
| 3975 | } |
| 3976 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3977 | if (!netif_running(dev)) { |
| 3978 | err = -ENETDOWN; |
| 3979 | goto out; |
| 3980 | } |
| 3981 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3982 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3983 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3984 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3985 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3986 | /* Reason Code 0 is reserved */ |
| 3987 | err = -EINVAL; |
| 3988 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3989 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3990 | |
| 3991 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3992 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3993 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3994 | } |
| 3995 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 3996 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 3997 | |
| 3998 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 3999 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4000 | |
| 4001 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4002 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4003 | dev_put(dev); |
| 4004 | unlock_rtnl: |
| 4005 | rtnl_unlock(); |
| 4006 | return err; |
| 4007 | } |
| 4008 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4009 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4010 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4011 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4012 | struct net_device *dev; |
| 4013 | struct cfg80211_ibss_params ibss; |
| 4014 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4015 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4016 | int err; |
| 4017 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4018 | memset(&ibss, 0, sizeof(ibss)); |
| 4019 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4020 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4021 | return -EINVAL; |
| 4022 | |
| 4023 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4024 | !info->attrs[NL80211_ATTR_SSID] || |
| 4025 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4026 | return -EINVAL; |
| 4027 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4028 | ibss.beacon_interval = 100; |
| 4029 | |
| 4030 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4031 | ibss.beacon_interval = |
| 4032 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4033 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4034 | return -EINVAL; |
| 4035 | } |
| 4036 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4037 | rtnl_lock(); |
| 4038 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4039 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4040 | if (err) |
| 4041 | goto unlock_rtnl; |
| 4042 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4043 | if (!rdev->ops->join_ibss) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4044 | err = -EOPNOTSUPP; |
| 4045 | goto out; |
| 4046 | } |
| 4047 | |
| 4048 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { |
| 4049 | err = -EOPNOTSUPP; |
| 4050 | goto out; |
| 4051 | } |
| 4052 | |
| 4053 | if (!netif_running(dev)) { |
| 4054 | err = -ENETDOWN; |
| 4055 | goto out; |
| 4056 | } |
| 4057 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4058 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4059 | |
| 4060 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4061 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4062 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4063 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4064 | |
| 4065 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4066 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4067 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4068 | } |
| 4069 | |
| 4070 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4071 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4072 | if (!ibss.channel || |
| 4073 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
| 4074 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) { |
| 4075 | err = -EINVAL; |
| 4076 | goto out; |
| 4077 | } |
| 4078 | |
| 4079 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4080 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4081 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4082 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4083 | connkeys = nl80211_parse_connkeys(rdev, |
| 4084 | info->attrs[NL80211_ATTR_KEYS]); |
| 4085 | if (IS_ERR(connkeys)) { |
| 4086 | err = PTR_ERR(connkeys); |
| 4087 | connkeys = NULL; |
| 4088 | goto out; |
| 4089 | } |
| 4090 | } |
| 4091 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4092 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4093 | u8 *rates = |
| 4094 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4095 | int n_rates = |
| 4096 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4097 | struct ieee80211_supported_band *sband = |
| 4098 | wiphy->bands[ibss.channel->band]; |
| 4099 | int i, j; |
| 4100 | |
| 4101 | if (n_rates == 0) { |
| 4102 | err = -EINVAL; |
| 4103 | goto out; |
| 4104 | } |
| 4105 | |
| 4106 | for (i = 0; i < n_rates; i++) { |
| 4107 | int rate = (rates[i] & 0x7f) * 5; |
| 4108 | bool found = false; |
| 4109 | |
| 4110 | for (j = 0; j < sband->n_bitrates; j++) { |
| 4111 | if (sband->bitrates[j].bitrate == rate) { |
| 4112 | found = true; |
| 4113 | ibss.basic_rates |= BIT(j); |
| 4114 | break; |
| 4115 | } |
| 4116 | } |
| 4117 | if (!found) { |
| 4118 | err = -EINVAL; |
| 4119 | goto out; |
| 4120 | } |
| 4121 | } |
| 4122 | } else { |
| 4123 | /* |
| 4124 | * If no rates were explicitly configured, |
| 4125 | * use the mandatory rate set for 11b or |
| 4126 | * 11a for maximum compatibility. |
| 4127 | */ |
| 4128 | struct ieee80211_supported_band *sband = |
| 4129 | wiphy->bands[ibss.channel->band]; |
| 4130 | int j; |
| 4131 | u32 flag = ibss.channel->band == IEEE80211_BAND_5GHZ ? |
| 4132 | IEEE80211_RATE_MANDATORY_A : |
| 4133 | IEEE80211_RATE_MANDATORY_B; |
| 4134 | |
| 4135 | for (j = 0; j < sband->n_bitrates; j++) { |
| 4136 | if (sband->bitrates[j].flags & flag) |
| 4137 | ibss.basic_rates |= BIT(j); |
| 4138 | } |
| 4139 | } |
| 4140 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4141 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4142 | |
| 4143 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4144 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4145 | dev_put(dev); |
| 4146 | unlock_rtnl: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4147 | if (err) |
| 4148 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4149 | rtnl_unlock(); |
| 4150 | return err; |
| 4151 | } |
| 4152 | |
| 4153 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4154 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4155 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4156 | struct net_device *dev; |
| 4157 | int err; |
| 4158 | |
| 4159 | rtnl_lock(); |
| 4160 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4161 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4162 | if (err) |
| 4163 | goto unlock_rtnl; |
| 4164 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4165 | if (!rdev->ops->leave_ibss) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4166 | err = -EOPNOTSUPP; |
| 4167 | goto out; |
| 4168 | } |
| 4169 | |
| 4170 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { |
| 4171 | err = -EOPNOTSUPP; |
| 4172 | goto out; |
| 4173 | } |
| 4174 | |
| 4175 | if (!netif_running(dev)) { |
| 4176 | err = -ENETDOWN; |
| 4177 | goto out; |
| 4178 | } |
| 4179 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4180 | err = cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4181 | |
| 4182 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4183 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4184 | dev_put(dev); |
| 4185 | unlock_rtnl: |
| 4186 | rtnl_unlock(); |
| 4187 | return err; |
| 4188 | } |
| 4189 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4190 | #ifdef CONFIG_NL80211_TESTMODE |
| 4191 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4192 | .name = "testmode", |
| 4193 | }; |
| 4194 | |
| 4195 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4196 | { |
| 4197 | struct cfg80211_registered_device *rdev; |
| 4198 | int err; |
| 4199 | |
| 4200 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4201 | return -EINVAL; |
| 4202 | |
| 4203 | rtnl_lock(); |
| 4204 | |
| 4205 | rdev = cfg80211_get_dev_from_info(info); |
| 4206 | if (IS_ERR(rdev)) { |
| 4207 | err = PTR_ERR(rdev); |
| 4208 | goto unlock_rtnl; |
| 4209 | } |
| 4210 | |
| 4211 | err = -EOPNOTSUPP; |
| 4212 | if (rdev->ops->testmode_cmd) { |
| 4213 | rdev->testmode_info = info; |
| 4214 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4215 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4216 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4217 | rdev->testmode_info = NULL; |
| 4218 | } |
| 4219 | |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 4220 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4221 | |
| 4222 | unlock_rtnl: |
| 4223 | rtnl_unlock(); |
| 4224 | return err; |
| 4225 | } |
| 4226 | |
| 4227 | static struct sk_buff * |
| 4228 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4229 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4230 | { |
| 4231 | struct sk_buff *skb; |
| 4232 | void *hdr; |
| 4233 | struct nlattr *data; |
| 4234 | |
| 4235 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4236 | if (!skb) |
| 4237 | return NULL; |
| 4238 | |
| 4239 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4240 | if (!hdr) { |
| 4241 | kfree_skb(skb); |
| 4242 | return NULL; |
| 4243 | } |
| 4244 | |
| 4245 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4246 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4247 | |
| 4248 | ((void **)skb->cb)[0] = rdev; |
| 4249 | ((void **)skb->cb)[1] = hdr; |
| 4250 | ((void **)skb->cb)[2] = data; |
| 4251 | |
| 4252 | return skb; |
| 4253 | |
| 4254 | nla_put_failure: |
| 4255 | kfree_skb(skb); |
| 4256 | return NULL; |
| 4257 | } |
| 4258 | |
| 4259 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4260 | int approxlen) |
| 4261 | { |
| 4262 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4263 | |
| 4264 | if (WARN_ON(!rdev->testmode_info)) |
| 4265 | return NULL; |
| 4266 | |
| 4267 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4268 | rdev->testmode_info->snd_pid, |
| 4269 | rdev->testmode_info->snd_seq, |
| 4270 | GFP_KERNEL); |
| 4271 | } |
| 4272 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4273 | |
| 4274 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4275 | { |
| 4276 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4277 | void *hdr = ((void **)skb->cb)[1]; |
| 4278 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4279 | |
| 4280 | if (WARN_ON(!rdev->testmode_info)) { |
| 4281 | kfree_skb(skb); |
| 4282 | return -EINVAL; |
| 4283 | } |
| 4284 | |
| 4285 | nla_nest_end(skb, data); |
| 4286 | genlmsg_end(skb, hdr); |
| 4287 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4288 | } |
| 4289 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4290 | |
| 4291 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4292 | int approxlen, gfp_t gfp) |
| 4293 | { |
| 4294 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4295 | |
| 4296 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4297 | } |
| 4298 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4299 | |
| 4300 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4301 | { |
| 4302 | void *hdr = ((void **)skb->cb)[1]; |
| 4303 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4304 | |
| 4305 | nla_nest_end(skb, data); |
| 4306 | genlmsg_end(skb, hdr); |
| 4307 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4308 | } |
| 4309 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4310 | #endif |
| 4311 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4312 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4313 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4314 | struct cfg80211_registered_device *rdev; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4315 | struct net_device *dev; |
| 4316 | struct cfg80211_connect_params connect; |
| 4317 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4318 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4319 | int err; |
| 4320 | |
| 4321 | memset(&connect, 0, sizeof(connect)); |
| 4322 | |
| 4323 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4324 | return -EINVAL; |
| 4325 | |
| 4326 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4327 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4328 | return -EINVAL; |
| 4329 | |
| 4330 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4331 | connect.auth_type = |
| 4332 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4333 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4334 | return -EINVAL; |
| 4335 | } else |
| 4336 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4337 | |
| 4338 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4339 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4340 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4341 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4342 | if (err) |
| 4343 | return err; |
| 4344 | rtnl_lock(); |
| 4345 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4346 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4347 | if (err) |
| 4348 | goto unlock_rtnl; |
| 4349 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 4350 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 4351 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4352 | err = -EOPNOTSUPP; |
| 4353 | goto out; |
| 4354 | } |
| 4355 | |
| 4356 | if (!netif_running(dev)) { |
| 4357 | err = -ENETDOWN; |
| 4358 | goto out; |
| 4359 | } |
| 4360 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4361 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4362 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4363 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4364 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4365 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4366 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4367 | |
| 4368 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4369 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4370 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4371 | } |
| 4372 | |
| 4373 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4374 | connect.channel = |
| 4375 | ieee80211_get_channel(wiphy, |
| 4376 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4377 | if (!connect.channel || |
| 4378 | connect.channel->flags & IEEE80211_CHAN_DISABLED) { |
| 4379 | err = -EINVAL; |
| 4380 | goto out; |
| 4381 | } |
| 4382 | } |
| 4383 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4384 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4385 | connkeys = nl80211_parse_connkeys(rdev, |
| 4386 | info->attrs[NL80211_ATTR_KEYS]); |
| 4387 | if (IS_ERR(connkeys)) { |
| 4388 | err = PTR_ERR(connkeys); |
| 4389 | connkeys = NULL; |
| 4390 | goto out; |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4395 | |
| 4396 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4397 | cfg80211_unlock_rdev(rdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4398 | dev_put(dev); |
| 4399 | unlock_rtnl: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4400 | if (err) |
| 4401 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4402 | rtnl_unlock(); |
| 4403 | return err; |
| 4404 | } |
| 4405 | |
| 4406 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4407 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4408 | struct cfg80211_registered_device *rdev; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4409 | struct net_device *dev; |
| 4410 | int err; |
| 4411 | u16 reason; |
| 4412 | |
| 4413 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4414 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4415 | else |
| 4416 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4417 | |
| 4418 | if (reason == 0) |
| 4419 | return -EINVAL; |
| 4420 | |
| 4421 | rtnl_lock(); |
| 4422 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4423 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4424 | if (err) |
| 4425 | goto unlock_rtnl; |
| 4426 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 4427 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 4428 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4429 | err = -EOPNOTSUPP; |
| 4430 | goto out; |
| 4431 | } |
| 4432 | |
| 4433 | if (!netif_running(dev)) { |
| 4434 | err = -ENETDOWN; |
| 4435 | goto out; |
| 4436 | } |
| 4437 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4438 | err = cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4439 | |
| 4440 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4441 | cfg80211_unlock_rdev(rdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4442 | dev_put(dev); |
| 4443 | unlock_rtnl: |
| 4444 | rtnl_unlock(); |
| 4445 | return err; |
| 4446 | } |
| 4447 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4448 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4449 | { |
| 4450 | struct cfg80211_registered_device *rdev; |
| 4451 | struct net *net; |
| 4452 | int err; |
| 4453 | u32 pid; |
| 4454 | |
| 4455 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4456 | return -EINVAL; |
| 4457 | |
| 4458 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4459 | |
| 4460 | rtnl_lock(); |
| 4461 | |
| 4462 | rdev = cfg80211_get_dev_from_info(info); |
| 4463 | if (IS_ERR(rdev)) { |
| 4464 | err = PTR_ERR(rdev); |
Johannes Berg | 8a8e05e | 2009-10-08 21:02:02 +0200 | [diff] [blame] | 4465 | goto out_rtnl; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | net = get_net_ns_by_pid(pid); |
| 4469 | if (IS_ERR(net)) { |
| 4470 | err = PTR_ERR(net); |
| 4471 | goto out; |
| 4472 | } |
| 4473 | |
| 4474 | err = 0; |
| 4475 | |
| 4476 | /* check if anything to do */ |
| 4477 | if (net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4478 | goto out_put_net; |
| 4479 | |
| 4480 | err = cfg80211_switch_netns(rdev, net); |
| 4481 | out_put_net: |
| 4482 | put_net(net); |
| 4483 | out: |
| 4484 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 8a8e05e | 2009-10-08 21:02:02 +0200 | [diff] [blame] | 4485 | out_rtnl: |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4486 | rtnl_unlock(); |
| 4487 | return err; |
| 4488 | } |
| 4489 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4490 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4491 | { |
| 4492 | struct cfg80211_registered_device *rdev; |
| 4493 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4494 | struct cfg80211_pmksa *pmksa) = NULL; |
| 4495 | int err; |
| 4496 | struct net_device *dev; |
| 4497 | struct cfg80211_pmksa pmksa; |
| 4498 | |
| 4499 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4500 | |
| 4501 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4502 | return -EINVAL; |
| 4503 | |
| 4504 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4505 | return -EINVAL; |
| 4506 | |
| 4507 | rtnl_lock(); |
| 4508 | |
| 4509 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4510 | if (err) |
| 4511 | goto out_rtnl; |
| 4512 | |
| 4513 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4514 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4515 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 4516 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 4517 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4518 | err = -EOPNOTSUPP; |
| 4519 | goto out; |
| 4520 | } |
| 4521 | |
| 4522 | switch (info->genlhdr->cmd) { |
| 4523 | case NL80211_CMD_SET_PMKSA: |
| 4524 | rdev_ops = rdev->ops->set_pmksa; |
| 4525 | break; |
| 4526 | case NL80211_CMD_DEL_PMKSA: |
| 4527 | rdev_ops = rdev->ops->del_pmksa; |
| 4528 | break; |
| 4529 | default: |
| 4530 | WARN_ON(1); |
| 4531 | break; |
| 4532 | } |
| 4533 | |
| 4534 | if (!rdev_ops) { |
| 4535 | err = -EOPNOTSUPP; |
| 4536 | goto out; |
| 4537 | } |
| 4538 | |
| 4539 | err = rdev_ops(&rdev->wiphy, dev, &pmksa); |
| 4540 | |
| 4541 | out: |
| 4542 | cfg80211_unlock_rdev(rdev); |
| 4543 | dev_put(dev); |
| 4544 | out_rtnl: |
| 4545 | rtnl_unlock(); |
| 4546 | |
| 4547 | return err; |
| 4548 | } |
| 4549 | |
| 4550 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4551 | { |
| 4552 | struct cfg80211_registered_device *rdev; |
| 4553 | int err; |
| 4554 | struct net_device *dev; |
| 4555 | |
| 4556 | rtnl_lock(); |
| 4557 | |
| 4558 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4559 | if (err) |
| 4560 | goto out_rtnl; |
| 4561 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 4562 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 4563 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4564 | err = -EOPNOTSUPP; |
| 4565 | goto out; |
| 4566 | } |
| 4567 | |
| 4568 | if (!rdev->ops->flush_pmksa) { |
| 4569 | err = -EOPNOTSUPP; |
| 4570 | goto out; |
| 4571 | } |
| 4572 | |
| 4573 | err = rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
| 4574 | |
| 4575 | out: |
| 4576 | cfg80211_unlock_rdev(rdev); |
| 4577 | dev_put(dev); |
| 4578 | out_rtnl: |
| 4579 | rtnl_unlock(); |
| 4580 | |
| 4581 | return err; |
| 4582 | |
| 4583 | } |
| 4584 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4585 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4586 | struct genl_info *info) |
| 4587 | { |
| 4588 | struct cfg80211_registered_device *rdev; |
| 4589 | struct net_device *dev; |
| 4590 | struct ieee80211_channel *chan; |
| 4591 | struct sk_buff *msg; |
| 4592 | void *hdr; |
| 4593 | u64 cookie; |
| 4594 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4595 | u32 freq, duration; |
| 4596 | int err; |
| 4597 | |
| 4598 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4599 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4600 | return -EINVAL; |
| 4601 | |
| 4602 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4603 | |
| 4604 | /* |
| 4605 | * We should be on that channel for at least one jiffie, |
| 4606 | * and more than 5 seconds seems excessive. |
| 4607 | */ |
| 4608 | if (!duration || !msecs_to_jiffies(duration) || duration > 5000) |
| 4609 | return -EINVAL; |
| 4610 | |
| 4611 | rtnl_lock(); |
| 4612 | |
| 4613 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4614 | if (err) |
| 4615 | goto unlock_rtnl; |
| 4616 | |
| 4617 | if (!rdev->ops->remain_on_channel) { |
| 4618 | err = -EOPNOTSUPP; |
| 4619 | goto out; |
| 4620 | } |
| 4621 | |
| 4622 | if (!netif_running(dev)) { |
| 4623 | err = -ENETDOWN; |
| 4624 | goto out; |
| 4625 | } |
| 4626 | |
| 4627 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4628 | channel_type = nla_get_u32( |
| 4629 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4630 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4631 | channel_type != NL80211_CHAN_HT20 && |
| 4632 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 579d753 | 2010-05-18 14:36:34 +0200 | [diff] [blame] | 4633 | channel_type != NL80211_CHAN_HT40MINUS) { |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4634 | err = -EINVAL; |
| 4635 | goto out; |
Johannes Berg | 579d753 | 2010-05-18 14:36:34 +0200 | [diff] [blame] | 4636 | } |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4640 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
| 4641 | if (chan == NULL) { |
| 4642 | err = -EINVAL; |
| 4643 | goto out; |
| 4644 | } |
| 4645 | |
| 4646 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4647 | if (!msg) { |
| 4648 | err = -ENOMEM; |
| 4649 | goto out; |
| 4650 | } |
| 4651 | |
| 4652 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 4653 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 4654 | |
| 4655 | if (IS_ERR(hdr)) { |
| 4656 | err = PTR_ERR(hdr); |
| 4657 | goto free_msg; |
| 4658 | } |
| 4659 | |
| 4660 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 4661 | channel_type, duration, &cookie); |
| 4662 | |
| 4663 | if (err) |
| 4664 | goto free_msg; |
| 4665 | |
| 4666 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4667 | |
| 4668 | genlmsg_end(msg, hdr); |
| 4669 | err = genlmsg_reply(msg, info); |
| 4670 | goto out; |
| 4671 | |
| 4672 | nla_put_failure: |
| 4673 | err = -ENOBUFS; |
| 4674 | free_msg: |
| 4675 | nlmsg_free(msg); |
| 4676 | out: |
| 4677 | cfg80211_unlock_rdev(rdev); |
| 4678 | dev_put(dev); |
| 4679 | unlock_rtnl: |
| 4680 | rtnl_unlock(); |
| 4681 | return err; |
| 4682 | } |
| 4683 | |
| 4684 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 4685 | struct genl_info *info) |
| 4686 | { |
| 4687 | struct cfg80211_registered_device *rdev; |
| 4688 | struct net_device *dev; |
| 4689 | u64 cookie; |
| 4690 | int err; |
| 4691 | |
| 4692 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 4693 | return -EINVAL; |
| 4694 | |
| 4695 | rtnl_lock(); |
| 4696 | |
| 4697 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4698 | if (err) |
| 4699 | goto unlock_rtnl; |
| 4700 | |
| 4701 | if (!rdev->ops->cancel_remain_on_channel) { |
| 4702 | err = -EOPNOTSUPP; |
| 4703 | goto out; |
| 4704 | } |
| 4705 | |
| 4706 | if (!netif_running(dev)) { |
| 4707 | err = -ENETDOWN; |
| 4708 | goto out; |
| 4709 | } |
| 4710 | |
| 4711 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 4712 | |
| 4713 | err = rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
| 4714 | |
| 4715 | out: |
| 4716 | cfg80211_unlock_rdev(rdev); |
| 4717 | dev_put(dev); |
| 4718 | unlock_rtnl: |
| 4719 | rtnl_unlock(); |
| 4720 | return err; |
| 4721 | } |
| 4722 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4723 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4724 | u8 *rates, u8 rates_len) |
| 4725 | { |
| 4726 | u8 i; |
| 4727 | u32 mask = 0; |
| 4728 | |
| 4729 | for (i = 0; i < rates_len; i++) { |
| 4730 | int rate = (rates[i] & 0x7f) * 5; |
| 4731 | int ridx; |
| 4732 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4733 | struct ieee80211_rate *srate = |
| 4734 | &sband->bitrates[ridx]; |
| 4735 | if (rate == srate->bitrate) { |
| 4736 | mask |= 1 << ridx; |
| 4737 | break; |
| 4738 | } |
| 4739 | } |
| 4740 | if (ridx == sband->n_bitrates) |
| 4741 | return 0; /* rate not found */ |
| 4742 | } |
| 4743 | |
| 4744 | return mask; |
| 4745 | } |
| 4746 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4747 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 4748 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 4749 | .len = NL80211_MAX_SUPP_RATES }, |
| 4750 | }; |
| 4751 | |
| 4752 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 4753 | struct genl_info *info) |
| 4754 | { |
| 4755 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 4756 | struct cfg80211_registered_device *rdev; |
| 4757 | struct cfg80211_bitrate_mask mask; |
| 4758 | int err, rem, i; |
| 4759 | struct net_device *dev; |
| 4760 | struct nlattr *tx_rates; |
| 4761 | struct ieee80211_supported_band *sband; |
| 4762 | |
| 4763 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 4764 | return -EINVAL; |
| 4765 | |
| 4766 | rtnl_lock(); |
| 4767 | |
| 4768 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4769 | if (err) |
| 4770 | goto unlock_rtnl; |
| 4771 | |
| 4772 | if (!rdev->ops->set_bitrate_mask) { |
| 4773 | err = -EOPNOTSUPP; |
| 4774 | goto unlock; |
| 4775 | } |
| 4776 | |
| 4777 | memset(&mask, 0, sizeof(mask)); |
| 4778 | /* Default to all rates enabled */ |
| 4779 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 4780 | sband = rdev->wiphy.bands[i]; |
| 4781 | mask.control[i].legacy = |
| 4782 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 4783 | } |
| 4784 | |
| 4785 | /* |
| 4786 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 4787 | * directly to the enum ieee80211_band values used in cfg80211. |
| 4788 | */ |
| 4789 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 4790 | { |
| 4791 | enum ieee80211_band band = nla_type(tx_rates); |
| 4792 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
| 4793 | err = -EINVAL; |
| 4794 | goto unlock; |
| 4795 | } |
| 4796 | sband = rdev->wiphy.bands[band]; |
| 4797 | if (sband == NULL) { |
| 4798 | err = -EINVAL; |
| 4799 | goto unlock; |
| 4800 | } |
| 4801 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 4802 | nla_len(tx_rates), nl80211_txattr_policy); |
| 4803 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4804 | mask.control[band].legacy = rateset_to_mask( |
| 4805 | sband, |
| 4806 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4807 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 4808 | if (mask.control[band].legacy == 0) { |
| 4809 | err = -EINVAL; |
| 4810 | goto unlock; |
| 4811 | } |
| 4812 | } |
| 4813 | } |
| 4814 | |
| 4815 | err = rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
| 4816 | |
| 4817 | unlock: |
| 4818 | dev_put(dev); |
| 4819 | cfg80211_unlock_rdev(rdev); |
| 4820 | unlock_rtnl: |
| 4821 | rtnl_unlock(); |
| 4822 | return err; |
| 4823 | } |
| 4824 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4825 | 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] | 4826 | { |
| 4827 | struct cfg80211_registered_device *rdev; |
| 4828 | struct net_device *dev; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4829 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4830 | int err; |
| 4831 | |
| 4832 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 4833 | return -EINVAL; |
| 4834 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4835 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 4836 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4837 | |
| 4838 | rtnl_lock(); |
| 4839 | |
| 4840 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4841 | if (err) |
| 4842 | goto unlock_rtnl; |
| 4843 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4844 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 4845 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 4846 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4847 | err = -EOPNOTSUPP; |
| 4848 | goto out; |
| 4849 | } |
| 4850 | |
| 4851 | /* not much point in registering if we can't reply */ |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4852 | if (!rdev->ops->mgmt_tx) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4853 | err = -EOPNOTSUPP; |
| 4854 | goto out; |
| 4855 | } |
| 4856 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4857 | err = cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
| 4858 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4859 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 4860 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
| 4861 | out: |
| 4862 | cfg80211_unlock_rdev(rdev); |
| 4863 | dev_put(dev); |
| 4864 | unlock_rtnl: |
| 4865 | rtnl_unlock(); |
| 4866 | return err; |
| 4867 | } |
| 4868 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4869 | 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] | 4870 | { |
| 4871 | struct cfg80211_registered_device *rdev; |
| 4872 | struct net_device *dev; |
| 4873 | struct ieee80211_channel *chan; |
| 4874 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4875 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4876 | u32 freq; |
| 4877 | int err; |
| 4878 | void *hdr; |
| 4879 | u64 cookie; |
| 4880 | struct sk_buff *msg; |
| 4881 | |
| 4882 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 4883 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4884 | return -EINVAL; |
| 4885 | |
| 4886 | rtnl_lock(); |
| 4887 | |
| 4888 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4889 | if (err) |
| 4890 | goto unlock_rtnl; |
| 4891 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4892 | if (!rdev->ops->mgmt_tx) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4893 | err = -EOPNOTSUPP; |
| 4894 | goto out; |
| 4895 | } |
| 4896 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 4897 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 4898 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 4899 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4900 | err = -EOPNOTSUPP; |
| 4901 | goto out; |
| 4902 | } |
| 4903 | |
| 4904 | if (!netif_running(dev)) { |
| 4905 | err = -ENETDOWN; |
| 4906 | goto out; |
| 4907 | } |
| 4908 | |
| 4909 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4910 | channel_type = nla_get_u32( |
| 4911 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4912 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4913 | channel_type != NL80211_CHAN_HT20 && |
| 4914 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 579d753 | 2010-05-18 14:36:34 +0200 | [diff] [blame] | 4915 | channel_type != NL80211_CHAN_HT40MINUS) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4916 | err = -EINVAL; |
| 4917 | goto out; |
Johannes Berg | 579d753 | 2010-05-18 14:36:34 +0200 | [diff] [blame] | 4918 | } |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 4919 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 4923 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
| 4924 | if (chan == NULL) { |
| 4925 | err = -EINVAL; |
| 4926 | goto out; |
| 4927 | } |
| 4928 | |
| 4929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4930 | if (!msg) { |
| 4931 | err = -ENOMEM; |
| 4932 | goto out; |
| 4933 | } |
| 4934 | |
| 4935 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4936 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4937 | |
| 4938 | if (IS_ERR(hdr)) { |
| 4939 | err = PTR_ERR(hdr); |
| 4940 | goto free_msg; |
| 4941 | } |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 4942 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, channel_type, |
| 4943 | channel_type_valid, |
| 4944 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 4945 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
| 4946 | &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4947 | if (err) |
| 4948 | goto free_msg; |
| 4949 | |
| 4950 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 4951 | |
| 4952 | genlmsg_end(msg, hdr); |
| 4953 | err = genlmsg_reply(msg, info); |
| 4954 | goto out; |
| 4955 | |
| 4956 | nla_put_failure: |
| 4957 | err = -ENOBUFS; |
| 4958 | free_msg: |
| 4959 | nlmsg_free(msg); |
| 4960 | out: |
| 4961 | cfg80211_unlock_rdev(rdev); |
| 4962 | dev_put(dev); |
| 4963 | unlock_rtnl: |
| 4964 | rtnl_unlock(); |
| 4965 | return err; |
| 4966 | } |
| 4967 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 4968 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 4969 | { |
| 4970 | struct cfg80211_registered_device *rdev; |
| 4971 | struct wireless_dev *wdev; |
| 4972 | struct net_device *dev; |
| 4973 | u8 ps_state; |
| 4974 | bool state; |
| 4975 | int err; |
| 4976 | |
| 4977 | if (!info->attrs[NL80211_ATTR_PS_STATE]) { |
| 4978 | err = -EINVAL; |
| 4979 | goto out; |
| 4980 | } |
| 4981 | |
| 4982 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 4983 | |
| 4984 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) { |
| 4985 | err = -EINVAL; |
| 4986 | goto out; |
| 4987 | } |
| 4988 | |
| 4989 | rtnl_lock(); |
| 4990 | |
| 4991 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 4992 | if (err) |
| 4993 | goto unlock_rdev; |
| 4994 | |
| 4995 | wdev = dev->ieee80211_ptr; |
| 4996 | |
| 4997 | if (!rdev->ops->set_power_mgmt) { |
| 4998 | err = -EOPNOTSUPP; |
| 4999 | goto unlock_rdev; |
| 5000 | } |
| 5001 | |
| 5002 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5003 | |
| 5004 | if (state == wdev->ps) |
| 5005 | goto unlock_rdev; |
| 5006 | |
| 5007 | wdev->ps = state; |
| 5008 | |
| 5009 | if (rdev->ops->set_power_mgmt(wdev->wiphy, dev, wdev->ps, |
| 5010 | wdev->ps_timeout)) |
| 5011 | /* assume this means it's off */ |
| 5012 | wdev->ps = false; |
| 5013 | |
| 5014 | unlock_rdev: |
| 5015 | cfg80211_unlock_rdev(rdev); |
| 5016 | dev_put(dev); |
| 5017 | rtnl_unlock(); |
| 5018 | |
| 5019 | out: |
| 5020 | return err; |
| 5021 | } |
| 5022 | |
| 5023 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5024 | { |
| 5025 | struct cfg80211_registered_device *rdev; |
| 5026 | enum nl80211_ps_state ps_state; |
| 5027 | struct wireless_dev *wdev; |
| 5028 | struct net_device *dev; |
| 5029 | struct sk_buff *msg; |
| 5030 | void *hdr; |
| 5031 | int err; |
| 5032 | |
| 5033 | rtnl_lock(); |
| 5034 | |
| 5035 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5036 | if (err) |
| 5037 | goto unlock_rtnl; |
| 5038 | |
| 5039 | wdev = dev->ieee80211_ptr; |
| 5040 | |
| 5041 | if (!rdev->ops->set_power_mgmt) { |
| 5042 | err = -EOPNOTSUPP; |
| 5043 | goto out; |
| 5044 | } |
| 5045 | |
| 5046 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5047 | if (!msg) { |
| 5048 | err = -ENOMEM; |
| 5049 | goto out; |
| 5050 | } |
| 5051 | |
| 5052 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5053 | NL80211_CMD_GET_POWER_SAVE); |
| 5054 | if (!hdr) { |
| 5055 | err = -ENOMEM; |
| 5056 | goto free_msg; |
| 5057 | } |
| 5058 | |
| 5059 | if (wdev->ps) |
| 5060 | ps_state = NL80211_PS_ENABLED; |
| 5061 | else |
| 5062 | ps_state = NL80211_PS_DISABLED; |
| 5063 | |
| 5064 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5065 | |
| 5066 | genlmsg_end(msg, hdr); |
| 5067 | err = genlmsg_reply(msg, info); |
| 5068 | goto out; |
| 5069 | |
| 5070 | nla_put_failure: |
| 5071 | err = -ENOBUFS; |
| 5072 | |
| 5073 | free_msg: |
| 5074 | nlmsg_free(msg); |
| 5075 | |
| 5076 | out: |
| 5077 | cfg80211_unlock_rdev(rdev); |
| 5078 | dev_put(dev); |
| 5079 | |
| 5080 | unlock_rtnl: |
| 5081 | rtnl_unlock(); |
| 5082 | |
| 5083 | return err; |
| 5084 | } |
| 5085 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5086 | static struct nla_policy |
| 5087 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5088 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5089 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5090 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5091 | }; |
| 5092 | |
| 5093 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5094 | s32 threshold, u32 hysteresis) |
| 5095 | { |
| 5096 | struct cfg80211_registered_device *rdev; |
| 5097 | struct wireless_dev *wdev; |
| 5098 | struct net_device *dev; |
| 5099 | int err; |
| 5100 | |
| 5101 | if (threshold > 0) |
| 5102 | return -EINVAL; |
| 5103 | |
| 5104 | rtnl_lock(); |
| 5105 | |
| 5106 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5107 | if (err) |
| 5108 | goto unlock_rdev; |
| 5109 | |
| 5110 | wdev = dev->ieee80211_ptr; |
| 5111 | |
| 5112 | if (!rdev->ops->set_cqm_rssi_config) { |
| 5113 | err = -EOPNOTSUPP; |
| 5114 | goto unlock_rdev; |
| 5115 | } |
| 5116 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame^] | 5117 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 5118 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5119 | err = -EOPNOTSUPP; |
| 5120 | goto unlock_rdev; |
| 5121 | } |
| 5122 | |
| 5123 | err = rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5124 | threshold, hysteresis); |
| 5125 | |
| 5126 | unlock_rdev: |
| 5127 | cfg80211_unlock_rdev(rdev); |
| 5128 | dev_put(dev); |
| 5129 | rtnl_unlock(); |
| 5130 | |
| 5131 | return err; |
| 5132 | } |
| 5133 | |
| 5134 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5135 | { |
| 5136 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5137 | struct nlattr *cqm; |
| 5138 | int err; |
| 5139 | |
| 5140 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5141 | if (!cqm) { |
| 5142 | err = -EINVAL; |
| 5143 | goto out; |
| 5144 | } |
| 5145 | |
| 5146 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5147 | nl80211_attr_cqm_policy); |
| 5148 | if (err) |
| 5149 | goto out; |
| 5150 | |
| 5151 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5152 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5153 | s32 threshold; |
| 5154 | u32 hysteresis; |
| 5155 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5156 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5157 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5158 | } else |
| 5159 | err = -EINVAL; |
| 5160 | |
| 5161 | out: |
| 5162 | return err; |
| 5163 | } |
| 5164 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5165 | static struct genl_ops nl80211_ops[] = { |
| 5166 | { |
| 5167 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5168 | .doit = nl80211_get_wiphy, |
| 5169 | .dumpit = nl80211_dump_wiphy, |
| 5170 | .policy = nl80211_policy, |
| 5171 | /* can be retrieved by unprivileged users */ |
| 5172 | }, |
| 5173 | { |
| 5174 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5175 | .doit = nl80211_set_wiphy, |
| 5176 | .policy = nl80211_policy, |
| 5177 | .flags = GENL_ADMIN_PERM, |
| 5178 | }, |
| 5179 | { |
| 5180 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5181 | .doit = nl80211_get_interface, |
| 5182 | .dumpit = nl80211_dump_interface, |
| 5183 | .policy = nl80211_policy, |
| 5184 | /* can be retrieved by unprivileged users */ |
| 5185 | }, |
| 5186 | { |
| 5187 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5188 | .doit = nl80211_set_interface, |
| 5189 | .policy = nl80211_policy, |
| 5190 | .flags = GENL_ADMIN_PERM, |
| 5191 | }, |
| 5192 | { |
| 5193 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5194 | .doit = nl80211_new_interface, |
| 5195 | .policy = nl80211_policy, |
| 5196 | .flags = GENL_ADMIN_PERM, |
| 5197 | }, |
| 5198 | { |
| 5199 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5200 | .doit = nl80211_del_interface, |
| 5201 | .policy = nl80211_policy, |
| 5202 | .flags = GENL_ADMIN_PERM, |
| 5203 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5204 | { |
| 5205 | .cmd = NL80211_CMD_GET_KEY, |
| 5206 | .doit = nl80211_get_key, |
| 5207 | .policy = nl80211_policy, |
| 5208 | .flags = GENL_ADMIN_PERM, |
| 5209 | }, |
| 5210 | { |
| 5211 | .cmd = NL80211_CMD_SET_KEY, |
| 5212 | .doit = nl80211_set_key, |
| 5213 | .policy = nl80211_policy, |
| 5214 | .flags = GENL_ADMIN_PERM, |
| 5215 | }, |
| 5216 | { |
| 5217 | .cmd = NL80211_CMD_NEW_KEY, |
| 5218 | .doit = nl80211_new_key, |
| 5219 | .policy = nl80211_policy, |
| 5220 | .flags = GENL_ADMIN_PERM, |
| 5221 | }, |
| 5222 | { |
| 5223 | .cmd = NL80211_CMD_DEL_KEY, |
| 5224 | .doit = nl80211_del_key, |
| 5225 | .policy = nl80211_policy, |
| 5226 | .flags = GENL_ADMIN_PERM, |
| 5227 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5228 | { |
| 5229 | .cmd = NL80211_CMD_SET_BEACON, |
| 5230 | .policy = nl80211_policy, |
| 5231 | .flags = GENL_ADMIN_PERM, |
| 5232 | .doit = nl80211_addset_beacon, |
| 5233 | }, |
| 5234 | { |
| 5235 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5236 | .policy = nl80211_policy, |
| 5237 | .flags = GENL_ADMIN_PERM, |
| 5238 | .doit = nl80211_addset_beacon, |
| 5239 | }, |
| 5240 | { |
| 5241 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5242 | .policy = nl80211_policy, |
| 5243 | .flags = GENL_ADMIN_PERM, |
| 5244 | .doit = nl80211_del_beacon, |
| 5245 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5246 | { |
| 5247 | .cmd = NL80211_CMD_GET_STATION, |
| 5248 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5249 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5250 | .policy = nl80211_policy, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5251 | }, |
| 5252 | { |
| 5253 | .cmd = NL80211_CMD_SET_STATION, |
| 5254 | .doit = nl80211_set_station, |
| 5255 | .policy = nl80211_policy, |
| 5256 | .flags = GENL_ADMIN_PERM, |
| 5257 | }, |
| 5258 | { |
| 5259 | .cmd = NL80211_CMD_NEW_STATION, |
| 5260 | .doit = nl80211_new_station, |
| 5261 | .policy = nl80211_policy, |
| 5262 | .flags = GENL_ADMIN_PERM, |
| 5263 | }, |
| 5264 | { |
| 5265 | .cmd = NL80211_CMD_DEL_STATION, |
| 5266 | .doit = nl80211_del_station, |
| 5267 | .policy = nl80211_policy, |
| 5268 | .flags = GENL_ADMIN_PERM, |
| 5269 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5270 | { |
| 5271 | .cmd = NL80211_CMD_GET_MPATH, |
| 5272 | .doit = nl80211_get_mpath, |
| 5273 | .dumpit = nl80211_dump_mpath, |
| 5274 | .policy = nl80211_policy, |
| 5275 | .flags = GENL_ADMIN_PERM, |
| 5276 | }, |
| 5277 | { |
| 5278 | .cmd = NL80211_CMD_SET_MPATH, |
| 5279 | .doit = nl80211_set_mpath, |
| 5280 | .policy = nl80211_policy, |
| 5281 | .flags = GENL_ADMIN_PERM, |
| 5282 | }, |
| 5283 | { |
| 5284 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5285 | .doit = nl80211_new_mpath, |
| 5286 | .policy = nl80211_policy, |
| 5287 | .flags = GENL_ADMIN_PERM, |
| 5288 | }, |
| 5289 | { |
| 5290 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5291 | .doit = nl80211_del_mpath, |
| 5292 | .policy = nl80211_policy, |
| 5293 | .flags = GENL_ADMIN_PERM, |
| 5294 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5295 | { |
| 5296 | .cmd = NL80211_CMD_SET_BSS, |
| 5297 | .doit = nl80211_set_bss, |
| 5298 | .policy = nl80211_policy, |
| 5299 | .flags = GENL_ADMIN_PERM, |
| 5300 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5301 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5302 | .cmd = NL80211_CMD_GET_REG, |
| 5303 | .doit = nl80211_get_reg, |
| 5304 | .policy = nl80211_policy, |
| 5305 | /* can be retrieved by unprivileged users */ |
| 5306 | }, |
| 5307 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5308 | .cmd = NL80211_CMD_SET_REG, |
| 5309 | .doit = nl80211_set_reg, |
| 5310 | .policy = nl80211_policy, |
| 5311 | .flags = GENL_ADMIN_PERM, |
| 5312 | }, |
| 5313 | { |
| 5314 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5315 | .doit = nl80211_req_set_reg, |
| 5316 | .policy = nl80211_policy, |
| 5317 | .flags = GENL_ADMIN_PERM, |
| 5318 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5319 | { |
| 5320 | .cmd = NL80211_CMD_GET_MESH_PARAMS, |
| 5321 | .doit = nl80211_get_mesh_params, |
| 5322 | .policy = nl80211_policy, |
| 5323 | /* can be retrieved by unprivileged users */ |
| 5324 | }, |
| 5325 | { |
| 5326 | .cmd = NL80211_CMD_SET_MESH_PARAMS, |
| 5327 | .doit = nl80211_set_mesh_params, |
| 5328 | .policy = nl80211_policy, |
| 5329 | .flags = GENL_ADMIN_PERM, |
| 5330 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 5331 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5332 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 5333 | .doit = nl80211_trigger_scan, |
| 5334 | .policy = nl80211_policy, |
| 5335 | .flags = GENL_ADMIN_PERM, |
| 5336 | }, |
| 5337 | { |
| 5338 | .cmd = NL80211_CMD_GET_SCAN, |
| 5339 | .policy = nl80211_policy, |
| 5340 | .dumpit = nl80211_dump_scan, |
| 5341 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 5342 | { |
| 5343 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 5344 | .doit = nl80211_authenticate, |
| 5345 | .policy = nl80211_policy, |
| 5346 | .flags = GENL_ADMIN_PERM, |
| 5347 | }, |
| 5348 | { |
| 5349 | .cmd = NL80211_CMD_ASSOCIATE, |
| 5350 | .doit = nl80211_associate, |
| 5351 | .policy = nl80211_policy, |
| 5352 | .flags = GENL_ADMIN_PERM, |
| 5353 | }, |
| 5354 | { |
| 5355 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 5356 | .doit = nl80211_deauthenticate, |
| 5357 | .policy = nl80211_policy, |
| 5358 | .flags = GENL_ADMIN_PERM, |
| 5359 | }, |
| 5360 | { |
| 5361 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 5362 | .doit = nl80211_disassociate, |
| 5363 | .policy = nl80211_policy, |
| 5364 | .flags = GENL_ADMIN_PERM, |
| 5365 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5366 | { |
| 5367 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 5368 | .doit = nl80211_join_ibss, |
| 5369 | .policy = nl80211_policy, |
| 5370 | .flags = GENL_ADMIN_PERM, |
| 5371 | }, |
| 5372 | { |
| 5373 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 5374 | .doit = nl80211_leave_ibss, |
| 5375 | .policy = nl80211_policy, |
| 5376 | .flags = GENL_ADMIN_PERM, |
| 5377 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5378 | #ifdef CONFIG_NL80211_TESTMODE |
| 5379 | { |
| 5380 | .cmd = NL80211_CMD_TESTMODE, |
| 5381 | .doit = nl80211_testmode_do, |
| 5382 | .policy = nl80211_policy, |
| 5383 | .flags = GENL_ADMIN_PERM, |
| 5384 | }, |
| 5385 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5386 | { |
| 5387 | .cmd = NL80211_CMD_CONNECT, |
| 5388 | .doit = nl80211_connect, |
| 5389 | .policy = nl80211_policy, |
| 5390 | .flags = GENL_ADMIN_PERM, |
| 5391 | }, |
| 5392 | { |
| 5393 | .cmd = NL80211_CMD_DISCONNECT, |
| 5394 | .doit = nl80211_disconnect, |
| 5395 | .policy = nl80211_policy, |
| 5396 | .flags = GENL_ADMIN_PERM, |
| 5397 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5398 | { |
| 5399 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 5400 | .doit = nl80211_wiphy_netns, |
| 5401 | .policy = nl80211_policy, |
| 5402 | .flags = GENL_ADMIN_PERM, |
| 5403 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 5404 | { |
| 5405 | .cmd = NL80211_CMD_GET_SURVEY, |
| 5406 | .policy = nl80211_policy, |
| 5407 | .dumpit = nl80211_dump_survey, |
| 5408 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5409 | { |
| 5410 | .cmd = NL80211_CMD_SET_PMKSA, |
| 5411 | .doit = nl80211_setdel_pmksa, |
| 5412 | .policy = nl80211_policy, |
| 5413 | .flags = GENL_ADMIN_PERM, |
| 5414 | }, |
| 5415 | { |
| 5416 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 5417 | .doit = nl80211_setdel_pmksa, |
| 5418 | .policy = nl80211_policy, |
| 5419 | .flags = GENL_ADMIN_PERM, |
| 5420 | }, |
| 5421 | { |
| 5422 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 5423 | .doit = nl80211_flush_pmksa, |
| 5424 | .policy = nl80211_policy, |
| 5425 | .flags = GENL_ADMIN_PERM, |
| 5426 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5427 | { |
| 5428 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 5429 | .doit = nl80211_remain_on_channel, |
| 5430 | .policy = nl80211_policy, |
| 5431 | .flags = GENL_ADMIN_PERM, |
| 5432 | }, |
| 5433 | { |
| 5434 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 5435 | .doit = nl80211_cancel_remain_on_channel, |
| 5436 | .policy = nl80211_policy, |
| 5437 | .flags = GENL_ADMIN_PERM, |
| 5438 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5439 | { |
| 5440 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 5441 | .doit = nl80211_set_tx_bitrate_mask, |
| 5442 | .policy = nl80211_policy, |
| 5443 | .flags = GENL_ADMIN_PERM, |
| 5444 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5445 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5446 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 5447 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5448 | .policy = nl80211_policy, |
| 5449 | .flags = GENL_ADMIN_PERM, |
| 5450 | }, |
| 5451 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5452 | .cmd = NL80211_CMD_FRAME, |
| 5453 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5454 | .policy = nl80211_policy, |
| 5455 | .flags = GENL_ADMIN_PERM, |
| 5456 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5457 | { |
| 5458 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 5459 | .doit = nl80211_set_power_save, |
| 5460 | .policy = nl80211_policy, |
| 5461 | .flags = GENL_ADMIN_PERM, |
| 5462 | }, |
| 5463 | { |
| 5464 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 5465 | .doit = nl80211_get_power_save, |
| 5466 | .policy = nl80211_policy, |
| 5467 | /* can be retrieved by unprivileged users */ |
| 5468 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5469 | { |
| 5470 | .cmd = NL80211_CMD_SET_CQM, |
| 5471 | .doit = nl80211_set_cqm, |
| 5472 | .policy = nl80211_policy, |
| 5473 | .flags = GENL_ADMIN_PERM, |
| 5474 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 5475 | { |
| 5476 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 5477 | .doit = nl80211_set_channel, |
| 5478 | .policy = nl80211_policy, |
| 5479 | .flags = GENL_ADMIN_PERM, |
| 5480 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5481 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5482 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5483 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 5484 | .name = "mlme", |
| 5485 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5486 | |
| 5487 | /* multicast groups */ |
| 5488 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 5489 | .name = "config", |
| 5490 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5491 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 5492 | .name = "scan", |
| 5493 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5494 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 5495 | .name = "regulatory", |
| 5496 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5497 | |
| 5498 | /* notification functions */ |
| 5499 | |
| 5500 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 5501 | { |
| 5502 | struct sk_buff *msg; |
| 5503 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5504 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5505 | if (!msg) |
| 5506 | return; |
| 5507 | |
| 5508 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 5509 | nlmsg_free(msg); |
| 5510 | return; |
| 5511 | } |
| 5512 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5513 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5514 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5515 | } |
| 5516 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5517 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 5518 | struct cfg80211_registered_device *rdev) |
| 5519 | { |
| 5520 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 5521 | struct nlattr *nest; |
| 5522 | int i; |
| 5523 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5524 | ASSERT_RDEV_LOCK(rdev); |
| 5525 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5526 | if (WARN_ON(!req)) |
| 5527 | return 0; |
| 5528 | |
| 5529 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 5530 | if (!nest) |
| 5531 | goto nla_put_failure; |
| 5532 | for (i = 0; i < req->n_ssids; i++) |
| 5533 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 5534 | nla_nest_end(msg, nest); |
| 5535 | |
| 5536 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 5537 | if (!nest) |
| 5538 | goto nla_put_failure; |
| 5539 | for (i = 0; i < req->n_channels; i++) |
| 5540 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 5541 | nla_nest_end(msg, nest); |
| 5542 | |
| 5543 | if (req->ie) |
| 5544 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 5545 | |
| 5546 | return 0; |
| 5547 | nla_put_failure: |
| 5548 | return -ENOBUFS; |
| 5549 | } |
| 5550 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5551 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 5552 | struct cfg80211_registered_device *rdev, |
| 5553 | struct net_device *netdev, |
| 5554 | u32 pid, u32 seq, int flags, |
| 5555 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5556 | { |
| 5557 | void *hdr; |
| 5558 | |
| 5559 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 5560 | if (!hdr) |
| 5561 | return -1; |
| 5562 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 5563 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5564 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5565 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 5566 | /* ignore errors and send incomplete event anyway */ |
| 5567 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5568 | |
| 5569 | return genlmsg_end(msg, hdr); |
| 5570 | |
| 5571 | nla_put_failure: |
| 5572 | genlmsg_cancel(msg, hdr); |
| 5573 | return -EMSGSIZE; |
| 5574 | } |
| 5575 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5576 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 5577 | struct net_device *netdev) |
| 5578 | { |
| 5579 | struct sk_buff *msg; |
| 5580 | |
| 5581 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 5582 | if (!msg) |
| 5583 | return; |
| 5584 | |
| 5585 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5586 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 5587 | nlmsg_free(msg); |
| 5588 | return; |
| 5589 | } |
| 5590 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5591 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5592 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5593 | } |
| 5594 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5595 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 5596 | struct net_device *netdev) |
| 5597 | { |
| 5598 | struct sk_buff *msg; |
| 5599 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5600 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5601 | if (!msg) |
| 5602 | return; |
| 5603 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5604 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5605 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5606 | nlmsg_free(msg); |
| 5607 | return; |
| 5608 | } |
| 5609 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5610 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5611 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5612 | } |
| 5613 | |
| 5614 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 5615 | struct net_device *netdev) |
| 5616 | { |
| 5617 | struct sk_buff *msg; |
| 5618 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5619 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5620 | if (!msg) |
| 5621 | return; |
| 5622 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 5623 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 5624 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5625 | nlmsg_free(msg); |
| 5626 | return; |
| 5627 | } |
| 5628 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5629 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5630 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5631 | } |
| 5632 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5633 | /* |
| 5634 | * This can happen on global regulatory changes or device specific settings |
| 5635 | * based on custom world regulatory domains. |
| 5636 | */ |
| 5637 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 5638 | { |
| 5639 | struct sk_buff *msg; |
| 5640 | void *hdr; |
| 5641 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5642 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5643 | if (!msg) |
| 5644 | return; |
| 5645 | |
| 5646 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 5647 | if (!hdr) { |
| 5648 | nlmsg_free(msg); |
| 5649 | return; |
| 5650 | } |
| 5651 | |
| 5652 | /* Userspace can always count this one always being set */ |
| 5653 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 5654 | |
| 5655 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 5656 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5657 | NL80211_REGDOM_TYPE_WORLD); |
| 5658 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 5659 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5660 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 5661 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 5662 | request->intersect) |
| 5663 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5664 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 5665 | else { |
| 5666 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 5667 | NL80211_REGDOM_TYPE_COUNTRY); |
| 5668 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 5669 | } |
| 5670 | |
| 5671 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 5672 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 5673 | |
| 5674 | if (genlmsg_end(msg, hdr) < 0) { |
| 5675 | nlmsg_free(msg); |
| 5676 | return; |
| 5677 | } |
| 5678 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 5679 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5680 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 5681 | GFP_ATOMIC); |
| 5682 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 5683 | |
| 5684 | return; |
| 5685 | |
| 5686 | nla_put_failure: |
| 5687 | genlmsg_cancel(msg, hdr); |
| 5688 | nlmsg_free(msg); |
| 5689 | } |
| 5690 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5691 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 5692 | struct net_device *netdev, |
| 5693 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5694 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5695 | { |
| 5696 | struct sk_buff *msg; |
| 5697 | void *hdr; |
| 5698 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5699 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5700 | if (!msg) |
| 5701 | return; |
| 5702 | |
| 5703 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5704 | if (!hdr) { |
| 5705 | nlmsg_free(msg); |
| 5706 | return; |
| 5707 | } |
| 5708 | |
| 5709 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5710 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5711 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 5712 | |
| 5713 | if (genlmsg_end(msg, hdr) < 0) { |
| 5714 | nlmsg_free(msg); |
| 5715 | return; |
| 5716 | } |
| 5717 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5718 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5719 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5720 | return; |
| 5721 | |
| 5722 | nla_put_failure: |
| 5723 | genlmsg_cancel(msg, hdr); |
| 5724 | nlmsg_free(msg); |
| 5725 | } |
| 5726 | |
| 5727 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5728 | struct net_device *netdev, const u8 *buf, |
| 5729 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5730 | { |
| 5731 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5732 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5733 | } |
| 5734 | |
| 5735 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 5736 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5737 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5738 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5739 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 5740 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5741 | } |
| 5742 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 5743 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5744 | struct net_device *netdev, const u8 *buf, |
| 5745 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5746 | { |
| 5747 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5748 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5749 | } |
| 5750 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 5751 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 5752 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5753 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5754 | { |
| 5755 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5756 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 5757 | } |
| 5758 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 5759 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 5760 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5761 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5762 | { |
| 5763 | struct sk_buff *msg; |
| 5764 | void *hdr; |
| 5765 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5766 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5767 | if (!msg) |
| 5768 | return; |
| 5769 | |
| 5770 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 5771 | if (!hdr) { |
| 5772 | nlmsg_free(msg); |
| 5773 | return; |
| 5774 | } |
| 5775 | |
| 5776 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5777 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5778 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 5779 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5780 | |
| 5781 | if (genlmsg_end(msg, hdr) < 0) { |
| 5782 | nlmsg_free(msg); |
| 5783 | return; |
| 5784 | } |
| 5785 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5786 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5787 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5788 | return; |
| 5789 | |
| 5790 | nla_put_failure: |
| 5791 | genlmsg_cancel(msg, hdr); |
| 5792 | nlmsg_free(msg); |
| 5793 | } |
| 5794 | |
| 5795 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5796 | struct net_device *netdev, const u8 *addr, |
| 5797 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5798 | { |
| 5799 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5800 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5804 | struct net_device *netdev, const u8 *addr, |
| 5805 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5806 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5807 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 5808 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 5809 | } |
| 5810 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5811 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 5812 | struct net_device *netdev, const u8 *bssid, |
| 5813 | const u8 *req_ie, size_t req_ie_len, |
| 5814 | const u8 *resp_ie, size_t resp_ie_len, |
| 5815 | u16 status, gfp_t gfp) |
| 5816 | { |
| 5817 | struct sk_buff *msg; |
| 5818 | void *hdr; |
| 5819 | |
| 5820 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5821 | if (!msg) |
| 5822 | return; |
| 5823 | |
| 5824 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 5825 | if (!hdr) { |
| 5826 | nlmsg_free(msg); |
| 5827 | return; |
| 5828 | } |
| 5829 | |
| 5830 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5831 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5832 | if (bssid) |
| 5833 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5834 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 5835 | if (req_ie) |
| 5836 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 5837 | if (resp_ie) |
| 5838 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 5839 | |
| 5840 | if (genlmsg_end(msg, hdr) < 0) { |
| 5841 | nlmsg_free(msg); |
| 5842 | return; |
| 5843 | } |
| 5844 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5845 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5846 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5847 | return; |
| 5848 | |
| 5849 | nla_put_failure: |
| 5850 | genlmsg_cancel(msg, hdr); |
| 5851 | nlmsg_free(msg); |
| 5852 | |
| 5853 | } |
| 5854 | |
| 5855 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 5856 | struct net_device *netdev, const u8 *bssid, |
| 5857 | const u8 *req_ie, size_t req_ie_len, |
| 5858 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 5859 | { |
| 5860 | struct sk_buff *msg; |
| 5861 | void *hdr; |
| 5862 | |
| 5863 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 5864 | if (!msg) |
| 5865 | return; |
| 5866 | |
| 5867 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 5868 | if (!hdr) { |
| 5869 | nlmsg_free(msg); |
| 5870 | return; |
| 5871 | } |
| 5872 | |
| 5873 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5874 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5875 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5876 | if (req_ie) |
| 5877 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 5878 | if (resp_ie) |
| 5879 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 5880 | |
| 5881 | if (genlmsg_end(msg, hdr) < 0) { |
| 5882 | nlmsg_free(msg); |
| 5883 | return; |
| 5884 | } |
| 5885 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5886 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5887 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5888 | return; |
| 5889 | |
| 5890 | nla_put_failure: |
| 5891 | genlmsg_cancel(msg, hdr); |
| 5892 | nlmsg_free(msg); |
| 5893 | |
| 5894 | } |
| 5895 | |
| 5896 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 5897 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5898 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5899 | { |
| 5900 | struct sk_buff *msg; |
| 5901 | void *hdr; |
| 5902 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 5903 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5904 | if (!msg) |
| 5905 | return; |
| 5906 | |
| 5907 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 5908 | if (!hdr) { |
| 5909 | nlmsg_free(msg); |
| 5910 | return; |
| 5911 | } |
| 5912 | |
| 5913 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5914 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5915 | if (from_ap && reason) |
| 5916 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 5917 | if (from_ap) |
| 5918 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 5919 | if (ie) |
| 5920 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 5921 | |
| 5922 | if (genlmsg_end(msg, hdr) < 0) { |
| 5923 | nlmsg_free(msg); |
| 5924 | return; |
| 5925 | } |
| 5926 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5927 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5928 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5929 | return; |
| 5930 | |
| 5931 | nla_put_failure: |
| 5932 | genlmsg_cancel(msg, hdr); |
| 5933 | nlmsg_free(msg); |
| 5934 | |
| 5935 | } |
| 5936 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5937 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 5938 | struct net_device *netdev, const u8 *bssid, |
| 5939 | gfp_t gfp) |
| 5940 | { |
| 5941 | struct sk_buff *msg; |
| 5942 | void *hdr; |
| 5943 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5944 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5945 | if (!msg) |
| 5946 | return; |
| 5947 | |
| 5948 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 5949 | if (!hdr) { |
| 5950 | nlmsg_free(msg); |
| 5951 | return; |
| 5952 | } |
| 5953 | |
| 5954 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5955 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5956 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 5957 | |
| 5958 | if (genlmsg_end(msg, hdr) < 0) { |
| 5959 | nlmsg_free(msg); |
| 5960 | return; |
| 5961 | } |
| 5962 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5963 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 5964 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5965 | return; |
| 5966 | |
| 5967 | nla_put_failure: |
| 5968 | genlmsg_cancel(msg, hdr); |
| 5969 | nlmsg_free(msg); |
| 5970 | } |
| 5971 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5972 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 5973 | struct net_device *netdev, const u8 *addr, |
| 5974 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5975 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5976 | { |
| 5977 | struct sk_buff *msg; |
| 5978 | void *hdr; |
| 5979 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 5980 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 5981 | if (!msg) |
| 5982 | return; |
| 5983 | |
| 5984 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 5985 | if (!hdr) { |
| 5986 | nlmsg_free(msg); |
| 5987 | return; |
| 5988 | } |
| 5989 | |
| 5990 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5991 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 5992 | if (addr) |
| 5993 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 5994 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
| 5995 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
| 5996 | if (tsc) |
| 5997 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 5998 | |
| 5999 | if (genlmsg_end(msg, hdr) < 0) { |
| 6000 | nlmsg_free(msg); |
| 6001 | return; |
| 6002 | } |
| 6003 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6004 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6005 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6006 | return; |
| 6007 | |
| 6008 | nla_put_failure: |
| 6009 | genlmsg_cancel(msg, hdr); |
| 6010 | nlmsg_free(msg); |
| 6011 | } |
| 6012 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6013 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6014 | struct ieee80211_channel *channel_before, |
| 6015 | struct ieee80211_channel *channel_after) |
| 6016 | { |
| 6017 | struct sk_buff *msg; |
| 6018 | void *hdr; |
| 6019 | struct nlattr *nl_freq; |
| 6020 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6021 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6022 | if (!msg) |
| 6023 | return; |
| 6024 | |
| 6025 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6026 | if (!hdr) { |
| 6027 | nlmsg_free(msg); |
| 6028 | return; |
| 6029 | } |
| 6030 | |
| 6031 | /* |
| 6032 | * Since we are applying the beacon hint to a wiphy we know its |
| 6033 | * wiphy_idx is valid |
| 6034 | */ |
| 6035 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6036 | |
| 6037 | /* Before */ |
| 6038 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6039 | if (!nl_freq) |
| 6040 | goto nla_put_failure; |
| 6041 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6042 | goto nla_put_failure; |
| 6043 | nla_nest_end(msg, nl_freq); |
| 6044 | |
| 6045 | /* After */ |
| 6046 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6047 | if (!nl_freq) |
| 6048 | goto nla_put_failure; |
| 6049 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6050 | goto nla_put_failure; |
| 6051 | nla_nest_end(msg, nl_freq); |
| 6052 | |
| 6053 | if (genlmsg_end(msg, hdr) < 0) { |
| 6054 | nlmsg_free(msg); |
| 6055 | return; |
| 6056 | } |
| 6057 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6058 | rcu_read_lock(); |
| 6059 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6060 | GFP_ATOMIC); |
| 6061 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6062 | |
| 6063 | return; |
| 6064 | |
| 6065 | nla_put_failure: |
| 6066 | genlmsg_cancel(msg, hdr); |
| 6067 | nlmsg_free(msg); |
| 6068 | } |
| 6069 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6070 | static void nl80211_send_remain_on_chan_event( |
| 6071 | int cmd, struct cfg80211_registered_device *rdev, |
| 6072 | struct net_device *netdev, u64 cookie, |
| 6073 | struct ieee80211_channel *chan, |
| 6074 | enum nl80211_channel_type channel_type, |
| 6075 | unsigned int duration, gfp_t gfp) |
| 6076 | { |
| 6077 | struct sk_buff *msg; |
| 6078 | void *hdr; |
| 6079 | |
| 6080 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6081 | if (!msg) |
| 6082 | return; |
| 6083 | |
| 6084 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6085 | if (!hdr) { |
| 6086 | nlmsg_free(msg); |
| 6087 | return; |
| 6088 | } |
| 6089 | |
| 6090 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6091 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6092 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 6093 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 6094 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6095 | |
| 6096 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 6097 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 6098 | |
| 6099 | if (genlmsg_end(msg, hdr) < 0) { |
| 6100 | nlmsg_free(msg); |
| 6101 | return; |
| 6102 | } |
| 6103 | |
| 6104 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6105 | nl80211_mlme_mcgrp.id, gfp); |
| 6106 | return; |
| 6107 | |
| 6108 | nla_put_failure: |
| 6109 | genlmsg_cancel(msg, hdr); |
| 6110 | nlmsg_free(msg); |
| 6111 | } |
| 6112 | |
| 6113 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 6114 | struct net_device *netdev, u64 cookie, |
| 6115 | struct ieee80211_channel *chan, |
| 6116 | enum nl80211_channel_type channel_type, |
| 6117 | unsigned int duration, gfp_t gfp) |
| 6118 | { |
| 6119 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6120 | rdev, netdev, cookie, chan, |
| 6121 | channel_type, duration, gfp); |
| 6122 | } |
| 6123 | |
| 6124 | void nl80211_send_remain_on_channel_cancel( |
| 6125 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 6126 | u64 cookie, struct ieee80211_channel *chan, |
| 6127 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 6128 | { |
| 6129 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6130 | rdev, netdev, cookie, chan, |
| 6131 | channel_type, 0, gfp); |
| 6132 | } |
| 6133 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 6134 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 6135 | struct net_device *dev, const u8 *mac_addr, |
| 6136 | struct station_info *sinfo, gfp_t gfp) |
| 6137 | { |
| 6138 | struct sk_buff *msg; |
| 6139 | |
| 6140 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6141 | if (!msg) |
| 6142 | return; |
| 6143 | |
| 6144 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 6145 | nlmsg_free(msg); |
| 6146 | return; |
| 6147 | } |
| 6148 | |
| 6149 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6150 | nl80211_mlme_mcgrp.id, gfp); |
| 6151 | } |
| 6152 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6153 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 6154 | struct net_device *netdev, u32 nlpid, |
| 6155 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6156 | { |
| 6157 | struct sk_buff *msg; |
| 6158 | void *hdr; |
| 6159 | int err; |
| 6160 | |
| 6161 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6162 | if (!msg) |
| 6163 | return -ENOMEM; |
| 6164 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6165 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6166 | if (!hdr) { |
| 6167 | nlmsg_free(msg); |
| 6168 | return -ENOMEM; |
| 6169 | } |
| 6170 | |
| 6171 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6172 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6173 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 6174 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6175 | |
| 6176 | err = genlmsg_end(msg, hdr); |
| 6177 | if (err < 0) { |
| 6178 | nlmsg_free(msg); |
| 6179 | return err; |
| 6180 | } |
| 6181 | |
| 6182 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 6183 | if (err < 0) |
| 6184 | return err; |
| 6185 | return 0; |
| 6186 | |
| 6187 | nla_put_failure: |
| 6188 | genlmsg_cancel(msg, hdr); |
| 6189 | nlmsg_free(msg); |
| 6190 | return -ENOBUFS; |
| 6191 | } |
| 6192 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6193 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 6194 | struct net_device *netdev, u64 cookie, |
| 6195 | const u8 *buf, size_t len, bool ack, |
| 6196 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6197 | { |
| 6198 | struct sk_buff *msg; |
| 6199 | void *hdr; |
| 6200 | |
| 6201 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6202 | if (!msg) |
| 6203 | return; |
| 6204 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6205 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6206 | if (!hdr) { |
| 6207 | nlmsg_free(msg); |
| 6208 | return; |
| 6209 | } |
| 6210 | |
| 6211 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6212 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6213 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6214 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6215 | if (ack) |
| 6216 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 6217 | |
| 6218 | if (genlmsg_end(msg, hdr) < 0) { |
| 6219 | nlmsg_free(msg); |
| 6220 | return; |
| 6221 | } |
| 6222 | |
| 6223 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 6224 | return; |
| 6225 | |
| 6226 | nla_put_failure: |
| 6227 | genlmsg_cancel(msg, hdr); |
| 6228 | nlmsg_free(msg); |
| 6229 | } |
| 6230 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6231 | void |
| 6232 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 6233 | struct net_device *netdev, |
| 6234 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 6235 | gfp_t gfp) |
| 6236 | { |
| 6237 | struct sk_buff *msg; |
| 6238 | struct nlattr *pinfoattr; |
| 6239 | void *hdr; |
| 6240 | |
| 6241 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6242 | if (!msg) |
| 6243 | return; |
| 6244 | |
| 6245 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 6246 | if (!hdr) { |
| 6247 | nlmsg_free(msg); |
| 6248 | return; |
| 6249 | } |
| 6250 | |
| 6251 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6252 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6253 | |
| 6254 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 6255 | if (!pinfoattr) |
| 6256 | goto nla_put_failure; |
| 6257 | |
| 6258 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 6259 | rssi_event); |
| 6260 | |
| 6261 | nla_nest_end(msg, pinfoattr); |
| 6262 | |
| 6263 | if (genlmsg_end(msg, hdr) < 0) { |
| 6264 | nlmsg_free(msg); |
| 6265 | return; |
| 6266 | } |
| 6267 | |
| 6268 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6269 | nl80211_mlme_mcgrp.id, gfp); |
| 6270 | return; |
| 6271 | |
| 6272 | nla_put_failure: |
| 6273 | genlmsg_cancel(msg, hdr); |
| 6274 | nlmsg_free(msg); |
| 6275 | } |
| 6276 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6277 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 6278 | unsigned long state, |
| 6279 | void *_notify) |
| 6280 | { |
| 6281 | struct netlink_notify *notify = _notify; |
| 6282 | struct cfg80211_registered_device *rdev; |
| 6283 | struct wireless_dev *wdev; |
| 6284 | |
| 6285 | if (state != NETLINK_URELEASE) |
| 6286 | return NOTIFY_DONE; |
| 6287 | |
| 6288 | rcu_read_lock(); |
| 6289 | |
| 6290 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 6291 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6292 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6293 | |
| 6294 | rcu_read_unlock(); |
| 6295 | |
| 6296 | return NOTIFY_DONE; |
| 6297 | } |
| 6298 | |
| 6299 | static struct notifier_block nl80211_netlink_notifier = { |
| 6300 | .notifier_call = nl80211_netlink_notify, |
| 6301 | }; |
| 6302 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6303 | /* initialisation/exit functions */ |
| 6304 | |
| 6305 | int nl80211_init(void) |
| 6306 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 6307 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6308 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 6309 | err = genl_register_family_with_ops(&nl80211_fam, |
| 6310 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6311 | if (err) |
| 6312 | return err; |
| 6313 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6314 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 6315 | if (err) |
| 6316 | goto err_out; |
| 6317 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6318 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 6319 | if (err) |
| 6320 | goto err_out; |
| 6321 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6322 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 6323 | if (err) |
| 6324 | goto err_out; |
| 6325 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6326 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 6327 | if (err) |
| 6328 | goto err_out; |
| 6329 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6330 | #ifdef CONFIG_NL80211_TESTMODE |
| 6331 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 6332 | if (err) |
| 6333 | goto err_out; |
| 6334 | #endif |
| 6335 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6336 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 6337 | if (err) |
| 6338 | goto err_out; |
| 6339 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6340 | return 0; |
| 6341 | err_out: |
| 6342 | genl_unregister_family(&nl80211_fam); |
| 6343 | return err; |
| 6344 | } |
| 6345 | |
| 6346 | void nl80211_exit(void) |
| 6347 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6348 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6349 | genl_unregister_family(&nl80211_fam); |
| 6350 | } |