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