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