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 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 26 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
| 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 49 | /* internal helper: get rdev and dev */ |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 50 | static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs, |
| 51 | struct cfg80211_registered_device **rdev, |
| 52 | struct net_device **dev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
| 54 | int ifindex; |
| 55 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 56 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 57 | return -EINVAL; |
| 58 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 59 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 60 | *dev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | if (!*dev) |
| 62 | return -ENODEV; |
| 63 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 64 | *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 65 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 67 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 74 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 75 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 76 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 77 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 78 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 79 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 80 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 81 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 82 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 83 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 84 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 85 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 86 | |
| 87 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 88 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 89 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 90 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 91 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 92 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 93 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 94 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 95 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 96 | .len = WLAN_MAX_KEY_LEN }, |
| 97 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 98 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 99 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 100 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 101 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 102 | |
| 103 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 104 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 105 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 106 | .len = IEEE80211_MAX_DATA_LEN }, |
| 107 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 108 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 109 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 110 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 111 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 112 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 113 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 114 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 115 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 116 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 117 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 118 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 119 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 120 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 121 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 122 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 123 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 124 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 125 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 126 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 127 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 128 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 129 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 130 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 131 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 132 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 133 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 134 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 135 | |
| 136 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 137 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 138 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 139 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 140 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 141 | |
| 142 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 143 | .len = IEEE80211_MAX_SSID_LEN }, |
| 144 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 145 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 146 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 147 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_STA_FLAGS2] = { |
| 150 | .len = sizeof(struct nl80211_sta_flag_update), |
| 151 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 152 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 153 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 154 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 155 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 156 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 157 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 158 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 159 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 160 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 161 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 162 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 163 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 164 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 166 | .len = IEEE80211_MAX_DATA_LEN }, |
| 167 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 168 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 169 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 170 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 171 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 172 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 173 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 174 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 175 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 176 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 177 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 178 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 179 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 180 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 181 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 182 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 183 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 184 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 185 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 186 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 187 | .len = IEEE80211_MAX_DATA_LEN }, |
| 188 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 189 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 190 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 191 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 192 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 193 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 194 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 195 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 196 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 197 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 198 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 199 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 200 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 201 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 202 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 203 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 204 | .len = NL80211_HT_CAPABILITY_LEN |
| 205 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 206 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame^] | 207 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 208 | }; |
| 209 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 210 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 211 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 212 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 213 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 214 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 215 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 216 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 217 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 218 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 219 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 220 | }; |
| 221 | |
| 222 | /* policy for the key default flags */ |
| 223 | static const struct nla_policy |
| 224 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 225 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 226 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 227 | }; |
| 228 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 229 | /* policy for WoWLAN attributes */ |
| 230 | static const struct nla_policy |
| 231 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 232 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 233 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 234 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 235 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 236 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 237 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 238 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 239 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 240 | }; |
| 241 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 242 | /* policy for GTK rekey offload attributes */ |
| 243 | static const struct nla_policy |
| 244 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 245 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 246 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 247 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 248 | }; |
| 249 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 250 | static const struct nla_policy |
| 251 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 252 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 253 | .len = IEEE80211_MAX_SSID_LEN }, |
| 254 | }; |
| 255 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 256 | /* ifidx get helper */ |
| 257 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 258 | { |
| 259 | int res; |
| 260 | |
| 261 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 262 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 263 | nl80211_policy); |
| 264 | if (res) |
| 265 | return res; |
| 266 | |
| 267 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 268 | return -EINVAL; |
| 269 | |
| 270 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 271 | if (!res) |
| 272 | return -EINVAL; |
| 273 | return res; |
| 274 | } |
| 275 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 276 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 277 | struct netlink_callback *cb, |
| 278 | struct cfg80211_registered_device **rdev, |
| 279 | struct net_device **dev) |
| 280 | { |
| 281 | int ifidx = cb->args[0]; |
| 282 | int err; |
| 283 | |
| 284 | if (!ifidx) |
| 285 | ifidx = nl80211_get_ifidx(cb); |
| 286 | if (ifidx < 0) |
| 287 | return ifidx; |
| 288 | |
| 289 | cb->args[0] = ifidx; |
| 290 | |
| 291 | rtnl_lock(); |
| 292 | |
| 293 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 294 | if (!*dev) { |
| 295 | err = -ENODEV; |
| 296 | goto out_rtnl; |
| 297 | } |
| 298 | |
| 299 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 300 | if (IS_ERR(*rdev)) { |
| 301 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 302 | goto out_rtnl; |
| 303 | } |
| 304 | |
| 305 | return 0; |
| 306 | out_rtnl: |
| 307 | rtnl_unlock(); |
| 308 | return err; |
| 309 | } |
| 310 | |
| 311 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 312 | { |
| 313 | cfg80211_unlock_rdev(rdev); |
| 314 | rtnl_unlock(); |
| 315 | } |
| 316 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 317 | /* IE validation */ |
| 318 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 319 | { |
| 320 | const u8 *pos; |
| 321 | int len; |
| 322 | |
| 323 | if (!attr) |
| 324 | return true; |
| 325 | |
| 326 | pos = nla_data(attr); |
| 327 | len = nla_len(attr); |
| 328 | |
| 329 | while (len) { |
| 330 | u8 elemlen; |
| 331 | |
| 332 | if (len < 2) |
| 333 | return false; |
| 334 | len -= 2; |
| 335 | |
| 336 | elemlen = pos[1]; |
| 337 | if (elemlen > len) |
| 338 | return false; |
| 339 | |
| 340 | len -= elemlen; |
| 341 | pos += 2 + elemlen; |
| 342 | } |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 347 | /* message building helper */ |
| 348 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 349 | int flags, u8 cmd) |
| 350 | { |
| 351 | /* since there is no private header just add the generic one */ |
| 352 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 353 | } |
| 354 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 355 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 356 | struct ieee80211_channel *chan) |
| 357 | { |
| 358 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 359 | chan->center_freq); |
| 360 | |
| 361 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 362 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 363 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 364 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 365 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 366 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 367 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 368 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 369 | |
| 370 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 371 | DBM_TO_MBM(chan->max_power)); |
| 372 | |
| 373 | return 0; |
| 374 | |
| 375 | nla_put_failure: |
| 376 | return -ENOBUFS; |
| 377 | } |
| 378 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 379 | /* netlink command implementations */ |
| 380 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 381 | struct key_parse { |
| 382 | struct key_params p; |
| 383 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 384 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 385 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 386 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 390 | { |
| 391 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 392 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 393 | nl80211_key_policy); |
| 394 | if (err) |
| 395 | return err; |
| 396 | |
| 397 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 398 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 399 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 400 | if (k->def) { |
| 401 | k->def_uni = true; |
| 402 | k->def_multi = true; |
| 403 | } |
| 404 | if (k->defmgmt) |
| 405 | k->def_multi = true; |
| 406 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 407 | if (tb[NL80211_KEY_IDX]) |
| 408 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 409 | |
| 410 | if (tb[NL80211_KEY_DATA]) { |
| 411 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 412 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 413 | } |
| 414 | |
| 415 | if (tb[NL80211_KEY_SEQ]) { |
| 416 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 417 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 418 | } |
| 419 | |
| 420 | if (tb[NL80211_KEY_CIPHER]) |
| 421 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 422 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 423 | if (tb[NL80211_KEY_TYPE]) { |
| 424 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 425 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 426 | return -EINVAL; |
| 427 | } |
| 428 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 429 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 430 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 431 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 432 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 433 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 434 | if (err) |
| 435 | return err; |
| 436 | |
| 437 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 438 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 439 | } |
| 440 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 445 | { |
| 446 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 447 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 448 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 449 | } |
| 450 | |
| 451 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 452 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 453 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 454 | } |
| 455 | |
| 456 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 457 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 458 | |
| 459 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 460 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 461 | |
| 462 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 463 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 464 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 465 | if (k->def) { |
| 466 | k->def_uni = true; |
| 467 | k->def_multi = true; |
| 468 | } |
| 469 | if (k->defmgmt) |
| 470 | k->def_multi = true; |
| 471 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 472 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 473 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 474 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 475 | return -EINVAL; |
| 476 | } |
| 477 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 478 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 479 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 480 | int err = nla_parse_nested( |
| 481 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 482 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 483 | nl80211_key_default_policy); |
| 484 | if (err) |
| 485 | return err; |
| 486 | |
| 487 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 488 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 489 | } |
| 490 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 495 | { |
| 496 | int err; |
| 497 | |
| 498 | memset(k, 0, sizeof(*k)); |
| 499 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 500 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 501 | |
| 502 | if (info->attrs[NL80211_ATTR_KEY]) |
| 503 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 504 | else |
| 505 | err = nl80211_parse_key_old(info, k); |
| 506 | |
| 507 | if (err) |
| 508 | return err; |
| 509 | |
| 510 | if (k->def && k->defmgmt) |
| 511 | return -EINVAL; |
| 512 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 513 | if (k->defmgmt) { |
| 514 | if (k->def_uni || !k->def_multi) |
| 515 | return -EINVAL; |
| 516 | } |
| 517 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 518 | if (k->idx != -1) { |
| 519 | if (k->defmgmt) { |
| 520 | if (k->idx < 4 || k->idx > 5) |
| 521 | return -EINVAL; |
| 522 | } else if (k->def) { |
| 523 | if (k->idx < 0 || k->idx > 3) |
| 524 | return -EINVAL; |
| 525 | } else { |
| 526 | if (k->idx < 0 || k->idx > 5) |
| 527 | return -EINVAL; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 534 | static struct cfg80211_cached_keys * |
| 535 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 536 | struct nlattr *keys) |
| 537 | { |
| 538 | struct key_parse parse; |
| 539 | struct nlattr *key; |
| 540 | struct cfg80211_cached_keys *result; |
| 541 | int rem, err, def = 0; |
| 542 | |
| 543 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 544 | if (!result) |
| 545 | return ERR_PTR(-ENOMEM); |
| 546 | |
| 547 | result->def = -1; |
| 548 | result->defmgmt = -1; |
| 549 | |
| 550 | nla_for_each_nested(key, keys, rem) { |
| 551 | memset(&parse, 0, sizeof(parse)); |
| 552 | parse.idx = -1; |
| 553 | |
| 554 | err = nl80211_parse_key_new(key, &parse); |
| 555 | if (err) |
| 556 | goto error; |
| 557 | err = -EINVAL; |
| 558 | if (!parse.p.key) |
| 559 | goto error; |
| 560 | if (parse.idx < 0 || parse.idx > 4) |
| 561 | goto error; |
| 562 | if (parse.def) { |
| 563 | if (def) |
| 564 | goto error; |
| 565 | def = 1; |
| 566 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 567 | if (!parse.def_uni || !parse.def_multi) |
| 568 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 569 | } else if (parse.defmgmt) |
| 570 | goto error; |
| 571 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 572 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 573 | if (err) |
| 574 | goto error; |
| 575 | result->params[parse.idx].cipher = parse.p.cipher; |
| 576 | result->params[parse.idx].key_len = parse.p.key_len; |
| 577 | result->params[parse.idx].key = result->data[parse.idx]; |
| 578 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 579 | } |
| 580 | |
| 581 | return result; |
| 582 | error: |
| 583 | kfree(result); |
| 584 | return ERR_PTR(err); |
| 585 | } |
| 586 | |
| 587 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 588 | { |
| 589 | ASSERT_WDEV_LOCK(wdev); |
| 590 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 591 | switch (wdev->iftype) { |
| 592 | case NL80211_IFTYPE_AP: |
| 593 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 594 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 595 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 596 | break; |
| 597 | case NL80211_IFTYPE_ADHOC: |
| 598 | if (!wdev->current_bss) |
| 599 | return -ENOLINK; |
| 600 | break; |
| 601 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 602 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 603 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 604 | return -ENOLINK; |
| 605 | break; |
| 606 | default: |
| 607 | return -EINVAL; |
| 608 | } |
| 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 613 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 614 | { |
| 615 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 616 | int i; |
| 617 | |
| 618 | if (!nl_modes) |
| 619 | goto nla_put_failure; |
| 620 | |
| 621 | i = 0; |
| 622 | while (ifmodes) { |
| 623 | if (ifmodes & 1) |
| 624 | NLA_PUT_FLAG(msg, i); |
| 625 | ifmodes >>= 1; |
| 626 | i++; |
| 627 | } |
| 628 | |
| 629 | nla_nest_end(msg, nl_modes); |
| 630 | return 0; |
| 631 | |
| 632 | nla_put_failure: |
| 633 | return -ENOBUFS; |
| 634 | } |
| 635 | |
| 636 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 637 | struct sk_buff *msg) |
| 638 | { |
| 639 | struct nlattr *nl_combis; |
| 640 | int i, j; |
| 641 | |
| 642 | nl_combis = nla_nest_start(msg, |
| 643 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 644 | if (!nl_combis) |
| 645 | goto nla_put_failure; |
| 646 | |
| 647 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 648 | const struct ieee80211_iface_combination *c; |
| 649 | struct nlattr *nl_combi, *nl_limits; |
| 650 | |
| 651 | c = &wiphy->iface_combinations[i]; |
| 652 | |
| 653 | nl_combi = nla_nest_start(msg, i + 1); |
| 654 | if (!nl_combi) |
| 655 | goto nla_put_failure; |
| 656 | |
| 657 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 658 | if (!nl_limits) |
| 659 | goto nla_put_failure; |
| 660 | |
| 661 | for (j = 0; j < c->n_limits; j++) { |
| 662 | struct nlattr *nl_limit; |
| 663 | |
| 664 | nl_limit = nla_nest_start(msg, j + 1); |
| 665 | if (!nl_limit) |
| 666 | goto nla_put_failure; |
| 667 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 668 | c->limits[j].max); |
| 669 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 670 | c->limits[j].types)) |
| 671 | goto nla_put_failure; |
| 672 | nla_nest_end(msg, nl_limit); |
| 673 | } |
| 674 | |
| 675 | nla_nest_end(msg, nl_limits); |
| 676 | |
| 677 | if (c->beacon_int_infra_match) |
| 678 | NLA_PUT_FLAG(msg, |
| 679 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 680 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 681 | c->num_different_channels); |
| 682 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 683 | c->max_interfaces); |
| 684 | |
| 685 | nla_nest_end(msg, nl_combi); |
| 686 | } |
| 687 | |
| 688 | nla_nest_end(msg, nl_combis); |
| 689 | |
| 690 | return 0; |
| 691 | nla_put_failure: |
| 692 | return -ENOBUFS; |
| 693 | } |
| 694 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 695 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 696 | struct cfg80211_registered_device *dev) |
| 697 | { |
| 698 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 699 | struct nlattr *nl_bands, *nl_band; |
| 700 | struct nlattr *nl_freqs, *nl_freq; |
| 701 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 702 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 703 | enum ieee80211_band band; |
| 704 | struct ieee80211_channel *chan; |
| 705 | struct ieee80211_rate *rate; |
| 706 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 707 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 708 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 709 | |
| 710 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 711 | if (!hdr) |
| 712 | return -1; |
| 713 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 714 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 715 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 716 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 717 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 718 | cfg80211_rdev_list_generation); |
| 719 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 720 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 721 | dev->wiphy.retry_short); |
| 722 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 723 | dev->wiphy.retry_long); |
| 724 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 725 | dev->wiphy.frag_threshold); |
| 726 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 727 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 728 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 729 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 730 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 731 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 732 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 733 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 734 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 735 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 736 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 737 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 738 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 739 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 740 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 741 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 742 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 743 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 744 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 745 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 746 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 747 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 748 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 749 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) |
| 750 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT); |
| 751 | if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) |
| 752 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 753 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 754 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 755 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 756 | dev->wiphy.cipher_suites); |
| 757 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 758 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 759 | dev->wiphy.max_num_pmkids); |
| 760 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 761 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 762 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 763 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 764 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 765 | dev->wiphy.available_antennas_tx); |
| 766 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 767 | dev->wiphy.available_antennas_rx); |
| 768 | |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 769 | if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) |
| 770 | NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 771 | dev->wiphy.probe_resp_offload); |
| 772 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 773 | if ((dev->wiphy.available_antennas_tx || |
| 774 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 775 | u32 tx_ant = 0, rx_ant = 0; |
| 776 | int res; |
| 777 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 778 | if (!res) { |
| 779 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 780 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 781 | } |
| 782 | } |
| 783 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 784 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 785 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 786 | goto nla_put_failure; |
| 787 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 788 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 789 | if (!nl_bands) |
| 790 | goto nla_put_failure; |
| 791 | |
| 792 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 793 | if (!dev->wiphy.bands[band]) |
| 794 | continue; |
| 795 | |
| 796 | nl_band = nla_nest_start(msg, band); |
| 797 | if (!nl_band) |
| 798 | goto nla_put_failure; |
| 799 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 800 | /* add HT info */ |
| 801 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 802 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 803 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 804 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 805 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 806 | dev->wiphy.bands[band]->ht_cap.cap); |
| 807 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 808 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 809 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 810 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 811 | } |
| 812 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 813 | /* add frequencies */ |
| 814 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 815 | if (!nl_freqs) |
| 816 | goto nla_put_failure; |
| 817 | |
| 818 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 819 | nl_freq = nla_nest_start(msg, i); |
| 820 | if (!nl_freq) |
| 821 | goto nla_put_failure; |
| 822 | |
| 823 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 824 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 825 | if (nl80211_msg_put_channel(msg, chan)) |
| 826 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 827 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 828 | nla_nest_end(msg, nl_freq); |
| 829 | } |
| 830 | |
| 831 | nla_nest_end(msg, nl_freqs); |
| 832 | |
| 833 | /* add bitrates */ |
| 834 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 835 | if (!nl_rates) |
| 836 | goto nla_put_failure; |
| 837 | |
| 838 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 839 | nl_rate = nla_nest_start(msg, i); |
| 840 | if (!nl_rate) |
| 841 | goto nla_put_failure; |
| 842 | |
| 843 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 844 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 845 | rate->bitrate); |
| 846 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 847 | NLA_PUT_FLAG(msg, |
| 848 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 849 | |
| 850 | nla_nest_end(msg, nl_rate); |
| 851 | } |
| 852 | |
| 853 | nla_nest_end(msg, nl_rates); |
| 854 | |
| 855 | nla_nest_end(msg, nl_band); |
| 856 | } |
| 857 | nla_nest_end(msg, nl_bands); |
| 858 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 859 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 860 | if (!nl_cmds) |
| 861 | goto nla_put_failure; |
| 862 | |
| 863 | i = 0; |
| 864 | #define CMD(op, n) \ |
| 865 | do { \ |
| 866 | if (dev->ops->op) { \ |
| 867 | i++; \ |
| 868 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 869 | } \ |
| 870 | } while (0) |
| 871 | |
| 872 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 873 | CMD(change_virtual_intf, SET_INTERFACE); |
| 874 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 875 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 876 | CMD(add_station, NEW_STATION); |
| 877 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 878 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 879 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 880 | CMD(auth, AUTHENTICATE); |
| 881 | CMD(assoc, ASSOCIATE); |
| 882 | CMD(deauth, DEAUTHENTICATE); |
| 883 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 884 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 885 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 886 | CMD(set_pmksa, SET_PMKSA); |
| 887 | CMD(del_pmksa, DEL_PMKSA); |
| 888 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 889 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 890 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 891 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 892 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 893 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 894 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 895 | i++; |
| 896 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 897 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 898 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 899 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 900 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 901 | CMD(tdls_mgmt, TDLS_MGMT); |
| 902 | CMD(tdls_oper, TDLS_OPER); |
| 903 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 904 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 905 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 906 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 907 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 908 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 909 | i++; |
| 910 | NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS); |
| 911 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 912 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 913 | #ifdef CONFIG_NL80211_TESTMODE |
| 914 | CMD(testmode_cmd, TESTMODE); |
| 915 | #endif |
| 916 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 917 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 918 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 919 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 920 | i++; |
| 921 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 922 | } |
| 923 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 924 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 925 | i++; |
| 926 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 927 | } |
| 928 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 929 | nla_nest_end(msg, nl_cmds); |
| 930 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 931 | if (dev->ops->remain_on_channel && |
| 932 | dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 933 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 934 | dev->wiphy.max_remain_on_channel_duration); |
| 935 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 936 | if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 937 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 938 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 939 | if (mgmt_stypes) { |
| 940 | u16 stypes; |
| 941 | struct nlattr *nl_ftypes, *nl_ifs; |
| 942 | enum nl80211_iftype ift; |
| 943 | |
| 944 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 945 | if (!nl_ifs) |
| 946 | goto nla_put_failure; |
| 947 | |
| 948 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 949 | nl_ftypes = nla_nest_start(msg, ift); |
| 950 | if (!nl_ftypes) |
| 951 | goto nla_put_failure; |
| 952 | i = 0; |
| 953 | stypes = mgmt_stypes[ift].tx; |
| 954 | while (stypes) { |
| 955 | if (stypes & 1) |
| 956 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 957 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 958 | stypes >>= 1; |
| 959 | i++; |
| 960 | } |
| 961 | nla_nest_end(msg, nl_ftypes); |
| 962 | } |
| 963 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 964 | nla_nest_end(msg, nl_ifs); |
| 965 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 966 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 967 | if (!nl_ifs) |
| 968 | goto nla_put_failure; |
| 969 | |
| 970 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 971 | nl_ftypes = nla_nest_start(msg, ift); |
| 972 | if (!nl_ftypes) |
| 973 | goto nla_put_failure; |
| 974 | i = 0; |
| 975 | stypes = mgmt_stypes[ift].rx; |
| 976 | while (stypes) { |
| 977 | if (stypes & 1) |
| 978 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 979 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 980 | stypes >>= 1; |
| 981 | i++; |
| 982 | } |
| 983 | nla_nest_end(msg, nl_ftypes); |
| 984 | } |
| 985 | nla_nest_end(msg, nl_ifs); |
| 986 | } |
| 987 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 988 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 989 | struct nlattr *nl_wowlan; |
| 990 | |
| 991 | nl_wowlan = nla_nest_start(msg, |
| 992 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 993 | if (!nl_wowlan) |
| 994 | goto nla_put_failure; |
| 995 | |
| 996 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 997 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 998 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 999 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 1000 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 1001 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 1002 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 1003 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 1004 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 1005 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 1006 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 1007 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 1008 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 1009 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 1010 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 1011 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1012 | if (dev->wiphy.wowlan.n_patterns) { |
| 1013 | struct nl80211_wowlan_pattern_support pat = { |
| 1014 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1015 | .min_pattern_len = |
| 1016 | dev->wiphy.wowlan.pattern_min_len, |
| 1017 | .max_pattern_len = |
| 1018 | dev->wiphy.wowlan.pattern_max_len, |
| 1019 | }; |
| 1020 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1021 | sizeof(pat), &pat); |
| 1022 | } |
| 1023 | |
| 1024 | nla_nest_end(msg, nl_wowlan); |
| 1025 | } |
| 1026 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1027 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1028 | dev->wiphy.software_iftypes)) |
| 1029 | goto nla_put_failure; |
| 1030 | |
| 1031 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1032 | goto nla_put_failure; |
| 1033 | |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1034 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) |
| 1035 | NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1036 | dev->wiphy.ap_sme_capa); |
| 1037 | |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1038 | NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features); |
| 1039 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1040 | if (dev->wiphy.ht_capa_mod_mask) |
| 1041 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1042 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1043 | dev->wiphy.ht_capa_mod_mask); |
| 1044 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1045 | return genlmsg_end(msg, hdr); |
| 1046 | |
| 1047 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1048 | genlmsg_cancel(msg, hdr); |
| 1049 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1053 | { |
| 1054 | int idx = 0; |
| 1055 | int start = cb->args[0]; |
| 1056 | struct cfg80211_registered_device *dev; |
| 1057 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1058 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1059 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1060 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1061 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1062 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1063 | continue; |
| 1064 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1065 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1066 | dev) < 0) { |
| 1067 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1068 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1069 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1070 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1071 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1072 | |
| 1073 | cb->args[0] = idx; |
| 1074 | |
| 1075 | return skb->len; |
| 1076 | } |
| 1077 | |
| 1078 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1079 | { |
| 1080 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1081 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1082 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1083 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1084 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1085 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1086 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1087 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1088 | nlmsg_free(msg); |
| 1089 | return -ENOBUFS; |
| 1090 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1091 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1092 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1095 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1096 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1097 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1098 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1099 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1100 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1101 | }; |
| 1102 | |
| 1103 | static int parse_txq_params(struct nlattr *tb[], |
| 1104 | struct ieee80211_txq_params *txq_params) |
| 1105 | { |
| 1106 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1107 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1108 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1109 | return -EINVAL; |
| 1110 | |
| 1111 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1112 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1113 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1114 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1115 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1116 | |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1120 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1121 | { |
| 1122 | /* |
| 1123 | * You can only set the channel explicitly for AP, mesh |
| 1124 | * and WDS type interfaces; all others have their channel |
| 1125 | * managed via their respective "establish a connection" |
| 1126 | * command (connect, join, ...) |
| 1127 | * |
| 1128 | * Monitors are special as they are normally slaved to |
| 1129 | * whatever else is going on, so they behave as though |
| 1130 | * you tried setting the wiphy channel itself. |
| 1131 | */ |
| 1132 | return !wdev || |
| 1133 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1134 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1135 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1136 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1137 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1141 | struct wireless_dev *wdev, |
| 1142 | struct genl_info *info) |
| 1143 | { |
| 1144 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1145 | u32 freq; |
| 1146 | int result; |
| 1147 | |
| 1148 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1149 | return -EINVAL; |
| 1150 | |
| 1151 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1152 | return -EOPNOTSUPP; |
| 1153 | |
| 1154 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1155 | channel_type = nla_get_u32(info->attrs[ |
| 1156 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1157 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1158 | channel_type != NL80211_CHAN_HT20 && |
| 1159 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1160 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1161 | return -EINVAL; |
| 1162 | } |
| 1163 | |
| 1164 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1165 | |
| 1166 | mutex_lock(&rdev->devlist_mtx); |
| 1167 | if (wdev) { |
| 1168 | wdev_lock(wdev); |
| 1169 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1170 | wdev_unlock(wdev); |
| 1171 | } else { |
| 1172 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1173 | } |
| 1174 | mutex_unlock(&rdev->devlist_mtx); |
| 1175 | |
| 1176 | return result; |
| 1177 | } |
| 1178 | |
| 1179 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1180 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1181 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1182 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1183 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1184 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1185 | } |
| 1186 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1187 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1188 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1190 | struct net_device *dev = info->user_ptr[1]; |
| 1191 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1192 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1193 | |
| 1194 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1195 | return -EINVAL; |
| 1196 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1197 | if (netif_running(dev)) |
| 1198 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1199 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1200 | if (!rdev->ops->set_wds_peer) |
| 1201 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1202 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1203 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1204 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1205 | |
| 1206 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1207 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1211 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1212 | { |
| 1213 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1214 | struct net_device *netdev = NULL; |
| 1215 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1216 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1217 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1218 | u32 changed; |
| 1219 | u8 retry_short = 0, retry_long = 0; |
| 1220 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1221 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1222 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1223 | /* |
| 1224 | * Try to find the wiphy and netdev. Normally this |
| 1225 | * function shouldn't need the netdev, but this is |
| 1226 | * done for backward compatibility -- previously |
| 1227 | * setting the channel was done per wiphy, but now |
| 1228 | * it is per netdev. Previous userland like hostapd |
| 1229 | * also passed a netdev to set_wiphy, so that it is |
| 1230 | * possible to let that go to the right netdev! |
| 1231 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1232 | mutex_lock(&cfg80211_mutex); |
| 1233 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1234 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1235 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1236 | |
| 1237 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1238 | if (netdev && netdev->ieee80211_ptr) { |
| 1239 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1240 | mutex_lock(&rdev->mtx); |
| 1241 | } else |
| 1242 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1245 | if (!netdev) { |
| 1246 | rdev = __cfg80211_rdev_from_info(info); |
| 1247 | if (IS_ERR(rdev)) { |
| 1248 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1249 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1250 | } |
| 1251 | wdev = NULL; |
| 1252 | netdev = NULL; |
| 1253 | result = 0; |
| 1254 | |
| 1255 | mutex_lock(&rdev->mtx); |
| 1256 | } else if (netif_running(netdev) && |
| 1257 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1258 | wdev = netdev->ieee80211_ptr; |
| 1259 | else |
| 1260 | wdev = NULL; |
| 1261 | |
| 1262 | /* |
| 1263 | * end workaround code, by now the rdev is available |
| 1264 | * and locked, and wdev may or may not be NULL. |
| 1265 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1266 | |
| 1267 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1268 | result = cfg80211_dev_rename( |
| 1269 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1270 | |
| 1271 | mutex_unlock(&cfg80211_mutex); |
| 1272 | |
| 1273 | if (result) |
| 1274 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1275 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1276 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1277 | struct ieee80211_txq_params txq_params; |
| 1278 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1279 | |
| 1280 | if (!rdev->ops->set_txq_params) { |
| 1281 | result = -EOPNOTSUPP; |
| 1282 | goto bad_res; |
| 1283 | } |
| 1284 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1285 | if (!netdev) { |
| 1286 | result = -EINVAL; |
| 1287 | goto bad_res; |
| 1288 | } |
| 1289 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1290 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1291 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1292 | result = -EINVAL; |
| 1293 | goto bad_res; |
| 1294 | } |
| 1295 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1296 | nla_for_each_nested(nl_txq_params, |
| 1297 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1298 | rem_txq_params) { |
| 1299 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1300 | nla_data(nl_txq_params), |
| 1301 | nla_len(nl_txq_params), |
| 1302 | txq_params_policy); |
| 1303 | result = parse_txq_params(tb, &txq_params); |
| 1304 | if (result) |
| 1305 | goto bad_res; |
| 1306 | |
| 1307 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1308 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1309 | &txq_params); |
| 1310 | if (result) |
| 1311 | goto bad_res; |
| 1312 | } |
| 1313 | } |
| 1314 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1315 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1316 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1317 | if (result) |
| 1318 | goto bad_res; |
| 1319 | } |
| 1320 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1321 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1322 | enum nl80211_tx_power_setting type; |
| 1323 | int idx, mbm = 0; |
| 1324 | |
| 1325 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1326 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1327 | goto bad_res; |
| 1328 | } |
| 1329 | |
| 1330 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1331 | type = nla_get_u32(info->attrs[idx]); |
| 1332 | |
| 1333 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1334 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1335 | result = -EINVAL; |
| 1336 | goto bad_res; |
| 1337 | } |
| 1338 | |
| 1339 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1340 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1341 | mbm = nla_get_u32(info->attrs[idx]); |
| 1342 | } |
| 1343 | |
| 1344 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1345 | if (result) |
| 1346 | goto bad_res; |
| 1347 | } |
| 1348 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1349 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1350 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1351 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1352 | if ((!rdev->wiphy.available_antennas_tx && |
| 1353 | !rdev->wiphy.available_antennas_rx) || |
| 1354 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1355 | result = -EOPNOTSUPP; |
| 1356 | goto bad_res; |
| 1357 | } |
| 1358 | |
| 1359 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1360 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1361 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1362 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1363 | * available antenna masks, except for the "all" mask */ |
| 1364 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1365 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1366 | result = -EINVAL; |
| 1367 | goto bad_res; |
| 1368 | } |
| 1369 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1370 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1371 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1372 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1373 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1374 | if (result) |
| 1375 | goto bad_res; |
| 1376 | } |
| 1377 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1378 | changed = 0; |
| 1379 | |
| 1380 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1381 | retry_short = nla_get_u8( |
| 1382 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1383 | if (retry_short == 0) { |
| 1384 | result = -EINVAL; |
| 1385 | goto bad_res; |
| 1386 | } |
| 1387 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1388 | } |
| 1389 | |
| 1390 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1391 | retry_long = nla_get_u8( |
| 1392 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1393 | if (retry_long == 0) { |
| 1394 | result = -EINVAL; |
| 1395 | goto bad_res; |
| 1396 | } |
| 1397 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1398 | } |
| 1399 | |
| 1400 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1401 | frag_threshold = nla_get_u32( |
| 1402 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1403 | if (frag_threshold < 256) { |
| 1404 | result = -EINVAL; |
| 1405 | goto bad_res; |
| 1406 | } |
| 1407 | if (frag_threshold != (u32) -1) { |
| 1408 | /* |
| 1409 | * Fragments (apart from the last one) are required to |
| 1410 | * have even length. Make the fragmentation code |
| 1411 | * simpler by stripping LSB should someone try to use |
| 1412 | * odd threshold value. |
| 1413 | */ |
| 1414 | frag_threshold &= ~0x1; |
| 1415 | } |
| 1416 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1417 | } |
| 1418 | |
| 1419 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1420 | rts_threshold = nla_get_u32( |
| 1421 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1422 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1423 | } |
| 1424 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1425 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1426 | coverage_class = nla_get_u8( |
| 1427 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1428 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1429 | } |
| 1430 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1431 | if (changed) { |
| 1432 | u8 old_retry_short, old_retry_long; |
| 1433 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1434 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1435 | |
| 1436 | if (!rdev->ops->set_wiphy_params) { |
| 1437 | result = -EOPNOTSUPP; |
| 1438 | goto bad_res; |
| 1439 | } |
| 1440 | |
| 1441 | old_retry_short = rdev->wiphy.retry_short; |
| 1442 | old_retry_long = rdev->wiphy.retry_long; |
| 1443 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1444 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1445 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1446 | |
| 1447 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1448 | rdev->wiphy.retry_short = retry_short; |
| 1449 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1450 | rdev->wiphy.retry_long = retry_long; |
| 1451 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1452 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1453 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1454 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1455 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1456 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1457 | |
| 1458 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1459 | if (result) { |
| 1460 | rdev->wiphy.retry_short = old_retry_short; |
| 1461 | rdev->wiphy.retry_long = old_retry_long; |
| 1462 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1463 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1464 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1465 | } |
| 1466 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1467 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1468 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1469 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1470 | if (netdev) |
| 1471 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1472 | return result; |
| 1473 | } |
| 1474 | |
| 1475 | |
| 1476 | 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] | 1477 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1478 | struct net_device *dev) |
| 1479 | { |
| 1480 | void *hdr; |
| 1481 | |
| 1482 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1483 | if (!hdr) |
| 1484 | return -1; |
| 1485 | |
| 1486 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1487 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1488 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1489 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1490 | |
| 1491 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1492 | rdev->devlist_generation ^ |
| 1493 | (cfg80211_rdev_list_generation << 2)); |
| 1494 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1495 | return genlmsg_end(msg, hdr); |
| 1496 | |
| 1497 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1498 | genlmsg_cancel(msg, hdr); |
| 1499 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1503 | { |
| 1504 | int wp_idx = 0; |
| 1505 | int if_idx = 0; |
| 1506 | int wp_start = cb->args[0]; |
| 1507 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1508 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1509 | struct wireless_dev *wdev; |
| 1510 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1511 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1512 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1513 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1514 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1515 | if (wp_idx < wp_start) { |
| 1516 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1517 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1518 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1519 | if_idx = 0; |
| 1520 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1521 | mutex_lock(&rdev->devlist_mtx); |
| 1522 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1523 | if (if_idx < if_start) { |
| 1524 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1525 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1526 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1527 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1528 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1529 | rdev, wdev->netdev) < 0) { |
| 1530 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1531 | goto out; |
| 1532 | } |
| 1533 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1534 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1535 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1536 | |
| 1537 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1538 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1539 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1540 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1541 | |
| 1542 | cb->args[0] = wp_idx; |
| 1543 | cb->args[1] = if_idx; |
| 1544 | |
| 1545 | return skb->len; |
| 1546 | } |
| 1547 | |
| 1548 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1549 | { |
| 1550 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1551 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1552 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1553 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1554 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1555 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1556 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1557 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1558 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1559 | dev, netdev) < 0) { |
| 1560 | nlmsg_free(msg); |
| 1561 | return -ENOBUFS; |
| 1562 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1563 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1564 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1565 | } |
| 1566 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1567 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1568 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1569 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1570 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1571 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1572 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1573 | }; |
| 1574 | |
| 1575 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1576 | { |
| 1577 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1578 | int flag; |
| 1579 | |
| 1580 | *mntrflags = 0; |
| 1581 | |
| 1582 | if (!nla) |
| 1583 | return -EINVAL; |
| 1584 | |
| 1585 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1586 | nla, mntr_flags_policy)) |
| 1587 | return -EINVAL; |
| 1588 | |
| 1589 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1590 | if (flags[flag]) |
| 1591 | *mntrflags |= (1<<flag); |
| 1592 | |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1596 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1597 | struct net_device *netdev, u8 use_4addr, |
| 1598 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1599 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1600 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1601 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1602 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1603 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1604 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1605 | |
| 1606 | switch (iftype) { |
| 1607 | case NL80211_IFTYPE_AP_VLAN: |
| 1608 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1609 | return 0; |
| 1610 | break; |
| 1611 | case NL80211_IFTYPE_STATION: |
| 1612 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1613 | return 0; |
| 1614 | break; |
| 1615 | default: |
| 1616 | break; |
| 1617 | } |
| 1618 | |
| 1619 | return -EOPNOTSUPP; |
| 1620 | } |
| 1621 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1622 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1623 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1625 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1626 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1627 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1628 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1629 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1630 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1631 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1632 | memset(¶ms, 0, sizeof(params)); |
| 1633 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1634 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1635 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1636 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1637 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1638 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1639 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1640 | if (ntype > NL80211_IFTYPE_MAX) |
| 1641 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1642 | } |
| 1643 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1644 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1645 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1646 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1647 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1648 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1649 | if (netif_running(dev)) |
| 1650 | return -EBUSY; |
| 1651 | |
| 1652 | wdev_lock(wdev); |
| 1653 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1654 | IEEE80211_MAX_MESH_ID_LEN); |
| 1655 | wdev->mesh_id_up_len = |
| 1656 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1657 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1658 | wdev->mesh_id_up_len); |
| 1659 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1660 | } |
| 1661 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1662 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1663 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1664 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1665 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1666 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1667 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1668 | } else { |
| 1669 | params.use_4addr = -1; |
| 1670 | } |
| 1671 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1672 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1673 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1674 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1675 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1676 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1677 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1678 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1679 | |
| 1680 | flags = &_flags; |
| 1681 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1682 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1683 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1684 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1685 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1686 | else |
| 1687 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1688 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1689 | if (!err && params.use_4addr != -1) |
| 1690 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1691 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1692 | return err; |
| 1693 | } |
| 1694 | |
| 1695 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1696 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1698 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1699 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1700 | int err; |
| 1701 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1702 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1703 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1704 | memset(¶ms, 0, sizeof(params)); |
| 1705 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1706 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1707 | return -EINVAL; |
| 1708 | |
| 1709 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1710 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1711 | if (type > NL80211_IFTYPE_MAX) |
| 1712 | return -EINVAL; |
| 1713 | } |
| 1714 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1715 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1716 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1717 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1718 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1719 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1720 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1721 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1722 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1723 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1724 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1725 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1726 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1727 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1728 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1729 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1730 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1731 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1732 | if (IS_ERR(dev)) |
| 1733 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1734 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1735 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1736 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1737 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1738 | |
| 1739 | wdev_lock(wdev); |
| 1740 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1741 | IEEE80211_MAX_MESH_ID_LEN); |
| 1742 | wdev->mesh_id_up_len = |
| 1743 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1744 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1745 | wdev->mesh_id_up_len); |
| 1746 | wdev_unlock(wdev); |
| 1747 | } |
| 1748 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1749 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1753 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1755 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1756 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1757 | if (!rdev->ops->del_virtual_intf) |
| 1758 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1760 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1761 | } |
| 1762 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1763 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 1764 | { |
| 1765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1766 | struct net_device *dev = info->user_ptr[1]; |
| 1767 | u16 noack_map; |
| 1768 | |
| 1769 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 1770 | return -EINVAL; |
| 1771 | |
| 1772 | if (!rdev->ops->set_noack_map) |
| 1773 | return -EOPNOTSUPP; |
| 1774 | |
| 1775 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 1776 | |
| 1777 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 1778 | } |
| 1779 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1780 | struct get_key_cookie { |
| 1781 | struct sk_buff *msg; |
| 1782 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1783 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1784 | }; |
| 1785 | |
| 1786 | static void get_key_callback(void *c, struct key_params *params) |
| 1787 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1788 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1789 | struct get_key_cookie *cookie = c; |
| 1790 | |
| 1791 | if (params->key) |
| 1792 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1793 | params->key_len, params->key); |
| 1794 | |
| 1795 | if (params->seq) |
| 1796 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1797 | params->seq_len, params->seq); |
| 1798 | |
| 1799 | if (params->cipher) |
| 1800 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1801 | params->cipher); |
| 1802 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1803 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1804 | if (!key) |
| 1805 | goto nla_put_failure; |
| 1806 | |
| 1807 | if (params->key) |
| 1808 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1809 | params->key_len, params->key); |
| 1810 | |
| 1811 | if (params->seq) |
| 1812 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1813 | params->seq_len, params->seq); |
| 1814 | |
| 1815 | if (params->cipher) |
| 1816 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1817 | params->cipher); |
| 1818 | |
| 1819 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1820 | |
| 1821 | nla_nest_end(cookie->msg, key); |
| 1822 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1823 | return; |
| 1824 | nla_put_failure: |
| 1825 | cookie->error = 1; |
| 1826 | } |
| 1827 | |
| 1828 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1829 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1831 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1832 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1833 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1834 | const u8 *mac_addr = NULL; |
| 1835 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1836 | struct get_key_cookie cookie = { |
| 1837 | .error = 0, |
| 1838 | }; |
| 1839 | void *hdr; |
| 1840 | struct sk_buff *msg; |
| 1841 | |
| 1842 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1843 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1844 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1845 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1846 | return -EINVAL; |
| 1847 | |
| 1848 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1849 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1850 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1851 | pairwise = !!mac_addr; |
| 1852 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1853 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1854 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1855 | return -EINVAL; |
| 1856 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1857 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1858 | return -EINVAL; |
| 1859 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1860 | } |
| 1861 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1862 | if (!rdev->ops->get_key) |
| 1863 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1864 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1865 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1866 | if (!msg) |
| 1867 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1868 | |
| 1869 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1870 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1871 | if (IS_ERR(hdr)) |
| 1872 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1873 | |
| 1874 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1875 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1876 | |
| 1877 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1878 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1879 | if (mac_addr) |
| 1880 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1881 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1882 | if (pairwise && mac_addr && |
| 1883 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1884 | return -ENOENT; |
| 1885 | |
| 1886 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1887 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1888 | |
| 1889 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1890 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1891 | |
| 1892 | if (cookie.error) |
| 1893 | goto nla_put_failure; |
| 1894 | |
| 1895 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1896 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1897 | |
| 1898 | nla_put_failure: |
| 1899 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1900 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1901 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1902 | return err; |
| 1903 | } |
| 1904 | |
| 1905 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1906 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1908 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1909 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1910 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1911 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1912 | err = nl80211_parse_key(info, &key); |
| 1913 | if (err) |
| 1914 | return err; |
| 1915 | |
| 1916 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1917 | return -EINVAL; |
| 1918 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1919 | /* only support setting default key */ |
| 1920 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1921 | return -EINVAL; |
| 1922 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1923 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1924 | |
| 1925 | if (key.def) { |
| 1926 | if (!rdev->ops->set_default_key) { |
| 1927 | err = -EOPNOTSUPP; |
| 1928 | goto out; |
| 1929 | } |
| 1930 | |
| 1931 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1932 | if (err) |
| 1933 | goto out; |
| 1934 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1935 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1936 | key.def_uni, key.def_multi); |
| 1937 | |
| 1938 | if (err) |
| 1939 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1940 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1941 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1942 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1943 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1944 | } else { |
| 1945 | if (key.def_uni || !key.def_multi) { |
| 1946 | err = -EINVAL; |
| 1947 | goto out; |
| 1948 | } |
| 1949 | |
| 1950 | if (!rdev->ops->set_default_mgmt_key) { |
| 1951 | err = -EOPNOTSUPP; |
| 1952 | goto out; |
| 1953 | } |
| 1954 | |
| 1955 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1956 | if (err) |
| 1957 | goto out; |
| 1958 | |
| 1959 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1960 | dev, key.idx); |
| 1961 | if (err) |
| 1962 | goto out; |
| 1963 | |
| 1964 | #ifdef CONFIG_CFG80211_WEXT |
| 1965 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1966 | #endif |
| 1967 | } |
| 1968 | |
| 1969 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1970 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1971 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1972 | return err; |
| 1973 | } |
| 1974 | |
| 1975 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1976 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1978 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1979 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1980 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1981 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1982 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1983 | err = nl80211_parse_key(info, &key); |
| 1984 | if (err) |
| 1985 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1986 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1987 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1988 | return -EINVAL; |
| 1989 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1990 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1991 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1992 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1993 | if (key.type == -1) { |
| 1994 | if (mac_addr) |
| 1995 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1996 | else |
| 1997 | key.type = NL80211_KEYTYPE_GROUP; |
| 1998 | } |
| 1999 | |
| 2000 | /* for now */ |
| 2001 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2002 | key.type != NL80211_KEYTYPE_GROUP) |
| 2003 | return -EINVAL; |
| 2004 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2005 | if (!rdev->ops->add_key) |
| 2006 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2007 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2008 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2009 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2010 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2011 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2012 | |
| 2013 | wdev_lock(dev->ieee80211_ptr); |
| 2014 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2015 | if (!err) |
| 2016 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2017 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2018 | mac_addr, &key.p); |
| 2019 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2020 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2021 | return err; |
| 2022 | } |
| 2023 | |
| 2024 | static int nl80211_del_key(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 | 41ade00 | 2007-12-19 02:03:29 +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 | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2029 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2030 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2031 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2032 | err = nl80211_parse_key(info, &key); |
| 2033 | if (err) |
| 2034 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2035 | |
| 2036 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2037 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2038 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2039 | if (key.type == -1) { |
| 2040 | if (mac_addr) |
| 2041 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2042 | else |
| 2043 | key.type = NL80211_KEYTYPE_GROUP; |
| 2044 | } |
| 2045 | |
| 2046 | /* for now */ |
| 2047 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2048 | key.type != NL80211_KEYTYPE_GROUP) |
| 2049 | return -EINVAL; |
| 2050 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2051 | if (!rdev->ops->del_key) |
| 2052 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2053 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2054 | wdev_lock(dev->ieee80211_ptr); |
| 2055 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2056 | |
| 2057 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2058 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2059 | err = -ENOENT; |
| 2060 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2061 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2062 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2063 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2064 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2065 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2066 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2067 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2068 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2069 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2070 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2071 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2072 | } |
| 2073 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2074 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2075 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2076 | return err; |
| 2077 | } |
| 2078 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2079 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2080 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2081 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2082 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2083 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2084 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2085 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2086 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2087 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2088 | return -EINVAL; |
| 2089 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2090 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2091 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2092 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2093 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2094 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2095 | if (!bcn->head_len) |
| 2096 | return -EINVAL; |
| 2097 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2101 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2102 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2103 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2104 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2105 | } |
| 2106 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2107 | if (!haveinfo) |
| 2108 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2109 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2110 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2111 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2112 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2116 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2117 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2118 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2119 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2120 | } |
| 2121 | |
| 2122 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2123 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2124 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2125 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2126 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2127 | } |
| 2128 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2129 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2130 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2131 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2132 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2133 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2134 | } |
| 2135 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2136 | return 0; |
| 2137 | } |
| 2138 | |
| 2139 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2140 | { |
| 2141 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2142 | struct net_device *dev = info->user_ptr[1]; |
| 2143 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2144 | struct cfg80211_ap_settings params; |
| 2145 | int err; |
| 2146 | |
| 2147 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2148 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2149 | return -EOPNOTSUPP; |
| 2150 | |
| 2151 | if (!rdev->ops->start_ap) |
| 2152 | return -EOPNOTSUPP; |
| 2153 | |
| 2154 | if (wdev->beacon_interval) |
| 2155 | return -EALREADY; |
| 2156 | |
| 2157 | memset(¶ms, 0, sizeof(params)); |
| 2158 | |
| 2159 | /* these are required for START_AP */ |
| 2160 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2161 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2162 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2163 | return -EINVAL; |
| 2164 | |
| 2165 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2166 | if (err) |
| 2167 | return err; |
| 2168 | |
| 2169 | params.beacon_interval = |
| 2170 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2171 | params.dtim_period = |
| 2172 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2173 | |
| 2174 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2175 | if (err) |
| 2176 | return err; |
| 2177 | |
| 2178 | /* |
| 2179 | * In theory, some of these attributes should be required here |
| 2180 | * but since they were not used when the command was originally |
| 2181 | * added, keep them optional for old user space programs to let |
| 2182 | * them continue to work with drivers that do not need the |
| 2183 | * additional information -- drivers must check! |
| 2184 | */ |
| 2185 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2186 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2187 | params.ssid_len = |
| 2188 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2189 | if (params.ssid_len == 0 || |
| 2190 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2191 | return -EINVAL; |
| 2192 | } |
| 2193 | |
| 2194 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2195 | params.hidden_ssid = nla_get_u32( |
| 2196 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2197 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2198 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2199 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2200 | return -EINVAL; |
| 2201 | } |
| 2202 | |
| 2203 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2204 | |
| 2205 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2206 | params.auth_type = nla_get_u32( |
| 2207 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2208 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2209 | return -EINVAL; |
| 2210 | } else |
| 2211 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2212 | |
| 2213 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2214 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2215 | if (err) |
| 2216 | return err; |
| 2217 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame^] | 2218 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2219 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2220 | return -EOPNOTSUPP; |
| 2221 | params.inactivity_timeout = nla_get_u16( |
| 2222 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2223 | } |
| 2224 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2225 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
| 2226 | if (!err) |
| 2227 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2228 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2229 | } |
| 2230 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2231 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2232 | { |
| 2233 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2234 | struct net_device *dev = info->user_ptr[1]; |
| 2235 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2236 | struct cfg80211_beacon_data params; |
| 2237 | int err; |
| 2238 | |
| 2239 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2240 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2241 | return -EOPNOTSUPP; |
| 2242 | |
| 2243 | if (!rdev->ops->change_beacon) |
| 2244 | return -EOPNOTSUPP; |
| 2245 | |
| 2246 | if (!wdev->beacon_interval) |
| 2247 | return -EINVAL; |
| 2248 | |
| 2249 | err = nl80211_parse_beacon(info, ¶ms); |
| 2250 | if (err) |
| 2251 | return err; |
| 2252 | |
| 2253 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); |
| 2254 | } |
| 2255 | |
| 2256 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2257 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2259 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2260 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2261 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2262 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2263 | if (!rdev->ops->stop_ap) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2264 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2265 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2266 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2267 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2268 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2269 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2270 | if (!wdev->beacon_interval) |
| 2271 | return -ENOENT; |
| 2272 | |
| 2273 | err = rdev->ops->stop_ap(&rdev->wiphy, dev); |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2274 | if (!err) |
| 2275 | wdev->beacon_interval = 0; |
| 2276 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2277 | } |
| 2278 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2279 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2280 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2281 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2282 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2283 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2284 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2285 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2286 | }; |
| 2287 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2288 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2289 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2290 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2291 | { |
| 2292 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2293 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2294 | int flag; |
| 2295 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2296 | /* |
| 2297 | * Try parsing the new attribute first so userspace |
| 2298 | * can specify both for older kernels. |
| 2299 | */ |
| 2300 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2301 | if (nla) { |
| 2302 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2303 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2304 | sta_flags = nla_data(nla); |
| 2305 | params->sta_flags_mask = sta_flags->mask; |
| 2306 | params->sta_flags_set = sta_flags->set; |
| 2307 | if ((params->sta_flags_mask | |
| 2308 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2309 | return -EINVAL; |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
| 2313 | /* if present, parse the old attribute */ |
| 2314 | |
| 2315 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2316 | if (!nla) |
| 2317 | return 0; |
| 2318 | |
| 2319 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2320 | nla, sta_flags_policy)) |
| 2321 | return -EINVAL; |
| 2322 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2323 | /* |
| 2324 | * Only allow certain flags for interface types so that |
| 2325 | * other attributes are silently ignored. Remember that |
| 2326 | * this is backward compatibility code with old userspace |
| 2327 | * and shouldn't be hit in other cases anyway. |
| 2328 | */ |
| 2329 | switch (iftype) { |
| 2330 | case NL80211_IFTYPE_AP: |
| 2331 | case NL80211_IFTYPE_AP_VLAN: |
| 2332 | case NL80211_IFTYPE_P2P_GO: |
| 2333 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2334 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2335 | BIT(NL80211_STA_FLAG_WME) | |
| 2336 | BIT(NL80211_STA_FLAG_MFP); |
| 2337 | break; |
| 2338 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2339 | case NL80211_IFTYPE_STATION: |
| 2340 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2341 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2342 | break; |
| 2343 | case NL80211_IFTYPE_MESH_POINT: |
| 2344 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2345 | BIT(NL80211_STA_FLAG_MFP) | |
| 2346 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2347 | default: |
| 2348 | return -EINVAL; |
| 2349 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2350 | |
| 2351 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2352 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2353 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2354 | |
| 2355 | return 0; |
| 2356 | } |
| 2357 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2358 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2359 | int attr) |
| 2360 | { |
| 2361 | struct nlattr *rate; |
| 2362 | u16 bitrate; |
| 2363 | |
| 2364 | rate = nla_nest_start(msg, attr); |
| 2365 | if (!rate) |
| 2366 | goto nla_put_failure; |
| 2367 | |
| 2368 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2369 | bitrate = cfg80211_calculate_bitrate(info); |
| 2370 | if (bitrate > 0) |
| 2371 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2372 | |
| 2373 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2374 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2375 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2376 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2377 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2378 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2379 | |
| 2380 | nla_nest_end(msg, rate); |
| 2381 | return true; |
| 2382 | |
| 2383 | nla_put_failure: |
| 2384 | return false; |
| 2385 | } |
| 2386 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2387 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2388 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2389 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2390 | { |
| 2391 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2392 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2393 | |
| 2394 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2395 | if (!hdr) |
| 2396 | return -1; |
| 2397 | |
| 2398 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2399 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2400 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2401 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2402 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2403 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2404 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2405 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2406 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2407 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2408 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2409 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2410 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2411 | sinfo->inactive_time); |
| 2412 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2413 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2414 | sinfo->rx_bytes); |
| 2415 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2416 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2417 | sinfo->tx_bytes); |
| 2418 | if (sinfo->filled & STATION_INFO_LLID) |
| 2419 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2420 | sinfo->llid); |
| 2421 | if (sinfo->filled & STATION_INFO_PLID) |
| 2422 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2423 | sinfo->plid); |
| 2424 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2425 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2426 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2427 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2428 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2429 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2430 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2431 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2432 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2433 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2434 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2435 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2436 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2437 | } |
| 2438 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2439 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2440 | NL80211_STA_INFO_RX_BITRATE)) |
| 2441 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2442 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2443 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2444 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2445 | sinfo->rx_packets); |
| 2446 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2447 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2448 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2449 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2450 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2451 | sinfo->tx_retries); |
| 2452 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2453 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2454 | sinfo->tx_failed); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2455 | if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) |
| 2456 | NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2457 | sinfo->beacon_loss_count); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2458 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2459 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2460 | if (!bss_param) |
| 2461 | goto nla_put_failure; |
| 2462 | |
| 2463 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2464 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2465 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2466 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2467 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2468 | NLA_PUT_FLAG(msg, |
| 2469 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2470 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2471 | sinfo->bss_param.dtim_period); |
| 2472 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2473 | sinfo->bss_param.beacon_interval); |
| 2474 | |
| 2475 | nla_nest_end(msg, bss_param); |
| 2476 | } |
Helmut Schaa | bb6e753 | 2011-10-13 16:30:39 +0200 | [diff] [blame] | 2477 | if (sinfo->filled & STATION_INFO_STA_FLAGS) |
| 2478 | NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2479 | sizeof(struct nl80211_sta_flag_update), |
| 2480 | &sinfo->sta_flags); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2481 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2482 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2483 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2484 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2485 | sinfo->assoc_req_ies); |
| 2486 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2487 | return genlmsg_end(msg, hdr); |
| 2488 | |
| 2489 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2490 | genlmsg_cancel(msg, hdr); |
| 2491 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2492 | } |
| 2493 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2494 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2495 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2496 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2497 | struct station_info sinfo; |
| 2498 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2499 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2500 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2501 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2502 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2503 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2504 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2505 | if (err) |
| 2506 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2507 | |
| 2508 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2509 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2510 | goto out_err; |
| 2511 | } |
| 2512 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2513 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2514 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2515 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2516 | mac_addr, &sinfo); |
| 2517 | if (err == -ENOENT) |
| 2518 | break; |
| 2519 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2520 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2521 | |
| 2522 | if (nl80211_send_station(skb, |
| 2523 | NETLINK_CB(cb->skb).pid, |
| 2524 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2525 | netdev, mac_addr, |
| 2526 | &sinfo) < 0) |
| 2527 | goto out; |
| 2528 | |
| 2529 | sta_idx++; |
| 2530 | } |
| 2531 | |
| 2532 | |
| 2533 | out: |
| 2534 | cb->args[1] = sta_idx; |
| 2535 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2536 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2537 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2538 | |
| 2539 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2540 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2541 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2542 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2543 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2545 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2546 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2547 | struct sk_buff *msg; |
| 2548 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2549 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2550 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2551 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2552 | |
| 2553 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2554 | return -EINVAL; |
| 2555 | |
| 2556 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2557 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2558 | if (!rdev->ops->get_station) |
| 2559 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2560 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2561 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2562 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2563 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2564 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2565 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2566 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2567 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2568 | |
| 2569 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2570 | dev, mac_addr, &sinfo) < 0) { |
| 2571 | nlmsg_free(msg); |
| 2572 | return -ENOBUFS; |
| 2573 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2574 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2575 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2579 | * 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] | 2580 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2581 | static struct net_device *get_vlan(struct genl_info *info, |
| 2582 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2583 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2584 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2585 | struct net_device *v; |
| 2586 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2587 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2588 | if (!vlanattr) |
| 2589 | return NULL; |
| 2590 | |
| 2591 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 2592 | if (!v) |
| 2593 | return ERR_PTR(-ENODEV); |
| 2594 | |
| 2595 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 2596 | ret = -EINVAL; |
| 2597 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2598 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2599 | |
| 2600 | if (!netif_running(v)) { |
| 2601 | ret = -ENETDOWN; |
| 2602 | goto error; |
| 2603 | } |
| 2604 | |
| 2605 | return v; |
| 2606 | error: |
| 2607 | dev_put(v); |
| 2608 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2612 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2613 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2614 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2615 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2616 | struct station_parameters params; |
| 2617 | u8 *mac_addr = NULL; |
| 2618 | |
| 2619 | memset(¶ms, 0, sizeof(params)); |
| 2620 | |
| 2621 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2622 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2623 | |
| 2624 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2625 | return -EINVAL; |
| 2626 | |
| 2627 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2628 | return -EINVAL; |
| 2629 | |
| 2630 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2631 | |
| 2632 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2633 | params.supported_rates = |
| 2634 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2635 | params.supported_rates_len = |
| 2636 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2637 | } |
| 2638 | |
| 2639 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2640 | params.listen_interval = |
| 2641 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2642 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2643 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2644 | params.ht_capa = |
| 2645 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2646 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2647 | if (!rdev->ops->change_station) |
| 2648 | return -EOPNOTSUPP; |
| 2649 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2650 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2651 | return -EINVAL; |
| 2652 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2653 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2654 | params.plink_action = |
| 2655 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2656 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2657 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2658 | params.plink_state = |
| 2659 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2660 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2661 | switch (dev->ieee80211_ptr->iftype) { |
| 2662 | case NL80211_IFTYPE_AP: |
| 2663 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2664 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2665 | /* disallow mesh-specific things */ |
| 2666 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2667 | return -EINVAL; |
| 2668 | |
| 2669 | /* TDLS can't be set, ... */ |
| 2670 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 2671 | return -EINVAL; |
| 2672 | /* |
| 2673 | * ... but don't bother the driver with it. This works around |
| 2674 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 2675 | * TLDS_PEER flag in the mask even for AP mode. |
| 2676 | */ |
| 2677 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2678 | |
| 2679 | /* accept only the listed bits */ |
| 2680 | if (params.sta_flags_mask & |
| 2681 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2682 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2683 | BIT(NL80211_STA_FLAG_WME) | |
| 2684 | BIT(NL80211_STA_FLAG_MFP))) |
| 2685 | return -EINVAL; |
| 2686 | |
| 2687 | /* must be last in here for error handling */ |
| 2688 | params.vlan = get_vlan(info, rdev); |
| 2689 | if (IS_ERR(params.vlan)) |
| 2690 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2691 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2692 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2693 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2694 | /* |
| 2695 | * Don't allow userspace to change the TDLS_PEER flag, |
| 2696 | * but silently ignore attempts to change it since we |
| 2697 | * don't have state here to verify that it doesn't try |
| 2698 | * to change the flag. |
| 2699 | */ |
| 2700 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 2701 | /* fall through */ |
| 2702 | case NL80211_IFTYPE_ADHOC: |
| 2703 | /* disallow things sta doesn't support */ |
| 2704 | if (params.plink_action) |
| 2705 | return -EINVAL; |
| 2706 | if (params.ht_capa) |
| 2707 | return -EINVAL; |
| 2708 | if (params.listen_interval >= 0) |
| 2709 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2710 | /* reject any changes other than AUTHORIZED */ |
| 2711 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2712 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2713 | break; |
| 2714 | case NL80211_IFTYPE_MESH_POINT: |
| 2715 | /* disallow things mesh doesn't support */ |
| 2716 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2717 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2718 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2719 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2720 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2721 | return -EINVAL; |
| 2722 | /* |
| 2723 | * No special handling for TDLS here -- the userspace |
| 2724 | * mesh code doesn't have this bug. |
| 2725 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2726 | if (params.sta_flags_mask & |
| 2727 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2728 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2729 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2730 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2731 | break; |
| 2732 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2733 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2734 | } |
| 2735 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2736 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2737 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2738 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2739 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2740 | if (params.vlan) |
| 2741 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2742 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2743 | return err; |
| 2744 | } |
| 2745 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2746 | static struct nla_policy |
| 2747 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2748 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2749 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2750 | }; |
| 2751 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2752 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2753 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2755 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2756 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2757 | struct station_parameters params; |
| 2758 | u8 *mac_addr = NULL; |
| 2759 | |
| 2760 | memset(¶ms, 0, sizeof(params)); |
| 2761 | |
| 2762 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2763 | return -EINVAL; |
| 2764 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2765 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2766 | return -EINVAL; |
| 2767 | |
| 2768 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2769 | return -EINVAL; |
| 2770 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2771 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2772 | return -EINVAL; |
| 2773 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2774 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2775 | params.supported_rates = |
| 2776 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2777 | params.supported_rates_len = |
| 2778 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2779 | params.listen_interval = |
| 2780 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2781 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2782 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2783 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2784 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2785 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2786 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2787 | params.ht_capa = |
| 2788 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2789 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2790 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2791 | params.plink_action = |
| 2792 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2793 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2794 | if (!rdev->ops->add_station) |
| 2795 | return -EOPNOTSUPP; |
| 2796 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2797 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2798 | return -EINVAL; |
| 2799 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2800 | switch (dev->ieee80211_ptr->iftype) { |
| 2801 | case NL80211_IFTYPE_AP: |
| 2802 | case NL80211_IFTYPE_AP_VLAN: |
| 2803 | case NL80211_IFTYPE_P2P_GO: |
| 2804 | /* parse WME attributes if sta is WME capable */ |
| 2805 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 2806 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 2807 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2808 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2809 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2810 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2811 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2812 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2813 | nl80211_sta_wme_policy); |
| 2814 | if (err) |
| 2815 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2816 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2817 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2818 | params.uapsd_queues = |
| 2819 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 2820 | if (params.uapsd_queues & |
| 2821 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2822 | return -EINVAL; |
| 2823 | |
| 2824 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2825 | params.max_sp = |
| 2826 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 2827 | |
| 2828 | if (params.max_sp & |
| 2829 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2830 | return -EINVAL; |
| 2831 | |
| 2832 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 2833 | } |
| 2834 | /* TDLS peers cannot be added */ |
| 2835 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2836 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2837 | /* but don't bother the driver with it */ |
| 2838 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2839 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2840 | /* must be last in here for error handling */ |
| 2841 | params.vlan = get_vlan(info, rdev); |
| 2842 | if (IS_ERR(params.vlan)) |
| 2843 | return PTR_ERR(params.vlan); |
| 2844 | break; |
| 2845 | case NL80211_IFTYPE_MESH_POINT: |
| 2846 | /* TDLS peers cannot be added */ |
| 2847 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2848 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2849 | break; |
| 2850 | case NL80211_IFTYPE_STATION: |
| 2851 | /* Only TDLS peers can be added */ |
| 2852 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 2853 | return -EINVAL; |
| 2854 | /* Can only add if TDLS ... */ |
| 2855 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 2856 | return -EOPNOTSUPP; |
| 2857 | /* ... with external setup is supported */ |
| 2858 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 2859 | return -EOPNOTSUPP; |
| 2860 | break; |
| 2861 | default: |
| 2862 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2863 | } |
| 2864 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2865 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2866 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2867 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2868 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2869 | if (params.vlan) |
| 2870 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2871 | return err; |
| 2872 | } |
| 2873 | |
| 2874 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2875 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2876 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2877 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2878 | u8 *mac_addr = NULL; |
| 2879 | |
| 2880 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2881 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2882 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2883 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2884 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2885 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2886 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2887 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2888 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2889 | if (!rdev->ops->del_station) |
| 2890 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2891 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2892 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2893 | } |
| 2894 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2895 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2896 | int flags, struct net_device *dev, |
| 2897 | u8 *dst, u8 *next_hop, |
| 2898 | struct mpath_info *pinfo) |
| 2899 | { |
| 2900 | void *hdr; |
| 2901 | struct nlattr *pinfoattr; |
| 2902 | |
| 2903 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2904 | if (!hdr) |
| 2905 | return -1; |
| 2906 | |
| 2907 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2908 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2909 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2910 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2911 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2912 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2913 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2914 | if (!pinfoattr) |
| 2915 | goto nla_put_failure; |
| 2916 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2917 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2918 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2919 | if (pinfo->filled & MPATH_INFO_SN) |
| 2920 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2921 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2922 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2923 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2924 | pinfo->metric); |
| 2925 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2926 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2927 | pinfo->exptime); |
| 2928 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2929 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2930 | pinfo->flags); |
| 2931 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2932 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2933 | pinfo->discovery_timeout); |
| 2934 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2935 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2936 | pinfo->discovery_retries); |
| 2937 | |
| 2938 | nla_nest_end(msg, pinfoattr); |
| 2939 | |
| 2940 | return genlmsg_end(msg, hdr); |
| 2941 | |
| 2942 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2943 | genlmsg_cancel(msg, hdr); |
| 2944 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2948 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2949 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2950 | struct mpath_info pinfo; |
| 2951 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2952 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2953 | u8 dst[ETH_ALEN]; |
| 2954 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2955 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2956 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2957 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2958 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2959 | if (err) |
| 2960 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2961 | |
| 2962 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2963 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2964 | goto out_err; |
| 2965 | } |
| 2966 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2967 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2968 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2969 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2970 | } |
| 2971 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2972 | while (1) { |
| 2973 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2974 | dst, next_hop, &pinfo); |
| 2975 | if (err == -ENOENT) |
| 2976 | break; |
| 2977 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2978 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2979 | |
| 2980 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2981 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2982 | netdev, dst, next_hop, |
| 2983 | &pinfo) < 0) |
| 2984 | goto out; |
| 2985 | |
| 2986 | path_idx++; |
| 2987 | } |
| 2988 | |
| 2989 | |
| 2990 | out: |
| 2991 | cb->args[1] = path_idx; |
| 2992 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2993 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2994 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2995 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2999 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3000 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3001 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3002 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3003 | struct mpath_info pinfo; |
| 3004 | struct sk_buff *msg; |
| 3005 | u8 *dst = NULL; |
| 3006 | u8 next_hop[ETH_ALEN]; |
| 3007 | |
| 3008 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3009 | |
| 3010 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3011 | return -EINVAL; |
| 3012 | |
| 3013 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3014 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3015 | if (!rdev->ops->get_mpath) |
| 3016 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3017 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3018 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3019 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3020 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3021 | 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] | 3022 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3023 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3024 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3025 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3026 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3027 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3028 | |
| 3029 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3030 | dev, dst, next_hop, &pinfo) < 0) { |
| 3031 | nlmsg_free(msg); |
| 3032 | return -ENOBUFS; |
| 3033 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3034 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3035 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3039 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3041 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3042 | u8 *dst = NULL; |
| 3043 | u8 *next_hop = NULL; |
| 3044 | |
| 3045 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3046 | return -EINVAL; |
| 3047 | |
| 3048 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3049 | return -EINVAL; |
| 3050 | |
| 3051 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3052 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3053 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3054 | if (!rdev->ops->change_mpath) |
| 3055 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3056 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3057 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3058 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3059 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3060 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3061 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3062 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3063 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3064 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3066 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3067 | u8 *dst = NULL; |
| 3068 | u8 *next_hop = NULL; |
| 3069 | |
| 3070 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3071 | return -EINVAL; |
| 3072 | |
| 3073 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3074 | return -EINVAL; |
| 3075 | |
| 3076 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3077 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3078 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3079 | if (!rdev->ops->add_mpath) |
| 3080 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3081 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3082 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3083 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3084 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3085 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3089 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3091 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3092 | u8 *dst = NULL; |
| 3093 | |
| 3094 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3095 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3096 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3097 | if (!rdev->ops->del_mpath) |
| 3098 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3099 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3100 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3103 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3104 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3106 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3107 | struct bss_parameters params; |
| 3108 | |
| 3109 | memset(¶ms, 0, sizeof(params)); |
| 3110 | /* default to not changing parameters */ |
| 3111 | params.use_cts_prot = -1; |
| 3112 | params.use_short_preamble = -1; |
| 3113 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3114 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3115 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3116 | |
| 3117 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3118 | params.use_cts_prot = |
| 3119 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3120 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3121 | params.use_short_preamble = |
| 3122 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3123 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3124 | params.use_short_slot_time = |
| 3125 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3126 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3127 | params.basic_rates = |
| 3128 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3129 | params.basic_rates_len = |
| 3130 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3131 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3132 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3133 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3134 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3135 | params.ht_opmode = |
| 3136 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3137 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3138 | if (!rdev->ops->change_bss) |
| 3139 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3140 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3141 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3142 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3143 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3144 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3145 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3146 | } |
| 3147 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3148 | 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] | 3149 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3150 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3151 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3152 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3153 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3154 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3155 | }; |
| 3156 | |
| 3157 | static int parse_reg_rule(struct nlattr *tb[], |
| 3158 | struct ieee80211_reg_rule *reg_rule) |
| 3159 | { |
| 3160 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3161 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3162 | |
| 3163 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3164 | return -EINVAL; |
| 3165 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3166 | return -EINVAL; |
| 3167 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3168 | return -EINVAL; |
| 3169 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3170 | return -EINVAL; |
| 3171 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3172 | return -EINVAL; |
| 3173 | |
| 3174 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3175 | |
| 3176 | freq_range->start_freq_khz = |
| 3177 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3178 | freq_range->end_freq_khz = |
| 3179 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3180 | freq_range->max_bandwidth_khz = |
| 3181 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3182 | |
| 3183 | power_rule->max_eirp = |
| 3184 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3185 | |
| 3186 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3187 | power_rule->max_antenna_gain = |
| 3188 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3189 | |
| 3190 | return 0; |
| 3191 | } |
| 3192 | |
| 3193 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3194 | { |
| 3195 | int r; |
| 3196 | char *data = NULL; |
| 3197 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3198 | /* |
| 3199 | * You should only get this when cfg80211 hasn't yet initialized |
| 3200 | * completely when built-in to the kernel right between the time |
| 3201 | * window between nl80211_init() and regulatory_init(), if that is |
| 3202 | * even possible. |
| 3203 | */ |
| 3204 | mutex_lock(&cfg80211_mutex); |
| 3205 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3206 | mutex_unlock(&cfg80211_mutex); |
| 3207 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3208 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3209 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3210 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3211 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3212 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3213 | |
| 3214 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3215 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3216 | r = regulatory_hint_user(data); |
| 3217 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3218 | return r; |
| 3219 | } |
| 3220 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3221 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3222 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3223 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3225 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3226 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3227 | struct mesh_config cur_params; |
| 3228 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3229 | void *hdr; |
| 3230 | struct nlattr *pinfoattr; |
| 3231 | struct sk_buff *msg; |
| 3232 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3233 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3234 | return -EOPNOTSUPP; |
| 3235 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3236 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3237 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3238 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3239 | wdev_lock(wdev); |
| 3240 | /* If not connected, get default parameters */ |
| 3241 | if (!wdev->mesh_id_len) |
| 3242 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3243 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3244 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3245 | &cur_params); |
| 3246 | wdev_unlock(wdev); |
| 3247 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3248 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3249 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3250 | |
| 3251 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3252 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3253 | if (!msg) |
| 3254 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3255 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3256 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3257 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3258 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3259 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3260 | if (!pinfoattr) |
| 3261 | goto nla_put_failure; |
| 3262 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3263 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3264 | cur_params.dot11MeshRetryTimeout); |
| 3265 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3266 | cur_params.dot11MeshConfirmTimeout); |
| 3267 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3268 | cur_params.dot11MeshHoldingTimeout); |
| 3269 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3270 | cur_params.dot11MeshMaxPeerLinks); |
| 3271 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3272 | cur_params.dot11MeshMaxRetries); |
| 3273 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3274 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3275 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3276 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3277 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3278 | cur_params.auto_open_plinks); |
| 3279 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3280 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3281 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3282 | cur_params.path_refresh_time); |
| 3283 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3284 | cur_params.min_discovery_timeout); |
| 3285 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3286 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3287 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3288 | cur_params.dot11MeshHWMPpreqMinInterval); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3289 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3290 | cur_params.dot11MeshHWMPperrMinInterval); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3291 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3292 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3293 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3294 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3295 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3296 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3297 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3298 | cur_params.dot11MeshGateAnnouncementProtocol); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3299 | NLA_PUT_U8(msg, NL80211_MESHCONF_FORWARDING, |
| 3300 | cur_params.dot11MeshForwarding); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3301 | NLA_PUT_U32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 3302 | cur_params.rssi_threshold); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3303 | nla_nest_end(msg, pinfoattr); |
| 3304 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3305 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3306 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3307 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3308 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3309 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3310 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3311 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3314 | 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] | 3315 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3316 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3317 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3318 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3319 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3320 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3321 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3322 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3323 | |
| 3324 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3325 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3326 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3327 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3328 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3329 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3330 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3331 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3332 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3333 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3334 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3335 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32}, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3336 | }; |
| 3337 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3338 | static const struct nla_policy |
| 3339 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3340 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3341 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3342 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3343 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3344 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3345 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3346 | }; |
| 3347 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3348 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3349 | struct mesh_config *cfg, |
| 3350 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3351 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3352 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3353 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3354 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3355 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3356 | do {\ |
| 3357 | if (table[attr_num]) {\ |
| 3358 | cfg->param = nla_fn(table[attr_num]); \ |
| 3359 | mask |= (1 << (attr_num - 1)); \ |
| 3360 | } \ |
| 3361 | } while (0);\ |
| 3362 | |
| 3363 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3364 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3365 | return -EINVAL; |
| 3366 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3367 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3368 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3369 | return -EINVAL; |
| 3370 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3371 | /* This makes sure that there aren't more than 32 mesh config |
| 3372 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3373 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3374 | |
| 3375 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3376 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3377 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3378 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3379 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3380 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3381 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3382 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3383 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3384 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3385 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3386 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3387 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3388 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3389 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3390 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3391 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3392 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3393 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3394 | nla_get_u8); |
| 3395 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3396 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3397 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3398 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3399 | nla_get_u16); |
| 3400 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3401 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3402 | nla_get_u32); |
| 3403 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3404 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3405 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3406 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
| 3407 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3408 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3409 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3410 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3411 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3412 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3413 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3414 | dot11MeshHWMPRootMode, mask, |
| 3415 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3416 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3417 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3418 | dot11MeshHWMPRannInterval, mask, |
| 3419 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3420 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3421 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3422 | dot11MeshGateAnnouncementProtocol, mask, |
| 3423 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3424 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3425 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
| 3426 | mask, NL80211_MESHCONF_FORWARDING, nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3427 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
| 3428 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3429 | if (mask_out) |
| 3430 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3431 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3432 | return 0; |
| 3433 | |
| 3434 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3435 | } |
| 3436 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3437 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3438 | struct mesh_setup *setup) |
| 3439 | { |
| 3440 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3441 | |
| 3442 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3443 | return -EINVAL; |
| 3444 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3445 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3446 | nl80211_mesh_setup_params_policy)) |
| 3447 | return -EINVAL; |
| 3448 | |
| 3449 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3450 | setup->path_sel_proto = |
| 3451 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3452 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3453 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3454 | |
| 3455 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3456 | setup->path_metric = |
| 3457 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3458 | IEEE80211_PATH_METRIC_VENDOR : |
| 3459 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3460 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3461 | |
| 3462 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3463 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3464 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3465 | if (!is_valid_ie_attr(ieattr)) |
| 3466 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3467 | setup->ie = nla_data(ieattr); |
| 3468 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3469 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3470 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3471 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3472 | |
| 3473 | return 0; |
| 3474 | } |
| 3475 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3476 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3477 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3478 | { |
| 3479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3480 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3481 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3482 | struct mesh_config cfg; |
| 3483 | u32 mask; |
| 3484 | int err; |
| 3485 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3486 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3487 | return -EOPNOTSUPP; |
| 3488 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3489 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3490 | return -EOPNOTSUPP; |
| 3491 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3492 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3493 | if (err) |
| 3494 | return err; |
| 3495 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3496 | wdev_lock(wdev); |
| 3497 | if (!wdev->mesh_id_len) |
| 3498 | err = -ENOLINK; |
| 3499 | |
| 3500 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3501 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3502 | mask, &cfg); |
| 3503 | |
| 3504 | wdev_unlock(wdev); |
| 3505 | |
| 3506 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3509 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3510 | { |
| 3511 | struct sk_buff *msg; |
| 3512 | void *hdr = NULL; |
| 3513 | struct nlattr *nl_reg_rules; |
| 3514 | unsigned int i; |
| 3515 | int err = -EINVAL; |
| 3516 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3517 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3518 | |
| 3519 | if (!cfg80211_regdomain) |
| 3520 | goto out; |
| 3521 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3522 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3523 | if (!msg) { |
| 3524 | err = -ENOBUFS; |
| 3525 | goto out; |
| 3526 | } |
| 3527 | |
| 3528 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3529 | NL80211_CMD_GET_REG); |
| 3530 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3531 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3532 | |
| 3533 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3534 | cfg80211_regdomain->alpha2); |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3535 | if (cfg80211_regdomain->dfs_region) |
| 3536 | NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION, |
| 3537 | cfg80211_regdomain->dfs_region); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3538 | |
| 3539 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3540 | if (!nl_reg_rules) |
| 3541 | goto nla_put_failure; |
| 3542 | |
| 3543 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3544 | struct nlattr *nl_reg_rule; |
| 3545 | const struct ieee80211_reg_rule *reg_rule; |
| 3546 | const struct ieee80211_freq_range *freq_range; |
| 3547 | const struct ieee80211_power_rule *power_rule; |
| 3548 | |
| 3549 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3550 | freq_range = ®_rule->freq_range; |
| 3551 | power_rule = ®_rule->power_rule; |
| 3552 | |
| 3553 | nl_reg_rule = nla_nest_start(msg, i); |
| 3554 | if (!nl_reg_rule) |
| 3555 | goto nla_put_failure; |
| 3556 | |
| 3557 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3558 | reg_rule->flags); |
| 3559 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3560 | freq_range->start_freq_khz); |
| 3561 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3562 | freq_range->end_freq_khz); |
| 3563 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3564 | freq_range->max_bandwidth_khz); |
| 3565 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3566 | power_rule->max_antenna_gain); |
| 3567 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3568 | power_rule->max_eirp); |
| 3569 | |
| 3570 | nla_nest_end(msg, nl_reg_rule); |
| 3571 | } |
| 3572 | |
| 3573 | nla_nest_end(msg, nl_reg_rules); |
| 3574 | |
| 3575 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3576 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3577 | goto out; |
| 3578 | |
| 3579 | nla_put_failure: |
| 3580 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3581 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3582 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3583 | err = -EMSGSIZE; |
| 3584 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3585 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3586 | return err; |
| 3587 | } |
| 3588 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3589 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3590 | { |
| 3591 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3592 | struct nlattr *nl_reg_rule; |
| 3593 | char *alpha2 = NULL; |
| 3594 | int rem_reg_rules = 0, r = 0; |
| 3595 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3596 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3597 | struct ieee80211_regdomain *rd = NULL; |
| 3598 | |
| 3599 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3600 | return -EINVAL; |
| 3601 | |
| 3602 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3603 | return -EINVAL; |
| 3604 | |
| 3605 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3606 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3607 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 3608 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 3609 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3610 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3611 | rem_reg_rules) { |
| 3612 | num_rules++; |
| 3613 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3614 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3617 | mutex_lock(&cfg80211_mutex); |
| 3618 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3619 | if (!reg_is_valid_request(alpha2)) { |
| 3620 | r = -EINVAL; |
| 3621 | goto bad_reg; |
| 3622 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3623 | |
| 3624 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3625 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3626 | |
| 3627 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3628 | if (!rd) { |
| 3629 | r = -ENOMEM; |
| 3630 | goto bad_reg; |
| 3631 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3632 | |
| 3633 | rd->n_reg_rules = num_rules; |
| 3634 | rd->alpha2[0] = alpha2[0]; |
| 3635 | rd->alpha2[1] = alpha2[1]; |
| 3636 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3637 | /* |
| 3638 | * Disable DFS master mode if the DFS region was |
| 3639 | * not supported or known on this kernel. |
| 3640 | */ |
| 3641 | if (reg_supported_dfs_region(dfs_region)) |
| 3642 | rd->dfs_region = dfs_region; |
| 3643 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3644 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3645 | rem_reg_rules) { |
| 3646 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3647 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3648 | reg_rule_policy); |
| 3649 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3650 | if (r) |
| 3651 | goto bad_reg; |
| 3652 | |
| 3653 | rule_idx++; |
| 3654 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3655 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3656 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3657 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3658 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | BUG_ON(rule_idx != num_rules); |
| 3662 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3663 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3664 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3665 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3666 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3667 | return r; |
| 3668 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3669 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3670 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3671 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3672 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3673 | } |
| 3674 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3675 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3676 | { |
| 3677 | struct nlattr *attr1, *attr2; |
| 3678 | int n_channels = 0, tmp1, tmp2; |
| 3679 | |
| 3680 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3681 | n_channels++; |
| 3682 | /* |
| 3683 | * Some hardware has a limited channel list for |
| 3684 | * scanning, and it is pretty much nonsensical |
| 3685 | * to scan for a channel twice, so disallow that |
| 3686 | * and don't require drivers to check that the |
| 3687 | * channel list they get isn't longer than what |
| 3688 | * they can scan, as long as they can scan all |
| 3689 | * the channels they registered at once. |
| 3690 | */ |
| 3691 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3692 | if (attr1 != attr2 && |
| 3693 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3694 | return 0; |
| 3695 | } |
| 3696 | |
| 3697 | return n_channels; |
| 3698 | } |
| 3699 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3700 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3701 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3703 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3704 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3705 | struct nlattr *attr; |
| 3706 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3707 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3708 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3709 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3710 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3711 | return -EINVAL; |
| 3712 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3713 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3714 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3715 | if (!rdev->ops->scan) |
| 3716 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3717 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3718 | if (rdev->scan_req) |
| 3719 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3720 | |
| 3721 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3722 | n_channels = validate_scan_freqs( |
| 3723 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3724 | if (!n_channels) |
| 3725 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3726 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3727 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3728 | n_channels = 0; |
| 3729 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3730 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3731 | if (wiphy->bands[band]) |
| 3732 | n_channels += wiphy->bands[band]->n_channels; |
| 3733 | } |
| 3734 | |
| 3735 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3736 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3737 | n_ssids++; |
| 3738 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3739 | if (n_ssids > wiphy->max_scan_ssids) |
| 3740 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3741 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3742 | if (info->attrs[NL80211_ATTR_IE]) |
| 3743 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3744 | else |
| 3745 | ie_len = 0; |
| 3746 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3747 | if (ie_len > wiphy->max_scan_ie_len) |
| 3748 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3749 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3750 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3751 | + sizeof(*request->ssids) * n_ssids |
| 3752 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3753 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3754 | if (!request) |
| 3755 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3756 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3757 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3758 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3759 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3760 | if (ie_len) { |
| 3761 | if (request->ssids) |
| 3762 | request->ie = (void *)(request->ssids + n_ssids); |
| 3763 | else |
| 3764 | request->ie = (void *)(request->channels + n_channels); |
| 3765 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3766 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3767 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3768 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3769 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3770 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3771 | struct ieee80211_channel *chan; |
| 3772 | |
| 3773 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3774 | |
| 3775 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3776 | err = -EINVAL; |
| 3777 | goto out_free; |
| 3778 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3779 | |
| 3780 | /* ignore disabled channels */ |
| 3781 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3782 | continue; |
| 3783 | |
| 3784 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3785 | i++; |
| 3786 | } |
| 3787 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3788 | enum ieee80211_band band; |
| 3789 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3790 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3791 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3792 | int j; |
| 3793 | if (!wiphy->bands[band]) |
| 3794 | continue; |
| 3795 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3796 | struct ieee80211_channel *chan; |
| 3797 | |
| 3798 | chan = &wiphy->bands[band]->channels[j]; |
| 3799 | |
| 3800 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3801 | continue; |
| 3802 | |
| 3803 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3804 | i++; |
| 3805 | } |
| 3806 | } |
| 3807 | } |
| 3808 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3809 | if (!i) { |
| 3810 | err = -EINVAL; |
| 3811 | goto out_free; |
| 3812 | } |
| 3813 | |
| 3814 | request->n_channels = i; |
| 3815 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3816 | i = 0; |
| 3817 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3818 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3819 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3820 | err = -EINVAL; |
| 3821 | goto out_free; |
| 3822 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3823 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3824 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3825 | i++; |
| 3826 | } |
| 3827 | } |
| 3828 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3829 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3830 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3831 | memcpy((void *)request->ie, |
| 3832 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3833 | request->ie_len); |
| 3834 | } |
| 3835 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3836 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3837 | if (wiphy->bands[i]) |
| 3838 | request->rates[i] = |
| 3839 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3840 | |
| 3841 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3842 | nla_for_each_nested(attr, |
| 3843 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3844 | tmp) { |
| 3845 | enum ieee80211_band band = nla_type(attr); |
| 3846 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3847 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3848 | err = -EINVAL; |
| 3849 | goto out_free; |
| 3850 | } |
| 3851 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3852 | nla_data(attr), |
| 3853 | nla_len(attr), |
| 3854 | &request->rates[band]); |
| 3855 | if (err) |
| 3856 | goto out_free; |
| 3857 | } |
| 3858 | } |
| 3859 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3860 | request->no_cck = |
| 3861 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3862 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3863 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3864 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3865 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3866 | rdev->scan_req = request; |
| 3867 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3868 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3869 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3870 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3871 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3872 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3873 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3874 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3875 | kfree(request); |
| 3876 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3877 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3878 | return err; |
| 3879 | } |
| 3880 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3881 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3882 | struct genl_info *info) |
| 3883 | { |
| 3884 | struct cfg80211_sched_scan_request *request; |
| 3885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3886 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3887 | struct nlattr *attr; |
| 3888 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3889 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3890 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3891 | enum ieee80211_band band; |
| 3892 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3893 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3894 | |
| 3895 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3896 | !rdev->ops->sched_scan_start) |
| 3897 | return -EOPNOTSUPP; |
| 3898 | |
| 3899 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3900 | return -EINVAL; |
| 3901 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3902 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3903 | return -EINVAL; |
| 3904 | |
| 3905 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3906 | if (interval == 0) |
| 3907 | return -EINVAL; |
| 3908 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3909 | wiphy = &rdev->wiphy; |
| 3910 | |
| 3911 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3912 | n_channels = validate_scan_freqs( |
| 3913 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3914 | if (!n_channels) |
| 3915 | return -EINVAL; |
| 3916 | } else { |
| 3917 | n_channels = 0; |
| 3918 | |
| 3919 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3920 | if (wiphy->bands[band]) |
| 3921 | n_channels += wiphy->bands[band]->n_channels; |
| 3922 | } |
| 3923 | |
| 3924 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3925 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3926 | tmp) |
| 3927 | n_ssids++; |
| 3928 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3929 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3930 | return -EINVAL; |
| 3931 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3932 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3933 | nla_for_each_nested(attr, |
| 3934 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3935 | tmp) |
| 3936 | n_match_sets++; |
| 3937 | |
| 3938 | if (n_match_sets > wiphy->max_match_sets) |
| 3939 | return -EINVAL; |
| 3940 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3941 | if (info->attrs[NL80211_ATTR_IE]) |
| 3942 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3943 | else |
| 3944 | ie_len = 0; |
| 3945 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3946 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3947 | return -EINVAL; |
| 3948 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3949 | mutex_lock(&rdev->sched_scan_mtx); |
| 3950 | |
| 3951 | if (rdev->sched_scan_req) { |
| 3952 | err = -EINPROGRESS; |
| 3953 | goto out; |
| 3954 | } |
| 3955 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3956 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3957 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3958 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3959 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3960 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3961 | if (!request) { |
| 3962 | err = -ENOMEM; |
| 3963 | goto out; |
| 3964 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3965 | |
| 3966 | if (n_ssids) |
| 3967 | request->ssids = (void *)&request->channels[n_channels]; |
| 3968 | request->n_ssids = n_ssids; |
| 3969 | if (ie_len) { |
| 3970 | if (request->ssids) |
| 3971 | request->ie = (void *)(request->ssids + n_ssids); |
| 3972 | else |
| 3973 | request->ie = (void *)(request->channels + n_channels); |
| 3974 | } |
| 3975 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3976 | if (n_match_sets) { |
| 3977 | if (request->ie) |
| 3978 | request->match_sets = (void *)(request->ie + ie_len); |
| 3979 | else if (request->ssids) |
| 3980 | request->match_sets = |
| 3981 | (void *)(request->ssids + n_ssids); |
| 3982 | else |
| 3983 | request->match_sets = |
| 3984 | (void *)(request->channels + n_channels); |
| 3985 | } |
| 3986 | request->n_match_sets = n_match_sets; |
| 3987 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3988 | i = 0; |
| 3989 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3990 | /* user specified, bail out if channel not found */ |
| 3991 | nla_for_each_nested(attr, |
| 3992 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3993 | tmp) { |
| 3994 | struct ieee80211_channel *chan; |
| 3995 | |
| 3996 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3997 | |
| 3998 | if (!chan) { |
| 3999 | err = -EINVAL; |
| 4000 | goto out_free; |
| 4001 | } |
| 4002 | |
| 4003 | /* ignore disabled channels */ |
| 4004 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4005 | continue; |
| 4006 | |
| 4007 | request->channels[i] = chan; |
| 4008 | i++; |
| 4009 | } |
| 4010 | } else { |
| 4011 | /* all channels */ |
| 4012 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4013 | int j; |
| 4014 | if (!wiphy->bands[band]) |
| 4015 | continue; |
| 4016 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4017 | struct ieee80211_channel *chan; |
| 4018 | |
| 4019 | chan = &wiphy->bands[band]->channels[j]; |
| 4020 | |
| 4021 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4022 | continue; |
| 4023 | |
| 4024 | request->channels[i] = chan; |
| 4025 | i++; |
| 4026 | } |
| 4027 | } |
| 4028 | } |
| 4029 | |
| 4030 | if (!i) { |
| 4031 | err = -EINVAL; |
| 4032 | goto out_free; |
| 4033 | } |
| 4034 | |
| 4035 | request->n_channels = i; |
| 4036 | |
| 4037 | i = 0; |
| 4038 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4039 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4040 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4041 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4042 | err = -EINVAL; |
| 4043 | goto out_free; |
| 4044 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4045 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4046 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4047 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4048 | i++; |
| 4049 | } |
| 4050 | } |
| 4051 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4052 | i = 0; |
| 4053 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4054 | nla_for_each_nested(attr, |
| 4055 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4056 | tmp) { |
| 4057 | struct nlattr *ssid; |
| 4058 | |
| 4059 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4060 | nla_data(attr), nla_len(attr), |
| 4061 | nl80211_match_policy); |
| 4062 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 4063 | if (ssid) { |
| 4064 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4065 | err = -EINVAL; |
| 4066 | goto out_free; |
| 4067 | } |
| 4068 | memcpy(request->match_sets[i].ssid.ssid, |
| 4069 | nla_data(ssid), nla_len(ssid)); |
| 4070 | request->match_sets[i].ssid.ssid_len = |
| 4071 | nla_len(ssid); |
| 4072 | } |
| 4073 | i++; |
| 4074 | } |
| 4075 | } |
| 4076 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4077 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4078 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4079 | memcpy((void *)request->ie, |
| 4080 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4081 | request->ie_len); |
| 4082 | } |
| 4083 | |
| 4084 | request->dev = dev; |
| 4085 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4086 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4087 | |
| 4088 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 4089 | if (!err) { |
| 4090 | rdev->sched_scan_req = request; |
| 4091 | nl80211_send_sched_scan(rdev, dev, |
| 4092 | NL80211_CMD_START_SCHED_SCAN); |
| 4093 | goto out; |
| 4094 | } |
| 4095 | |
| 4096 | out_free: |
| 4097 | kfree(request); |
| 4098 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4099 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4100 | return err; |
| 4101 | } |
| 4102 | |
| 4103 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4104 | struct genl_info *info) |
| 4105 | { |
| 4106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4107 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4108 | |
| 4109 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4110 | !rdev->ops->sched_scan_stop) |
| 4111 | return -EOPNOTSUPP; |
| 4112 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4113 | mutex_lock(&rdev->sched_scan_mtx); |
| 4114 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4115 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4116 | |
| 4117 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4118 | } |
| 4119 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4120 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4121 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4122 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4123 | struct wireless_dev *wdev, |
| 4124 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4125 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4126 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4127 | void *hdr; |
| 4128 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4129 | |
| 4130 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4131 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4132 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4133 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4134 | if (!hdr) |
| 4135 | return -1; |
| 4136 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4137 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4138 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4139 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4140 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4141 | |
| 4142 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4143 | if (!bss) |
| 4144 | goto nla_put_failure; |
| 4145 | if (!is_zero_ether_addr(res->bssid)) |
| 4146 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 4147 | if (res->information_elements && res->len_information_elements) |
| 4148 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4149 | res->len_information_elements, |
| 4150 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 4151 | if (res->beacon_ies && res->len_beacon_ies && |
| 4152 | res->beacon_ies != res->information_elements) |
| 4153 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 4154 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4155 | if (res->tsf) |
| 4156 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 4157 | if (res->beacon_interval) |
| 4158 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 4159 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 4160 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 4161 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4162 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4163 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4164 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4165 | case CFG80211_SIGNAL_TYPE_MBM: |
| 4166 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 4167 | break; |
| 4168 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 4169 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 4170 | break; |
| 4171 | default: |
| 4172 | break; |
| 4173 | } |
| 4174 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4175 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4176 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4177 | case NL80211_IFTYPE_STATION: |
| 4178 | if (intbss == wdev->current_bss) |
| 4179 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4180 | NL80211_BSS_STATUS_ASSOCIATED); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4181 | break; |
| 4182 | case NL80211_IFTYPE_ADHOC: |
| 4183 | if (intbss == wdev->current_bss) |
| 4184 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4185 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 4186 | break; |
| 4187 | default: |
| 4188 | break; |
| 4189 | } |
| 4190 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4191 | nla_nest_end(msg, bss); |
| 4192 | |
| 4193 | return genlmsg_end(msg, hdr); |
| 4194 | |
| 4195 | nla_put_failure: |
| 4196 | genlmsg_cancel(msg, hdr); |
| 4197 | return -EMSGSIZE; |
| 4198 | } |
| 4199 | |
| 4200 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4201 | struct netlink_callback *cb) |
| 4202 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4203 | struct cfg80211_registered_device *rdev; |
| 4204 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4205 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4206 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4207 | int start = cb->args[1], idx = 0; |
| 4208 | int err; |
| 4209 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4210 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4211 | if (err) |
| 4212 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4213 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4214 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4215 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4216 | wdev_lock(wdev); |
| 4217 | spin_lock_bh(&rdev->bss_lock); |
| 4218 | cfg80211_bss_expire(rdev); |
| 4219 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4220 | cb->seq = rdev->bss_generation; |
| 4221 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4222 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4223 | if (++idx <= start) |
| 4224 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4225 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4226 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4227 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4228 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4229 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4230 | } |
| 4231 | } |
| 4232 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4233 | spin_unlock_bh(&rdev->bss_lock); |
| 4234 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4235 | |
| 4236 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4237 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4238 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4239 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4240 | } |
| 4241 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4242 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4243 | int flags, struct net_device *dev, |
| 4244 | struct survey_info *survey) |
| 4245 | { |
| 4246 | void *hdr; |
| 4247 | struct nlattr *infoattr; |
| 4248 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4249 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4250 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4251 | if (!hdr) |
| 4252 | return -ENOMEM; |
| 4253 | |
| 4254 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4255 | |
| 4256 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4257 | if (!infoattr) |
| 4258 | goto nla_put_failure; |
| 4259 | |
| 4260 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4261 | survey->channel->center_freq); |
| 4262 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4263 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4264 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4265 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4266 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4267 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4268 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4269 | survey->channel_time); |
| 4270 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4271 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4272 | survey->channel_time_busy); |
| 4273 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4274 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4275 | survey->channel_time_ext_busy); |
| 4276 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4277 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4278 | survey->channel_time_rx); |
| 4279 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4280 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4281 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4282 | |
| 4283 | nla_nest_end(msg, infoattr); |
| 4284 | |
| 4285 | return genlmsg_end(msg, hdr); |
| 4286 | |
| 4287 | nla_put_failure: |
| 4288 | genlmsg_cancel(msg, hdr); |
| 4289 | return -EMSGSIZE; |
| 4290 | } |
| 4291 | |
| 4292 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4293 | struct netlink_callback *cb) |
| 4294 | { |
| 4295 | struct survey_info survey; |
| 4296 | struct cfg80211_registered_device *dev; |
| 4297 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4298 | int survey_idx = cb->args[1]; |
| 4299 | int res; |
| 4300 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4301 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4302 | if (res) |
| 4303 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4304 | |
| 4305 | if (!dev->ops->dump_survey) { |
| 4306 | res = -EOPNOTSUPP; |
| 4307 | goto out_err; |
| 4308 | } |
| 4309 | |
| 4310 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4311 | struct ieee80211_channel *chan; |
| 4312 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4313 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4314 | &survey); |
| 4315 | if (res == -ENOENT) |
| 4316 | break; |
| 4317 | if (res) |
| 4318 | goto out_err; |
| 4319 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4320 | /* Survey without a channel doesn't make sense */ |
| 4321 | if (!survey.channel) { |
| 4322 | res = -EINVAL; |
| 4323 | goto out; |
| 4324 | } |
| 4325 | |
| 4326 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4327 | survey.channel->center_freq); |
| 4328 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4329 | survey_idx++; |
| 4330 | continue; |
| 4331 | } |
| 4332 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4333 | if (nl80211_send_survey(skb, |
| 4334 | NETLINK_CB(cb->skb).pid, |
| 4335 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4336 | netdev, |
| 4337 | &survey) < 0) |
| 4338 | goto out; |
| 4339 | survey_idx++; |
| 4340 | } |
| 4341 | |
| 4342 | out: |
| 4343 | cb->args[1] = survey_idx; |
| 4344 | res = skb->len; |
| 4345 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4346 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4347 | return res; |
| 4348 | } |
| 4349 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4350 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4351 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4352 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4353 | } |
| 4354 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4355 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4356 | { |
| 4357 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4358 | NL80211_WPA_VERSION_2)); |
| 4359 | } |
| 4360 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4361 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4362 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4363 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4364 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4365 | struct ieee80211_channel *chan; |
| 4366 | const u8 *bssid, *ssid, *ie = NULL; |
| 4367 | int err, ssid_len, ie_len = 0; |
| 4368 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4369 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4370 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4371 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4372 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4373 | return -EINVAL; |
| 4374 | |
| 4375 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4376 | return -EINVAL; |
| 4377 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4378 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4379 | return -EINVAL; |
| 4380 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4381 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4382 | return -EINVAL; |
| 4383 | |
| 4384 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4385 | return -EINVAL; |
| 4386 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4387 | err = nl80211_parse_key(info, &key); |
| 4388 | if (err) |
| 4389 | return err; |
| 4390 | |
| 4391 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4392 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4393 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4394 | if (!key.p.key || !key.p.key_len) |
| 4395 | return -EINVAL; |
| 4396 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4397 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4398 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4399 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4400 | return -EINVAL; |
| 4401 | if (key.idx > 4) |
| 4402 | return -EINVAL; |
| 4403 | } else { |
| 4404 | key.p.key_len = 0; |
| 4405 | key.p.key = NULL; |
| 4406 | } |
| 4407 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4408 | if (key.idx >= 0) { |
| 4409 | int i; |
| 4410 | bool ok = false; |
| 4411 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4412 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4413 | ok = true; |
| 4414 | break; |
| 4415 | } |
| 4416 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4417 | if (!ok) |
| 4418 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4419 | } |
| 4420 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4421 | if (!rdev->ops->auth) |
| 4422 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4423 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4424 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4425 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4426 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4427 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4428 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4429 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4430 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4431 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4432 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4433 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4434 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4435 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4436 | |
| 4437 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4438 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4439 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4440 | } |
| 4441 | |
| 4442 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4443 | if (!nl80211_valid_auth_type(auth_type)) |
| 4444 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4445 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4446 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4447 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4448 | /* |
| 4449 | * Since we no longer track auth state, ignore |
| 4450 | * requests to only change local state. |
| 4451 | */ |
| 4452 | if (local_state_change) |
| 4453 | return 0; |
| 4454 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4455 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4456 | ssid, ssid_len, ie, ie_len, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4457 | key.p.key, key.p.key_len, key.idx); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4458 | } |
| 4459 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4460 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4461 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4462 | struct cfg80211_crypto_settings *settings, |
| 4463 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4464 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4465 | memset(settings, 0, sizeof(*settings)); |
| 4466 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4467 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4468 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4469 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4470 | u16 proto; |
| 4471 | proto = nla_get_u16( |
| 4472 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4473 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4474 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4475 | proto != ETH_P_PAE) |
| 4476 | return -EINVAL; |
| 4477 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4478 | settings->control_port_no_encrypt = true; |
| 4479 | } else |
| 4480 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4481 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4482 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4483 | void *data; |
| 4484 | int len, i; |
| 4485 | |
| 4486 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4487 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4488 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4489 | |
| 4490 | if (len % sizeof(u32)) |
| 4491 | return -EINVAL; |
| 4492 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4493 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4494 | return -EINVAL; |
| 4495 | |
| 4496 | memcpy(settings->ciphers_pairwise, data, len); |
| 4497 | |
| 4498 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4499 | if (!cfg80211_supported_cipher_suite( |
| 4500 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4501 | settings->ciphers_pairwise[i])) |
| 4502 | return -EINVAL; |
| 4503 | } |
| 4504 | |
| 4505 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4506 | settings->cipher_group = |
| 4507 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4508 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4509 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4510 | return -EINVAL; |
| 4511 | } |
| 4512 | |
| 4513 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4514 | settings->wpa_versions = |
| 4515 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4516 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4517 | return -EINVAL; |
| 4518 | } |
| 4519 | |
| 4520 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4521 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4522 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4523 | |
| 4524 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4525 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4526 | settings->n_akm_suites = len / sizeof(u32); |
| 4527 | |
| 4528 | if (len % sizeof(u32)) |
| 4529 | return -EINVAL; |
| 4530 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4531 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4532 | return -EINVAL; |
| 4533 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4534 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4535 | } |
| 4536 | |
| 4537 | return 0; |
| 4538 | } |
| 4539 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4540 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4541 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4542 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4543 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4544 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4545 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4546 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4547 | int err, ssid_len, ie_len = 0; |
| 4548 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4549 | u32 flags = 0; |
| 4550 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 4551 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4552 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4553 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4554 | return -EINVAL; |
| 4555 | |
| 4556 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4557 | !info->attrs[NL80211_ATTR_SSID] || |
| 4558 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4559 | return -EINVAL; |
| 4560 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4561 | if (!rdev->ops->assoc) |
| 4562 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4563 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4564 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4565 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4566 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4567 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4568 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4569 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4570 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4571 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4572 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4573 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4574 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4575 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4576 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4577 | |
| 4578 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4579 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4580 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4581 | } |
| 4582 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4583 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4584 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4585 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4586 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4587 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4588 | else if (mfp != NL80211_MFP_NO) |
| 4589 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4590 | } |
| 4591 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4592 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4593 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4594 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4595 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 4596 | flags |= ASSOC_REQ_DISABLE_HT; |
| 4597 | |
| 4598 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 4599 | ht_capa_mask = |
| 4600 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 4601 | |
| 4602 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 4603 | if (!ht_capa_mask) |
| 4604 | return -EINVAL; |
| 4605 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4606 | } |
| 4607 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4608 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4609 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4610 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4611 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4612 | &crypto, flags, ht_capa, |
| 4613 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4614 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4615 | return err; |
| 4616 | } |
| 4617 | |
| 4618 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4619 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4621 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4622 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4623 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4624 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4625 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4626 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4627 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4628 | return -EINVAL; |
| 4629 | |
| 4630 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4631 | return -EINVAL; |
| 4632 | |
| 4633 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4634 | return -EINVAL; |
| 4635 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4636 | if (!rdev->ops->deauth) |
| 4637 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4638 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4639 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4640 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4641 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4642 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4643 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4644 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4645 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4646 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4647 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4648 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4649 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4650 | |
| 4651 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4652 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4653 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4654 | } |
| 4655 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4656 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4657 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4658 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4659 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4663 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4665 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4666 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4667 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4668 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4669 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4670 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4671 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4672 | return -EINVAL; |
| 4673 | |
| 4674 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4675 | return -EINVAL; |
| 4676 | |
| 4677 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4678 | return -EINVAL; |
| 4679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4680 | if (!rdev->ops->disassoc) |
| 4681 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4682 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4683 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4684 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4685 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4686 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4687 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4688 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4689 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4690 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4691 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4692 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4693 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4694 | |
| 4695 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4696 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4697 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4698 | } |
| 4699 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4700 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4701 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4702 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4703 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4704 | } |
| 4705 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4706 | static bool |
| 4707 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4708 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4709 | int rateval) |
| 4710 | { |
| 4711 | struct wiphy *wiphy = &rdev->wiphy; |
| 4712 | bool found = false; |
| 4713 | int band, i; |
| 4714 | |
| 4715 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4716 | struct ieee80211_supported_band *sband; |
| 4717 | |
| 4718 | sband = wiphy->bands[band]; |
| 4719 | if (!sband) |
| 4720 | continue; |
| 4721 | |
| 4722 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4723 | if (sband->bitrates[i].bitrate == rateval) { |
| 4724 | mcast_rate[band] = i + 1; |
| 4725 | found = true; |
| 4726 | break; |
| 4727 | } |
| 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | return found; |
| 4732 | } |
| 4733 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4734 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4735 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4736 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4737 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4738 | struct cfg80211_ibss_params ibss; |
| 4739 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4740 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4741 | int err; |
| 4742 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4743 | memset(&ibss, 0, sizeof(ibss)); |
| 4744 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4745 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4746 | return -EINVAL; |
| 4747 | |
| 4748 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4749 | !info->attrs[NL80211_ATTR_SSID] || |
| 4750 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4751 | return -EINVAL; |
| 4752 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4753 | ibss.beacon_interval = 100; |
| 4754 | |
| 4755 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4756 | ibss.beacon_interval = |
| 4757 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4758 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4759 | return -EINVAL; |
| 4760 | } |
| 4761 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4762 | if (!rdev->ops->join_ibss) |
| 4763 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4764 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4765 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4766 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4767 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4768 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4769 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4770 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4771 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4772 | |
| 4773 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4774 | return -EINVAL; |
| 4775 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4776 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4777 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4778 | |
| 4779 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4780 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4781 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4782 | } |
| 4783 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 4784 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4785 | enum nl80211_channel_type channel_type; |
| 4786 | |
| 4787 | channel_type = nla_get_u32( |
| 4788 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4789 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4790 | channel_type != NL80211_CHAN_HT20 && |
| 4791 | channel_type != NL80211_CHAN_HT40MINUS && |
| 4792 | channel_type != NL80211_CHAN_HT40PLUS) |
| 4793 | return -EINVAL; |
| 4794 | |
| 4795 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4796 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 4797 | return -EINVAL; |
| 4798 | |
| 4799 | ibss.channel_type = channel_type; |
| 4800 | } else { |
| 4801 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 4802 | } |
| 4803 | |
| 4804 | ibss.channel = rdev_freq_to_chan(rdev, |
| 4805 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 4806 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4807 | if (!ibss.channel || |
| 4808 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4809 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4810 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4811 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 4812 | /* Both channels should be able to initiate communication */ |
| 4813 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 4814 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 4815 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 4816 | ibss.channel_type)) |
| 4817 | return -EINVAL; |
| 4818 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4819 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4820 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4821 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4822 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4823 | u8 *rates = |
| 4824 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4825 | int n_rates = |
| 4826 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4827 | struct ieee80211_supported_band *sband = |
| 4828 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4829 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4830 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4831 | &ibss.basic_rates); |
| 4832 | if (err) |
| 4833 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4834 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4835 | |
| 4836 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4837 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4838 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4839 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4840 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4841 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4842 | connkeys = nl80211_parse_connkeys(rdev, |
| 4843 | info->attrs[NL80211_ATTR_KEYS]); |
| 4844 | if (IS_ERR(connkeys)) |
| 4845 | return PTR_ERR(connkeys); |
| 4846 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4847 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4848 | ibss.control_port = |
| 4849 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 4850 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4851 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4852 | if (err) |
| 4853 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4854 | return err; |
| 4855 | } |
| 4856 | |
| 4857 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4858 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4859 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4860 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4861 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4862 | if (!rdev->ops->leave_ibss) |
| 4863 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4864 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4865 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4866 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4867 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4868 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4869 | } |
| 4870 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4871 | #ifdef CONFIG_NL80211_TESTMODE |
| 4872 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4873 | .name = "testmode", |
| 4874 | }; |
| 4875 | |
| 4876 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4877 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4878 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4879 | int err; |
| 4880 | |
| 4881 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4882 | return -EINVAL; |
| 4883 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4884 | err = -EOPNOTSUPP; |
| 4885 | if (rdev->ops->testmode_cmd) { |
| 4886 | rdev->testmode_info = info; |
| 4887 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4888 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4889 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4890 | rdev->testmode_info = NULL; |
| 4891 | } |
| 4892 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4893 | return err; |
| 4894 | } |
| 4895 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4896 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4897 | struct netlink_callback *cb) |
| 4898 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4899 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4900 | int err; |
| 4901 | long phy_idx; |
| 4902 | void *data = NULL; |
| 4903 | int data_len = 0; |
| 4904 | |
| 4905 | if (cb->args[0]) { |
| 4906 | /* |
| 4907 | * 0 is a valid index, but not valid for args[0], |
| 4908 | * so we need to offset by 1. |
| 4909 | */ |
| 4910 | phy_idx = cb->args[0] - 1; |
| 4911 | } else { |
| 4912 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4913 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4914 | nl80211_policy); |
| 4915 | if (err) |
| 4916 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4917 | if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) { |
| 4918 | phy_idx = nla_get_u32( |
| 4919 | nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4920 | } else { |
| 4921 | struct net_device *netdev; |
| 4922 | |
| 4923 | err = get_rdev_dev_by_ifindex(sock_net(skb->sk), |
| 4924 | nl80211_fam.attrbuf, |
| 4925 | &rdev, &netdev); |
| 4926 | if (err) |
| 4927 | return err; |
| 4928 | dev_put(netdev); |
| 4929 | phy_idx = rdev->wiphy_idx; |
| 4930 | cfg80211_unlock_rdev(rdev); |
| 4931 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4932 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4933 | cb->args[1] = |
| 4934 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4935 | } |
| 4936 | |
| 4937 | if (cb->args[1]) { |
| 4938 | data = nla_data((void *)cb->args[1]); |
| 4939 | data_len = nla_len((void *)cb->args[1]); |
| 4940 | } |
| 4941 | |
| 4942 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4943 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4944 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4945 | mutex_unlock(&cfg80211_mutex); |
| 4946 | return -ENOENT; |
| 4947 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4948 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4949 | mutex_unlock(&cfg80211_mutex); |
| 4950 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4951 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4952 | err = -EOPNOTSUPP; |
| 4953 | goto out_err; |
| 4954 | } |
| 4955 | |
| 4956 | while (1) { |
| 4957 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4958 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4959 | NL80211_CMD_TESTMODE); |
| 4960 | struct nlattr *tmdata; |
| 4961 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4962 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4963 | genlmsg_cancel(skb, hdr); |
| 4964 | break; |
| 4965 | } |
| 4966 | |
| 4967 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4968 | if (!tmdata) { |
| 4969 | genlmsg_cancel(skb, hdr); |
| 4970 | break; |
| 4971 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4972 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
| 4973 | data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4974 | nla_nest_end(skb, tmdata); |
| 4975 | |
| 4976 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4977 | genlmsg_cancel(skb, hdr); |
| 4978 | break; |
| 4979 | } else if (err) { |
| 4980 | genlmsg_cancel(skb, hdr); |
| 4981 | goto out_err; |
| 4982 | } |
| 4983 | |
| 4984 | genlmsg_end(skb, hdr); |
| 4985 | } |
| 4986 | |
| 4987 | err = skb->len; |
| 4988 | /* see above */ |
| 4989 | cb->args[0] = phy_idx + 1; |
| 4990 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4991 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4992 | return err; |
| 4993 | } |
| 4994 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4995 | static struct sk_buff * |
| 4996 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4997 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4998 | { |
| 4999 | struct sk_buff *skb; |
| 5000 | void *hdr; |
| 5001 | struct nlattr *data; |
| 5002 | |
| 5003 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5004 | if (!skb) |
| 5005 | return NULL; |
| 5006 | |
| 5007 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 5008 | if (!hdr) { |
| 5009 | kfree_skb(skb); |
| 5010 | return NULL; |
| 5011 | } |
| 5012 | |
| 5013 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5014 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5015 | |
| 5016 | ((void **)skb->cb)[0] = rdev; |
| 5017 | ((void **)skb->cb)[1] = hdr; |
| 5018 | ((void **)skb->cb)[2] = data; |
| 5019 | |
| 5020 | return skb; |
| 5021 | |
| 5022 | nla_put_failure: |
| 5023 | kfree_skb(skb); |
| 5024 | return NULL; |
| 5025 | } |
| 5026 | |
| 5027 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5028 | int approxlen) |
| 5029 | { |
| 5030 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5031 | |
| 5032 | if (WARN_ON(!rdev->testmode_info)) |
| 5033 | return NULL; |
| 5034 | |
| 5035 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 5036 | rdev->testmode_info->snd_pid, |
| 5037 | rdev->testmode_info->snd_seq, |
| 5038 | GFP_KERNEL); |
| 5039 | } |
| 5040 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5041 | |
| 5042 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5043 | { |
| 5044 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5045 | void *hdr = ((void **)skb->cb)[1]; |
| 5046 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5047 | |
| 5048 | if (WARN_ON(!rdev->testmode_info)) { |
| 5049 | kfree_skb(skb); |
| 5050 | return -EINVAL; |
| 5051 | } |
| 5052 | |
| 5053 | nla_nest_end(skb, data); |
| 5054 | genlmsg_end(skb, hdr); |
| 5055 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5056 | } |
| 5057 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5058 | |
| 5059 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5060 | int approxlen, gfp_t gfp) |
| 5061 | { |
| 5062 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5063 | |
| 5064 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5065 | } |
| 5066 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5067 | |
| 5068 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5069 | { |
| 5070 | void *hdr = ((void **)skb->cb)[1]; |
| 5071 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5072 | |
| 5073 | nla_nest_end(skb, data); |
| 5074 | genlmsg_end(skb, hdr); |
| 5075 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5076 | } |
| 5077 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5078 | #endif |
| 5079 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5080 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5081 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5082 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5083 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5084 | struct cfg80211_connect_params connect; |
| 5085 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5086 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5087 | int err; |
| 5088 | |
| 5089 | memset(&connect, 0, sizeof(connect)); |
| 5090 | |
| 5091 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5092 | return -EINVAL; |
| 5093 | |
| 5094 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5095 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5096 | return -EINVAL; |
| 5097 | |
| 5098 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5099 | connect.auth_type = |
| 5100 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 5101 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 5102 | return -EINVAL; |
| 5103 | } else |
| 5104 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5105 | |
| 5106 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5107 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5108 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5109 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5110 | if (err) |
| 5111 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5112 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5113 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5114 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5115 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5116 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5117 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5118 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5119 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5120 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5121 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5122 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5123 | |
| 5124 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5125 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5126 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5127 | } |
| 5128 | |
| 5129 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5130 | connect.channel = |
| 5131 | ieee80211_get_channel(wiphy, |
| 5132 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5133 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5134 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5135 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5136 | } |
| 5137 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5138 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5139 | connkeys = nl80211_parse_connkeys(rdev, |
| 5140 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5141 | if (IS_ERR(connkeys)) |
| 5142 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5143 | } |
| 5144 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5145 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5146 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5147 | |
| 5148 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5149 | memcpy(&connect.ht_capa_mask, |
| 5150 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5151 | sizeof(connect.ht_capa_mask)); |
| 5152 | |
| 5153 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5154 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5155 | return -EINVAL; |
| 5156 | memcpy(&connect.ht_capa, |
| 5157 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5158 | sizeof(connect.ht_capa)); |
| 5159 | } |
| 5160 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5161 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5162 | if (err) |
| 5163 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5164 | return err; |
| 5165 | } |
| 5166 | |
| 5167 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5168 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5169 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5170 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5171 | u16 reason; |
| 5172 | |
| 5173 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5174 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5175 | else |
| 5176 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5177 | |
| 5178 | if (reason == 0) |
| 5179 | return -EINVAL; |
| 5180 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5181 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5182 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5183 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5184 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5185 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5186 | } |
| 5187 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5188 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5189 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5190 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5191 | struct net *net; |
| 5192 | int err; |
| 5193 | u32 pid; |
| 5194 | |
| 5195 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5196 | return -EINVAL; |
| 5197 | |
| 5198 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5199 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5200 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5201 | if (IS_ERR(net)) |
| 5202 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5203 | |
| 5204 | err = 0; |
| 5205 | |
| 5206 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5207 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5208 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5209 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5210 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5211 | return err; |
| 5212 | } |
| 5213 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5214 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5215 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5216 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5217 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5218 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5219 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5220 | struct cfg80211_pmksa pmksa; |
| 5221 | |
| 5222 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5223 | |
| 5224 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5225 | return -EINVAL; |
| 5226 | |
| 5227 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5228 | return -EINVAL; |
| 5229 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5230 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5231 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5232 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5233 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5234 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5235 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5236 | |
| 5237 | switch (info->genlhdr->cmd) { |
| 5238 | case NL80211_CMD_SET_PMKSA: |
| 5239 | rdev_ops = rdev->ops->set_pmksa; |
| 5240 | break; |
| 5241 | case NL80211_CMD_DEL_PMKSA: |
| 5242 | rdev_ops = rdev->ops->del_pmksa; |
| 5243 | break; |
| 5244 | default: |
| 5245 | WARN_ON(1); |
| 5246 | break; |
| 5247 | } |
| 5248 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5249 | if (!rdev_ops) |
| 5250 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5252 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5253 | } |
| 5254 | |
| 5255 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5256 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5257 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5258 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5259 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5260 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5261 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5262 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5263 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5264 | if (!rdev->ops->flush_pmksa) |
| 5265 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5266 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5267 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5268 | } |
| 5269 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5270 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5271 | { |
| 5272 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5273 | struct net_device *dev = info->user_ptr[1]; |
| 5274 | u8 action_code, dialog_token; |
| 5275 | u16 status_code; |
| 5276 | u8 *peer; |
| 5277 | |
| 5278 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5279 | !rdev->ops->tdls_mgmt) |
| 5280 | return -EOPNOTSUPP; |
| 5281 | |
| 5282 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5283 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5284 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5285 | !info->attrs[NL80211_ATTR_IE] || |
| 5286 | !info->attrs[NL80211_ATTR_MAC]) |
| 5287 | return -EINVAL; |
| 5288 | |
| 5289 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5290 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5291 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5292 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5293 | |
| 5294 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5295 | dialog_token, status_code, |
| 5296 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5297 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5298 | } |
| 5299 | |
| 5300 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5301 | { |
| 5302 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5303 | struct net_device *dev = info->user_ptr[1]; |
| 5304 | enum nl80211_tdls_operation operation; |
| 5305 | u8 *peer; |
| 5306 | |
| 5307 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5308 | !rdev->ops->tdls_oper) |
| 5309 | return -EOPNOTSUPP; |
| 5310 | |
| 5311 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5312 | !info->attrs[NL80211_ATTR_MAC]) |
| 5313 | return -EINVAL; |
| 5314 | |
| 5315 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5316 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5317 | |
| 5318 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5319 | } |
| 5320 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5321 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5322 | struct genl_info *info) |
| 5323 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5324 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5325 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5326 | struct ieee80211_channel *chan; |
| 5327 | struct sk_buff *msg; |
| 5328 | void *hdr; |
| 5329 | u64 cookie; |
| 5330 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5331 | u32 freq, duration; |
| 5332 | int err; |
| 5333 | |
| 5334 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5335 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5336 | return -EINVAL; |
| 5337 | |
| 5338 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5339 | |
| 5340 | /* |
| 5341 | * We should be on that channel for at least one jiffie, |
| 5342 | * and more than 5 seconds seems excessive. |
| 5343 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5344 | if (!duration || !msecs_to_jiffies(duration) || |
| 5345 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5346 | return -EINVAL; |
| 5347 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5348 | if (!rdev->ops->remain_on_channel || |
| 5349 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5350 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5351 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5352 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5353 | channel_type = nla_get_u32( |
| 5354 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5355 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5356 | channel_type != NL80211_CHAN_HT20 && |
| 5357 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5358 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5359 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5363 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5364 | if (chan == NULL) |
| 5365 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5366 | |
| 5367 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5368 | if (!msg) |
| 5369 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5370 | |
| 5371 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5372 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5373 | |
| 5374 | if (IS_ERR(hdr)) { |
| 5375 | err = PTR_ERR(hdr); |
| 5376 | goto free_msg; |
| 5377 | } |
| 5378 | |
| 5379 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5380 | channel_type, duration, &cookie); |
| 5381 | |
| 5382 | if (err) |
| 5383 | goto free_msg; |
| 5384 | |
| 5385 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5386 | |
| 5387 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5388 | |
| 5389 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5390 | |
| 5391 | nla_put_failure: |
| 5392 | err = -ENOBUFS; |
| 5393 | free_msg: |
| 5394 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5395 | return err; |
| 5396 | } |
| 5397 | |
| 5398 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5399 | struct genl_info *info) |
| 5400 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5402 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5403 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5404 | |
| 5405 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5406 | return -EINVAL; |
| 5407 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5408 | if (!rdev->ops->cancel_remain_on_channel) |
| 5409 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5410 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5411 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5412 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5413 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5414 | } |
| 5415 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5416 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5417 | u8 *rates, u8 rates_len) |
| 5418 | { |
| 5419 | u8 i; |
| 5420 | u32 mask = 0; |
| 5421 | |
| 5422 | for (i = 0; i < rates_len; i++) { |
| 5423 | int rate = (rates[i] & 0x7f) * 5; |
| 5424 | int ridx; |
| 5425 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5426 | struct ieee80211_rate *srate = |
| 5427 | &sband->bitrates[ridx]; |
| 5428 | if (rate == srate->bitrate) { |
| 5429 | mask |= 1 << ridx; |
| 5430 | break; |
| 5431 | } |
| 5432 | } |
| 5433 | if (ridx == sband->n_bitrates) |
| 5434 | return 0; /* rate not found */ |
| 5435 | } |
| 5436 | |
| 5437 | return mask; |
| 5438 | } |
| 5439 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5440 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5441 | u8 *rates, u8 rates_len, |
| 5442 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 5443 | { |
| 5444 | u8 i; |
| 5445 | |
| 5446 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 5447 | |
| 5448 | for (i = 0; i < rates_len; i++) { |
| 5449 | int ridx, rbit; |
| 5450 | |
| 5451 | ridx = rates[i] / 8; |
| 5452 | rbit = BIT(rates[i] % 8); |
| 5453 | |
| 5454 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 5455 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5456 | return false; |
| 5457 | |
| 5458 | /* check availability */ |
| 5459 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 5460 | mcs[ridx] |= rbit; |
| 5461 | else |
| 5462 | return false; |
| 5463 | } |
| 5464 | |
| 5465 | return true; |
| 5466 | } |
| 5467 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5468 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5469 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5470 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5471 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 5472 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5473 | }; |
| 5474 | |
| 5475 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5476 | struct genl_info *info) |
| 5477 | { |
| 5478 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5480 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5481 | int rem, i; |
| 5482 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5483 | struct nlattr *tx_rates; |
| 5484 | struct ieee80211_supported_band *sband; |
| 5485 | |
| 5486 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5487 | return -EINVAL; |
| 5488 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5489 | if (!rdev->ops->set_bitrate_mask) |
| 5490 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5491 | |
| 5492 | memset(&mask, 0, sizeof(mask)); |
| 5493 | /* Default to all rates enabled */ |
| 5494 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5495 | sband = rdev->wiphy.bands[i]; |
| 5496 | mask.control[i].legacy = |
| 5497 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5498 | if (sband) |
| 5499 | memcpy(mask.control[i].mcs, |
| 5500 | sband->ht_cap.mcs.rx_mask, |
| 5501 | sizeof(mask.control[i].mcs)); |
| 5502 | else |
| 5503 | memset(mask.control[i].mcs, 0, |
| 5504 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | /* |
| 5508 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5509 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5510 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5511 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5512 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5513 | { |
| 5514 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5515 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5516 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5517 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5518 | if (sband == NULL) |
| 5519 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5520 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5521 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5522 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5523 | mask.control[band].legacy = rateset_to_mask( |
| 5524 | sband, |
| 5525 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5526 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5527 | } |
| 5528 | if (tb[NL80211_TXRATE_MCS]) { |
| 5529 | if (!ht_rateset_to_mask( |
| 5530 | sband, |
| 5531 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 5532 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 5533 | mask.control[band].mcs)) |
| 5534 | return -EINVAL; |
| 5535 | } |
| 5536 | |
| 5537 | if (mask.control[band].legacy == 0) { |
| 5538 | /* don't allow empty legacy rates if HT |
| 5539 | * is not even supported. */ |
| 5540 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 5541 | return -EINVAL; |
| 5542 | |
| 5543 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5544 | if (mask.control[band].mcs[i]) |
| 5545 | break; |
| 5546 | |
| 5547 | /* legacy and mcs rates may not be both empty */ |
| 5548 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5549 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5550 | } |
| 5551 | } |
| 5552 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5553 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5554 | } |
| 5555 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5556 | 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] | 5557 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5559 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5560 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5561 | |
| 5562 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5563 | return -EINVAL; |
| 5564 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5565 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5566 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5567 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5568 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5569 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5570 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5571 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5572 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5573 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5574 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5575 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5576 | |
| 5577 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5578 | if (!rdev->ops->mgmt_tx) |
| 5579 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5580 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5581 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5582 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5583 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5584 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5585 | } |
| 5586 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5587 | 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] | 5588 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5590 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5591 | struct ieee80211_channel *chan; |
| 5592 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5593 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5594 | u32 freq; |
| 5595 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 5596 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5597 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5598 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5599 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5600 | bool offchan, no_cck, dont_wait_for_ack; |
| 5601 | |
| 5602 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5603 | |
| 5604 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5605 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5606 | return -EINVAL; |
| 5607 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5608 | if (!rdev->ops->mgmt_tx) |
| 5609 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5610 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5611 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5612 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5613 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5614 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5615 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5616 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5617 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5618 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5619 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5620 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5621 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5622 | return -EINVAL; |
| 5623 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5624 | } |
| 5625 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5626 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5627 | channel_type = nla_get_u32( |
| 5628 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5629 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5630 | channel_type != NL80211_CHAN_HT20 && |
| 5631 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5632 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5633 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5634 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5635 | } |
| 5636 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5637 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5638 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5639 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 5640 | return -EINVAL; |
| 5641 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5642 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5643 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5644 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5645 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5646 | if (chan == NULL) |
| 5647 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5648 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5649 | if (!dont_wait_for_ack) { |
| 5650 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5651 | if (!msg) |
| 5652 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5653 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5654 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5655 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5656 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5657 | if (IS_ERR(hdr)) { |
| 5658 | err = PTR_ERR(hdr); |
| 5659 | goto free_msg; |
| 5660 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5661 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5662 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5663 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5664 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5665 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5666 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5667 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5668 | if (err) |
| 5669 | goto free_msg; |
| 5670 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5671 | if (msg) { |
| 5672 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5673 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5674 | genlmsg_end(msg, hdr); |
| 5675 | return genlmsg_reply(msg, info); |
| 5676 | } |
| 5677 | |
| 5678 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5679 | |
| 5680 | nla_put_failure: |
| 5681 | err = -ENOBUFS; |
| 5682 | free_msg: |
| 5683 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5684 | return err; |
| 5685 | } |
| 5686 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5687 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5688 | { |
| 5689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5690 | struct net_device *dev = info->user_ptr[1]; |
| 5691 | u64 cookie; |
| 5692 | |
| 5693 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5694 | return -EINVAL; |
| 5695 | |
| 5696 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5697 | return -EOPNOTSUPP; |
| 5698 | |
| 5699 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5700 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5701 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5702 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5703 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5704 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5705 | return -EOPNOTSUPP; |
| 5706 | |
| 5707 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5708 | |
| 5709 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5710 | } |
| 5711 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5712 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5713 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5714 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5715 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5716 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5717 | u8 ps_state; |
| 5718 | bool state; |
| 5719 | int err; |
| 5720 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5721 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5722 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5723 | |
| 5724 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5725 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5726 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5727 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5728 | |
| 5729 | wdev = dev->ieee80211_ptr; |
| 5730 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5731 | if (!rdev->ops->set_power_mgmt) |
| 5732 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5733 | |
| 5734 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5735 | |
| 5736 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5737 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5738 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5739 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5740 | wdev->ps_timeout); |
| 5741 | if (!err) |
| 5742 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5743 | return err; |
| 5744 | } |
| 5745 | |
| 5746 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5747 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5748 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5749 | enum nl80211_ps_state ps_state; |
| 5750 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5751 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5752 | struct sk_buff *msg; |
| 5753 | void *hdr; |
| 5754 | int err; |
| 5755 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5756 | wdev = dev->ieee80211_ptr; |
| 5757 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5758 | if (!rdev->ops->set_power_mgmt) |
| 5759 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5760 | |
| 5761 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5762 | if (!msg) |
| 5763 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5764 | |
| 5765 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5766 | NL80211_CMD_GET_POWER_SAVE); |
| 5767 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5768 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5769 | goto free_msg; |
| 5770 | } |
| 5771 | |
| 5772 | if (wdev->ps) |
| 5773 | ps_state = NL80211_PS_ENABLED; |
| 5774 | else |
| 5775 | ps_state = NL80211_PS_DISABLED; |
| 5776 | |
| 5777 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5778 | |
| 5779 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5780 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5781 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5782 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5783 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5784 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5785 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5786 | return err; |
| 5787 | } |
| 5788 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5789 | static struct nla_policy |
| 5790 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5791 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5792 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5793 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5794 | }; |
| 5795 | |
| 5796 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5797 | s32 threshold, u32 hysteresis) |
| 5798 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5800 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5801 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5802 | |
| 5803 | if (threshold > 0) |
| 5804 | return -EINVAL; |
| 5805 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5806 | wdev = dev->ieee80211_ptr; |
| 5807 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5808 | if (!rdev->ops->set_cqm_rssi_config) |
| 5809 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5810 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5811 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5812 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5813 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5814 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5815 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5816 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5820 | { |
| 5821 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5822 | struct nlattr *cqm; |
| 5823 | int err; |
| 5824 | |
| 5825 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5826 | if (!cqm) { |
| 5827 | err = -EINVAL; |
| 5828 | goto out; |
| 5829 | } |
| 5830 | |
| 5831 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5832 | nl80211_attr_cqm_policy); |
| 5833 | if (err) |
| 5834 | goto out; |
| 5835 | |
| 5836 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5837 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5838 | s32 threshold; |
| 5839 | u32 hysteresis; |
| 5840 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5841 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5842 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5843 | } else |
| 5844 | err = -EINVAL; |
| 5845 | |
| 5846 | out: |
| 5847 | return err; |
| 5848 | } |
| 5849 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5850 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5851 | { |
| 5852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5853 | struct net_device *dev = info->user_ptr[1]; |
| 5854 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5855 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5856 | int err; |
| 5857 | |
| 5858 | /* start with default */ |
| 5859 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5860 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5861 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5862 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5863 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5864 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5865 | if (err) |
| 5866 | return err; |
| 5867 | } |
| 5868 | |
| 5869 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5870 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5871 | return -EINVAL; |
| 5872 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5873 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5874 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5875 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 5876 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5877 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 5878 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5879 | return -EINVAL; |
| 5880 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5881 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5882 | /* parse additional setup parameters if given */ |
| 5883 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5884 | if (err) |
| 5885 | return err; |
| 5886 | } |
| 5887 | |
| 5888 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5892 | { |
| 5893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5894 | struct net_device *dev = info->user_ptr[1]; |
| 5895 | |
| 5896 | return cfg80211_leave_mesh(rdev, dev); |
| 5897 | } |
| 5898 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5899 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5900 | { |
| 5901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5902 | struct sk_buff *msg; |
| 5903 | void *hdr; |
| 5904 | |
| 5905 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5906 | return -EOPNOTSUPP; |
| 5907 | |
| 5908 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5909 | if (!msg) |
| 5910 | return -ENOMEM; |
| 5911 | |
| 5912 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5913 | NL80211_CMD_GET_WOWLAN); |
| 5914 | if (!hdr) |
| 5915 | goto nla_put_failure; |
| 5916 | |
| 5917 | if (rdev->wowlan) { |
| 5918 | struct nlattr *nl_wowlan; |
| 5919 | |
| 5920 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5921 | if (!nl_wowlan) |
| 5922 | goto nla_put_failure; |
| 5923 | |
| 5924 | if (rdev->wowlan->any) |
| 5925 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5926 | if (rdev->wowlan->disconnect) |
| 5927 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5928 | if (rdev->wowlan->magic_pkt) |
| 5929 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5930 | if (rdev->wowlan->gtk_rekey_failure) |
| 5931 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5932 | if (rdev->wowlan->eap_identity_req) |
| 5933 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5934 | if (rdev->wowlan->four_way_handshake) |
| 5935 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5936 | if (rdev->wowlan->rfkill_release) |
| 5937 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5938 | if (rdev->wowlan->n_patterns) { |
| 5939 | struct nlattr *nl_pats, *nl_pat; |
| 5940 | int i, pat_len; |
| 5941 | |
| 5942 | nl_pats = nla_nest_start(msg, |
| 5943 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5944 | if (!nl_pats) |
| 5945 | goto nla_put_failure; |
| 5946 | |
| 5947 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5948 | nl_pat = nla_nest_start(msg, i + 1); |
| 5949 | if (!nl_pat) |
| 5950 | goto nla_put_failure; |
| 5951 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5952 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5953 | DIV_ROUND_UP(pat_len, 8), |
| 5954 | rdev->wowlan->patterns[i].mask); |
| 5955 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5956 | pat_len, |
| 5957 | rdev->wowlan->patterns[i].pattern); |
| 5958 | nla_nest_end(msg, nl_pat); |
| 5959 | } |
| 5960 | nla_nest_end(msg, nl_pats); |
| 5961 | } |
| 5962 | |
| 5963 | nla_nest_end(msg, nl_wowlan); |
| 5964 | } |
| 5965 | |
| 5966 | genlmsg_end(msg, hdr); |
| 5967 | return genlmsg_reply(msg, info); |
| 5968 | |
| 5969 | nla_put_failure: |
| 5970 | nlmsg_free(msg); |
| 5971 | return -ENOBUFS; |
| 5972 | } |
| 5973 | |
| 5974 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5975 | { |
| 5976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5977 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5978 | struct cfg80211_wowlan no_triggers = {}; |
| 5979 | struct cfg80211_wowlan new_triggers = {}; |
| 5980 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5981 | int err, i; |
| 5982 | |
| 5983 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5984 | return -EOPNOTSUPP; |
| 5985 | |
| 5986 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5987 | goto no_triggers; |
| 5988 | |
| 5989 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5990 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5991 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5992 | nl80211_wowlan_policy); |
| 5993 | if (err) |
| 5994 | return err; |
| 5995 | |
| 5996 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5997 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5998 | return -EINVAL; |
| 5999 | new_triggers.any = true; |
| 6000 | } |
| 6001 | |
| 6002 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6003 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6004 | return -EINVAL; |
| 6005 | new_triggers.disconnect = true; |
| 6006 | } |
| 6007 | |
| 6008 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6009 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6010 | return -EINVAL; |
| 6011 | new_triggers.magic_pkt = true; |
| 6012 | } |
| 6013 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6014 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6015 | return -EINVAL; |
| 6016 | |
| 6017 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6018 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6019 | return -EINVAL; |
| 6020 | new_triggers.gtk_rekey_failure = true; |
| 6021 | } |
| 6022 | |
| 6023 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6024 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6025 | return -EINVAL; |
| 6026 | new_triggers.eap_identity_req = true; |
| 6027 | } |
| 6028 | |
| 6029 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6030 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6031 | return -EINVAL; |
| 6032 | new_triggers.four_way_handshake = true; |
| 6033 | } |
| 6034 | |
| 6035 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6036 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6037 | return -EINVAL; |
| 6038 | new_triggers.rfkill_release = true; |
| 6039 | } |
| 6040 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6041 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6042 | struct nlattr *pat; |
| 6043 | int n_patterns = 0; |
| 6044 | int rem, pat_len, mask_len; |
| 6045 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6046 | |
| 6047 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6048 | rem) |
| 6049 | n_patterns++; |
| 6050 | if (n_patterns > wowlan->n_patterns) |
| 6051 | return -EINVAL; |
| 6052 | |
| 6053 | new_triggers.patterns = kcalloc(n_patterns, |
| 6054 | sizeof(new_triggers.patterns[0]), |
| 6055 | GFP_KERNEL); |
| 6056 | if (!new_triggers.patterns) |
| 6057 | return -ENOMEM; |
| 6058 | |
| 6059 | new_triggers.n_patterns = n_patterns; |
| 6060 | i = 0; |
| 6061 | |
| 6062 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6063 | rem) { |
| 6064 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6065 | nla_data(pat), nla_len(pat), NULL); |
| 6066 | err = -EINVAL; |
| 6067 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6068 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6069 | goto error; |
| 6070 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6071 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6072 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6073 | mask_len) |
| 6074 | goto error; |
| 6075 | if (pat_len > wowlan->pattern_max_len || |
| 6076 | pat_len < wowlan->pattern_min_len) |
| 6077 | goto error; |
| 6078 | |
| 6079 | new_triggers.patterns[i].mask = |
| 6080 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6081 | if (!new_triggers.patterns[i].mask) { |
| 6082 | err = -ENOMEM; |
| 6083 | goto error; |
| 6084 | } |
| 6085 | new_triggers.patterns[i].pattern = |
| 6086 | new_triggers.patterns[i].mask + mask_len; |
| 6087 | memcpy(new_triggers.patterns[i].mask, |
| 6088 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6089 | mask_len); |
| 6090 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6091 | memcpy(new_triggers.patterns[i].pattern, |
| 6092 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6093 | pat_len); |
| 6094 | i++; |
| 6095 | } |
| 6096 | } |
| 6097 | |
| 6098 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 6099 | struct cfg80211_wowlan *ntrig; |
| 6100 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 6101 | GFP_KERNEL); |
| 6102 | if (!ntrig) { |
| 6103 | err = -ENOMEM; |
| 6104 | goto error; |
| 6105 | } |
| 6106 | cfg80211_rdev_free_wowlan(rdev); |
| 6107 | rdev->wowlan = ntrig; |
| 6108 | } else { |
| 6109 | no_triggers: |
| 6110 | cfg80211_rdev_free_wowlan(rdev); |
| 6111 | rdev->wowlan = NULL; |
| 6112 | } |
| 6113 | |
| 6114 | return 0; |
| 6115 | error: |
| 6116 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6117 | kfree(new_triggers.patterns[i].mask); |
| 6118 | kfree(new_triggers.patterns); |
| 6119 | return err; |
| 6120 | } |
| 6121 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6122 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6123 | { |
| 6124 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6125 | struct net_device *dev = info->user_ptr[1]; |
| 6126 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6127 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6128 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6129 | int err; |
| 6130 | |
| 6131 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6132 | return -EINVAL; |
| 6133 | |
| 6134 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6135 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6136 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6137 | nl80211_rekey_policy); |
| 6138 | if (err) |
| 6139 | return err; |
| 6140 | |
| 6141 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6142 | return -ERANGE; |
| 6143 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6144 | return -ERANGE; |
| 6145 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6146 | return -ERANGE; |
| 6147 | |
| 6148 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6149 | NL80211_KEK_LEN); |
| 6150 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6151 | NL80211_KCK_LEN); |
| 6152 | memcpy(rekey_data.replay_ctr, |
| 6153 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6154 | NL80211_REPLAY_CTR_LEN); |
| 6155 | |
| 6156 | wdev_lock(wdev); |
| 6157 | if (!wdev->current_bss) { |
| 6158 | err = -ENOTCONN; |
| 6159 | goto out; |
| 6160 | } |
| 6161 | |
| 6162 | if (!rdev->ops->set_rekey_data) { |
| 6163 | err = -EOPNOTSUPP; |
| 6164 | goto out; |
| 6165 | } |
| 6166 | |
| 6167 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 6168 | out: |
| 6169 | wdev_unlock(wdev); |
| 6170 | return err; |
| 6171 | } |
| 6172 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6173 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6174 | struct genl_info *info) |
| 6175 | { |
| 6176 | struct net_device *dev = info->user_ptr[1]; |
| 6177 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6178 | |
| 6179 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6180 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6181 | return -EINVAL; |
| 6182 | |
| 6183 | if (wdev->ap_unexpected_nlpid) |
| 6184 | return -EBUSY; |
| 6185 | |
| 6186 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 6187 | return 0; |
| 6188 | } |
| 6189 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6190 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6191 | struct genl_info *info) |
| 6192 | { |
| 6193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6194 | struct net_device *dev = info->user_ptr[1]; |
| 6195 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6196 | struct sk_buff *msg; |
| 6197 | void *hdr; |
| 6198 | const u8 *addr; |
| 6199 | u64 cookie; |
| 6200 | int err; |
| 6201 | |
| 6202 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6203 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6204 | return -EOPNOTSUPP; |
| 6205 | |
| 6206 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6207 | return -EINVAL; |
| 6208 | |
| 6209 | if (!rdev->ops->probe_client) |
| 6210 | return -EOPNOTSUPP; |
| 6211 | |
| 6212 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6213 | if (!msg) |
| 6214 | return -ENOMEM; |
| 6215 | |
| 6216 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6217 | NL80211_CMD_PROBE_CLIENT); |
| 6218 | |
| 6219 | if (IS_ERR(hdr)) { |
| 6220 | err = PTR_ERR(hdr); |
| 6221 | goto free_msg; |
| 6222 | } |
| 6223 | |
| 6224 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6225 | |
| 6226 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6227 | if (err) |
| 6228 | goto free_msg; |
| 6229 | |
| 6230 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6231 | |
| 6232 | genlmsg_end(msg, hdr); |
| 6233 | |
| 6234 | return genlmsg_reply(msg, info); |
| 6235 | |
| 6236 | nla_put_failure: |
| 6237 | err = -ENOBUFS; |
| 6238 | free_msg: |
| 6239 | nlmsg_free(msg); |
| 6240 | return err; |
| 6241 | } |
| 6242 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6243 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6244 | { |
| 6245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6246 | |
| 6247 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6248 | return -EOPNOTSUPP; |
| 6249 | |
| 6250 | if (rdev->ap_beacons_nlpid) |
| 6251 | return -EBUSY; |
| 6252 | |
| 6253 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 6254 | |
| 6255 | return 0; |
| 6256 | } |
| 6257 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6258 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6259 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6260 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6261 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6262 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6263 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6264 | |
| 6265 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6266 | struct genl_info *info) |
| 6267 | { |
| 6268 | struct cfg80211_registered_device *rdev; |
| 6269 | struct net_device *dev; |
| 6270 | int err; |
| 6271 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6272 | |
| 6273 | if (rtnl) |
| 6274 | rtnl_lock(); |
| 6275 | |
| 6276 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 6277 | rdev = cfg80211_get_dev_from_info(info); |
| 6278 | if (IS_ERR(rdev)) { |
| 6279 | if (rtnl) |
| 6280 | rtnl_unlock(); |
| 6281 | return PTR_ERR(rdev); |
| 6282 | } |
| 6283 | info->user_ptr[0] = rdev; |
| 6284 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6285 | err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs, |
| 6286 | &rdev, &dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6287 | if (err) { |
| 6288 | if (rtnl) |
| 6289 | rtnl_unlock(); |
| 6290 | return err; |
| 6291 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6292 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 6293 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 6294 | cfg80211_unlock_rdev(rdev); |
| 6295 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6296 | if (rtnl) |
| 6297 | rtnl_unlock(); |
| 6298 | return -ENETDOWN; |
| 6299 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6300 | info->user_ptr[0] = rdev; |
| 6301 | info->user_ptr[1] = dev; |
| 6302 | } |
| 6303 | |
| 6304 | return 0; |
| 6305 | } |
| 6306 | |
| 6307 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6308 | struct genl_info *info) |
| 6309 | { |
| 6310 | if (info->user_ptr[0]) |
| 6311 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 6312 | if (info->user_ptr[1]) |
| 6313 | dev_put(info->user_ptr[1]); |
| 6314 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6315 | rtnl_unlock(); |
| 6316 | } |
| 6317 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6318 | static struct genl_ops nl80211_ops[] = { |
| 6319 | { |
| 6320 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6321 | .doit = nl80211_get_wiphy, |
| 6322 | .dumpit = nl80211_dump_wiphy, |
| 6323 | .policy = nl80211_policy, |
| 6324 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6325 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6326 | }, |
| 6327 | { |
| 6328 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6329 | .doit = nl80211_set_wiphy, |
| 6330 | .policy = nl80211_policy, |
| 6331 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6332 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6333 | }, |
| 6334 | { |
| 6335 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6336 | .doit = nl80211_get_interface, |
| 6337 | .dumpit = nl80211_dump_interface, |
| 6338 | .policy = nl80211_policy, |
| 6339 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6340 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6341 | }, |
| 6342 | { |
| 6343 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6344 | .doit = nl80211_set_interface, |
| 6345 | .policy = nl80211_policy, |
| 6346 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6347 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6348 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6349 | }, |
| 6350 | { |
| 6351 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6352 | .doit = nl80211_new_interface, |
| 6353 | .policy = nl80211_policy, |
| 6354 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6355 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6356 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6357 | }, |
| 6358 | { |
| 6359 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6360 | .doit = nl80211_del_interface, |
| 6361 | .policy = nl80211_policy, |
| 6362 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6363 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6364 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6365 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6366 | { |
| 6367 | .cmd = NL80211_CMD_GET_KEY, |
| 6368 | .doit = nl80211_get_key, |
| 6369 | .policy = nl80211_policy, |
| 6370 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6371 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6372 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6373 | }, |
| 6374 | { |
| 6375 | .cmd = NL80211_CMD_SET_KEY, |
| 6376 | .doit = nl80211_set_key, |
| 6377 | .policy = nl80211_policy, |
| 6378 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6379 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6380 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6381 | }, |
| 6382 | { |
| 6383 | .cmd = NL80211_CMD_NEW_KEY, |
| 6384 | .doit = nl80211_new_key, |
| 6385 | .policy = nl80211_policy, |
| 6386 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6388 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6389 | }, |
| 6390 | { |
| 6391 | .cmd = NL80211_CMD_DEL_KEY, |
| 6392 | .doit = nl80211_del_key, |
| 6393 | .policy = nl80211_policy, |
| 6394 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6396 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6397 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6398 | { |
| 6399 | .cmd = NL80211_CMD_SET_BEACON, |
| 6400 | .policy = nl80211_policy, |
| 6401 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6402 | .doit = nl80211_set_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6403 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6404 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6405 | }, |
| 6406 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6407 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6408 | .policy = nl80211_policy, |
| 6409 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6410 | .doit = nl80211_start_ap, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6411 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6412 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6413 | }, |
| 6414 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6415 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6416 | .policy = nl80211_policy, |
| 6417 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6418 | .doit = nl80211_stop_ap, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6419 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6420 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6421 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6422 | { |
| 6423 | .cmd = NL80211_CMD_GET_STATION, |
| 6424 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6425 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6426 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6427 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6428 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6429 | }, |
| 6430 | { |
| 6431 | .cmd = NL80211_CMD_SET_STATION, |
| 6432 | .doit = nl80211_set_station, |
| 6433 | .policy = nl80211_policy, |
| 6434 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6435 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6436 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6437 | }, |
| 6438 | { |
| 6439 | .cmd = NL80211_CMD_NEW_STATION, |
| 6440 | .doit = nl80211_new_station, |
| 6441 | .policy = nl80211_policy, |
| 6442 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6444 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6445 | }, |
| 6446 | { |
| 6447 | .cmd = NL80211_CMD_DEL_STATION, |
| 6448 | .doit = nl80211_del_station, |
| 6449 | .policy = nl80211_policy, |
| 6450 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6451 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6452 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6453 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6454 | { |
| 6455 | .cmd = NL80211_CMD_GET_MPATH, |
| 6456 | .doit = nl80211_get_mpath, |
| 6457 | .dumpit = nl80211_dump_mpath, |
| 6458 | .policy = nl80211_policy, |
| 6459 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6460 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6461 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6462 | }, |
| 6463 | { |
| 6464 | .cmd = NL80211_CMD_SET_MPATH, |
| 6465 | .doit = nl80211_set_mpath, |
| 6466 | .policy = nl80211_policy, |
| 6467 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6468 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6469 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6470 | }, |
| 6471 | { |
| 6472 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6473 | .doit = nl80211_new_mpath, |
| 6474 | .policy = nl80211_policy, |
| 6475 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6476 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6477 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6478 | }, |
| 6479 | { |
| 6480 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6481 | .doit = nl80211_del_mpath, |
| 6482 | .policy = nl80211_policy, |
| 6483 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6484 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6485 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6486 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6487 | { |
| 6488 | .cmd = NL80211_CMD_SET_BSS, |
| 6489 | .doit = nl80211_set_bss, |
| 6490 | .policy = nl80211_policy, |
| 6491 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6492 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6493 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6494 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6495 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6496 | .cmd = NL80211_CMD_GET_REG, |
| 6497 | .doit = nl80211_get_reg, |
| 6498 | .policy = nl80211_policy, |
| 6499 | /* can be retrieved by unprivileged users */ |
| 6500 | }, |
| 6501 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6502 | .cmd = NL80211_CMD_SET_REG, |
| 6503 | .doit = nl80211_set_reg, |
| 6504 | .policy = nl80211_policy, |
| 6505 | .flags = GENL_ADMIN_PERM, |
| 6506 | }, |
| 6507 | { |
| 6508 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6509 | .doit = nl80211_req_set_reg, |
| 6510 | .policy = nl80211_policy, |
| 6511 | .flags = GENL_ADMIN_PERM, |
| 6512 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6513 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6514 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6515 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6516 | .policy = nl80211_policy, |
| 6517 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6518 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6519 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6520 | }, |
| 6521 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6522 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6523 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6524 | .policy = nl80211_policy, |
| 6525 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6526 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6527 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6528 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6529 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6530 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6531 | .doit = nl80211_trigger_scan, |
| 6532 | .policy = nl80211_policy, |
| 6533 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6534 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6535 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6536 | }, |
| 6537 | { |
| 6538 | .cmd = NL80211_CMD_GET_SCAN, |
| 6539 | .policy = nl80211_policy, |
| 6540 | .dumpit = nl80211_dump_scan, |
| 6541 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6542 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6543 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6544 | .doit = nl80211_start_sched_scan, |
| 6545 | .policy = nl80211_policy, |
| 6546 | .flags = GENL_ADMIN_PERM, |
| 6547 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6548 | NL80211_FLAG_NEED_RTNL, |
| 6549 | }, |
| 6550 | { |
| 6551 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6552 | .doit = nl80211_stop_sched_scan, |
| 6553 | .policy = nl80211_policy, |
| 6554 | .flags = GENL_ADMIN_PERM, |
| 6555 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6556 | NL80211_FLAG_NEED_RTNL, |
| 6557 | }, |
| 6558 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6559 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6560 | .doit = nl80211_authenticate, |
| 6561 | .policy = nl80211_policy, |
| 6562 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6564 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6565 | }, |
| 6566 | { |
| 6567 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6568 | .doit = nl80211_associate, |
| 6569 | .policy = nl80211_policy, |
| 6570 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6571 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6572 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6573 | }, |
| 6574 | { |
| 6575 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6576 | .doit = nl80211_deauthenticate, |
| 6577 | .policy = nl80211_policy, |
| 6578 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6579 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6580 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6581 | }, |
| 6582 | { |
| 6583 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6584 | .doit = nl80211_disassociate, |
| 6585 | .policy = nl80211_policy, |
| 6586 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6587 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6588 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6589 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6590 | { |
| 6591 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6592 | .doit = nl80211_join_ibss, |
| 6593 | .policy = nl80211_policy, |
| 6594 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6595 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6596 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6597 | }, |
| 6598 | { |
| 6599 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6600 | .doit = nl80211_leave_ibss, |
| 6601 | .policy = nl80211_policy, |
| 6602 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6603 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6604 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6605 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6606 | #ifdef CONFIG_NL80211_TESTMODE |
| 6607 | { |
| 6608 | .cmd = NL80211_CMD_TESTMODE, |
| 6609 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6610 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6611 | .policy = nl80211_policy, |
| 6612 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6613 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6614 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6615 | }, |
| 6616 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6617 | { |
| 6618 | .cmd = NL80211_CMD_CONNECT, |
| 6619 | .doit = nl80211_connect, |
| 6620 | .policy = nl80211_policy, |
| 6621 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6622 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6623 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6624 | }, |
| 6625 | { |
| 6626 | .cmd = NL80211_CMD_DISCONNECT, |
| 6627 | .doit = nl80211_disconnect, |
| 6628 | .policy = nl80211_policy, |
| 6629 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6630 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6631 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6632 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6633 | { |
| 6634 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6635 | .doit = nl80211_wiphy_netns, |
| 6636 | .policy = nl80211_policy, |
| 6637 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6638 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6639 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6640 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6641 | { |
| 6642 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6643 | .policy = nl80211_policy, |
| 6644 | .dumpit = nl80211_dump_survey, |
| 6645 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6646 | { |
| 6647 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6648 | .doit = nl80211_setdel_pmksa, |
| 6649 | .policy = nl80211_policy, |
| 6650 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6651 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6652 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6653 | }, |
| 6654 | { |
| 6655 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6656 | .doit = nl80211_setdel_pmksa, |
| 6657 | .policy = nl80211_policy, |
| 6658 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6659 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6660 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6661 | }, |
| 6662 | { |
| 6663 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6664 | .doit = nl80211_flush_pmksa, |
| 6665 | .policy = nl80211_policy, |
| 6666 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6667 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6668 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6669 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6670 | { |
| 6671 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6672 | .doit = nl80211_remain_on_channel, |
| 6673 | .policy = nl80211_policy, |
| 6674 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6675 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6676 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6677 | }, |
| 6678 | { |
| 6679 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6680 | .doit = nl80211_cancel_remain_on_channel, |
| 6681 | .policy = nl80211_policy, |
| 6682 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6683 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6684 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6685 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6686 | { |
| 6687 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6688 | .doit = nl80211_set_tx_bitrate_mask, |
| 6689 | .policy = nl80211_policy, |
| 6690 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6691 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6692 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6693 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6694 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6695 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6696 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6697 | .policy = nl80211_policy, |
| 6698 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6699 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6700 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6701 | }, |
| 6702 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6703 | .cmd = NL80211_CMD_FRAME, |
| 6704 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6705 | .policy = nl80211_policy, |
| 6706 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6707 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6708 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6709 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6710 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6711 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6712 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6713 | .policy = nl80211_policy, |
| 6714 | .flags = GENL_ADMIN_PERM, |
| 6715 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6716 | NL80211_FLAG_NEED_RTNL, |
| 6717 | }, |
| 6718 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6719 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6720 | .doit = nl80211_set_power_save, |
| 6721 | .policy = nl80211_policy, |
| 6722 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6723 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6724 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6725 | }, |
| 6726 | { |
| 6727 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6728 | .doit = nl80211_get_power_save, |
| 6729 | .policy = nl80211_policy, |
| 6730 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6731 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6732 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6733 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6734 | { |
| 6735 | .cmd = NL80211_CMD_SET_CQM, |
| 6736 | .doit = nl80211_set_cqm, |
| 6737 | .policy = nl80211_policy, |
| 6738 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6739 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6740 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6741 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6742 | { |
| 6743 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6744 | .doit = nl80211_set_channel, |
| 6745 | .policy = nl80211_policy, |
| 6746 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6747 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6748 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6749 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6750 | { |
| 6751 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6752 | .doit = nl80211_set_wds_peer, |
| 6753 | .policy = nl80211_policy, |
| 6754 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6755 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6756 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6757 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6758 | { |
| 6759 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6760 | .doit = nl80211_join_mesh, |
| 6761 | .policy = nl80211_policy, |
| 6762 | .flags = GENL_ADMIN_PERM, |
| 6763 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6764 | NL80211_FLAG_NEED_RTNL, |
| 6765 | }, |
| 6766 | { |
| 6767 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6768 | .doit = nl80211_leave_mesh, |
| 6769 | .policy = nl80211_policy, |
| 6770 | .flags = GENL_ADMIN_PERM, |
| 6771 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6772 | NL80211_FLAG_NEED_RTNL, |
| 6773 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6774 | { |
| 6775 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6776 | .doit = nl80211_get_wowlan, |
| 6777 | .policy = nl80211_policy, |
| 6778 | /* can be retrieved by unprivileged users */ |
| 6779 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6780 | NL80211_FLAG_NEED_RTNL, |
| 6781 | }, |
| 6782 | { |
| 6783 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6784 | .doit = nl80211_set_wowlan, |
| 6785 | .policy = nl80211_policy, |
| 6786 | .flags = GENL_ADMIN_PERM, |
| 6787 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6788 | NL80211_FLAG_NEED_RTNL, |
| 6789 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6790 | { |
| 6791 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6792 | .doit = nl80211_set_rekey_data, |
| 6793 | .policy = nl80211_policy, |
| 6794 | .flags = GENL_ADMIN_PERM, |
| 6795 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6796 | NL80211_FLAG_NEED_RTNL, |
| 6797 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6798 | { |
| 6799 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 6800 | .doit = nl80211_tdls_mgmt, |
| 6801 | .policy = nl80211_policy, |
| 6802 | .flags = GENL_ADMIN_PERM, |
| 6803 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6804 | NL80211_FLAG_NEED_RTNL, |
| 6805 | }, |
| 6806 | { |
| 6807 | .cmd = NL80211_CMD_TDLS_OPER, |
| 6808 | .doit = nl80211_tdls_oper, |
| 6809 | .policy = nl80211_policy, |
| 6810 | .flags = GENL_ADMIN_PERM, |
| 6811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6812 | NL80211_FLAG_NEED_RTNL, |
| 6813 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6814 | { |
| 6815 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 6816 | .doit = nl80211_register_unexpected_frame, |
| 6817 | .policy = nl80211_policy, |
| 6818 | .flags = GENL_ADMIN_PERM, |
| 6819 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6820 | NL80211_FLAG_NEED_RTNL, |
| 6821 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6822 | { |
| 6823 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 6824 | .doit = nl80211_probe_client, |
| 6825 | .policy = nl80211_policy, |
| 6826 | .flags = GENL_ADMIN_PERM, |
| 6827 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6828 | NL80211_FLAG_NEED_RTNL, |
| 6829 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6830 | { |
| 6831 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 6832 | .doit = nl80211_register_beacons, |
| 6833 | .policy = nl80211_policy, |
| 6834 | .flags = GENL_ADMIN_PERM, |
| 6835 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6836 | NL80211_FLAG_NEED_RTNL, |
| 6837 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 6838 | { |
| 6839 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 6840 | .doit = nl80211_set_noack_map, |
| 6841 | .policy = nl80211_policy, |
| 6842 | .flags = GENL_ADMIN_PERM, |
| 6843 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6844 | NL80211_FLAG_NEED_RTNL, |
| 6845 | }, |
| 6846 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6847 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6848 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6849 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6850 | .name = "mlme", |
| 6851 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6852 | |
| 6853 | /* multicast groups */ |
| 6854 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6855 | .name = "config", |
| 6856 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6857 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6858 | .name = "scan", |
| 6859 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6860 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6861 | .name = "regulatory", |
| 6862 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6863 | |
| 6864 | /* notification functions */ |
| 6865 | |
| 6866 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6867 | { |
| 6868 | struct sk_buff *msg; |
| 6869 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6870 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6871 | if (!msg) |
| 6872 | return; |
| 6873 | |
| 6874 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6875 | nlmsg_free(msg); |
| 6876 | return; |
| 6877 | } |
| 6878 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6879 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6880 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6881 | } |
| 6882 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6883 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6884 | struct cfg80211_registered_device *rdev) |
| 6885 | { |
| 6886 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6887 | struct nlattr *nest; |
| 6888 | int i; |
| 6889 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6890 | ASSERT_RDEV_LOCK(rdev); |
| 6891 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6892 | if (WARN_ON(!req)) |
| 6893 | return 0; |
| 6894 | |
| 6895 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6896 | if (!nest) |
| 6897 | goto nla_put_failure; |
| 6898 | for (i = 0; i < req->n_ssids; i++) |
| 6899 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6900 | nla_nest_end(msg, nest); |
| 6901 | |
| 6902 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6903 | if (!nest) |
| 6904 | goto nla_put_failure; |
| 6905 | for (i = 0; i < req->n_channels; i++) |
| 6906 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6907 | nla_nest_end(msg, nest); |
| 6908 | |
| 6909 | if (req->ie) |
| 6910 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6911 | |
| 6912 | return 0; |
| 6913 | nla_put_failure: |
| 6914 | return -ENOBUFS; |
| 6915 | } |
| 6916 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6917 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6918 | struct cfg80211_registered_device *rdev, |
| 6919 | struct net_device *netdev, |
| 6920 | u32 pid, u32 seq, int flags, |
| 6921 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6922 | { |
| 6923 | void *hdr; |
| 6924 | |
| 6925 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6926 | if (!hdr) |
| 6927 | return -1; |
| 6928 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6929 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6930 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6931 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6932 | /* ignore errors and send incomplete event anyway */ |
| 6933 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6934 | |
| 6935 | return genlmsg_end(msg, hdr); |
| 6936 | |
| 6937 | nla_put_failure: |
| 6938 | genlmsg_cancel(msg, hdr); |
| 6939 | return -EMSGSIZE; |
| 6940 | } |
| 6941 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6942 | static int |
| 6943 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6944 | struct cfg80211_registered_device *rdev, |
| 6945 | struct net_device *netdev, |
| 6946 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6947 | { |
| 6948 | void *hdr; |
| 6949 | |
| 6950 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6951 | if (!hdr) |
| 6952 | return -1; |
| 6953 | |
| 6954 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6955 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6956 | |
| 6957 | return genlmsg_end(msg, hdr); |
| 6958 | |
| 6959 | nla_put_failure: |
| 6960 | genlmsg_cancel(msg, hdr); |
| 6961 | return -EMSGSIZE; |
| 6962 | } |
| 6963 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6964 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6965 | struct net_device *netdev) |
| 6966 | { |
| 6967 | struct sk_buff *msg; |
| 6968 | |
| 6969 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6970 | if (!msg) |
| 6971 | return; |
| 6972 | |
| 6973 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6974 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6975 | nlmsg_free(msg); |
| 6976 | return; |
| 6977 | } |
| 6978 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6979 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6980 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6981 | } |
| 6982 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6983 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6984 | struct net_device *netdev) |
| 6985 | { |
| 6986 | struct sk_buff *msg; |
| 6987 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6988 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6989 | if (!msg) |
| 6990 | return; |
| 6991 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6992 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6993 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6994 | nlmsg_free(msg); |
| 6995 | return; |
| 6996 | } |
| 6997 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6998 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6999 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7000 | } |
| 7001 | |
| 7002 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 7003 | struct net_device *netdev) |
| 7004 | { |
| 7005 | struct sk_buff *msg; |
| 7006 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7007 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7008 | if (!msg) |
| 7009 | return; |
| 7010 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7011 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7012 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7013 | nlmsg_free(msg); |
| 7014 | return; |
| 7015 | } |
| 7016 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7017 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7018 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7019 | } |
| 7020 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7021 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7022 | struct net_device *netdev) |
| 7023 | { |
| 7024 | struct sk_buff *msg; |
| 7025 | |
| 7026 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7027 | if (!msg) |
| 7028 | return; |
| 7029 | |
| 7030 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7031 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7032 | nlmsg_free(msg); |
| 7033 | return; |
| 7034 | } |
| 7035 | |
| 7036 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7037 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7038 | } |
| 7039 | |
| 7040 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7041 | struct net_device *netdev, u32 cmd) |
| 7042 | { |
| 7043 | struct sk_buff *msg; |
| 7044 | |
| 7045 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7046 | if (!msg) |
| 7047 | return; |
| 7048 | |
| 7049 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7050 | nlmsg_free(msg); |
| 7051 | return; |
| 7052 | } |
| 7053 | |
| 7054 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7055 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7056 | } |
| 7057 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7058 | /* |
| 7059 | * This can happen on global regulatory changes or device specific settings |
| 7060 | * based on custom world regulatory domains. |
| 7061 | */ |
| 7062 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7063 | { |
| 7064 | struct sk_buff *msg; |
| 7065 | void *hdr; |
| 7066 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7067 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7068 | if (!msg) |
| 7069 | return; |
| 7070 | |
| 7071 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7072 | if (!hdr) { |
| 7073 | nlmsg_free(msg); |
| 7074 | return; |
| 7075 | } |
| 7076 | |
| 7077 | /* Userspace can always count this one always being set */ |
| 7078 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 7079 | |
| 7080 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 7081 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7082 | NL80211_REGDOM_TYPE_WORLD); |
| 7083 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 7084 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7085 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 7086 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7087 | request->intersect) |
| 7088 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7089 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 7090 | else { |
| 7091 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7092 | NL80211_REGDOM_TYPE_COUNTRY); |
| 7093 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 7094 | } |
| 7095 | |
| 7096 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 7097 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 7098 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7099 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7100 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7101 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7102 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7103 | GFP_ATOMIC); |
| 7104 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7105 | |
| 7106 | return; |
| 7107 | |
| 7108 | nla_put_failure: |
| 7109 | genlmsg_cancel(msg, hdr); |
| 7110 | nlmsg_free(msg); |
| 7111 | } |
| 7112 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7113 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7114 | struct net_device *netdev, |
| 7115 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7116 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7117 | { |
| 7118 | struct sk_buff *msg; |
| 7119 | void *hdr; |
| 7120 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7121 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7122 | if (!msg) |
| 7123 | return; |
| 7124 | |
| 7125 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7126 | if (!hdr) { |
| 7127 | nlmsg_free(msg); |
| 7128 | return; |
| 7129 | } |
| 7130 | |
| 7131 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7132 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7133 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7134 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7135 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7136 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7137 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7138 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7139 | return; |
| 7140 | |
| 7141 | nla_put_failure: |
| 7142 | genlmsg_cancel(msg, hdr); |
| 7143 | nlmsg_free(msg); |
| 7144 | } |
| 7145 | |
| 7146 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7147 | struct net_device *netdev, const u8 *buf, |
| 7148 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7149 | { |
| 7150 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7151 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7152 | } |
| 7153 | |
| 7154 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 7155 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7156 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7157 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7158 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7159 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7160 | } |
| 7161 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7162 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7163 | struct net_device *netdev, const u8 *buf, |
| 7164 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7165 | { |
| 7166 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7167 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7168 | } |
| 7169 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7170 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 7171 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7172 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7173 | { |
| 7174 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7175 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7176 | } |
| 7177 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7178 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7179 | struct net_device *netdev, const u8 *buf, |
| 7180 | size_t len, gfp_t gfp) |
| 7181 | { |
| 7182 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7183 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7184 | } |
| 7185 | |
| 7186 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7187 | struct net_device *netdev, const u8 *buf, |
| 7188 | size_t len, gfp_t gfp) |
| 7189 | { |
| 7190 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7191 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7192 | } |
| 7193 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7194 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7195 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7196 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7197 | { |
| 7198 | struct sk_buff *msg; |
| 7199 | void *hdr; |
| 7200 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7201 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7202 | if (!msg) |
| 7203 | return; |
| 7204 | |
| 7205 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7206 | if (!hdr) { |
| 7207 | nlmsg_free(msg); |
| 7208 | return; |
| 7209 | } |
| 7210 | |
| 7211 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7212 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7213 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 7214 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7215 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7216 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7217 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7218 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7219 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7220 | return; |
| 7221 | |
| 7222 | nla_put_failure: |
| 7223 | genlmsg_cancel(msg, hdr); |
| 7224 | nlmsg_free(msg); |
| 7225 | } |
| 7226 | |
| 7227 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7228 | struct net_device *netdev, const u8 *addr, |
| 7229 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7230 | { |
| 7231 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7232 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7233 | } |
| 7234 | |
| 7235 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7236 | struct net_device *netdev, const u8 *addr, |
| 7237 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7238 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7239 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 7240 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7241 | } |
| 7242 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7243 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 7244 | struct net_device *netdev, const u8 *bssid, |
| 7245 | const u8 *req_ie, size_t req_ie_len, |
| 7246 | const u8 *resp_ie, size_t resp_ie_len, |
| 7247 | u16 status, gfp_t gfp) |
| 7248 | { |
| 7249 | struct sk_buff *msg; |
| 7250 | void *hdr; |
| 7251 | |
| 7252 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7253 | if (!msg) |
| 7254 | return; |
| 7255 | |
| 7256 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 7257 | if (!hdr) { |
| 7258 | nlmsg_free(msg); |
| 7259 | return; |
| 7260 | } |
| 7261 | |
| 7262 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7263 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7264 | if (bssid) |
| 7265 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7266 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 7267 | if (req_ie) |
| 7268 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 7269 | if (resp_ie) |
| 7270 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 7271 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7272 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7273 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7274 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7275 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7276 | return; |
| 7277 | |
| 7278 | nla_put_failure: |
| 7279 | genlmsg_cancel(msg, hdr); |
| 7280 | nlmsg_free(msg); |
| 7281 | |
| 7282 | } |
| 7283 | |
| 7284 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 7285 | struct net_device *netdev, const u8 *bssid, |
| 7286 | const u8 *req_ie, size_t req_ie_len, |
| 7287 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 7288 | { |
| 7289 | struct sk_buff *msg; |
| 7290 | void *hdr; |
| 7291 | |
| 7292 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7293 | if (!msg) |
| 7294 | return; |
| 7295 | |
| 7296 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 7297 | if (!hdr) { |
| 7298 | nlmsg_free(msg); |
| 7299 | return; |
| 7300 | } |
| 7301 | |
| 7302 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7303 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7304 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7305 | if (req_ie) |
| 7306 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 7307 | if (resp_ie) |
| 7308 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 7309 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7310 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7311 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7312 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7313 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7314 | return; |
| 7315 | |
| 7316 | nla_put_failure: |
| 7317 | genlmsg_cancel(msg, hdr); |
| 7318 | nlmsg_free(msg); |
| 7319 | |
| 7320 | } |
| 7321 | |
| 7322 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 7323 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7324 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7325 | { |
| 7326 | struct sk_buff *msg; |
| 7327 | void *hdr; |
| 7328 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7329 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7330 | if (!msg) |
| 7331 | return; |
| 7332 | |
| 7333 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7334 | if (!hdr) { |
| 7335 | nlmsg_free(msg); |
| 7336 | return; |
| 7337 | } |
| 7338 | |
| 7339 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7340 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7341 | if (from_ap && reason) |
| 7342 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 7343 | if (from_ap) |
| 7344 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 7345 | if (ie) |
| 7346 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 7347 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7348 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7349 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7350 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7351 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7352 | return; |
| 7353 | |
| 7354 | nla_put_failure: |
| 7355 | genlmsg_cancel(msg, hdr); |
| 7356 | nlmsg_free(msg); |
| 7357 | |
| 7358 | } |
| 7359 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7360 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7361 | struct net_device *netdev, const u8 *bssid, |
| 7362 | gfp_t gfp) |
| 7363 | { |
| 7364 | struct sk_buff *msg; |
| 7365 | void *hdr; |
| 7366 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7367 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7368 | if (!msg) |
| 7369 | return; |
| 7370 | |
| 7371 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7372 | if (!hdr) { |
| 7373 | nlmsg_free(msg); |
| 7374 | return; |
| 7375 | } |
| 7376 | |
| 7377 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7378 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7379 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7380 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7381 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7382 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7383 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7384 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7385 | return; |
| 7386 | |
| 7387 | nla_put_failure: |
| 7388 | genlmsg_cancel(msg, hdr); |
| 7389 | nlmsg_free(msg); |
| 7390 | } |
| 7391 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7392 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7393 | struct net_device *netdev, |
| 7394 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7395 | gfp_t gfp) |
| 7396 | { |
| 7397 | struct sk_buff *msg; |
| 7398 | void *hdr; |
| 7399 | |
| 7400 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7401 | if (!msg) |
| 7402 | return; |
| 7403 | |
| 7404 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7405 | if (!hdr) { |
| 7406 | nlmsg_free(msg); |
| 7407 | return; |
| 7408 | } |
| 7409 | |
| 7410 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7411 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7412 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 7413 | if (ie_len && ie) |
| 7414 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 7415 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7416 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7417 | |
| 7418 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7419 | nl80211_mlme_mcgrp.id, gfp); |
| 7420 | return; |
| 7421 | |
| 7422 | nla_put_failure: |
| 7423 | genlmsg_cancel(msg, hdr); |
| 7424 | nlmsg_free(msg); |
| 7425 | } |
| 7426 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7427 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7428 | struct net_device *netdev, const u8 *addr, |
| 7429 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7430 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7431 | { |
| 7432 | struct sk_buff *msg; |
| 7433 | void *hdr; |
| 7434 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7435 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7436 | if (!msg) |
| 7437 | return; |
| 7438 | |
| 7439 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7440 | if (!hdr) { |
| 7441 | nlmsg_free(msg); |
| 7442 | return; |
| 7443 | } |
| 7444 | |
| 7445 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7446 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7447 | if (addr) |
| 7448 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7449 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 7450 | if (key_id != -1) |
| 7451 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7452 | if (tsc) |
| 7453 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 7454 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7455 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7456 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7457 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7458 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7459 | return; |
| 7460 | |
| 7461 | nla_put_failure: |
| 7462 | genlmsg_cancel(msg, hdr); |
| 7463 | nlmsg_free(msg); |
| 7464 | } |
| 7465 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7466 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7467 | struct ieee80211_channel *channel_before, |
| 7468 | struct ieee80211_channel *channel_after) |
| 7469 | { |
| 7470 | struct sk_buff *msg; |
| 7471 | void *hdr; |
| 7472 | struct nlattr *nl_freq; |
| 7473 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7474 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7475 | if (!msg) |
| 7476 | return; |
| 7477 | |
| 7478 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7479 | if (!hdr) { |
| 7480 | nlmsg_free(msg); |
| 7481 | return; |
| 7482 | } |
| 7483 | |
| 7484 | /* |
| 7485 | * Since we are applying the beacon hint to a wiphy we know its |
| 7486 | * wiphy_idx is valid |
| 7487 | */ |
| 7488 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 7489 | |
| 7490 | /* Before */ |
| 7491 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7492 | if (!nl_freq) |
| 7493 | goto nla_put_failure; |
| 7494 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7495 | goto nla_put_failure; |
| 7496 | nla_nest_end(msg, nl_freq); |
| 7497 | |
| 7498 | /* After */ |
| 7499 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7500 | if (!nl_freq) |
| 7501 | goto nla_put_failure; |
| 7502 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7503 | goto nla_put_failure; |
| 7504 | nla_nest_end(msg, nl_freq); |
| 7505 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7506 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7507 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7508 | rcu_read_lock(); |
| 7509 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7510 | GFP_ATOMIC); |
| 7511 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7512 | |
| 7513 | return; |
| 7514 | |
| 7515 | nla_put_failure: |
| 7516 | genlmsg_cancel(msg, hdr); |
| 7517 | nlmsg_free(msg); |
| 7518 | } |
| 7519 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7520 | static void nl80211_send_remain_on_chan_event( |
| 7521 | int cmd, struct cfg80211_registered_device *rdev, |
| 7522 | struct net_device *netdev, u64 cookie, |
| 7523 | struct ieee80211_channel *chan, |
| 7524 | enum nl80211_channel_type channel_type, |
| 7525 | unsigned int duration, gfp_t gfp) |
| 7526 | { |
| 7527 | struct sk_buff *msg; |
| 7528 | void *hdr; |
| 7529 | |
| 7530 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7531 | if (!msg) |
| 7532 | return; |
| 7533 | |
| 7534 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7535 | if (!hdr) { |
| 7536 | nlmsg_free(msg); |
| 7537 | return; |
| 7538 | } |
| 7539 | |
| 7540 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7541 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7542 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7543 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7544 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7545 | |
| 7546 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7547 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7548 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7549 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7550 | |
| 7551 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7552 | nl80211_mlme_mcgrp.id, gfp); |
| 7553 | return; |
| 7554 | |
| 7555 | nla_put_failure: |
| 7556 | genlmsg_cancel(msg, hdr); |
| 7557 | nlmsg_free(msg); |
| 7558 | } |
| 7559 | |
| 7560 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7561 | struct net_device *netdev, u64 cookie, |
| 7562 | struct ieee80211_channel *chan, |
| 7563 | enum nl80211_channel_type channel_type, |
| 7564 | unsigned int duration, gfp_t gfp) |
| 7565 | { |
| 7566 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7567 | rdev, netdev, cookie, chan, |
| 7568 | channel_type, duration, gfp); |
| 7569 | } |
| 7570 | |
| 7571 | void nl80211_send_remain_on_channel_cancel( |
| 7572 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7573 | u64 cookie, struct ieee80211_channel *chan, |
| 7574 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7575 | { |
| 7576 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7577 | rdev, netdev, cookie, chan, |
| 7578 | channel_type, 0, gfp); |
| 7579 | } |
| 7580 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7581 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7582 | struct net_device *dev, const u8 *mac_addr, |
| 7583 | struct station_info *sinfo, gfp_t gfp) |
| 7584 | { |
| 7585 | struct sk_buff *msg; |
| 7586 | |
| 7587 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7588 | if (!msg) |
| 7589 | return; |
| 7590 | |
| 7591 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 7592 | nlmsg_free(msg); |
| 7593 | return; |
| 7594 | } |
| 7595 | |
| 7596 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7597 | nl80211_mlme_mcgrp.id, gfp); |
| 7598 | } |
| 7599 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7600 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7601 | struct net_device *dev, const u8 *mac_addr, |
| 7602 | gfp_t gfp) |
| 7603 | { |
| 7604 | struct sk_buff *msg; |
| 7605 | void *hdr; |
| 7606 | |
| 7607 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7608 | if (!msg) |
| 7609 | return; |
| 7610 | |
| 7611 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7612 | if (!hdr) { |
| 7613 | nlmsg_free(msg); |
| 7614 | return; |
| 7615 | } |
| 7616 | |
| 7617 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7618 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7619 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7620 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7621 | |
| 7622 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7623 | nl80211_mlme_mcgrp.id, gfp); |
| 7624 | return; |
| 7625 | |
| 7626 | nla_put_failure: |
| 7627 | genlmsg_cancel(msg, hdr); |
| 7628 | nlmsg_free(msg); |
| 7629 | } |
| 7630 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7631 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 7632 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7633 | { |
| 7634 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7635 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7636 | struct sk_buff *msg; |
| 7637 | void *hdr; |
| 7638 | int err; |
| 7639 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 7640 | |
| 7641 | if (!nlpid) |
| 7642 | return false; |
| 7643 | |
| 7644 | msg = nlmsg_new(100, gfp); |
| 7645 | if (!msg) |
| 7646 | return true; |
| 7647 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7648 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7649 | if (!hdr) { |
| 7650 | nlmsg_free(msg); |
| 7651 | return true; |
| 7652 | } |
| 7653 | |
| 7654 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7655 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7656 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7657 | |
| 7658 | err = genlmsg_end(msg, hdr); |
| 7659 | if (err < 0) { |
| 7660 | nlmsg_free(msg); |
| 7661 | return true; |
| 7662 | } |
| 7663 | |
| 7664 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7665 | return true; |
| 7666 | |
| 7667 | nla_put_failure: |
| 7668 | genlmsg_cancel(msg, hdr); |
| 7669 | nlmsg_free(msg); |
| 7670 | return true; |
| 7671 | } |
| 7672 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7673 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 7674 | { |
| 7675 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 7676 | addr, gfp); |
| 7677 | } |
| 7678 | |
| 7679 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 7680 | const u8 *addr, gfp_t gfp) |
| 7681 | { |
| 7682 | return __nl80211_unexpected_frame(dev, |
| 7683 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 7684 | addr, gfp); |
| 7685 | } |
| 7686 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7687 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7688 | struct net_device *netdev, u32 nlpid, |
| 7689 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7690 | { |
| 7691 | struct sk_buff *msg; |
| 7692 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7693 | |
| 7694 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7695 | if (!msg) |
| 7696 | return -ENOMEM; |
| 7697 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7698 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7699 | if (!hdr) { |
| 7700 | nlmsg_free(msg); |
| 7701 | return -ENOMEM; |
| 7702 | } |
| 7703 | |
| 7704 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7705 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7706 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7707 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7708 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7709 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7710 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7711 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7712 | |
| 7713 | nla_put_failure: |
| 7714 | genlmsg_cancel(msg, hdr); |
| 7715 | nlmsg_free(msg); |
| 7716 | return -ENOBUFS; |
| 7717 | } |
| 7718 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7719 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7720 | struct net_device *netdev, u64 cookie, |
| 7721 | const u8 *buf, size_t len, bool ack, |
| 7722 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7723 | { |
| 7724 | struct sk_buff *msg; |
| 7725 | void *hdr; |
| 7726 | |
| 7727 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7728 | if (!msg) |
| 7729 | return; |
| 7730 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7731 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7732 | if (!hdr) { |
| 7733 | nlmsg_free(msg); |
| 7734 | return; |
| 7735 | } |
| 7736 | |
| 7737 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7738 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7739 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7740 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7741 | if (ack) |
| 7742 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7743 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7744 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7745 | |
| 7746 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7747 | return; |
| 7748 | |
| 7749 | nla_put_failure: |
| 7750 | genlmsg_cancel(msg, hdr); |
| 7751 | nlmsg_free(msg); |
| 7752 | } |
| 7753 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7754 | void |
| 7755 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7756 | struct net_device *netdev, |
| 7757 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7758 | gfp_t gfp) |
| 7759 | { |
| 7760 | struct sk_buff *msg; |
| 7761 | struct nlattr *pinfoattr; |
| 7762 | void *hdr; |
| 7763 | |
| 7764 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7765 | if (!msg) |
| 7766 | return; |
| 7767 | |
| 7768 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7769 | if (!hdr) { |
| 7770 | nlmsg_free(msg); |
| 7771 | return; |
| 7772 | } |
| 7773 | |
| 7774 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7775 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7776 | |
| 7777 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7778 | if (!pinfoattr) |
| 7779 | goto nla_put_failure; |
| 7780 | |
| 7781 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7782 | rssi_event); |
| 7783 | |
| 7784 | nla_nest_end(msg, pinfoattr); |
| 7785 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7786 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7787 | |
| 7788 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7789 | nl80211_mlme_mcgrp.id, gfp); |
| 7790 | return; |
| 7791 | |
| 7792 | nla_put_failure: |
| 7793 | genlmsg_cancel(msg, hdr); |
| 7794 | nlmsg_free(msg); |
| 7795 | } |
| 7796 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7797 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7798 | struct net_device *netdev, const u8 *bssid, |
| 7799 | const u8 *replay_ctr, gfp_t gfp) |
| 7800 | { |
| 7801 | struct sk_buff *msg; |
| 7802 | struct nlattr *rekey_attr; |
| 7803 | void *hdr; |
| 7804 | |
| 7805 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7806 | if (!msg) |
| 7807 | return; |
| 7808 | |
| 7809 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7810 | if (!hdr) { |
| 7811 | nlmsg_free(msg); |
| 7812 | return; |
| 7813 | } |
| 7814 | |
| 7815 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7816 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7817 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7818 | |
| 7819 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7820 | if (!rekey_attr) |
| 7821 | goto nla_put_failure; |
| 7822 | |
| 7823 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7824 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7825 | |
| 7826 | nla_nest_end(msg, rekey_attr); |
| 7827 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7828 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7829 | |
| 7830 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7831 | nl80211_mlme_mcgrp.id, gfp); |
| 7832 | return; |
| 7833 | |
| 7834 | nla_put_failure: |
| 7835 | genlmsg_cancel(msg, hdr); |
| 7836 | nlmsg_free(msg); |
| 7837 | } |
| 7838 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7839 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7840 | struct net_device *netdev, int index, |
| 7841 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7842 | { |
| 7843 | struct sk_buff *msg; |
| 7844 | struct nlattr *attr; |
| 7845 | void *hdr; |
| 7846 | |
| 7847 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7848 | if (!msg) |
| 7849 | return; |
| 7850 | |
| 7851 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7852 | if (!hdr) { |
| 7853 | nlmsg_free(msg); |
| 7854 | return; |
| 7855 | } |
| 7856 | |
| 7857 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7858 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7859 | |
| 7860 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7861 | if (!attr) |
| 7862 | goto nla_put_failure; |
| 7863 | |
| 7864 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7865 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7866 | if (preauth) |
| 7867 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7868 | |
| 7869 | nla_nest_end(msg, attr); |
| 7870 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7871 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7872 | |
| 7873 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7874 | nl80211_mlme_mcgrp.id, gfp); |
| 7875 | return; |
| 7876 | |
| 7877 | nla_put_failure: |
| 7878 | genlmsg_cancel(msg, hdr); |
| 7879 | nlmsg_free(msg); |
| 7880 | } |
| 7881 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7882 | void |
| 7883 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7884 | struct net_device *netdev, const u8 *peer, |
| 7885 | u32 num_packets, gfp_t gfp) |
| 7886 | { |
| 7887 | struct sk_buff *msg; |
| 7888 | struct nlattr *pinfoattr; |
| 7889 | void *hdr; |
| 7890 | |
| 7891 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7892 | if (!msg) |
| 7893 | return; |
| 7894 | |
| 7895 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7896 | if (!hdr) { |
| 7897 | nlmsg_free(msg); |
| 7898 | return; |
| 7899 | } |
| 7900 | |
| 7901 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7902 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7903 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7904 | |
| 7905 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7906 | if (!pinfoattr) |
| 7907 | goto nla_put_failure; |
| 7908 | |
| 7909 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7910 | |
| 7911 | nla_nest_end(msg, pinfoattr); |
| 7912 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7913 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7914 | |
| 7915 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7916 | nl80211_mlme_mcgrp.id, gfp); |
| 7917 | return; |
| 7918 | |
| 7919 | nla_put_failure: |
| 7920 | genlmsg_cancel(msg, hdr); |
| 7921 | nlmsg_free(msg); |
| 7922 | } |
| 7923 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7924 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 7925 | u64 cookie, bool acked, gfp_t gfp) |
| 7926 | { |
| 7927 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7928 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7929 | struct sk_buff *msg; |
| 7930 | void *hdr; |
| 7931 | int err; |
| 7932 | |
| 7933 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7934 | if (!msg) |
| 7935 | return; |
| 7936 | |
| 7937 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 7938 | if (!hdr) { |
| 7939 | nlmsg_free(msg); |
| 7940 | return; |
| 7941 | } |
| 7942 | |
| 7943 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7944 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7945 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7946 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7947 | if (acked) |
| 7948 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7949 | |
| 7950 | err = genlmsg_end(msg, hdr); |
| 7951 | if (err < 0) { |
| 7952 | nlmsg_free(msg); |
| 7953 | return; |
| 7954 | } |
| 7955 | |
| 7956 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7957 | nl80211_mlme_mcgrp.id, gfp); |
| 7958 | return; |
| 7959 | |
| 7960 | nla_put_failure: |
| 7961 | genlmsg_cancel(msg, hdr); |
| 7962 | nlmsg_free(msg); |
| 7963 | } |
| 7964 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 7965 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7966 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 7967 | const u8 *frame, size_t len, |
| 7968 | int freq, gfp_t gfp) |
| 7969 | { |
| 7970 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 7971 | struct sk_buff *msg; |
| 7972 | void *hdr; |
| 7973 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 7974 | |
| 7975 | if (!nlpid) |
| 7976 | return; |
| 7977 | |
| 7978 | msg = nlmsg_new(len + 100, gfp); |
| 7979 | if (!msg) |
| 7980 | return; |
| 7981 | |
| 7982 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 7983 | if (!hdr) { |
| 7984 | nlmsg_free(msg); |
| 7985 | return; |
| 7986 | } |
| 7987 | |
| 7988 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7989 | if (freq) |
| 7990 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7991 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame); |
| 7992 | |
| 7993 | genlmsg_end(msg, hdr); |
| 7994 | |
| 7995 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7996 | return; |
| 7997 | |
| 7998 | nla_put_failure: |
| 7999 | genlmsg_cancel(msg, hdr); |
| 8000 | nlmsg_free(msg); |
| 8001 | } |
| 8002 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 8003 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8004 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 8005 | unsigned long state, |
| 8006 | void *_notify) |
| 8007 | { |
| 8008 | struct netlink_notify *notify = _notify; |
| 8009 | struct cfg80211_registered_device *rdev; |
| 8010 | struct wireless_dev *wdev; |
| 8011 | |
| 8012 | if (state != NETLINK_URELEASE) |
| 8013 | return NOTIFY_DONE; |
| 8014 | |
| 8015 | rcu_read_lock(); |
| 8016 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8017 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8018 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8019 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8020 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 8021 | rdev->ap_beacons_nlpid = 0; |
| 8022 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8023 | |
| 8024 | rcu_read_unlock(); |
| 8025 | |
| 8026 | return NOTIFY_DONE; |
| 8027 | } |
| 8028 | |
| 8029 | static struct notifier_block nl80211_netlink_notifier = { |
| 8030 | .notifier_call = nl80211_netlink_notify, |
| 8031 | }; |
| 8032 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8033 | /* initialisation/exit functions */ |
| 8034 | |
| 8035 | int nl80211_init(void) |
| 8036 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8037 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8038 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8039 | err = genl_register_family_with_ops(&nl80211_fam, |
| 8040 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8041 | if (err) |
| 8042 | return err; |
| 8043 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8044 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 8045 | if (err) |
| 8046 | goto err_out; |
| 8047 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8048 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 8049 | if (err) |
| 8050 | goto err_out; |
| 8051 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8052 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 8053 | if (err) |
| 8054 | goto err_out; |
| 8055 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8056 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 8057 | if (err) |
| 8058 | goto err_out; |
| 8059 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8060 | #ifdef CONFIG_NL80211_TESTMODE |
| 8061 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 8062 | if (err) |
| 8063 | goto err_out; |
| 8064 | #endif |
| 8065 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8066 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 8067 | if (err) |
| 8068 | goto err_out; |
| 8069 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8070 | return 0; |
| 8071 | err_out: |
| 8072 | genl_unregister_family(&nl80211_fam); |
| 8073 | return err; |
| 8074 | } |
| 8075 | |
| 8076 | void nl80211_exit(void) |
| 8077 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8078 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8079 | genl_unregister_family(&nl80211_fam); |
| 8080 | } |