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