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