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