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