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