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 | 36aedc90 | 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 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 208 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 209 | }; |
| 210 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 211 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 212 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 213 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 214 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 215 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 216 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 217 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 218 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 219 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 220 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 221 | }; |
| 222 | |
| 223 | /* policy for the key default flags */ |
| 224 | static const struct nla_policy |
| 225 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 226 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 227 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 228 | }; |
| 229 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 230 | /* policy for WoWLAN attributes */ |
| 231 | static const struct nla_policy |
| 232 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 233 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 234 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 235 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 236 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 237 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 238 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 239 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 240 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 241 | }; |
| 242 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 243 | /* policy for GTK rekey offload attributes */ |
| 244 | static const struct nla_policy |
| 245 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 246 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 247 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 248 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 249 | }; |
| 250 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 251 | static const struct nla_policy |
| 252 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 253 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 254 | .len = IEEE80211_MAX_SSID_LEN }, |
| 255 | }; |
| 256 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 257 | /* ifidx get helper */ |
| 258 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 259 | { |
| 260 | int res; |
| 261 | |
| 262 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 263 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 264 | nl80211_policy); |
| 265 | if (res) |
| 266 | return res; |
| 267 | |
| 268 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 269 | return -EINVAL; |
| 270 | |
| 271 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 272 | if (!res) |
| 273 | return -EINVAL; |
| 274 | return res; |
| 275 | } |
| 276 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 277 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 278 | struct netlink_callback *cb, |
| 279 | struct cfg80211_registered_device **rdev, |
| 280 | struct net_device **dev) |
| 281 | { |
| 282 | int ifidx = cb->args[0]; |
| 283 | int err; |
| 284 | |
| 285 | if (!ifidx) |
| 286 | ifidx = nl80211_get_ifidx(cb); |
| 287 | if (ifidx < 0) |
| 288 | return ifidx; |
| 289 | |
| 290 | cb->args[0] = ifidx; |
| 291 | |
| 292 | rtnl_lock(); |
| 293 | |
| 294 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 295 | if (!*dev) { |
| 296 | err = -ENODEV; |
| 297 | goto out_rtnl; |
| 298 | } |
| 299 | |
| 300 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 301 | if (IS_ERR(*rdev)) { |
| 302 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 303 | goto out_rtnl; |
| 304 | } |
| 305 | |
| 306 | return 0; |
| 307 | out_rtnl: |
| 308 | rtnl_unlock(); |
| 309 | return err; |
| 310 | } |
| 311 | |
| 312 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 313 | { |
| 314 | cfg80211_unlock_rdev(rdev); |
| 315 | rtnl_unlock(); |
| 316 | } |
| 317 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 318 | /* IE validation */ |
| 319 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 320 | { |
| 321 | const u8 *pos; |
| 322 | int len; |
| 323 | |
| 324 | if (!attr) |
| 325 | return true; |
| 326 | |
| 327 | pos = nla_data(attr); |
| 328 | len = nla_len(attr); |
| 329 | |
| 330 | while (len) { |
| 331 | u8 elemlen; |
| 332 | |
| 333 | if (len < 2) |
| 334 | return false; |
| 335 | len -= 2; |
| 336 | |
| 337 | elemlen = pos[1]; |
| 338 | if (elemlen > len) |
| 339 | return false; |
| 340 | |
| 341 | len -= elemlen; |
| 342 | pos += 2 + elemlen; |
| 343 | } |
| 344 | |
| 345 | return true; |
| 346 | } |
| 347 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 348 | /* message building helper */ |
| 349 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 350 | int flags, u8 cmd) |
| 351 | { |
| 352 | /* since there is no private header just add the generic one */ |
| 353 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 354 | } |
| 355 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 356 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 357 | struct ieee80211_channel *chan) |
| 358 | { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 359 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 360 | chan->center_freq)) |
| 361 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 362 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 363 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 364 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 365 | goto nla_put_failure; |
| 366 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && |
| 367 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) |
| 368 | goto nla_put_failure; |
| 369 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && |
| 370 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 371 | goto nla_put_failure; |
| 372 | if ((chan->flags & IEEE80211_CHAN_RADAR) && |
| 373 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 374 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 375 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 376 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 377 | DBM_TO_MBM(chan->max_power))) |
| 378 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 379 | |
| 380 | return 0; |
| 381 | |
| 382 | nla_put_failure: |
| 383 | return -ENOBUFS; |
| 384 | } |
| 385 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 386 | /* netlink command implementations */ |
| 387 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 388 | struct key_parse { |
| 389 | struct key_params p; |
| 390 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 391 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 392 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 393 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 394 | }; |
| 395 | |
| 396 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 397 | { |
| 398 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 399 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 400 | nl80211_key_policy); |
| 401 | if (err) |
| 402 | return err; |
| 403 | |
| 404 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 405 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 406 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 407 | if (k->def) { |
| 408 | k->def_uni = true; |
| 409 | k->def_multi = true; |
| 410 | } |
| 411 | if (k->defmgmt) |
| 412 | k->def_multi = true; |
| 413 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 414 | if (tb[NL80211_KEY_IDX]) |
| 415 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 416 | |
| 417 | if (tb[NL80211_KEY_DATA]) { |
| 418 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 419 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 420 | } |
| 421 | |
| 422 | if (tb[NL80211_KEY_SEQ]) { |
| 423 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 424 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 425 | } |
| 426 | |
| 427 | if (tb[NL80211_KEY_CIPHER]) |
| 428 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 429 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 430 | if (tb[NL80211_KEY_TYPE]) { |
| 431 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 432 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 433 | return -EINVAL; |
| 434 | } |
| 435 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 436 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 437 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 438 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 439 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 440 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 441 | if (err) |
| 442 | return err; |
| 443 | |
| 444 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 445 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 446 | } |
| 447 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 452 | { |
| 453 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 454 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 455 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 456 | } |
| 457 | |
| 458 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 459 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 460 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 461 | } |
| 462 | |
| 463 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 464 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 465 | |
| 466 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 467 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 468 | |
| 469 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 470 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 471 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 472 | if (k->def) { |
| 473 | k->def_uni = true; |
| 474 | k->def_multi = true; |
| 475 | } |
| 476 | if (k->defmgmt) |
| 477 | k->def_multi = true; |
| 478 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 479 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 480 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 481 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 482 | return -EINVAL; |
| 483 | } |
| 484 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 485 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 486 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 487 | int err = nla_parse_nested( |
| 488 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 489 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 490 | nl80211_key_default_policy); |
| 491 | if (err) |
| 492 | return err; |
| 493 | |
| 494 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 495 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 496 | } |
| 497 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 502 | { |
| 503 | int err; |
| 504 | |
| 505 | memset(k, 0, sizeof(*k)); |
| 506 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 507 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 508 | |
| 509 | if (info->attrs[NL80211_ATTR_KEY]) |
| 510 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 511 | else |
| 512 | err = nl80211_parse_key_old(info, k); |
| 513 | |
| 514 | if (err) |
| 515 | return err; |
| 516 | |
| 517 | if (k->def && k->defmgmt) |
| 518 | return -EINVAL; |
| 519 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 520 | if (k->defmgmt) { |
| 521 | if (k->def_uni || !k->def_multi) |
| 522 | return -EINVAL; |
| 523 | } |
| 524 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 525 | if (k->idx != -1) { |
| 526 | if (k->defmgmt) { |
| 527 | if (k->idx < 4 || k->idx > 5) |
| 528 | return -EINVAL; |
| 529 | } else if (k->def) { |
| 530 | if (k->idx < 0 || k->idx > 3) |
| 531 | return -EINVAL; |
| 532 | } else { |
| 533 | if (k->idx < 0 || k->idx > 5) |
| 534 | return -EINVAL; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | return 0; |
| 539 | } |
| 540 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 541 | static struct cfg80211_cached_keys * |
| 542 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 543 | struct nlattr *keys) |
| 544 | { |
| 545 | struct key_parse parse; |
| 546 | struct nlattr *key; |
| 547 | struct cfg80211_cached_keys *result; |
| 548 | int rem, err, def = 0; |
| 549 | |
| 550 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 551 | if (!result) |
| 552 | return ERR_PTR(-ENOMEM); |
| 553 | |
| 554 | result->def = -1; |
| 555 | result->defmgmt = -1; |
| 556 | |
| 557 | nla_for_each_nested(key, keys, rem) { |
| 558 | memset(&parse, 0, sizeof(parse)); |
| 559 | parse.idx = -1; |
| 560 | |
| 561 | err = nl80211_parse_key_new(key, &parse); |
| 562 | if (err) |
| 563 | goto error; |
| 564 | err = -EINVAL; |
| 565 | if (!parse.p.key) |
| 566 | goto error; |
| 567 | if (parse.idx < 0 || parse.idx > 4) |
| 568 | goto error; |
| 569 | if (parse.def) { |
| 570 | if (def) |
| 571 | goto error; |
| 572 | def = 1; |
| 573 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 574 | if (!parse.def_uni || !parse.def_multi) |
| 575 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 576 | } else if (parse.defmgmt) |
| 577 | goto error; |
| 578 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 579 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 580 | if (err) |
| 581 | goto error; |
| 582 | result->params[parse.idx].cipher = parse.p.cipher; |
| 583 | result->params[parse.idx].key_len = parse.p.key_len; |
| 584 | result->params[parse.idx].key = result->data[parse.idx]; |
| 585 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 586 | } |
| 587 | |
| 588 | return result; |
| 589 | error: |
| 590 | kfree(result); |
| 591 | return ERR_PTR(err); |
| 592 | } |
| 593 | |
| 594 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 595 | { |
| 596 | ASSERT_WDEV_LOCK(wdev); |
| 597 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 598 | switch (wdev->iftype) { |
| 599 | case NL80211_IFTYPE_AP: |
| 600 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 601 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 602 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 603 | break; |
| 604 | case NL80211_IFTYPE_ADHOC: |
| 605 | if (!wdev->current_bss) |
| 606 | return -ENOLINK; |
| 607 | break; |
| 608 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 609 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 610 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 611 | return -ENOLINK; |
| 612 | break; |
| 613 | default: |
| 614 | return -EINVAL; |
| 615 | } |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 620 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 621 | { |
| 622 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 623 | int i; |
| 624 | |
| 625 | if (!nl_modes) |
| 626 | goto nla_put_failure; |
| 627 | |
| 628 | i = 0; |
| 629 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 630 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 631 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 632 | ifmodes >>= 1; |
| 633 | i++; |
| 634 | } |
| 635 | |
| 636 | nla_nest_end(msg, nl_modes); |
| 637 | return 0; |
| 638 | |
| 639 | nla_put_failure: |
| 640 | return -ENOBUFS; |
| 641 | } |
| 642 | |
| 643 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 644 | struct sk_buff *msg) |
| 645 | { |
| 646 | struct nlattr *nl_combis; |
| 647 | int i, j; |
| 648 | |
| 649 | nl_combis = nla_nest_start(msg, |
| 650 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 651 | if (!nl_combis) |
| 652 | goto nla_put_failure; |
| 653 | |
| 654 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 655 | const struct ieee80211_iface_combination *c; |
| 656 | struct nlattr *nl_combi, *nl_limits; |
| 657 | |
| 658 | c = &wiphy->iface_combinations[i]; |
| 659 | |
| 660 | nl_combi = nla_nest_start(msg, i + 1); |
| 661 | if (!nl_combi) |
| 662 | goto nla_put_failure; |
| 663 | |
| 664 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 665 | if (!nl_limits) |
| 666 | goto nla_put_failure; |
| 667 | |
| 668 | for (j = 0; j < c->n_limits; j++) { |
| 669 | struct nlattr *nl_limit; |
| 670 | |
| 671 | nl_limit = nla_nest_start(msg, j + 1); |
| 672 | if (!nl_limit) |
| 673 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 674 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 675 | c->limits[j].max)) |
| 676 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 677 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 678 | c->limits[j].types)) |
| 679 | goto nla_put_failure; |
| 680 | nla_nest_end(msg, nl_limit); |
| 681 | } |
| 682 | |
| 683 | nla_nest_end(msg, nl_limits); |
| 684 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 685 | if (c->beacon_int_infra_match && |
| 686 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 687 | goto nla_put_failure; |
| 688 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 689 | c->num_different_channels) || |
| 690 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 691 | c->max_interfaces)) |
| 692 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 693 | |
| 694 | nla_nest_end(msg, nl_combi); |
| 695 | } |
| 696 | |
| 697 | nla_nest_end(msg, nl_combis); |
| 698 | |
| 699 | return 0; |
| 700 | nla_put_failure: |
| 701 | return -ENOBUFS; |
| 702 | } |
| 703 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 704 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 705 | struct cfg80211_registered_device *dev) |
| 706 | { |
| 707 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 708 | struct nlattr *nl_bands, *nl_band; |
| 709 | struct nlattr *nl_freqs, *nl_freq; |
| 710 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 711 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 712 | enum ieee80211_band band; |
| 713 | struct ieee80211_channel *chan; |
| 714 | struct ieee80211_rate *rate; |
| 715 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 716 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 717 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 718 | |
| 719 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 720 | if (!hdr) |
| 721 | return -1; |
| 722 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 723 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
| 724 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || |
| 725 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 726 | cfg80211_rdev_list_generation) || |
| 727 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 728 | dev->wiphy.retry_short) || |
| 729 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 730 | dev->wiphy.retry_long) || |
| 731 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 732 | dev->wiphy.frag_threshold) || |
| 733 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 734 | dev->wiphy.rts_threshold) || |
| 735 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 736 | dev->wiphy.coverage_class) || |
| 737 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 738 | dev->wiphy.max_scan_ssids) || |
| 739 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 740 | dev->wiphy.max_sched_scan_ssids) || |
| 741 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 742 | dev->wiphy.max_scan_ie_len) || |
| 743 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 744 | dev->wiphy.max_sched_scan_ie_len) || |
| 745 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 746 | dev->wiphy.max_match_sets)) |
| 747 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 748 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 749 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
| 750 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 751 | goto nla_put_failure; |
| 752 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
| 753 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 754 | goto nla_put_failure; |
| 755 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 756 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 757 | goto nla_put_failure; |
| 758 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
| 759 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 760 | goto nla_put_failure; |
| 761 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 762 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 763 | goto nla_put_failure; |
| 764 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
| 765 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
| 766 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 767 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 768 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
| 769 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 770 | dev->wiphy.cipher_suites)) |
| 771 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 772 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 773 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 774 | dev->wiphy.max_num_pmkids)) |
| 775 | goto nla_put_failure; |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 776 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 777 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 778 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 779 | goto nla_put_failure; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 780 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 781 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 782 | dev->wiphy.available_antennas_tx) || |
| 783 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 784 | dev->wiphy.available_antennas_rx)) |
| 785 | goto nla_put_failure; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 786 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 787 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
| 788 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 789 | dev->wiphy.probe_resp_offload)) |
| 790 | goto nla_put_failure; |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 791 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 792 | if ((dev->wiphy.available_antennas_tx || |
| 793 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 794 | u32 tx_ant = 0, rx_ant = 0; |
| 795 | int res; |
| 796 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 797 | if (!res) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 798 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 799 | tx_ant) || |
| 800 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 801 | rx_ant)) |
| 802 | goto nla_put_failure; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 806 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 807 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 808 | goto nla_put_failure; |
| 809 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 810 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 811 | if (!nl_bands) |
| 812 | goto nla_put_failure; |
| 813 | |
| 814 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 815 | if (!dev->wiphy.bands[band]) |
| 816 | continue; |
| 817 | |
| 818 | nl_band = nla_nest_start(msg, band); |
| 819 | if (!nl_band) |
| 820 | goto nla_put_failure; |
| 821 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 822 | /* add HT info */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 823 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
| 824 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 825 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 826 | &dev->wiphy.bands[band]->ht_cap.mcs) || |
| 827 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 828 | dev->wiphy.bands[band]->ht_cap.cap) || |
| 829 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 830 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || |
| 831 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 832 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) |
| 833 | goto nla_put_failure; |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 834 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 835 | /* add frequencies */ |
| 836 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 837 | if (!nl_freqs) |
| 838 | goto nla_put_failure; |
| 839 | |
| 840 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 841 | nl_freq = nla_nest_start(msg, i); |
| 842 | if (!nl_freq) |
| 843 | goto nla_put_failure; |
| 844 | |
| 845 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 846 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 847 | if (nl80211_msg_put_channel(msg, chan)) |
| 848 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 849 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 850 | nla_nest_end(msg, nl_freq); |
| 851 | } |
| 852 | |
| 853 | nla_nest_end(msg, nl_freqs); |
| 854 | |
| 855 | /* add bitrates */ |
| 856 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 857 | if (!nl_rates) |
| 858 | goto nla_put_failure; |
| 859 | |
| 860 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 861 | nl_rate = nla_nest_start(msg, i); |
| 862 | if (!nl_rate) |
| 863 | goto nla_put_failure; |
| 864 | |
| 865 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 866 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 867 | rate->bitrate)) |
| 868 | goto nla_put_failure; |
| 869 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 870 | nla_put_flag(msg, |
| 871 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 872 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 873 | |
| 874 | nla_nest_end(msg, nl_rate); |
| 875 | } |
| 876 | |
| 877 | nla_nest_end(msg, nl_rates); |
| 878 | |
| 879 | nla_nest_end(msg, nl_band); |
| 880 | } |
| 881 | nla_nest_end(msg, nl_bands); |
| 882 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 883 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 884 | if (!nl_cmds) |
| 885 | goto nla_put_failure; |
| 886 | |
| 887 | i = 0; |
| 888 | #define CMD(op, n) \ |
| 889 | do { \ |
| 890 | if (dev->ops->op) { \ |
| 891 | i++; \ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 892 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 893 | goto nla_put_failure; \ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 894 | } \ |
| 895 | } while (0) |
| 896 | |
| 897 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 898 | CMD(change_virtual_intf, SET_INTERFACE); |
| 899 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 900 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 901 | CMD(add_station, NEW_STATION); |
| 902 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 903 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 904 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 905 | CMD(auth, AUTHENTICATE); |
| 906 | CMD(assoc, ASSOCIATE); |
| 907 | CMD(deauth, DEAUTHENTICATE); |
| 908 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 909 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 910 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 911 | CMD(set_pmksa, SET_PMKSA); |
| 912 | CMD(del_pmksa, DEL_PMKSA); |
| 913 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 914 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 915 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 916 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 917 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 918 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 919 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 920 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 921 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 922 | goto nla_put_failure; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 923 | } |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame^] | 924 | if (dev->ops->set_channel || dev->ops->start_ap) { |
| 925 | i++; |
| 926 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 927 | goto nla_put_failure; |
| 928 | } |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 929 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 930 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 931 | CMD(tdls_mgmt, TDLS_MGMT); |
| 932 | CMD(tdls_oper, TDLS_OPER); |
| 933 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 934 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 935 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 936 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 937 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 938 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 939 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 940 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 941 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 942 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 943 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 944 | #ifdef CONFIG_NL80211_TESTMODE |
| 945 | CMD(testmode_cmd, TESTMODE); |
| 946 | #endif |
| 947 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 948 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 949 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 950 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 951 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 952 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 953 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 954 | } |
| 955 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 956 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 957 | i++; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 958 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 959 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 960 | } |
| 961 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 962 | nla_nest_end(msg, nl_cmds); |
| 963 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 964 | if (dev->ops->remain_on_channel && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 965 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
| 966 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 967 | dev->wiphy.max_remain_on_channel_duration)) |
| 968 | goto nla_put_failure; |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 969 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 970 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
| 971 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 972 | goto nla_put_failure; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 973 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 974 | if (mgmt_stypes) { |
| 975 | u16 stypes; |
| 976 | struct nlattr *nl_ftypes, *nl_ifs; |
| 977 | enum nl80211_iftype ift; |
| 978 | |
| 979 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 980 | if (!nl_ifs) |
| 981 | goto nla_put_failure; |
| 982 | |
| 983 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 984 | nl_ftypes = nla_nest_start(msg, ift); |
| 985 | if (!nl_ftypes) |
| 986 | goto nla_put_failure; |
| 987 | i = 0; |
| 988 | stypes = mgmt_stypes[ift].tx; |
| 989 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 990 | if ((stypes & 1) && |
| 991 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 992 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 993 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 994 | stypes >>= 1; |
| 995 | i++; |
| 996 | } |
| 997 | nla_nest_end(msg, nl_ftypes); |
| 998 | } |
| 999 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1000 | nla_nest_end(msg, nl_ifs); |
| 1001 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1002 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1003 | if (!nl_ifs) |
| 1004 | goto nla_put_failure; |
| 1005 | |
| 1006 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1007 | nl_ftypes = nla_nest_start(msg, ift); |
| 1008 | if (!nl_ftypes) |
| 1009 | goto nla_put_failure; |
| 1010 | i = 0; |
| 1011 | stypes = mgmt_stypes[ift].rx; |
| 1012 | while (stypes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1013 | if ((stypes & 1) && |
| 1014 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1015 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1016 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1017 | stypes >>= 1; |
| 1018 | i++; |
| 1019 | } |
| 1020 | nla_nest_end(msg, nl_ftypes); |
| 1021 | } |
| 1022 | nla_nest_end(msg, nl_ifs); |
| 1023 | } |
| 1024 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1025 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 1026 | struct nlattr *nl_wowlan; |
| 1027 | |
| 1028 | nl_wowlan = nla_nest_start(msg, |
| 1029 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1030 | if (!nl_wowlan) |
| 1031 | goto nla_put_failure; |
| 1032 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1033 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
| 1034 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 1035 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && |
| 1036 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 1037 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && |
| 1038 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 1039 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
| 1040 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
| 1041 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
| 1042 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 1043 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
| 1044 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 1045 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
| 1046 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 1047 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
| 1048 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1049 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1050 | if (dev->wiphy.wowlan.n_patterns) { |
| 1051 | struct nl80211_wowlan_pattern_support pat = { |
| 1052 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1053 | .min_pattern_len = |
| 1054 | dev->wiphy.wowlan.pattern_min_len, |
| 1055 | .max_pattern_len = |
| 1056 | dev->wiphy.wowlan.pattern_max_len, |
| 1057 | }; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1058 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1059 | sizeof(pat), &pat)) |
| 1060 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | nla_nest_end(msg, nl_wowlan); |
| 1064 | } |
| 1065 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1066 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1067 | dev->wiphy.software_iftypes)) |
| 1068 | goto nla_put_failure; |
| 1069 | |
| 1070 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1071 | goto nla_put_failure; |
| 1072 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1073 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
| 1074 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1075 | dev->wiphy.ap_sme_capa)) |
| 1076 | goto nla_put_failure; |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1077 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1078 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
| 1079 | dev->wiphy.features)) |
| 1080 | goto nla_put_failure; |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1081 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1082 | if (dev->wiphy.ht_capa_mod_mask && |
| 1083 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1084 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1085 | dev->wiphy.ht_capa_mod_mask)) |
| 1086 | goto nla_put_failure; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1087 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1088 | return genlmsg_end(msg, hdr); |
| 1089 | |
| 1090 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1091 | genlmsg_cancel(msg, hdr); |
| 1092 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1096 | { |
| 1097 | int idx = 0; |
| 1098 | int start = cb->args[0]; |
| 1099 | struct cfg80211_registered_device *dev; |
| 1100 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1101 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1102 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1103 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1104 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1105 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1106 | continue; |
| 1107 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1108 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1109 | dev) < 0) { |
| 1110 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1111 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1112 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1113 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1114 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1115 | |
| 1116 | cb->args[0] = idx; |
| 1117 | |
| 1118 | return skb->len; |
| 1119 | } |
| 1120 | |
| 1121 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1122 | { |
| 1123 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1124 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1125 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1126 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1127 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1128 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1129 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1130 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1131 | nlmsg_free(msg); |
| 1132 | return -ENOBUFS; |
| 1133 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1134 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1135 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1138 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1139 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1140 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1141 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1142 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1143 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1144 | }; |
| 1145 | |
| 1146 | static int parse_txq_params(struct nlattr *tb[], |
| 1147 | struct ieee80211_txq_params *txq_params) |
| 1148 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1149 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1150 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1151 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1152 | return -EINVAL; |
| 1153 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1154 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1155 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1156 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1157 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1158 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1159 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1160 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1161 | return -EINVAL; |
| 1162 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1163 | return 0; |
| 1164 | } |
| 1165 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1166 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1167 | { |
| 1168 | /* |
| 1169 | * You can only set the channel explicitly for AP, mesh |
| 1170 | * and WDS type interfaces; all others have their channel |
| 1171 | * managed via their respective "establish a connection" |
| 1172 | * command (connect, join, ...) |
| 1173 | * |
| 1174 | * Monitors are special as they are normally slaved to |
| 1175 | * whatever else is going on, so they behave as though |
| 1176 | * you tried setting the wiphy channel itself. |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame^] | 1177 | * |
| 1178 | * For AP/GO modes, it's only for compatibility, you can |
| 1179 | * also give the channel to the start-AP command. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1180 | */ |
| 1181 | return !wdev || |
| 1182 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1183 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1184 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1185 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1186 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1187 | } |
| 1188 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1189 | static bool nl80211_valid_channel_type(struct genl_info *info, |
| 1190 | enum nl80211_channel_type *channel_type) |
| 1191 | { |
| 1192 | enum nl80211_channel_type tmp; |
| 1193 | |
| 1194 | if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) |
| 1195 | return false; |
| 1196 | |
| 1197 | tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1198 | if (tmp != NL80211_CHAN_NO_HT && |
| 1199 | tmp != NL80211_CHAN_HT20 && |
| 1200 | tmp != NL80211_CHAN_HT40PLUS && |
| 1201 | tmp != NL80211_CHAN_HT40MINUS) |
| 1202 | return false; |
| 1203 | |
| 1204 | if (channel_type) |
| 1205 | *channel_type = tmp; |
| 1206 | |
| 1207 | return true; |
| 1208 | } |
| 1209 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1210 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1211 | struct wireless_dev *wdev, |
| 1212 | struct genl_info *info) |
| 1213 | { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame^] | 1214 | struct ieee80211_channel *channel; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1215 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1216 | u32 freq; |
| 1217 | int result; |
| 1218 | |
| 1219 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1220 | return -EINVAL; |
| 1221 | |
| 1222 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1223 | return -EOPNOTSUPP; |
| 1224 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 1225 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 1226 | !nl80211_valid_channel_type(info, &channel_type)) |
| 1227 | return -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1228 | |
| 1229 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1230 | |
| 1231 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame^] | 1232 | if (wdev) switch (wdev->iftype) { |
| 1233 | case NL80211_IFTYPE_AP: |
| 1234 | case NL80211_IFTYPE_P2P_GO: |
| 1235 | if (wdev->beacon_interval) { |
| 1236 | result = -EBUSY; |
| 1237 | break; |
| 1238 | } |
| 1239 | channel = rdev_freq_to_chan(rdev, freq, channel_type); |
| 1240 | if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy, |
| 1241 | channel, |
| 1242 | channel_type)) { |
| 1243 | result = -EINVAL; |
| 1244 | break; |
| 1245 | } |
| 1246 | wdev->preset_chan = channel; |
| 1247 | wdev->preset_chantype = channel_type; |
| 1248 | result = 0; |
| 1249 | break; |
| 1250 | default: |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1251 | wdev_lock(wdev); |
| 1252 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1253 | wdev_unlock(wdev); |
| 1254 | } else { |
| 1255 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1256 | } |
| 1257 | mutex_unlock(&rdev->devlist_mtx); |
| 1258 | |
| 1259 | return result; |
| 1260 | } |
| 1261 | |
| 1262 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1263 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1265 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1266 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1267 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1270 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1271 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1272 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1273 | struct net_device *dev = info->user_ptr[1]; |
| 1274 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1275 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1276 | |
| 1277 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1278 | return -EINVAL; |
| 1279 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1280 | if (netif_running(dev)) |
| 1281 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1282 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1283 | if (!rdev->ops->set_wds_peer) |
| 1284 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1285 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1286 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1287 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1288 | |
| 1289 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1290 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1294 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1295 | { |
| 1296 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1297 | struct net_device *netdev = NULL; |
| 1298 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1299 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1300 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1301 | u32 changed; |
| 1302 | u8 retry_short = 0, retry_long = 0; |
| 1303 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1304 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1305 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1306 | /* |
| 1307 | * Try to find the wiphy and netdev. Normally this |
| 1308 | * function shouldn't need the netdev, but this is |
| 1309 | * done for backward compatibility -- previously |
| 1310 | * setting the channel was done per wiphy, but now |
| 1311 | * it is per netdev. Previous userland like hostapd |
| 1312 | * also passed a netdev to set_wiphy, so that it is |
| 1313 | * possible to let that go to the right netdev! |
| 1314 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1315 | mutex_lock(&cfg80211_mutex); |
| 1316 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1317 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1318 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1319 | |
| 1320 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1321 | if (netdev && netdev->ieee80211_ptr) { |
| 1322 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1323 | mutex_lock(&rdev->mtx); |
| 1324 | } else |
| 1325 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1326 | } |
| 1327 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1328 | if (!netdev) { |
| 1329 | rdev = __cfg80211_rdev_from_info(info); |
| 1330 | if (IS_ERR(rdev)) { |
| 1331 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1332 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1333 | } |
| 1334 | wdev = NULL; |
| 1335 | netdev = NULL; |
| 1336 | result = 0; |
| 1337 | |
| 1338 | mutex_lock(&rdev->mtx); |
| 1339 | } else if (netif_running(netdev) && |
| 1340 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1341 | wdev = netdev->ieee80211_ptr; |
| 1342 | else |
| 1343 | wdev = NULL; |
| 1344 | |
| 1345 | /* |
| 1346 | * end workaround code, by now the rdev is available |
| 1347 | * and locked, and wdev may or may not be NULL. |
| 1348 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1349 | |
| 1350 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1351 | result = cfg80211_dev_rename( |
| 1352 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1353 | |
| 1354 | mutex_unlock(&cfg80211_mutex); |
| 1355 | |
| 1356 | if (result) |
| 1357 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1358 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1359 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1360 | struct ieee80211_txq_params txq_params; |
| 1361 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1362 | |
| 1363 | if (!rdev->ops->set_txq_params) { |
| 1364 | result = -EOPNOTSUPP; |
| 1365 | goto bad_res; |
| 1366 | } |
| 1367 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1368 | if (!netdev) { |
| 1369 | result = -EINVAL; |
| 1370 | goto bad_res; |
| 1371 | } |
| 1372 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1373 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1374 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1375 | result = -EINVAL; |
| 1376 | goto bad_res; |
| 1377 | } |
| 1378 | |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 1379 | if (!netif_running(netdev)) { |
| 1380 | result = -ENETDOWN; |
| 1381 | goto bad_res; |
| 1382 | } |
| 1383 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1384 | nla_for_each_nested(nl_txq_params, |
| 1385 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1386 | rem_txq_params) { |
| 1387 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1388 | nla_data(nl_txq_params), |
| 1389 | nla_len(nl_txq_params), |
| 1390 | txq_params_policy); |
| 1391 | result = parse_txq_params(tb, &txq_params); |
| 1392 | if (result) |
| 1393 | goto bad_res; |
| 1394 | |
| 1395 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1396 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1397 | &txq_params); |
| 1398 | if (result) |
| 1399 | goto bad_res; |
| 1400 | } |
| 1401 | } |
| 1402 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1403 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1404 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1405 | if (result) |
| 1406 | goto bad_res; |
| 1407 | } |
| 1408 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1409 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1410 | enum nl80211_tx_power_setting type; |
| 1411 | int idx, mbm = 0; |
| 1412 | |
| 1413 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1414 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1415 | goto bad_res; |
| 1416 | } |
| 1417 | |
| 1418 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1419 | type = nla_get_u32(info->attrs[idx]); |
| 1420 | |
| 1421 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1422 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1423 | result = -EINVAL; |
| 1424 | goto bad_res; |
| 1425 | } |
| 1426 | |
| 1427 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1428 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1429 | mbm = nla_get_u32(info->attrs[idx]); |
| 1430 | } |
| 1431 | |
| 1432 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1433 | if (result) |
| 1434 | goto bad_res; |
| 1435 | } |
| 1436 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1437 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1438 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1439 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1440 | if ((!rdev->wiphy.available_antennas_tx && |
| 1441 | !rdev->wiphy.available_antennas_rx) || |
| 1442 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1443 | result = -EOPNOTSUPP; |
| 1444 | goto bad_res; |
| 1445 | } |
| 1446 | |
| 1447 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1448 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1449 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1450 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1451 | * available antenna masks, except for the "all" mask */ |
| 1452 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1453 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1454 | result = -EINVAL; |
| 1455 | goto bad_res; |
| 1456 | } |
| 1457 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1458 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1459 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1460 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1461 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1462 | if (result) |
| 1463 | goto bad_res; |
| 1464 | } |
| 1465 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1466 | changed = 0; |
| 1467 | |
| 1468 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1469 | retry_short = nla_get_u8( |
| 1470 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1471 | if (retry_short == 0) { |
| 1472 | result = -EINVAL; |
| 1473 | goto bad_res; |
| 1474 | } |
| 1475 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1476 | } |
| 1477 | |
| 1478 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1479 | retry_long = nla_get_u8( |
| 1480 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1481 | if (retry_long == 0) { |
| 1482 | result = -EINVAL; |
| 1483 | goto bad_res; |
| 1484 | } |
| 1485 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1486 | } |
| 1487 | |
| 1488 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1489 | frag_threshold = nla_get_u32( |
| 1490 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1491 | if (frag_threshold < 256) { |
| 1492 | result = -EINVAL; |
| 1493 | goto bad_res; |
| 1494 | } |
| 1495 | if (frag_threshold != (u32) -1) { |
| 1496 | /* |
| 1497 | * Fragments (apart from the last one) are required to |
| 1498 | * have even length. Make the fragmentation code |
| 1499 | * simpler by stripping LSB should someone try to use |
| 1500 | * odd threshold value. |
| 1501 | */ |
| 1502 | frag_threshold &= ~0x1; |
| 1503 | } |
| 1504 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1505 | } |
| 1506 | |
| 1507 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1508 | rts_threshold = nla_get_u32( |
| 1509 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1510 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1511 | } |
| 1512 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1513 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1514 | coverage_class = nla_get_u8( |
| 1515 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1516 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1517 | } |
| 1518 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1519 | if (changed) { |
| 1520 | u8 old_retry_short, old_retry_long; |
| 1521 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1522 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1523 | |
| 1524 | if (!rdev->ops->set_wiphy_params) { |
| 1525 | result = -EOPNOTSUPP; |
| 1526 | goto bad_res; |
| 1527 | } |
| 1528 | |
| 1529 | old_retry_short = rdev->wiphy.retry_short; |
| 1530 | old_retry_long = rdev->wiphy.retry_long; |
| 1531 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1532 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1533 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1534 | |
| 1535 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1536 | rdev->wiphy.retry_short = retry_short; |
| 1537 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1538 | rdev->wiphy.retry_long = retry_long; |
| 1539 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1540 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1541 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1542 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1543 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1544 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1545 | |
| 1546 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1547 | if (result) { |
| 1548 | rdev->wiphy.retry_short = old_retry_short; |
| 1549 | rdev->wiphy.retry_long = old_retry_long; |
| 1550 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1551 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1552 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1553 | } |
| 1554 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1555 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1556 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1557 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1558 | if (netdev) |
| 1559 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1560 | return result; |
| 1561 | } |
| 1562 | |
| 1563 | |
| 1564 | 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] | 1565 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1566 | struct net_device *dev) |
| 1567 | { |
| 1568 | void *hdr; |
| 1569 | |
| 1570 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1571 | if (!hdr) |
| 1572 | return -1; |
| 1573 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1574 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 1575 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 1576 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) || |
| 1577 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1578 | dev->ieee80211_ptr->iftype) || |
| 1579 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 1580 | rdev->devlist_generation ^ |
| 1581 | (cfg80211_rdev_list_generation << 2))) |
| 1582 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1583 | |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1584 | if (rdev->ops->get_channel) { |
| 1585 | struct ieee80211_channel *chan; |
| 1586 | enum nl80211_channel_type channel_type; |
| 1587 | |
| 1588 | chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type); |
John W. Linville | 59ef43e | 2012-04-18 14:17:13 -0400 | [diff] [blame] | 1589 | if (chan && |
| 1590 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 1591 | chan->center_freq) || |
| 1592 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 1593 | channel_type))) |
| 1594 | goto nla_put_failure; |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 1595 | } |
| 1596 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1597 | return genlmsg_end(msg, hdr); |
| 1598 | |
| 1599 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1600 | genlmsg_cancel(msg, hdr); |
| 1601 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1605 | { |
| 1606 | int wp_idx = 0; |
| 1607 | int if_idx = 0; |
| 1608 | int wp_start = cb->args[0]; |
| 1609 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1610 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1611 | struct wireless_dev *wdev; |
| 1612 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1613 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1614 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1615 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1616 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1617 | if (wp_idx < wp_start) { |
| 1618 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1619 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1620 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1621 | if_idx = 0; |
| 1622 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1623 | mutex_lock(&rdev->devlist_mtx); |
| 1624 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1625 | if (if_idx < if_start) { |
| 1626 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1627 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1628 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1629 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1630 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1631 | rdev, wdev->netdev) < 0) { |
| 1632 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1633 | goto out; |
| 1634 | } |
| 1635 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1636 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1637 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1638 | |
| 1639 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1640 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1641 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1642 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1643 | |
| 1644 | cb->args[0] = wp_idx; |
| 1645 | cb->args[1] = if_idx; |
| 1646 | |
| 1647 | return skb->len; |
| 1648 | } |
| 1649 | |
| 1650 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1651 | { |
| 1652 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1653 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1654 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1655 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1657 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1658 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1659 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1660 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1661 | dev, netdev) < 0) { |
| 1662 | nlmsg_free(msg); |
| 1663 | return -ENOBUFS; |
| 1664 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1665 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1666 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1667 | } |
| 1668 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1669 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1670 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1671 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1672 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1673 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1674 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1675 | }; |
| 1676 | |
| 1677 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1678 | { |
| 1679 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1680 | int flag; |
| 1681 | |
| 1682 | *mntrflags = 0; |
| 1683 | |
| 1684 | if (!nla) |
| 1685 | return -EINVAL; |
| 1686 | |
| 1687 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1688 | nla, mntr_flags_policy)) |
| 1689 | return -EINVAL; |
| 1690 | |
| 1691 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1692 | if (flags[flag]) |
| 1693 | *mntrflags |= (1<<flag); |
| 1694 | |
| 1695 | return 0; |
| 1696 | } |
| 1697 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1698 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1699 | struct net_device *netdev, u8 use_4addr, |
| 1700 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1701 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1702 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1703 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1704 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1705 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1706 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1707 | |
| 1708 | switch (iftype) { |
| 1709 | case NL80211_IFTYPE_AP_VLAN: |
| 1710 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1711 | return 0; |
| 1712 | break; |
| 1713 | case NL80211_IFTYPE_STATION: |
| 1714 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1715 | return 0; |
| 1716 | break; |
| 1717 | default: |
| 1718 | break; |
| 1719 | } |
| 1720 | |
| 1721 | return -EOPNOTSUPP; |
| 1722 | } |
| 1723 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1724 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1725 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1726 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1727 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1728 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1729 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1730 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1731 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1732 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1733 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1734 | memset(¶ms, 0, sizeof(params)); |
| 1735 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1736 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1737 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1738 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1739 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1740 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1741 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1742 | if (ntype > NL80211_IFTYPE_MAX) |
| 1743 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1744 | } |
| 1745 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1746 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1747 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1748 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1749 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1750 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1751 | if (netif_running(dev)) |
| 1752 | return -EBUSY; |
| 1753 | |
| 1754 | wdev_lock(wdev); |
| 1755 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1756 | IEEE80211_MAX_MESH_ID_LEN); |
| 1757 | wdev->mesh_id_up_len = |
| 1758 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1759 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1760 | wdev->mesh_id_up_len); |
| 1761 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1762 | } |
| 1763 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1764 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1765 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1766 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1767 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1768 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1769 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1770 | } else { |
| 1771 | params.use_4addr = -1; |
| 1772 | } |
| 1773 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1774 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1775 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1776 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1777 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1778 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1779 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1780 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1781 | |
| 1782 | flags = &_flags; |
| 1783 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1784 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1785 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1786 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1787 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1788 | else |
| 1789 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1790 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1791 | if (!err && params.use_4addr != -1) |
| 1792 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1793 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1794 | return err; |
| 1795 | } |
| 1796 | |
| 1797 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1798 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1800 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1801 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1802 | int err; |
| 1803 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1804 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1805 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1806 | memset(¶ms, 0, sizeof(params)); |
| 1807 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1808 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1809 | return -EINVAL; |
| 1810 | |
| 1811 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1812 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1813 | if (type > NL80211_IFTYPE_MAX) |
| 1814 | return -EINVAL; |
| 1815 | } |
| 1816 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1817 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1818 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1819 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1820 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1821 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1822 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1823 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1824 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1825 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1826 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1827 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1828 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1829 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1830 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1831 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1832 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1833 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1834 | if (IS_ERR(dev)) |
| 1835 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1836 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1837 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1838 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1839 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1840 | |
| 1841 | wdev_lock(wdev); |
| 1842 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1843 | IEEE80211_MAX_MESH_ID_LEN); |
| 1844 | wdev->mesh_id_up_len = |
| 1845 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1846 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1847 | wdev->mesh_id_up_len); |
| 1848 | wdev_unlock(wdev); |
| 1849 | } |
| 1850 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1851 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1855 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1857 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1859 | if (!rdev->ops->del_virtual_intf) |
| 1860 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1861 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1862 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1863 | } |
| 1864 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1865 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 1866 | { |
| 1867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1868 | struct net_device *dev = info->user_ptr[1]; |
| 1869 | u16 noack_map; |
| 1870 | |
| 1871 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 1872 | return -EINVAL; |
| 1873 | |
| 1874 | if (!rdev->ops->set_noack_map) |
| 1875 | return -EOPNOTSUPP; |
| 1876 | |
| 1877 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 1878 | |
| 1879 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 1880 | } |
| 1881 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1882 | struct get_key_cookie { |
| 1883 | struct sk_buff *msg; |
| 1884 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1885 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1886 | }; |
| 1887 | |
| 1888 | static void get_key_callback(void *c, struct key_params *params) |
| 1889 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1890 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1891 | struct get_key_cookie *cookie = c; |
| 1892 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1893 | if ((params->key && |
| 1894 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1895 | params->key_len, params->key)) || |
| 1896 | (params->seq && |
| 1897 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1898 | params->seq_len, params->seq)) || |
| 1899 | (params->cipher && |
| 1900 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1901 | params->cipher))) |
| 1902 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1903 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1904 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1905 | if (!key) |
| 1906 | goto nla_put_failure; |
| 1907 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1908 | if ((params->key && |
| 1909 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 1910 | params->key_len, params->key)) || |
| 1911 | (params->seq && |
| 1912 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 1913 | params->seq_len, params->seq)) || |
| 1914 | (params->cipher && |
| 1915 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 1916 | params->cipher))) |
| 1917 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1918 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1919 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 1920 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1921 | |
| 1922 | nla_nest_end(cookie->msg, key); |
| 1923 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1924 | return; |
| 1925 | nla_put_failure: |
| 1926 | cookie->error = 1; |
| 1927 | } |
| 1928 | |
| 1929 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1930 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1932 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1933 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1934 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1935 | const u8 *mac_addr = NULL; |
| 1936 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1937 | struct get_key_cookie cookie = { |
| 1938 | .error = 0, |
| 1939 | }; |
| 1940 | void *hdr; |
| 1941 | struct sk_buff *msg; |
| 1942 | |
| 1943 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1944 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1945 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1946 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1947 | return -EINVAL; |
| 1948 | |
| 1949 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1950 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1951 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1952 | pairwise = !!mac_addr; |
| 1953 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1954 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1955 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1956 | return -EINVAL; |
| 1957 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1958 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1959 | return -EINVAL; |
| 1960 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1961 | } |
| 1962 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1963 | if (!rdev->ops->get_key) |
| 1964 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1965 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1966 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1967 | if (!msg) |
| 1968 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1969 | |
| 1970 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1971 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1972 | if (IS_ERR(hdr)) |
| 1973 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1974 | |
| 1975 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1976 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1978 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 1979 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 1980 | goto nla_put_failure; |
| 1981 | if (mac_addr && |
| 1982 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 1983 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1984 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1985 | if (pairwise && mac_addr && |
| 1986 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1987 | return -ENOENT; |
| 1988 | |
| 1989 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1990 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1991 | |
| 1992 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1993 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1994 | |
| 1995 | if (cookie.error) |
| 1996 | goto nla_put_failure; |
| 1997 | |
| 1998 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1999 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2000 | |
| 2001 | nla_put_failure: |
| 2002 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2003 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2004 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2005 | return err; |
| 2006 | } |
| 2007 | |
| 2008 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2009 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2010 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2011 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2012 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2013 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2014 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2015 | err = nl80211_parse_key(info, &key); |
| 2016 | if (err) |
| 2017 | return err; |
| 2018 | |
| 2019 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2020 | return -EINVAL; |
| 2021 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2022 | /* only support setting default key */ |
| 2023 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2024 | return -EINVAL; |
| 2025 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2026 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2027 | |
| 2028 | if (key.def) { |
| 2029 | if (!rdev->ops->set_default_key) { |
| 2030 | err = -EOPNOTSUPP; |
| 2031 | goto out; |
| 2032 | } |
| 2033 | |
| 2034 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2035 | if (err) |
| 2036 | goto out; |
| 2037 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2038 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 2039 | key.def_uni, key.def_multi); |
| 2040 | |
| 2041 | if (err) |
| 2042 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2043 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2044 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2045 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2046 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2047 | } else { |
| 2048 | if (key.def_uni || !key.def_multi) { |
| 2049 | err = -EINVAL; |
| 2050 | goto out; |
| 2051 | } |
| 2052 | |
| 2053 | if (!rdev->ops->set_default_mgmt_key) { |
| 2054 | err = -EOPNOTSUPP; |
| 2055 | goto out; |
| 2056 | } |
| 2057 | |
| 2058 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2059 | if (err) |
| 2060 | goto out; |
| 2061 | |
| 2062 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 2063 | dev, key.idx); |
| 2064 | if (err) |
| 2065 | goto out; |
| 2066 | |
| 2067 | #ifdef CONFIG_CFG80211_WEXT |
| 2068 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2069 | #endif |
| 2070 | } |
| 2071 | |
| 2072 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2073 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2074 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2075 | return err; |
| 2076 | } |
| 2077 | |
| 2078 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2079 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2080 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2081 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2082 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2083 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2084 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2085 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2086 | err = nl80211_parse_key(info, &key); |
| 2087 | if (err) |
| 2088 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2089 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2090 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2091 | return -EINVAL; |
| 2092 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2093 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2094 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2095 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2096 | if (key.type == -1) { |
| 2097 | if (mac_addr) |
| 2098 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2099 | else |
| 2100 | key.type = NL80211_KEYTYPE_GROUP; |
| 2101 | } |
| 2102 | |
| 2103 | /* for now */ |
| 2104 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2105 | key.type != NL80211_KEYTYPE_GROUP) |
| 2106 | return -EINVAL; |
| 2107 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2108 | if (!rdev->ops->add_key) |
| 2109 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2110 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2111 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2112 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2113 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2114 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2115 | |
| 2116 | wdev_lock(dev->ieee80211_ptr); |
| 2117 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2118 | if (!err) |
| 2119 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2120 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2121 | mac_addr, &key.p); |
| 2122 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2123 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2124 | return err; |
| 2125 | } |
| 2126 | |
| 2127 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2128 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2130 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2131 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2132 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2133 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2134 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2135 | err = nl80211_parse_key(info, &key); |
| 2136 | if (err) |
| 2137 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2138 | |
| 2139 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2140 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2141 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2142 | if (key.type == -1) { |
| 2143 | if (mac_addr) |
| 2144 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2145 | else |
| 2146 | key.type = NL80211_KEYTYPE_GROUP; |
| 2147 | } |
| 2148 | |
| 2149 | /* for now */ |
| 2150 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2151 | key.type != NL80211_KEYTYPE_GROUP) |
| 2152 | return -EINVAL; |
| 2153 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2154 | if (!rdev->ops->del_key) |
| 2155 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2156 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2157 | wdev_lock(dev->ieee80211_ptr); |
| 2158 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2159 | |
| 2160 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2161 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2162 | err = -ENOENT; |
| 2163 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2164 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2165 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2166 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2167 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2168 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2169 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2170 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2171 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2172 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2173 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2174 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2175 | } |
| 2176 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2177 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2178 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2179 | return err; |
| 2180 | } |
| 2181 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2182 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2183 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2184 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2185 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2186 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2187 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2188 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2189 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2190 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2191 | return -EINVAL; |
| 2192 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2193 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2194 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2195 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2196 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2197 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2198 | if (!bcn->head_len) |
| 2199 | return -EINVAL; |
| 2200 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2204 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2205 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2206 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2207 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2208 | } |
| 2209 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2210 | if (!haveinfo) |
| 2211 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2212 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2213 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2214 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2215 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2219 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2220 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2221 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2222 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2223 | } |
| 2224 | |
| 2225 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2226 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2227 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2228 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2229 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2230 | } |
| 2231 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2232 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2233 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2234 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2235 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2236 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2237 | } |
| 2238 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2239 | return 0; |
| 2240 | } |
| 2241 | |
| 2242 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2243 | { |
| 2244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2245 | struct net_device *dev = info->user_ptr[1]; |
| 2246 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2247 | struct cfg80211_ap_settings params; |
| 2248 | int err; |
| 2249 | |
| 2250 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2251 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2252 | return -EOPNOTSUPP; |
| 2253 | |
| 2254 | if (!rdev->ops->start_ap) |
| 2255 | return -EOPNOTSUPP; |
| 2256 | |
| 2257 | if (wdev->beacon_interval) |
| 2258 | return -EALREADY; |
| 2259 | |
| 2260 | memset(¶ms, 0, sizeof(params)); |
| 2261 | |
| 2262 | /* these are required for START_AP */ |
| 2263 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2264 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2265 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2266 | return -EINVAL; |
| 2267 | |
| 2268 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2269 | if (err) |
| 2270 | return err; |
| 2271 | |
| 2272 | params.beacon_interval = |
| 2273 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2274 | params.dtim_period = |
| 2275 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2276 | |
| 2277 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2278 | if (err) |
| 2279 | return err; |
| 2280 | |
| 2281 | /* |
| 2282 | * In theory, some of these attributes should be required here |
| 2283 | * but since they were not used when the command was originally |
| 2284 | * added, keep them optional for old user space programs to let |
| 2285 | * them continue to work with drivers that do not need the |
| 2286 | * additional information -- drivers must check! |
| 2287 | */ |
| 2288 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2289 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2290 | params.ssid_len = |
| 2291 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2292 | if (params.ssid_len == 0 || |
| 2293 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2294 | return -EINVAL; |
| 2295 | } |
| 2296 | |
| 2297 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2298 | params.hidden_ssid = nla_get_u32( |
| 2299 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2300 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2301 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2302 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2303 | return -EINVAL; |
| 2304 | } |
| 2305 | |
| 2306 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2307 | |
| 2308 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2309 | params.auth_type = nla_get_u32( |
| 2310 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2311 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2312 | return -EINVAL; |
| 2313 | } else |
| 2314 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2315 | |
| 2316 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2317 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2318 | if (err) |
| 2319 | return err; |
| 2320 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2321 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2322 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2323 | return -EOPNOTSUPP; |
| 2324 | params.inactivity_timeout = nla_get_u16( |
| 2325 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2326 | } |
| 2327 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame^] | 2328 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2329 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 2330 | |
| 2331 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 2332 | !nl80211_valid_channel_type(info, &channel_type)) |
| 2333 | return -EINVAL; |
| 2334 | |
| 2335 | params.channel = rdev_freq_to_chan(rdev, |
| 2336 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 2337 | channel_type); |
| 2338 | if (!params.channel) |
| 2339 | return -EINVAL; |
| 2340 | params.channel_type = channel_type; |
| 2341 | } else if (wdev->preset_chan) { |
| 2342 | params.channel = wdev->preset_chan; |
| 2343 | params.channel_type = wdev->preset_chantype; |
| 2344 | } else |
| 2345 | return -EINVAL; |
| 2346 | |
| 2347 | if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel, |
| 2348 | params.channel_type)) |
| 2349 | return -EINVAL; |
| 2350 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2351 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
| 2352 | if (!err) |
| 2353 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2354 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2355 | } |
| 2356 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2357 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2358 | { |
| 2359 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2360 | struct net_device *dev = info->user_ptr[1]; |
| 2361 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2362 | struct cfg80211_beacon_data params; |
| 2363 | int err; |
| 2364 | |
| 2365 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2366 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2367 | return -EOPNOTSUPP; |
| 2368 | |
| 2369 | if (!rdev->ops->change_beacon) |
| 2370 | return -EOPNOTSUPP; |
| 2371 | |
| 2372 | if (!wdev->beacon_interval) |
| 2373 | return -EINVAL; |
| 2374 | |
| 2375 | err = nl80211_parse_beacon(info, ¶ms); |
| 2376 | if (err) |
| 2377 | return err; |
| 2378 | |
| 2379 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); |
| 2380 | } |
| 2381 | |
| 2382 | 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] | 2383 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2384 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2385 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2386 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2387 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2388 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2389 | if (!rdev->ops->stop_ap) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2390 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2391 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2392 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2393 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2394 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2395 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2396 | if (!wdev->beacon_interval) |
| 2397 | return -ENOENT; |
| 2398 | |
| 2399 | err = rdev->ops->stop_ap(&rdev->wiphy, dev); |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2400 | if (!err) |
| 2401 | wdev->beacon_interval = 0; |
| 2402 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2403 | } |
| 2404 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2405 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2406 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2407 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2408 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2409 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2410 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2411 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2412 | }; |
| 2413 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2414 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2415 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2416 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2417 | { |
| 2418 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2419 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2420 | int flag; |
| 2421 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2422 | /* |
| 2423 | * Try parsing the new attribute first so userspace |
| 2424 | * can specify both for older kernels. |
| 2425 | */ |
| 2426 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2427 | if (nla) { |
| 2428 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2429 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2430 | sta_flags = nla_data(nla); |
| 2431 | params->sta_flags_mask = sta_flags->mask; |
| 2432 | params->sta_flags_set = sta_flags->set; |
| 2433 | if ((params->sta_flags_mask | |
| 2434 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2435 | return -EINVAL; |
| 2436 | return 0; |
| 2437 | } |
| 2438 | |
| 2439 | /* if present, parse the old attribute */ |
| 2440 | |
| 2441 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2442 | if (!nla) |
| 2443 | return 0; |
| 2444 | |
| 2445 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2446 | nla, sta_flags_policy)) |
| 2447 | return -EINVAL; |
| 2448 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2449 | /* |
| 2450 | * Only allow certain flags for interface types so that |
| 2451 | * other attributes are silently ignored. Remember that |
| 2452 | * this is backward compatibility code with old userspace |
| 2453 | * and shouldn't be hit in other cases anyway. |
| 2454 | */ |
| 2455 | switch (iftype) { |
| 2456 | case NL80211_IFTYPE_AP: |
| 2457 | case NL80211_IFTYPE_AP_VLAN: |
| 2458 | case NL80211_IFTYPE_P2P_GO: |
| 2459 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2460 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2461 | BIT(NL80211_STA_FLAG_WME) | |
| 2462 | BIT(NL80211_STA_FLAG_MFP); |
| 2463 | break; |
| 2464 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2465 | case NL80211_IFTYPE_STATION: |
| 2466 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2467 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2468 | break; |
| 2469 | case NL80211_IFTYPE_MESH_POINT: |
| 2470 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2471 | BIT(NL80211_STA_FLAG_MFP) | |
| 2472 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2473 | default: |
| 2474 | return -EINVAL; |
| 2475 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2476 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2477 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 2478 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2479 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2480 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 2481 | /* no longer support new API additions in old API */ |
| 2482 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 2483 | return -EINVAL; |
| 2484 | } |
| 2485 | } |
| 2486 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2487 | return 0; |
| 2488 | } |
| 2489 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2490 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2491 | int attr) |
| 2492 | { |
| 2493 | struct nlattr *rate; |
| 2494 | u16 bitrate; |
| 2495 | |
| 2496 | rate = nla_nest_start(msg, attr); |
| 2497 | if (!rate) |
| 2498 | goto nla_put_failure; |
| 2499 | |
| 2500 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2501 | bitrate = cfg80211_calculate_bitrate(info); |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2502 | if ((bitrate > 0 && |
| 2503 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) || |
| 2504 | ((info->flags & RATE_INFO_FLAGS_MCS) && |
| 2505 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || |
| 2506 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && |
| 2507 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || |
| 2508 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && |
| 2509 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) |
| 2510 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2511 | |
| 2512 | nla_nest_end(msg, rate); |
| 2513 | return true; |
| 2514 | |
| 2515 | nla_put_failure: |
| 2516 | return false; |
| 2517 | } |
| 2518 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2519 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2520 | int flags, |
| 2521 | struct cfg80211_registered_device *rdev, |
| 2522 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2523 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2524 | { |
| 2525 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2526 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2527 | |
| 2528 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2529 | if (!hdr) |
| 2530 | return -1; |
| 2531 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2532 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2533 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 2534 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 2535 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2536 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2537 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2538 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2539 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2540 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 2541 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2542 | sinfo->connected_time)) |
| 2543 | goto nla_put_failure; |
| 2544 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 2545 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2546 | sinfo->inactive_time)) |
| 2547 | goto nla_put_failure; |
| 2548 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && |
| 2549 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2550 | sinfo->rx_bytes)) |
| 2551 | goto nla_put_failure; |
| 2552 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && |
| 2553 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2554 | sinfo->tx_bytes)) |
| 2555 | goto nla_put_failure; |
| 2556 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 2557 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 2558 | goto nla_put_failure; |
| 2559 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 2560 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 2561 | goto nla_put_failure; |
| 2562 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 2563 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2564 | sinfo->plink_state)) |
| 2565 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2566 | switch (rdev->wiphy.signal_type) { |
| 2567 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2568 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 2569 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 2570 | sinfo->signal)) |
| 2571 | goto nla_put_failure; |
| 2572 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 2573 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2574 | sinfo->signal_avg)) |
| 2575 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2576 | break; |
| 2577 | default: |
| 2578 | break; |
| 2579 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2580 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2581 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2582 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2583 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2584 | } |
| 2585 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2586 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2587 | NL80211_STA_INFO_RX_BITRATE)) |
| 2588 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2589 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2590 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 2591 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2592 | sinfo->rx_packets)) |
| 2593 | goto nla_put_failure; |
| 2594 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 2595 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2596 | sinfo->tx_packets)) |
| 2597 | goto nla_put_failure; |
| 2598 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 2599 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2600 | sinfo->tx_retries)) |
| 2601 | goto nla_put_failure; |
| 2602 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 2603 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2604 | sinfo->tx_failed)) |
| 2605 | goto nla_put_failure; |
| 2606 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 2607 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2608 | sinfo->beacon_loss_count)) |
| 2609 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2610 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2611 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2612 | if (!bss_param) |
| 2613 | goto nla_put_failure; |
| 2614 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2615 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 2616 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 2617 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 2618 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 2619 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 2620 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 2621 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2622 | sinfo->bss_param.dtim_period) || |
| 2623 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2624 | sinfo->bss_param.beacon_interval)) |
| 2625 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2626 | |
| 2627 | nla_nest_end(msg, bss_param); |
| 2628 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2629 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 2630 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2631 | sizeof(struct nl80211_sta_flag_update), |
| 2632 | &sinfo->sta_flags)) |
| 2633 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 2634 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 2635 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 2636 | sinfo->t_offset)) |
| 2637 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2638 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2639 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2640 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 2641 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2642 | sinfo->assoc_req_ies)) |
| 2643 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2644 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2645 | return genlmsg_end(msg, hdr); |
| 2646 | |
| 2647 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2648 | genlmsg_cancel(msg, hdr); |
| 2649 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2650 | } |
| 2651 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2652 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2653 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2654 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2655 | struct station_info sinfo; |
| 2656 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2657 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2658 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2659 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2660 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2661 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2662 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2663 | if (err) |
| 2664 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2665 | |
| 2666 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2667 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2668 | goto out_err; |
| 2669 | } |
| 2670 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2671 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2672 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2673 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2674 | mac_addr, &sinfo); |
| 2675 | if (err == -ENOENT) |
| 2676 | break; |
| 2677 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2678 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2679 | |
| 2680 | if (nl80211_send_station(skb, |
| 2681 | NETLINK_CB(cb->skb).pid, |
| 2682 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2683 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2684 | &sinfo) < 0) |
| 2685 | goto out; |
| 2686 | |
| 2687 | sta_idx++; |
| 2688 | } |
| 2689 | |
| 2690 | |
| 2691 | out: |
| 2692 | cb->args[1] = sta_idx; |
| 2693 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2694 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2695 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2696 | |
| 2697 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2698 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2699 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2700 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2701 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2703 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2704 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2705 | struct sk_buff *msg; |
| 2706 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2707 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2708 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2709 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2710 | |
| 2711 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2712 | return -EINVAL; |
| 2713 | |
| 2714 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2715 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2716 | if (!rdev->ops->get_station) |
| 2717 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2718 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2719 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2720 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2721 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2722 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2723 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2724 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2725 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2726 | |
| 2727 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2728 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2729 | nlmsg_free(msg); |
| 2730 | return -ENOBUFS; |
| 2731 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2732 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2733 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2737 | * 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] | 2738 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2739 | static struct net_device *get_vlan(struct genl_info *info, |
| 2740 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2741 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2742 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2743 | struct net_device *v; |
| 2744 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2745 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2746 | if (!vlanattr) |
| 2747 | return NULL; |
| 2748 | |
| 2749 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 2750 | if (!v) |
| 2751 | return ERR_PTR(-ENODEV); |
| 2752 | |
| 2753 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 2754 | ret = -EINVAL; |
| 2755 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2756 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2757 | |
| 2758 | if (!netif_running(v)) { |
| 2759 | ret = -ENETDOWN; |
| 2760 | goto error; |
| 2761 | } |
| 2762 | |
| 2763 | return v; |
| 2764 | error: |
| 2765 | dev_put(v); |
| 2766 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2770 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2771 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2772 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2773 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2774 | struct station_parameters params; |
| 2775 | u8 *mac_addr = NULL; |
| 2776 | |
| 2777 | memset(¶ms, 0, sizeof(params)); |
| 2778 | |
| 2779 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2780 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2781 | |
| 2782 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2783 | return -EINVAL; |
| 2784 | |
| 2785 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2786 | return -EINVAL; |
| 2787 | |
| 2788 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2789 | |
| 2790 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2791 | params.supported_rates = |
| 2792 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2793 | params.supported_rates_len = |
| 2794 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2795 | } |
| 2796 | |
| 2797 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2798 | params.listen_interval = |
| 2799 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2800 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2801 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2802 | params.ht_capa = |
| 2803 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2804 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2805 | if (!rdev->ops->change_station) |
| 2806 | return -EOPNOTSUPP; |
| 2807 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2808 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2809 | return -EINVAL; |
| 2810 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2811 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2812 | params.plink_action = |
| 2813 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2814 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2815 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2816 | params.plink_state = |
| 2817 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2818 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2819 | switch (dev->ieee80211_ptr->iftype) { |
| 2820 | case NL80211_IFTYPE_AP: |
| 2821 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2822 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2823 | /* disallow mesh-specific things */ |
| 2824 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2825 | return -EINVAL; |
| 2826 | |
| 2827 | /* TDLS can't be set, ... */ |
| 2828 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 2829 | return -EINVAL; |
| 2830 | /* |
| 2831 | * ... but don't bother the driver with it. This works around |
| 2832 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 2833 | * TLDS_PEER flag in the mask even for AP mode. |
| 2834 | */ |
| 2835 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2836 | |
| 2837 | /* accept only the listed bits */ |
| 2838 | if (params.sta_flags_mask & |
| 2839 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2840 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2841 | BIT(NL80211_STA_FLAG_WME) | |
| 2842 | BIT(NL80211_STA_FLAG_MFP))) |
| 2843 | return -EINVAL; |
| 2844 | |
| 2845 | /* must be last in here for error handling */ |
| 2846 | params.vlan = get_vlan(info, rdev); |
| 2847 | if (IS_ERR(params.vlan)) |
| 2848 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2849 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2850 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2851 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2852 | /* |
| 2853 | * Don't allow userspace to change the TDLS_PEER flag, |
| 2854 | * but silently ignore attempts to change it since we |
| 2855 | * don't have state here to verify that it doesn't try |
| 2856 | * to change the flag. |
| 2857 | */ |
| 2858 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 2859 | /* fall through */ |
| 2860 | case NL80211_IFTYPE_ADHOC: |
| 2861 | /* disallow things sta doesn't support */ |
| 2862 | if (params.plink_action) |
| 2863 | return -EINVAL; |
| 2864 | if (params.ht_capa) |
| 2865 | return -EINVAL; |
| 2866 | if (params.listen_interval >= 0) |
| 2867 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2868 | /* reject any changes other than AUTHORIZED */ |
| 2869 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2870 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2871 | break; |
| 2872 | case NL80211_IFTYPE_MESH_POINT: |
| 2873 | /* disallow things mesh doesn't support */ |
| 2874 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2875 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2876 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2877 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2878 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2879 | return -EINVAL; |
| 2880 | /* |
| 2881 | * No special handling for TDLS here -- the userspace |
| 2882 | * mesh code doesn't have this bug. |
| 2883 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2884 | if (params.sta_flags_mask & |
| 2885 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2886 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2887 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2888 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2889 | break; |
| 2890 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2891 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2892 | } |
| 2893 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2894 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2895 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2896 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2897 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2898 | if (params.vlan) |
| 2899 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2900 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2901 | return err; |
| 2902 | } |
| 2903 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2904 | static struct nla_policy |
| 2905 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2906 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2907 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2908 | }; |
| 2909 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2910 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2911 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2912 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2913 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2914 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2915 | struct station_parameters params; |
| 2916 | u8 *mac_addr = NULL; |
| 2917 | |
| 2918 | memset(¶ms, 0, sizeof(params)); |
| 2919 | |
| 2920 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2921 | return -EINVAL; |
| 2922 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2923 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2924 | return -EINVAL; |
| 2925 | |
| 2926 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2927 | return -EINVAL; |
| 2928 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2929 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2930 | return -EINVAL; |
| 2931 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2932 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2933 | params.supported_rates = |
| 2934 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2935 | params.supported_rates_len = |
| 2936 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2937 | params.listen_interval = |
| 2938 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2939 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2940 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2941 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2942 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2943 | |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2944 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2945 | params.ht_capa = |
| 2946 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2947 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2948 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2949 | params.plink_action = |
| 2950 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2951 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2952 | if (!rdev->ops->add_station) |
| 2953 | return -EOPNOTSUPP; |
| 2954 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2955 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2956 | return -EINVAL; |
| 2957 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2958 | switch (dev->ieee80211_ptr->iftype) { |
| 2959 | case NL80211_IFTYPE_AP: |
| 2960 | case NL80211_IFTYPE_AP_VLAN: |
| 2961 | case NL80211_IFTYPE_P2P_GO: |
| 2962 | /* parse WME attributes if sta is WME capable */ |
| 2963 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 2964 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 2965 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2966 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2967 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2968 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2969 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2970 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2971 | nl80211_sta_wme_policy); |
| 2972 | if (err) |
| 2973 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2974 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2975 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2976 | params.uapsd_queues = |
| 2977 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 2978 | if (params.uapsd_queues & |
| 2979 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2980 | return -EINVAL; |
| 2981 | |
| 2982 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2983 | params.max_sp = |
| 2984 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 2985 | |
| 2986 | if (params.max_sp & |
| 2987 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2988 | return -EINVAL; |
| 2989 | |
| 2990 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 2991 | } |
| 2992 | /* TDLS peers cannot be added */ |
| 2993 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2994 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2995 | /* but don't bother the driver with it */ |
| 2996 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2997 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2998 | /* must be last in here for error handling */ |
| 2999 | params.vlan = get_vlan(info, rdev); |
| 3000 | if (IS_ERR(params.vlan)) |
| 3001 | return PTR_ERR(params.vlan); |
| 3002 | break; |
| 3003 | case NL80211_IFTYPE_MESH_POINT: |
| 3004 | /* TDLS peers cannot be added */ |
| 3005 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 3006 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3007 | break; |
| 3008 | case NL80211_IFTYPE_STATION: |
| 3009 | /* Only TDLS peers can be added */ |
| 3010 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3011 | return -EINVAL; |
| 3012 | /* Can only add if TDLS ... */ |
| 3013 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 3014 | return -EOPNOTSUPP; |
| 3015 | /* ... with external setup is supported */ |
| 3016 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 3017 | return -EOPNOTSUPP; |
| 3018 | break; |
| 3019 | default: |
| 3020 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 3021 | } |
| 3022 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 3023 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3024 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3025 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3026 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3027 | if (params.vlan) |
| 3028 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3029 | return err; |
| 3030 | } |
| 3031 | |
| 3032 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 3033 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3035 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3036 | u8 *mac_addr = NULL; |
| 3037 | |
| 3038 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3039 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3040 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3041 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 3042 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3043 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3044 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3045 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 3046 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3047 | if (!rdev->ops->del_station) |
| 3048 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3049 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3050 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3051 | } |
| 3052 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3053 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 3054 | int flags, struct net_device *dev, |
| 3055 | u8 *dst, u8 *next_hop, |
| 3056 | struct mpath_info *pinfo) |
| 3057 | { |
| 3058 | void *hdr; |
| 3059 | struct nlattr *pinfoattr; |
| 3060 | |
| 3061 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 3062 | if (!hdr) |
| 3063 | return -1; |
| 3064 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3065 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3066 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 3067 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 3068 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 3069 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3070 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3071 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 3072 | if (!pinfoattr) |
| 3073 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3074 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 3075 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 3076 | pinfo->frame_qlen)) |
| 3077 | goto nla_put_failure; |
| 3078 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 3079 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 3080 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 3081 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 3082 | pinfo->metric)) || |
| 3083 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 3084 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 3085 | pinfo->exptime)) || |
| 3086 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 3087 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 3088 | pinfo->flags)) || |
| 3089 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 3090 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 3091 | pinfo->discovery_timeout)) || |
| 3092 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 3093 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 3094 | pinfo->discovery_retries))) |
| 3095 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3096 | |
| 3097 | nla_nest_end(msg, pinfoattr); |
| 3098 | |
| 3099 | return genlmsg_end(msg, hdr); |
| 3100 | |
| 3101 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3102 | genlmsg_cancel(msg, hdr); |
| 3103 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3107 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3108 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3109 | struct mpath_info pinfo; |
| 3110 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3111 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3112 | u8 dst[ETH_ALEN]; |
| 3113 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3114 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3115 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3116 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3117 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 3118 | if (err) |
| 3119 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3120 | |
| 3121 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3122 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3123 | goto out_err; |
| 3124 | } |
| 3125 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3126 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 3127 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 3128 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3129 | } |
| 3130 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3131 | while (1) { |
| 3132 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 3133 | dst, next_hop, &pinfo); |
| 3134 | if (err == -ENOENT) |
| 3135 | break; |
| 3136 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3137 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3138 | |
| 3139 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 3140 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 3141 | netdev, dst, next_hop, |
| 3142 | &pinfo) < 0) |
| 3143 | goto out; |
| 3144 | |
| 3145 | path_idx++; |
| 3146 | } |
| 3147 | |
| 3148 | |
| 3149 | out: |
| 3150 | cb->args[1] = path_idx; |
| 3151 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3152 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3153 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3154 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3155 | } |
| 3156 | |
| 3157 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3158 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3160 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3161 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3162 | struct mpath_info pinfo; |
| 3163 | struct sk_buff *msg; |
| 3164 | u8 *dst = NULL; |
| 3165 | u8 next_hop[ETH_ALEN]; |
| 3166 | |
| 3167 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3168 | |
| 3169 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3170 | return -EINVAL; |
| 3171 | |
| 3172 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3173 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3174 | if (!rdev->ops->get_mpath) |
| 3175 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3176 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3177 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3178 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3179 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3180 | 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] | 3181 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3182 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3183 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3184 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3185 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3186 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3187 | |
| 3188 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3189 | dev, dst, next_hop, &pinfo) < 0) { |
| 3190 | nlmsg_free(msg); |
| 3191 | return -ENOBUFS; |
| 3192 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3193 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3194 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3198 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3200 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3201 | u8 *dst = NULL; |
| 3202 | u8 *next_hop = NULL; |
| 3203 | |
| 3204 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3205 | return -EINVAL; |
| 3206 | |
| 3207 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3208 | return -EINVAL; |
| 3209 | |
| 3210 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3211 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3212 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3213 | if (!rdev->ops->change_mpath) |
| 3214 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3215 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3216 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3217 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3218 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3219 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3220 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3221 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3222 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3223 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3225 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3226 | u8 *dst = NULL; |
| 3227 | u8 *next_hop = NULL; |
| 3228 | |
| 3229 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3230 | return -EINVAL; |
| 3231 | |
| 3232 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3233 | return -EINVAL; |
| 3234 | |
| 3235 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3236 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3237 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3238 | if (!rdev->ops->add_mpath) |
| 3239 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3240 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3241 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3242 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3243 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3244 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3248 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3249 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3250 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3251 | u8 *dst = NULL; |
| 3252 | |
| 3253 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3254 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3255 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3256 | if (!rdev->ops->del_mpath) |
| 3257 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3258 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3259 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3260 | } |
| 3261 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3262 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3263 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3264 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3265 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3266 | struct bss_parameters params; |
| 3267 | |
| 3268 | memset(¶ms, 0, sizeof(params)); |
| 3269 | /* default to not changing parameters */ |
| 3270 | params.use_cts_prot = -1; |
| 3271 | params.use_short_preamble = -1; |
| 3272 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3273 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3274 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3275 | |
| 3276 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3277 | params.use_cts_prot = |
| 3278 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3279 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3280 | params.use_short_preamble = |
| 3281 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3282 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3283 | params.use_short_slot_time = |
| 3284 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3285 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3286 | params.basic_rates = |
| 3287 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3288 | params.basic_rates_len = |
| 3289 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3290 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3291 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3292 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3293 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3294 | params.ht_opmode = |
| 3295 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3296 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3297 | if (!rdev->ops->change_bss) |
| 3298 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3299 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3300 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3301 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3302 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3303 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3304 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3305 | } |
| 3306 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3307 | 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] | 3308 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3309 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3310 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3311 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3312 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3313 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3314 | }; |
| 3315 | |
| 3316 | static int parse_reg_rule(struct nlattr *tb[], |
| 3317 | struct ieee80211_reg_rule *reg_rule) |
| 3318 | { |
| 3319 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3320 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3321 | |
| 3322 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3323 | return -EINVAL; |
| 3324 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3325 | return -EINVAL; |
| 3326 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3327 | return -EINVAL; |
| 3328 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3329 | return -EINVAL; |
| 3330 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3331 | return -EINVAL; |
| 3332 | |
| 3333 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3334 | |
| 3335 | freq_range->start_freq_khz = |
| 3336 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3337 | freq_range->end_freq_khz = |
| 3338 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3339 | freq_range->max_bandwidth_khz = |
| 3340 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3341 | |
| 3342 | power_rule->max_eirp = |
| 3343 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3344 | |
| 3345 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3346 | power_rule->max_antenna_gain = |
| 3347 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3348 | |
| 3349 | return 0; |
| 3350 | } |
| 3351 | |
| 3352 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3353 | { |
| 3354 | int r; |
| 3355 | char *data = NULL; |
| 3356 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3357 | /* |
| 3358 | * You should only get this when cfg80211 hasn't yet initialized |
| 3359 | * completely when built-in to the kernel right between the time |
| 3360 | * window between nl80211_init() and regulatory_init(), if that is |
| 3361 | * even possible. |
| 3362 | */ |
| 3363 | mutex_lock(&cfg80211_mutex); |
| 3364 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3365 | mutex_unlock(&cfg80211_mutex); |
| 3366 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3367 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3368 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3369 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3370 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3371 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3372 | |
| 3373 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3374 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3375 | r = regulatory_hint_user(data); |
| 3376 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3377 | return r; |
| 3378 | } |
| 3379 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3380 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3381 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3382 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3383 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3384 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3385 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3386 | struct mesh_config cur_params; |
| 3387 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3388 | void *hdr; |
| 3389 | struct nlattr *pinfoattr; |
| 3390 | struct sk_buff *msg; |
| 3391 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3392 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3393 | return -EOPNOTSUPP; |
| 3394 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3395 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3396 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3397 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3398 | wdev_lock(wdev); |
| 3399 | /* If not connected, get default parameters */ |
| 3400 | if (!wdev->mesh_id_len) |
| 3401 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3402 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3403 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3404 | &cur_params); |
| 3405 | wdev_unlock(wdev); |
| 3406 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3407 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3408 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3409 | |
| 3410 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3411 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3412 | if (!msg) |
| 3413 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3414 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3415 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3416 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3417 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3418 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3419 | if (!pinfoattr) |
| 3420 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3421 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3422 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3423 | cur_params.dot11MeshRetryTimeout) || |
| 3424 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3425 | cur_params.dot11MeshConfirmTimeout) || |
| 3426 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3427 | cur_params.dot11MeshHoldingTimeout) || |
| 3428 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3429 | cur_params.dot11MeshMaxPeerLinks) || |
| 3430 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3431 | cur_params.dot11MeshMaxRetries) || |
| 3432 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 3433 | cur_params.dot11MeshTTL) || |
| 3434 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3435 | cur_params.element_ttl) || |
| 3436 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3437 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3438 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3439 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3440 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3441 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 3442 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3443 | cur_params.path_refresh_time) || |
| 3444 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3445 | cur_params.min_discovery_timeout) || |
| 3446 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3447 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 3448 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3449 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 3450 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3451 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 3452 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3453 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 3454 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3455 | cur_params.dot11MeshHWMPRootMode) || |
| 3456 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3457 | cur_params.dot11MeshHWMPRannInterval) || |
| 3458 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3459 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 3460 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 3461 | cur_params.dot11MeshForwarding) || |
| 3462 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3463 | cur_params.rssi_threshold) || |
| 3464 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
| 3465 | cur_params.ht_opmode)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3466 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3467 | nla_nest_end(msg, pinfoattr); |
| 3468 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3469 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3470 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3471 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3472 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3473 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3474 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3475 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3478 | 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] | 3479 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3480 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3481 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3482 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3483 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3484 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3485 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3486 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3487 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3488 | |
| 3489 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3490 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3491 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3492 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3493 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3494 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3495 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3496 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3497 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3498 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3499 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3500 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32}, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3501 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16}, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3502 | }; |
| 3503 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3504 | static const struct nla_policy |
| 3505 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3506 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3507 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3508 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3509 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3510 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3511 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3512 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3513 | }; |
| 3514 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3515 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3516 | struct mesh_config *cfg, |
| 3517 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3518 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3519 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3520 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3521 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3522 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3523 | do {\ |
| 3524 | if (table[attr_num]) {\ |
| 3525 | cfg->param = nla_fn(table[attr_num]); \ |
| 3526 | mask |= (1 << (attr_num - 1)); \ |
| 3527 | } \ |
| 3528 | } while (0);\ |
| 3529 | |
| 3530 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3531 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3532 | return -EINVAL; |
| 3533 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3534 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3535 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3536 | return -EINVAL; |
| 3537 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3538 | /* This makes sure that there aren't more than 32 mesh config |
| 3539 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3540 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3541 | |
| 3542 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3543 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3544 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3545 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3546 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3547 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3548 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3549 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3550 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3551 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3552 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3553 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3554 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3555 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3556 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3557 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3558 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3559 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 3560 | mask, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3561 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3562 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3563 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3564 | nla_get_u8); |
| 3565 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3566 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3567 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3568 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3569 | nla_get_u16); |
| 3570 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3571 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3572 | nla_get_u32); |
| 3573 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3574 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3575 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3576 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
| 3577 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3578 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3579 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3580 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3581 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3582 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3583 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3584 | dot11MeshHWMPRootMode, mask, |
| 3585 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3586 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3587 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3588 | dot11MeshHWMPRannInterval, mask, |
| 3589 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3590 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3591 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3592 | dot11MeshGateAnnouncementProtocol, mask, |
| 3593 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3594 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3595 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
| 3596 | mask, NL80211_MESHCONF_FORWARDING, nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3597 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
| 3598 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32); |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 3599 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
| 3600 | mask, NL80211_MESHCONF_HT_OPMODE, nla_get_u16); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3601 | if (mask_out) |
| 3602 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3603 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3604 | return 0; |
| 3605 | |
| 3606 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3607 | } |
| 3608 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3609 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3610 | struct mesh_setup *setup) |
| 3611 | { |
| 3612 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3613 | |
| 3614 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3615 | return -EINVAL; |
| 3616 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3617 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3618 | nl80211_mesh_setup_params_policy)) |
| 3619 | return -EINVAL; |
| 3620 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3621 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 3622 | setup->sync_method = |
| 3623 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 3624 | IEEE80211_SYNC_METHOD_VENDOR : |
| 3625 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 3626 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3627 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3628 | setup->path_sel_proto = |
| 3629 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3630 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3631 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3632 | |
| 3633 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3634 | setup->path_metric = |
| 3635 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3636 | IEEE80211_PATH_METRIC_VENDOR : |
| 3637 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3638 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3639 | |
| 3640 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3641 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3642 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3643 | if (!is_valid_ie_attr(ieattr)) |
| 3644 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3645 | setup->ie = nla_data(ieattr); |
| 3646 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3647 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3648 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3649 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3650 | |
| 3651 | return 0; |
| 3652 | } |
| 3653 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3654 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3655 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3656 | { |
| 3657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3658 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3659 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3660 | struct mesh_config cfg; |
| 3661 | u32 mask; |
| 3662 | int err; |
| 3663 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3664 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3665 | return -EOPNOTSUPP; |
| 3666 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3667 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3668 | return -EOPNOTSUPP; |
| 3669 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3670 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3671 | if (err) |
| 3672 | return err; |
| 3673 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3674 | wdev_lock(wdev); |
| 3675 | if (!wdev->mesh_id_len) |
| 3676 | err = -ENOLINK; |
| 3677 | |
| 3678 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3679 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3680 | mask, &cfg); |
| 3681 | |
| 3682 | wdev_unlock(wdev); |
| 3683 | |
| 3684 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3685 | } |
| 3686 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3687 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3688 | { |
| 3689 | struct sk_buff *msg; |
| 3690 | void *hdr = NULL; |
| 3691 | struct nlattr *nl_reg_rules; |
| 3692 | unsigned int i; |
| 3693 | int err = -EINVAL; |
| 3694 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3695 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3696 | |
| 3697 | if (!cfg80211_regdomain) |
| 3698 | goto out; |
| 3699 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3700 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3701 | if (!msg) { |
| 3702 | err = -ENOBUFS; |
| 3703 | goto out; |
| 3704 | } |
| 3705 | |
| 3706 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3707 | NL80211_CMD_GET_REG); |
| 3708 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3709 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3710 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3711 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 3712 | cfg80211_regdomain->alpha2) || |
| 3713 | (cfg80211_regdomain->dfs_region && |
| 3714 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, |
| 3715 | cfg80211_regdomain->dfs_region))) |
| 3716 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3717 | |
| 3718 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3719 | if (!nl_reg_rules) |
| 3720 | goto nla_put_failure; |
| 3721 | |
| 3722 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3723 | struct nlattr *nl_reg_rule; |
| 3724 | const struct ieee80211_reg_rule *reg_rule; |
| 3725 | const struct ieee80211_freq_range *freq_range; |
| 3726 | const struct ieee80211_power_rule *power_rule; |
| 3727 | |
| 3728 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3729 | freq_range = ®_rule->freq_range; |
| 3730 | power_rule = ®_rule->power_rule; |
| 3731 | |
| 3732 | nl_reg_rule = nla_nest_start(msg, i); |
| 3733 | if (!nl_reg_rule) |
| 3734 | goto nla_put_failure; |
| 3735 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3736 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3737 | reg_rule->flags) || |
| 3738 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3739 | freq_range->start_freq_khz) || |
| 3740 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3741 | freq_range->end_freq_khz) || |
| 3742 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3743 | freq_range->max_bandwidth_khz) || |
| 3744 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3745 | power_rule->max_antenna_gain) || |
| 3746 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3747 | power_rule->max_eirp)) |
| 3748 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3749 | |
| 3750 | nla_nest_end(msg, nl_reg_rule); |
| 3751 | } |
| 3752 | |
| 3753 | nla_nest_end(msg, nl_reg_rules); |
| 3754 | |
| 3755 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3756 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3757 | goto out; |
| 3758 | |
| 3759 | nla_put_failure: |
| 3760 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3761 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3762 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3763 | err = -EMSGSIZE; |
| 3764 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3765 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3766 | return err; |
| 3767 | } |
| 3768 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3769 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3770 | { |
| 3771 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3772 | struct nlattr *nl_reg_rule; |
| 3773 | char *alpha2 = NULL; |
| 3774 | int rem_reg_rules = 0, r = 0; |
| 3775 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3776 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3777 | struct ieee80211_regdomain *rd = NULL; |
| 3778 | |
| 3779 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3780 | return -EINVAL; |
| 3781 | |
| 3782 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3783 | return -EINVAL; |
| 3784 | |
| 3785 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3786 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3787 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 3788 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 3789 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3790 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3791 | rem_reg_rules) { |
| 3792 | num_rules++; |
| 3793 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3794 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3797 | mutex_lock(&cfg80211_mutex); |
| 3798 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3799 | if (!reg_is_valid_request(alpha2)) { |
| 3800 | r = -EINVAL; |
| 3801 | goto bad_reg; |
| 3802 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3803 | |
| 3804 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3805 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3806 | |
| 3807 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3808 | if (!rd) { |
| 3809 | r = -ENOMEM; |
| 3810 | goto bad_reg; |
| 3811 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3812 | |
| 3813 | rd->n_reg_rules = num_rules; |
| 3814 | rd->alpha2[0] = alpha2[0]; |
| 3815 | rd->alpha2[1] = alpha2[1]; |
| 3816 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3817 | /* |
| 3818 | * Disable DFS master mode if the DFS region was |
| 3819 | * not supported or known on this kernel. |
| 3820 | */ |
| 3821 | if (reg_supported_dfs_region(dfs_region)) |
| 3822 | rd->dfs_region = dfs_region; |
| 3823 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3824 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3825 | rem_reg_rules) { |
| 3826 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3827 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3828 | reg_rule_policy); |
| 3829 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3830 | if (r) |
| 3831 | goto bad_reg; |
| 3832 | |
| 3833 | rule_idx++; |
| 3834 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3835 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3836 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3837 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3838 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | BUG_ON(rule_idx != num_rules); |
| 3842 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3843 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3844 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3845 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3846 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3847 | return r; |
| 3848 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3849 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3850 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3851 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3852 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3853 | } |
| 3854 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3855 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3856 | { |
| 3857 | struct nlattr *attr1, *attr2; |
| 3858 | int n_channels = 0, tmp1, tmp2; |
| 3859 | |
| 3860 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3861 | n_channels++; |
| 3862 | /* |
| 3863 | * Some hardware has a limited channel list for |
| 3864 | * scanning, and it is pretty much nonsensical |
| 3865 | * to scan for a channel twice, so disallow that |
| 3866 | * and don't require drivers to check that the |
| 3867 | * channel list they get isn't longer than what |
| 3868 | * they can scan, as long as they can scan all |
| 3869 | * the channels they registered at once. |
| 3870 | */ |
| 3871 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3872 | if (attr1 != attr2 && |
| 3873 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3874 | return 0; |
| 3875 | } |
| 3876 | |
| 3877 | return n_channels; |
| 3878 | } |
| 3879 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3880 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3881 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3882 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3883 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3884 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3885 | struct nlattr *attr; |
| 3886 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3887 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3888 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3889 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3890 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3891 | return -EINVAL; |
| 3892 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3893 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3894 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3895 | if (!rdev->ops->scan) |
| 3896 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3897 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3898 | if (rdev->scan_req) |
| 3899 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3900 | |
| 3901 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3902 | n_channels = validate_scan_freqs( |
| 3903 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3904 | if (!n_channels) |
| 3905 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3906 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3907 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3908 | n_channels = 0; |
| 3909 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3910 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3911 | if (wiphy->bands[band]) |
| 3912 | n_channels += wiphy->bands[band]->n_channels; |
| 3913 | } |
| 3914 | |
| 3915 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3916 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3917 | n_ssids++; |
| 3918 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3919 | if (n_ssids > wiphy->max_scan_ssids) |
| 3920 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3921 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3922 | if (info->attrs[NL80211_ATTR_IE]) |
| 3923 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3924 | else |
| 3925 | ie_len = 0; |
| 3926 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3927 | if (ie_len > wiphy->max_scan_ie_len) |
| 3928 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3929 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3930 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3931 | + sizeof(*request->ssids) * n_ssids |
| 3932 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3933 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3934 | if (!request) |
| 3935 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3936 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3937 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3938 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3939 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3940 | if (ie_len) { |
| 3941 | if (request->ssids) |
| 3942 | request->ie = (void *)(request->ssids + n_ssids); |
| 3943 | else |
| 3944 | request->ie = (void *)(request->channels + n_channels); |
| 3945 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3946 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3947 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3948 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3949 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3950 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3951 | struct ieee80211_channel *chan; |
| 3952 | |
| 3953 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3954 | |
| 3955 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3956 | err = -EINVAL; |
| 3957 | goto out_free; |
| 3958 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3959 | |
| 3960 | /* ignore disabled channels */ |
| 3961 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3962 | continue; |
| 3963 | |
| 3964 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3965 | i++; |
| 3966 | } |
| 3967 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3968 | enum ieee80211_band band; |
| 3969 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3970 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3971 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3972 | int j; |
| 3973 | if (!wiphy->bands[band]) |
| 3974 | continue; |
| 3975 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3976 | struct ieee80211_channel *chan; |
| 3977 | |
| 3978 | chan = &wiphy->bands[band]->channels[j]; |
| 3979 | |
| 3980 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3981 | continue; |
| 3982 | |
| 3983 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3984 | i++; |
| 3985 | } |
| 3986 | } |
| 3987 | } |
| 3988 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3989 | if (!i) { |
| 3990 | err = -EINVAL; |
| 3991 | goto out_free; |
| 3992 | } |
| 3993 | |
| 3994 | request->n_channels = i; |
| 3995 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3996 | i = 0; |
| 3997 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3998 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3999 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4000 | err = -EINVAL; |
| 4001 | goto out_free; |
| 4002 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4003 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4004 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4005 | i++; |
| 4006 | } |
| 4007 | } |
| 4008 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4009 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4010 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 4011 | memcpy((void *)request->ie, |
| 4012 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 4013 | request->ie_len); |
| 4014 | } |
| 4015 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4016 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 4017 | if (wiphy->bands[i]) |
| 4018 | request->rates[i] = |
| 4019 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4020 | |
| 4021 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 4022 | nla_for_each_nested(attr, |
| 4023 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 4024 | tmp) { |
| 4025 | enum ieee80211_band band = nla_type(attr); |
| 4026 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 4027 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4028 | err = -EINVAL; |
| 4029 | goto out_free; |
| 4030 | } |
| 4031 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 4032 | nla_data(attr), |
| 4033 | nla_len(attr), |
| 4034 | &request->rates[band]); |
| 4035 | if (err) |
| 4036 | goto out_free; |
| 4037 | } |
| 4038 | } |
| 4039 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 4040 | request->no_cck = |
| 4041 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 4042 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4043 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4044 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4045 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4046 | rdev->scan_req = request; |
| 4047 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4048 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4049 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4050 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4051 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4052 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4053 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4054 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4055 | kfree(request); |
| 4056 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4057 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4058 | return err; |
| 4059 | } |
| 4060 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4061 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 4062 | struct genl_info *info) |
| 4063 | { |
| 4064 | struct cfg80211_sched_scan_request *request; |
| 4065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4066 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4067 | struct nlattr *attr; |
| 4068 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4069 | 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] | 4070 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4071 | enum ieee80211_band band; |
| 4072 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4073 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4074 | |
| 4075 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4076 | !rdev->ops->sched_scan_start) |
| 4077 | return -EOPNOTSUPP; |
| 4078 | |
| 4079 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4080 | return -EINVAL; |
| 4081 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4082 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 4083 | return -EINVAL; |
| 4084 | |
| 4085 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 4086 | if (interval == 0) |
| 4087 | return -EINVAL; |
| 4088 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4089 | wiphy = &rdev->wiphy; |
| 4090 | |
| 4091 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4092 | n_channels = validate_scan_freqs( |
| 4093 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 4094 | if (!n_channels) |
| 4095 | return -EINVAL; |
| 4096 | } else { |
| 4097 | n_channels = 0; |
| 4098 | |
| 4099 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 4100 | if (wiphy->bands[band]) |
| 4101 | n_channels += wiphy->bands[band]->n_channels; |
| 4102 | } |
| 4103 | |
| 4104 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 4105 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4106 | tmp) |
| 4107 | n_ssids++; |
| 4108 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 4109 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4110 | return -EINVAL; |
| 4111 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4112 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 4113 | nla_for_each_nested(attr, |
| 4114 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4115 | tmp) |
| 4116 | n_match_sets++; |
| 4117 | |
| 4118 | if (n_match_sets > wiphy->max_match_sets) |
| 4119 | return -EINVAL; |
| 4120 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4121 | if (info->attrs[NL80211_ATTR_IE]) |
| 4122 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4123 | else |
| 4124 | ie_len = 0; |
| 4125 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 4126 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4127 | return -EINVAL; |
| 4128 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4129 | mutex_lock(&rdev->sched_scan_mtx); |
| 4130 | |
| 4131 | if (rdev->sched_scan_req) { |
| 4132 | err = -EINPROGRESS; |
| 4133 | goto out; |
| 4134 | } |
| 4135 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4136 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4137 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4138 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 4139 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4140 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4141 | if (!request) { |
| 4142 | err = -ENOMEM; |
| 4143 | goto out; |
| 4144 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4145 | |
| 4146 | if (n_ssids) |
| 4147 | request->ssids = (void *)&request->channels[n_channels]; |
| 4148 | request->n_ssids = n_ssids; |
| 4149 | if (ie_len) { |
| 4150 | if (request->ssids) |
| 4151 | request->ie = (void *)(request->ssids + n_ssids); |
| 4152 | else |
| 4153 | request->ie = (void *)(request->channels + n_channels); |
| 4154 | } |
| 4155 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4156 | if (n_match_sets) { |
| 4157 | if (request->ie) |
| 4158 | request->match_sets = (void *)(request->ie + ie_len); |
| 4159 | else if (request->ssids) |
| 4160 | request->match_sets = |
| 4161 | (void *)(request->ssids + n_ssids); |
| 4162 | else |
| 4163 | request->match_sets = |
| 4164 | (void *)(request->channels + n_channels); |
| 4165 | } |
| 4166 | request->n_match_sets = n_match_sets; |
| 4167 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4168 | i = 0; |
| 4169 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4170 | /* user specified, bail out if channel not found */ |
| 4171 | nla_for_each_nested(attr, |
| 4172 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4173 | tmp) { |
| 4174 | struct ieee80211_channel *chan; |
| 4175 | |
| 4176 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4177 | |
| 4178 | if (!chan) { |
| 4179 | err = -EINVAL; |
| 4180 | goto out_free; |
| 4181 | } |
| 4182 | |
| 4183 | /* ignore disabled channels */ |
| 4184 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4185 | continue; |
| 4186 | |
| 4187 | request->channels[i] = chan; |
| 4188 | i++; |
| 4189 | } |
| 4190 | } else { |
| 4191 | /* all channels */ |
| 4192 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4193 | int j; |
| 4194 | if (!wiphy->bands[band]) |
| 4195 | continue; |
| 4196 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4197 | struct ieee80211_channel *chan; |
| 4198 | |
| 4199 | chan = &wiphy->bands[band]->channels[j]; |
| 4200 | |
| 4201 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4202 | continue; |
| 4203 | |
| 4204 | request->channels[i] = chan; |
| 4205 | i++; |
| 4206 | } |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | if (!i) { |
| 4211 | err = -EINVAL; |
| 4212 | goto out_free; |
| 4213 | } |
| 4214 | |
| 4215 | request->n_channels = i; |
| 4216 | |
| 4217 | i = 0; |
| 4218 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4219 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4220 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4221 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4222 | err = -EINVAL; |
| 4223 | goto out_free; |
| 4224 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4225 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4226 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4227 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4228 | i++; |
| 4229 | } |
| 4230 | } |
| 4231 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4232 | i = 0; |
| 4233 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4234 | nla_for_each_nested(attr, |
| 4235 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4236 | tmp) { |
| 4237 | struct nlattr *ssid; |
| 4238 | |
| 4239 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4240 | nla_data(attr), nla_len(attr), |
| 4241 | nl80211_match_policy); |
| 4242 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 4243 | if (ssid) { |
| 4244 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4245 | err = -EINVAL; |
| 4246 | goto out_free; |
| 4247 | } |
| 4248 | memcpy(request->match_sets[i].ssid.ssid, |
| 4249 | nla_data(ssid), nla_len(ssid)); |
| 4250 | request->match_sets[i].ssid.ssid_len = |
| 4251 | nla_len(ssid); |
| 4252 | } |
| 4253 | i++; |
| 4254 | } |
| 4255 | } |
| 4256 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4257 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4258 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4259 | memcpy((void *)request->ie, |
| 4260 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4261 | request->ie_len); |
| 4262 | } |
| 4263 | |
| 4264 | request->dev = dev; |
| 4265 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4266 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4267 | |
| 4268 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 4269 | if (!err) { |
| 4270 | rdev->sched_scan_req = request; |
| 4271 | nl80211_send_sched_scan(rdev, dev, |
| 4272 | NL80211_CMD_START_SCHED_SCAN); |
| 4273 | goto out; |
| 4274 | } |
| 4275 | |
| 4276 | out_free: |
| 4277 | kfree(request); |
| 4278 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4279 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4280 | return err; |
| 4281 | } |
| 4282 | |
| 4283 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4284 | struct genl_info *info) |
| 4285 | { |
| 4286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4287 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4288 | |
| 4289 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4290 | !rdev->ops->sched_scan_stop) |
| 4291 | return -EOPNOTSUPP; |
| 4292 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4293 | mutex_lock(&rdev->sched_scan_mtx); |
| 4294 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4295 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4296 | |
| 4297 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4298 | } |
| 4299 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4300 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4301 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4302 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4303 | struct wireless_dev *wdev, |
| 4304 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4305 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4306 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4307 | void *hdr; |
| 4308 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4309 | |
| 4310 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4311 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4312 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4313 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4314 | if (!hdr) |
| 4315 | return -1; |
| 4316 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4317 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4318 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4319 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
| 4320 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 4321 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4322 | |
| 4323 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4324 | if (!bss) |
| 4325 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4326 | if ((!is_zero_ether_addr(res->bssid) && |
| 4327 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || |
| 4328 | (res->information_elements && res->len_information_elements && |
| 4329 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4330 | res->len_information_elements, |
| 4331 | res->information_elements)) || |
| 4332 | (res->beacon_ies && res->len_beacon_ies && |
| 4333 | res->beacon_ies != res->information_elements && |
| 4334 | nla_put(msg, NL80211_BSS_BEACON_IES, |
| 4335 | res->len_beacon_ies, res->beacon_ies))) |
| 4336 | goto nla_put_failure; |
| 4337 | if (res->tsf && |
| 4338 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) |
| 4339 | goto nla_put_failure; |
| 4340 | if (res->beacon_interval && |
| 4341 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 4342 | goto nla_put_failure; |
| 4343 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 4344 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
| 4345 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4346 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 4347 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4348 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4349 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4350 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4351 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 4352 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4353 | break; |
| 4354 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4355 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 4356 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4357 | break; |
| 4358 | default: |
| 4359 | break; |
| 4360 | } |
| 4361 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4362 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4363 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4364 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4365 | if (intbss == wdev->current_bss && |
| 4366 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4367 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 4368 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4369 | break; |
| 4370 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4371 | if (intbss == wdev->current_bss && |
| 4372 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 4373 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 4374 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4375 | break; |
| 4376 | default: |
| 4377 | break; |
| 4378 | } |
| 4379 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4380 | nla_nest_end(msg, bss); |
| 4381 | |
| 4382 | return genlmsg_end(msg, hdr); |
| 4383 | |
| 4384 | nla_put_failure: |
| 4385 | genlmsg_cancel(msg, hdr); |
| 4386 | return -EMSGSIZE; |
| 4387 | } |
| 4388 | |
| 4389 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4390 | struct netlink_callback *cb) |
| 4391 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4392 | struct cfg80211_registered_device *rdev; |
| 4393 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4394 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4395 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4396 | int start = cb->args[1], idx = 0; |
| 4397 | int err; |
| 4398 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4399 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4400 | if (err) |
| 4401 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4402 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4403 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4404 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4405 | wdev_lock(wdev); |
| 4406 | spin_lock_bh(&rdev->bss_lock); |
| 4407 | cfg80211_bss_expire(rdev); |
| 4408 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4409 | cb->seq = rdev->bss_generation; |
| 4410 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4411 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4412 | if (++idx <= start) |
| 4413 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4414 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4415 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4416 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4417 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4418 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4419 | } |
| 4420 | } |
| 4421 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4422 | spin_unlock_bh(&rdev->bss_lock); |
| 4423 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4424 | |
| 4425 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4426 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4427 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4428 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4429 | } |
| 4430 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4431 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4432 | int flags, struct net_device *dev, |
| 4433 | struct survey_info *survey) |
| 4434 | { |
| 4435 | void *hdr; |
| 4436 | struct nlattr *infoattr; |
| 4437 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4438 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4439 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4440 | if (!hdr) |
| 4441 | return -ENOMEM; |
| 4442 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4443 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 4444 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4445 | |
| 4446 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4447 | if (!infoattr) |
| 4448 | goto nla_put_failure; |
| 4449 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4450 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4451 | survey->channel->center_freq)) |
| 4452 | goto nla_put_failure; |
| 4453 | |
| 4454 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 4455 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 4456 | goto nla_put_failure; |
| 4457 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 4458 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 4459 | goto nla_put_failure; |
| 4460 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 4461 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4462 | survey->channel_time)) |
| 4463 | goto nla_put_failure; |
| 4464 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 4465 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4466 | survey->channel_time_busy)) |
| 4467 | goto nla_put_failure; |
| 4468 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 4469 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4470 | survey->channel_time_ext_busy)) |
| 4471 | goto nla_put_failure; |
| 4472 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 4473 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4474 | survey->channel_time_rx)) |
| 4475 | goto nla_put_failure; |
| 4476 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 4477 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4478 | survey->channel_time_tx)) |
| 4479 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4480 | |
| 4481 | nla_nest_end(msg, infoattr); |
| 4482 | |
| 4483 | return genlmsg_end(msg, hdr); |
| 4484 | |
| 4485 | nla_put_failure: |
| 4486 | genlmsg_cancel(msg, hdr); |
| 4487 | return -EMSGSIZE; |
| 4488 | } |
| 4489 | |
| 4490 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4491 | struct netlink_callback *cb) |
| 4492 | { |
| 4493 | struct survey_info survey; |
| 4494 | struct cfg80211_registered_device *dev; |
| 4495 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4496 | int survey_idx = cb->args[1]; |
| 4497 | int res; |
| 4498 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4499 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4500 | if (res) |
| 4501 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4502 | |
| 4503 | if (!dev->ops->dump_survey) { |
| 4504 | res = -EOPNOTSUPP; |
| 4505 | goto out_err; |
| 4506 | } |
| 4507 | |
| 4508 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4509 | struct ieee80211_channel *chan; |
| 4510 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4511 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4512 | &survey); |
| 4513 | if (res == -ENOENT) |
| 4514 | break; |
| 4515 | if (res) |
| 4516 | goto out_err; |
| 4517 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4518 | /* Survey without a channel doesn't make sense */ |
| 4519 | if (!survey.channel) { |
| 4520 | res = -EINVAL; |
| 4521 | goto out; |
| 4522 | } |
| 4523 | |
| 4524 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4525 | survey.channel->center_freq); |
| 4526 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4527 | survey_idx++; |
| 4528 | continue; |
| 4529 | } |
| 4530 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4531 | if (nl80211_send_survey(skb, |
| 4532 | NETLINK_CB(cb->skb).pid, |
| 4533 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4534 | netdev, |
| 4535 | &survey) < 0) |
| 4536 | goto out; |
| 4537 | survey_idx++; |
| 4538 | } |
| 4539 | |
| 4540 | out: |
| 4541 | cb->args[1] = survey_idx; |
| 4542 | res = skb->len; |
| 4543 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4544 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4545 | return res; |
| 4546 | } |
| 4547 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4548 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4549 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4550 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4551 | } |
| 4552 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4553 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4554 | { |
| 4555 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4556 | NL80211_WPA_VERSION_2)); |
| 4557 | } |
| 4558 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4559 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4560 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4561 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4562 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4563 | struct ieee80211_channel *chan; |
| 4564 | const u8 *bssid, *ssid, *ie = NULL; |
| 4565 | int err, ssid_len, ie_len = 0; |
| 4566 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4567 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4568 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4569 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4570 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4571 | return -EINVAL; |
| 4572 | |
| 4573 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4574 | return -EINVAL; |
| 4575 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4576 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4577 | return -EINVAL; |
| 4578 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4579 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4580 | return -EINVAL; |
| 4581 | |
| 4582 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4583 | return -EINVAL; |
| 4584 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4585 | err = nl80211_parse_key(info, &key); |
| 4586 | if (err) |
| 4587 | return err; |
| 4588 | |
| 4589 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4590 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4591 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4592 | if (!key.p.key || !key.p.key_len) |
| 4593 | return -EINVAL; |
| 4594 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4595 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4596 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4597 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4598 | return -EINVAL; |
| 4599 | if (key.idx > 4) |
| 4600 | return -EINVAL; |
| 4601 | } else { |
| 4602 | key.p.key_len = 0; |
| 4603 | key.p.key = NULL; |
| 4604 | } |
| 4605 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4606 | if (key.idx >= 0) { |
| 4607 | int i; |
| 4608 | bool ok = false; |
| 4609 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4610 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4611 | ok = true; |
| 4612 | break; |
| 4613 | } |
| 4614 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4615 | if (!ok) |
| 4616 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4617 | } |
| 4618 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | if (!rdev->ops->auth) |
| 4620 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4621 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4622 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4623 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4624 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4625 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4626 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4627 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4628 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4629 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4630 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4631 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4632 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4633 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4634 | |
| 4635 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4636 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4637 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4638 | } |
| 4639 | |
| 4640 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4641 | if (!nl80211_valid_auth_type(auth_type)) |
| 4642 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4643 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4644 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4645 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4646 | /* |
| 4647 | * Since we no longer track auth state, ignore |
| 4648 | * requests to only change local state. |
| 4649 | */ |
| 4650 | if (local_state_change) |
| 4651 | return 0; |
| 4652 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4653 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4654 | ssid, ssid_len, ie, ie_len, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4655 | key.p.key, key.p.key_len, key.idx); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4656 | } |
| 4657 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4658 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4659 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4660 | struct cfg80211_crypto_settings *settings, |
| 4661 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4662 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4663 | memset(settings, 0, sizeof(*settings)); |
| 4664 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4665 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4666 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4667 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4668 | u16 proto; |
| 4669 | proto = nla_get_u16( |
| 4670 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4671 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4672 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4673 | proto != ETH_P_PAE) |
| 4674 | return -EINVAL; |
| 4675 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4676 | settings->control_port_no_encrypt = true; |
| 4677 | } else |
| 4678 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4679 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4680 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4681 | void *data; |
| 4682 | int len, i; |
| 4683 | |
| 4684 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4685 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4686 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4687 | |
| 4688 | if (len % sizeof(u32)) |
| 4689 | return -EINVAL; |
| 4690 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4691 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4692 | return -EINVAL; |
| 4693 | |
| 4694 | memcpy(settings->ciphers_pairwise, data, len); |
| 4695 | |
| 4696 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4697 | if (!cfg80211_supported_cipher_suite( |
| 4698 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4699 | settings->ciphers_pairwise[i])) |
| 4700 | return -EINVAL; |
| 4701 | } |
| 4702 | |
| 4703 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4704 | settings->cipher_group = |
| 4705 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4706 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4707 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4708 | return -EINVAL; |
| 4709 | } |
| 4710 | |
| 4711 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4712 | settings->wpa_versions = |
| 4713 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4714 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4715 | return -EINVAL; |
| 4716 | } |
| 4717 | |
| 4718 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4719 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4720 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4721 | |
| 4722 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4723 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4724 | settings->n_akm_suites = len / sizeof(u32); |
| 4725 | |
| 4726 | if (len % sizeof(u32)) |
| 4727 | return -EINVAL; |
| 4728 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4729 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4730 | return -EINVAL; |
| 4731 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4732 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | return 0; |
| 4736 | } |
| 4737 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4738 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4739 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4740 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4741 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4742 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4743 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4744 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4745 | int err, ssid_len, ie_len = 0; |
| 4746 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4747 | u32 flags = 0; |
| 4748 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 4749 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4750 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4751 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4752 | return -EINVAL; |
| 4753 | |
| 4754 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4755 | !info->attrs[NL80211_ATTR_SSID] || |
| 4756 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4757 | return -EINVAL; |
| 4758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4759 | if (!rdev->ops->assoc) |
| 4760 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4761 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4762 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4763 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4764 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4765 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4766 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4767 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4768 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4769 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4770 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4771 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4772 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4773 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4774 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4775 | |
| 4776 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4777 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4778 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4779 | } |
| 4780 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4781 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4782 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4783 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4784 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4785 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4786 | else if (mfp != NL80211_MFP_NO) |
| 4787 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4788 | } |
| 4789 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4790 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4791 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4792 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4793 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 4794 | flags |= ASSOC_REQ_DISABLE_HT; |
| 4795 | |
| 4796 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 4797 | ht_capa_mask = |
| 4798 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 4799 | |
| 4800 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 4801 | if (!ht_capa_mask) |
| 4802 | return -EINVAL; |
| 4803 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4804 | } |
| 4805 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4806 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4807 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4808 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4809 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4810 | &crypto, flags, ht_capa, |
| 4811 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4812 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4813 | return err; |
| 4814 | } |
| 4815 | |
| 4816 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4817 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4818 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4819 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4820 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4821 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4822 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4823 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4824 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4825 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4826 | return -EINVAL; |
| 4827 | |
| 4828 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4829 | return -EINVAL; |
| 4830 | |
| 4831 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4832 | return -EINVAL; |
| 4833 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4834 | if (!rdev->ops->deauth) |
| 4835 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4836 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4837 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4838 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4839 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4840 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4841 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4842 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4843 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4844 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4845 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4846 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4847 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4848 | |
| 4849 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4850 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4851 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4852 | } |
| 4853 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4854 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4855 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4856 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4857 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4861 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4863 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4864 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4865 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4866 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4867 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4868 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4869 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4870 | return -EINVAL; |
| 4871 | |
| 4872 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4873 | return -EINVAL; |
| 4874 | |
| 4875 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4876 | return -EINVAL; |
| 4877 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4878 | if (!rdev->ops->disassoc) |
| 4879 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4880 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4881 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4882 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4883 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4884 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4885 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4886 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4887 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4888 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4889 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4890 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4891 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4892 | |
| 4893 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4894 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4895 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4896 | } |
| 4897 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4898 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4899 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4900 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4901 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4902 | } |
| 4903 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4904 | static bool |
| 4905 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4906 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4907 | int rateval) |
| 4908 | { |
| 4909 | struct wiphy *wiphy = &rdev->wiphy; |
| 4910 | bool found = false; |
| 4911 | int band, i; |
| 4912 | |
| 4913 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4914 | struct ieee80211_supported_band *sband; |
| 4915 | |
| 4916 | sband = wiphy->bands[band]; |
| 4917 | if (!sband) |
| 4918 | continue; |
| 4919 | |
| 4920 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4921 | if (sband->bitrates[i].bitrate == rateval) { |
| 4922 | mcast_rate[band] = i + 1; |
| 4923 | found = true; |
| 4924 | break; |
| 4925 | } |
| 4926 | } |
| 4927 | } |
| 4928 | |
| 4929 | return found; |
| 4930 | } |
| 4931 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4932 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4933 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4934 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4935 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4936 | struct cfg80211_ibss_params ibss; |
| 4937 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4938 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4939 | int err; |
| 4940 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4941 | memset(&ibss, 0, sizeof(ibss)); |
| 4942 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4943 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4944 | return -EINVAL; |
| 4945 | |
| 4946 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4947 | !info->attrs[NL80211_ATTR_SSID] || |
| 4948 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4949 | return -EINVAL; |
| 4950 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4951 | ibss.beacon_interval = 100; |
| 4952 | |
| 4953 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4954 | ibss.beacon_interval = |
| 4955 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4956 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4957 | return -EINVAL; |
| 4958 | } |
| 4959 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4960 | if (!rdev->ops->join_ibss) |
| 4961 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4962 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4963 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4964 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4965 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4966 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4967 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4968 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4969 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4970 | |
| 4971 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4972 | return -EINVAL; |
| 4973 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4974 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4975 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4976 | |
| 4977 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4978 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4979 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4980 | } |
| 4981 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 4982 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4983 | enum nl80211_channel_type channel_type; |
| 4984 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 4985 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 4986 | return -EINVAL; |
| 4987 | |
| 4988 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4989 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 4990 | return -EINVAL; |
| 4991 | |
| 4992 | ibss.channel_type = channel_type; |
| 4993 | } else { |
| 4994 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 4995 | } |
| 4996 | |
| 4997 | ibss.channel = rdev_freq_to_chan(rdev, |
| 4998 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 4999 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5000 | if (!ibss.channel || |
| 5001 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5002 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5003 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5004 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 5005 | /* Both channels should be able to initiate communication */ |
| 5006 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 5007 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 5008 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 5009 | ibss.channel_type)) |
| 5010 | return -EINVAL; |
| 5011 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5012 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5013 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5014 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5015 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5016 | u8 *rates = |
| 5017 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5018 | int n_rates = |
| 5019 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5020 | struct ieee80211_supported_band *sband = |
| 5021 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5022 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5023 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 5024 | &ibss.basic_rates); |
| 5025 | if (err) |
| 5026 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5027 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 5028 | |
| 5029 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5030 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 5031 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5032 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 5033 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5034 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5035 | connkeys = nl80211_parse_connkeys(rdev, |
| 5036 | info->attrs[NL80211_ATTR_KEYS]); |
| 5037 | if (IS_ERR(connkeys)) |
| 5038 | return PTR_ERR(connkeys); |
| 5039 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5040 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 5041 | ibss.control_port = |
| 5042 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 5043 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5044 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5045 | if (err) |
| 5046 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5047 | return err; |
| 5048 | } |
| 5049 | |
| 5050 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 5051 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5052 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5053 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5054 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5055 | if (!rdev->ops->leave_ibss) |
| 5056 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5057 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5058 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 5059 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5060 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5061 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 5062 | } |
| 5063 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5064 | #ifdef CONFIG_NL80211_TESTMODE |
| 5065 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 5066 | .name = "testmode", |
| 5067 | }; |
| 5068 | |
| 5069 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 5070 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5072 | int err; |
| 5073 | |
| 5074 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 5075 | return -EINVAL; |
| 5076 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5077 | err = -EOPNOTSUPP; |
| 5078 | if (rdev->ops->testmode_cmd) { |
| 5079 | rdev->testmode_info = info; |
| 5080 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 5081 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 5082 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 5083 | rdev->testmode_info = NULL; |
| 5084 | } |
| 5085 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5086 | return err; |
| 5087 | } |
| 5088 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5089 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 5090 | struct netlink_callback *cb) |
| 5091 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5092 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5093 | int err; |
| 5094 | long phy_idx; |
| 5095 | void *data = NULL; |
| 5096 | int data_len = 0; |
| 5097 | |
| 5098 | if (cb->args[0]) { |
| 5099 | /* |
| 5100 | * 0 is a valid index, but not valid for args[0], |
| 5101 | * so we need to offset by 1. |
| 5102 | */ |
| 5103 | phy_idx = cb->args[0] - 1; |
| 5104 | } else { |
| 5105 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 5106 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 5107 | nl80211_policy); |
| 5108 | if (err) |
| 5109 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5110 | if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) { |
| 5111 | phy_idx = nla_get_u32( |
| 5112 | nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 5113 | } else { |
| 5114 | struct net_device *netdev; |
| 5115 | |
| 5116 | err = get_rdev_dev_by_ifindex(sock_net(skb->sk), |
| 5117 | nl80211_fam.attrbuf, |
| 5118 | &rdev, &netdev); |
| 5119 | if (err) |
| 5120 | return err; |
| 5121 | dev_put(netdev); |
| 5122 | phy_idx = rdev->wiphy_idx; |
| 5123 | cfg80211_unlock_rdev(rdev); |
| 5124 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5125 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 5126 | cb->args[1] = |
| 5127 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 5128 | } |
| 5129 | |
| 5130 | if (cb->args[1]) { |
| 5131 | data = nla_data((void *)cb->args[1]); |
| 5132 | data_len = nla_len((void *)cb->args[1]); |
| 5133 | } |
| 5134 | |
| 5135 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5136 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 5137 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5138 | mutex_unlock(&cfg80211_mutex); |
| 5139 | return -ENOENT; |
| 5140 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5141 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5142 | mutex_unlock(&cfg80211_mutex); |
| 5143 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5144 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5145 | err = -EOPNOTSUPP; |
| 5146 | goto out_err; |
| 5147 | } |
| 5148 | |
| 5149 | while (1) { |
| 5150 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 5151 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5152 | NL80211_CMD_TESTMODE); |
| 5153 | struct nlattr *tmdata; |
| 5154 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5155 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5156 | genlmsg_cancel(skb, hdr); |
| 5157 | break; |
| 5158 | } |
| 5159 | |
| 5160 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5161 | if (!tmdata) { |
| 5162 | genlmsg_cancel(skb, hdr); |
| 5163 | break; |
| 5164 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5165 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
| 5166 | data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5167 | nla_nest_end(skb, tmdata); |
| 5168 | |
| 5169 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5170 | genlmsg_cancel(skb, hdr); |
| 5171 | break; |
| 5172 | } else if (err) { |
| 5173 | genlmsg_cancel(skb, hdr); |
| 5174 | goto out_err; |
| 5175 | } |
| 5176 | |
| 5177 | genlmsg_end(skb, hdr); |
| 5178 | } |
| 5179 | |
| 5180 | err = skb->len; |
| 5181 | /* see above */ |
| 5182 | cb->args[0] = phy_idx + 1; |
| 5183 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5184 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5185 | return err; |
| 5186 | } |
| 5187 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5188 | static struct sk_buff * |
| 5189 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 5190 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 5191 | { |
| 5192 | struct sk_buff *skb; |
| 5193 | void *hdr; |
| 5194 | struct nlattr *data; |
| 5195 | |
| 5196 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5197 | if (!skb) |
| 5198 | return NULL; |
| 5199 | |
| 5200 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 5201 | if (!hdr) { |
| 5202 | kfree_skb(skb); |
| 5203 | return NULL; |
| 5204 | } |
| 5205 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5206 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 5207 | goto nla_put_failure; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5208 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5209 | |
| 5210 | ((void **)skb->cb)[0] = rdev; |
| 5211 | ((void **)skb->cb)[1] = hdr; |
| 5212 | ((void **)skb->cb)[2] = data; |
| 5213 | |
| 5214 | return skb; |
| 5215 | |
| 5216 | nla_put_failure: |
| 5217 | kfree_skb(skb); |
| 5218 | return NULL; |
| 5219 | } |
| 5220 | |
| 5221 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5222 | int approxlen) |
| 5223 | { |
| 5224 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5225 | |
| 5226 | if (WARN_ON(!rdev->testmode_info)) |
| 5227 | return NULL; |
| 5228 | |
| 5229 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 5230 | rdev->testmode_info->snd_pid, |
| 5231 | rdev->testmode_info->snd_seq, |
| 5232 | GFP_KERNEL); |
| 5233 | } |
| 5234 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5235 | |
| 5236 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5237 | { |
| 5238 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5239 | void *hdr = ((void **)skb->cb)[1]; |
| 5240 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5241 | |
| 5242 | if (WARN_ON(!rdev->testmode_info)) { |
| 5243 | kfree_skb(skb); |
| 5244 | return -EINVAL; |
| 5245 | } |
| 5246 | |
| 5247 | nla_nest_end(skb, data); |
| 5248 | genlmsg_end(skb, hdr); |
| 5249 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5250 | } |
| 5251 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5252 | |
| 5253 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5254 | int approxlen, gfp_t gfp) |
| 5255 | { |
| 5256 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5257 | |
| 5258 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5259 | } |
| 5260 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5261 | |
| 5262 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5263 | { |
| 5264 | void *hdr = ((void **)skb->cb)[1]; |
| 5265 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5266 | |
| 5267 | nla_nest_end(skb, data); |
| 5268 | genlmsg_end(skb, hdr); |
| 5269 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5270 | } |
| 5271 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5272 | #endif |
| 5273 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5274 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5275 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5276 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5277 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5278 | struct cfg80211_connect_params connect; |
| 5279 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5280 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5281 | int err; |
| 5282 | |
| 5283 | memset(&connect, 0, sizeof(connect)); |
| 5284 | |
| 5285 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5286 | return -EINVAL; |
| 5287 | |
| 5288 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5289 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5290 | return -EINVAL; |
| 5291 | |
| 5292 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5293 | connect.auth_type = |
| 5294 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 5295 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 5296 | return -EINVAL; |
| 5297 | } else |
| 5298 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5299 | |
| 5300 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5301 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5302 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5303 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5304 | if (err) |
| 5305 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5306 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5307 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5308 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5309 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5310 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5311 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5312 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5313 | connect.bg_scan_period = -1; |
| 5314 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5315 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5316 | connect.bg_scan_period = |
| 5317 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5318 | } |
| 5319 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5320 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5321 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5322 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5323 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5324 | |
| 5325 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5326 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5327 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5328 | } |
| 5329 | |
| 5330 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5331 | connect.channel = |
| 5332 | ieee80211_get_channel(wiphy, |
| 5333 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5334 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5335 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5336 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5337 | } |
| 5338 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5339 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5340 | connkeys = nl80211_parse_connkeys(rdev, |
| 5341 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5342 | if (IS_ERR(connkeys)) |
| 5343 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5344 | } |
| 5345 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5346 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5347 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5348 | |
| 5349 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5350 | memcpy(&connect.ht_capa_mask, |
| 5351 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5352 | sizeof(connect.ht_capa_mask)); |
| 5353 | |
| 5354 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5355 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5356 | return -EINVAL; |
| 5357 | memcpy(&connect.ht_capa, |
| 5358 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5359 | sizeof(connect.ht_capa)); |
| 5360 | } |
| 5361 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5362 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5363 | if (err) |
| 5364 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5365 | return err; |
| 5366 | } |
| 5367 | |
| 5368 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5369 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5371 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5372 | u16 reason; |
| 5373 | |
| 5374 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5375 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5376 | else |
| 5377 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5378 | |
| 5379 | if (reason == 0) |
| 5380 | return -EINVAL; |
| 5381 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5382 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5383 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5384 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5385 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5386 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5387 | } |
| 5388 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5389 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5390 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5392 | struct net *net; |
| 5393 | int err; |
| 5394 | u32 pid; |
| 5395 | |
| 5396 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5397 | return -EINVAL; |
| 5398 | |
| 5399 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5400 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5401 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5402 | if (IS_ERR(net)) |
| 5403 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5404 | |
| 5405 | err = 0; |
| 5406 | |
| 5407 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5408 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5409 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5410 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5411 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5412 | return err; |
| 5413 | } |
| 5414 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5415 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5416 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5418 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5419 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5420 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5421 | struct cfg80211_pmksa pmksa; |
| 5422 | |
| 5423 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5424 | |
| 5425 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5426 | return -EINVAL; |
| 5427 | |
| 5428 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5429 | return -EINVAL; |
| 5430 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5431 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5432 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5433 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5434 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5435 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5436 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5437 | |
| 5438 | switch (info->genlhdr->cmd) { |
| 5439 | case NL80211_CMD_SET_PMKSA: |
| 5440 | rdev_ops = rdev->ops->set_pmksa; |
| 5441 | break; |
| 5442 | case NL80211_CMD_DEL_PMKSA: |
| 5443 | rdev_ops = rdev->ops->del_pmksa; |
| 5444 | break; |
| 5445 | default: |
| 5446 | WARN_ON(1); |
| 5447 | break; |
| 5448 | } |
| 5449 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5450 | if (!rdev_ops) |
| 5451 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5452 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5453 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5457 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5459 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5460 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5462 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5463 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5464 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5465 | if (!rdev->ops->flush_pmksa) |
| 5466 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5467 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5468 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5469 | } |
| 5470 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5471 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5472 | { |
| 5473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5474 | struct net_device *dev = info->user_ptr[1]; |
| 5475 | u8 action_code, dialog_token; |
| 5476 | u16 status_code; |
| 5477 | u8 *peer; |
| 5478 | |
| 5479 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5480 | !rdev->ops->tdls_mgmt) |
| 5481 | return -EOPNOTSUPP; |
| 5482 | |
| 5483 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5484 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5485 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5486 | !info->attrs[NL80211_ATTR_IE] || |
| 5487 | !info->attrs[NL80211_ATTR_MAC]) |
| 5488 | return -EINVAL; |
| 5489 | |
| 5490 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5491 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5492 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5493 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5494 | |
| 5495 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5496 | dialog_token, status_code, |
| 5497 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5498 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5499 | } |
| 5500 | |
| 5501 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5502 | { |
| 5503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5504 | struct net_device *dev = info->user_ptr[1]; |
| 5505 | enum nl80211_tdls_operation operation; |
| 5506 | u8 *peer; |
| 5507 | |
| 5508 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5509 | !rdev->ops->tdls_oper) |
| 5510 | return -EOPNOTSUPP; |
| 5511 | |
| 5512 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5513 | !info->attrs[NL80211_ATTR_MAC]) |
| 5514 | return -EINVAL; |
| 5515 | |
| 5516 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5517 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5518 | |
| 5519 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5520 | } |
| 5521 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5522 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5523 | struct genl_info *info) |
| 5524 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5526 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5527 | struct ieee80211_channel *chan; |
| 5528 | struct sk_buff *msg; |
| 5529 | void *hdr; |
| 5530 | u64 cookie; |
| 5531 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5532 | u32 freq, duration; |
| 5533 | int err; |
| 5534 | |
| 5535 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5536 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5537 | return -EINVAL; |
| 5538 | |
| 5539 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5540 | |
| 5541 | /* |
| 5542 | * We should be on that channel for at least one jiffie, |
| 5543 | * and more than 5 seconds seems excessive. |
| 5544 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5545 | if (!duration || !msecs_to_jiffies(duration) || |
| 5546 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5547 | return -EINVAL; |
| 5548 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5549 | if (!rdev->ops->remain_on_channel || |
| 5550 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5551 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5552 | |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5553 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
| 5554 | !nl80211_valid_channel_type(info, &channel_type)) |
| 5555 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5556 | |
| 5557 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5558 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5559 | if (chan == NULL) |
| 5560 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5561 | |
| 5562 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5563 | if (!msg) |
| 5564 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5565 | |
| 5566 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5567 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5568 | |
| 5569 | if (IS_ERR(hdr)) { |
| 5570 | err = PTR_ERR(hdr); |
| 5571 | goto free_msg; |
| 5572 | } |
| 5573 | |
| 5574 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5575 | channel_type, duration, &cookie); |
| 5576 | |
| 5577 | if (err) |
| 5578 | goto free_msg; |
| 5579 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5580 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 5581 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5582 | |
| 5583 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5584 | |
| 5585 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5586 | |
| 5587 | nla_put_failure: |
| 5588 | err = -ENOBUFS; |
| 5589 | free_msg: |
| 5590 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5591 | return err; |
| 5592 | } |
| 5593 | |
| 5594 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5595 | struct genl_info *info) |
| 5596 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5597 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5598 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5599 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5600 | |
| 5601 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5602 | return -EINVAL; |
| 5603 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5604 | if (!rdev->ops->cancel_remain_on_channel) |
| 5605 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5606 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5607 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5608 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5609 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5610 | } |
| 5611 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5612 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5613 | u8 *rates, u8 rates_len) |
| 5614 | { |
| 5615 | u8 i; |
| 5616 | u32 mask = 0; |
| 5617 | |
| 5618 | for (i = 0; i < rates_len; i++) { |
| 5619 | int rate = (rates[i] & 0x7f) * 5; |
| 5620 | int ridx; |
| 5621 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5622 | struct ieee80211_rate *srate = |
| 5623 | &sband->bitrates[ridx]; |
| 5624 | if (rate == srate->bitrate) { |
| 5625 | mask |= 1 << ridx; |
| 5626 | break; |
| 5627 | } |
| 5628 | } |
| 5629 | if (ridx == sband->n_bitrates) |
| 5630 | return 0; /* rate not found */ |
| 5631 | } |
| 5632 | |
| 5633 | return mask; |
| 5634 | } |
| 5635 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5636 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5637 | u8 *rates, u8 rates_len, |
| 5638 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 5639 | { |
| 5640 | u8 i; |
| 5641 | |
| 5642 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 5643 | |
| 5644 | for (i = 0; i < rates_len; i++) { |
| 5645 | int ridx, rbit; |
| 5646 | |
| 5647 | ridx = rates[i] / 8; |
| 5648 | rbit = BIT(rates[i] % 8); |
| 5649 | |
| 5650 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 5651 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5652 | return false; |
| 5653 | |
| 5654 | /* check availability */ |
| 5655 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 5656 | mcs[ridx] |= rbit; |
| 5657 | else |
| 5658 | return false; |
| 5659 | } |
| 5660 | |
| 5661 | return true; |
| 5662 | } |
| 5663 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5664 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5665 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5666 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5667 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 5668 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5669 | }; |
| 5670 | |
| 5671 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5672 | struct genl_info *info) |
| 5673 | { |
| 5674 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5675 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5676 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5677 | int rem, i; |
| 5678 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5679 | struct nlattr *tx_rates; |
| 5680 | struct ieee80211_supported_band *sband; |
| 5681 | |
| 5682 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5683 | return -EINVAL; |
| 5684 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5685 | if (!rdev->ops->set_bitrate_mask) |
| 5686 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5687 | |
| 5688 | memset(&mask, 0, sizeof(mask)); |
| 5689 | /* Default to all rates enabled */ |
| 5690 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5691 | sband = rdev->wiphy.bands[i]; |
| 5692 | mask.control[i].legacy = |
| 5693 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5694 | if (sband) |
| 5695 | memcpy(mask.control[i].mcs, |
| 5696 | sband->ht_cap.mcs.rx_mask, |
| 5697 | sizeof(mask.control[i].mcs)); |
| 5698 | else |
| 5699 | memset(mask.control[i].mcs, 0, |
| 5700 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5701 | } |
| 5702 | |
| 5703 | /* |
| 5704 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5705 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5706 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5707 | 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] | 5708 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5709 | { |
| 5710 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5711 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5712 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5713 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5714 | if (sband == NULL) |
| 5715 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5716 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5717 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5718 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5719 | mask.control[band].legacy = rateset_to_mask( |
| 5720 | sband, |
| 5721 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5722 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 5723 | if ((mask.control[band].legacy == 0) && |
| 5724 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 5725 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5726 | } |
| 5727 | if (tb[NL80211_TXRATE_MCS]) { |
| 5728 | if (!ht_rateset_to_mask( |
| 5729 | sband, |
| 5730 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 5731 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 5732 | mask.control[band].mcs)) |
| 5733 | return -EINVAL; |
| 5734 | } |
| 5735 | |
| 5736 | if (mask.control[band].legacy == 0) { |
| 5737 | /* don't allow empty legacy rates if HT |
| 5738 | * is not even supported. */ |
| 5739 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 5740 | return -EINVAL; |
| 5741 | |
| 5742 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5743 | if (mask.control[band].mcs[i]) |
| 5744 | break; |
| 5745 | |
| 5746 | /* legacy and mcs rates may not be both empty */ |
| 5747 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5748 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5749 | } |
| 5750 | } |
| 5751 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5752 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5753 | } |
| 5754 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5755 | 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] | 5756 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5757 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5758 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5759 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5760 | |
| 5761 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5762 | return -EINVAL; |
| 5763 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5764 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5765 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5766 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5767 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5768 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5769 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5770 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5771 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5772 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5773 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5774 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5775 | |
| 5776 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5777 | if (!rdev->ops->mgmt_tx) |
| 5778 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5779 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5780 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5781 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5782 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5783 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5784 | } |
| 5785 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5786 | 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] | 5787 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5789 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5790 | struct ieee80211_channel *chan; |
| 5791 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5792 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5793 | u32 freq; |
| 5794 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 5795 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5796 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5797 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5798 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5799 | bool offchan, no_cck, dont_wait_for_ack; |
| 5800 | |
| 5801 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5802 | |
| 5803 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5804 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5805 | return -EINVAL; |
| 5806 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5807 | if (!rdev->ops->mgmt_tx) |
| 5808 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5809 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5810 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5811 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5812 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5813 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5814 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5815 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5816 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5817 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5818 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5819 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5820 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5821 | return -EINVAL; |
| 5822 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5823 | } |
| 5824 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5825 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | cd6c659 | 2012-05-10 21:27:18 +0200 | [diff] [blame] | 5826 | if (!nl80211_valid_channel_type(info, &channel_type)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5827 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5828 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5829 | } |
| 5830 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5831 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5832 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5833 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 5834 | return -EINVAL; |
| 5835 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5836 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5837 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5838 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5839 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5840 | if (chan == NULL) |
| 5841 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5842 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5843 | if (!dont_wait_for_ack) { |
| 5844 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5845 | if (!msg) |
| 5846 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5847 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5848 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5849 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5850 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5851 | if (IS_ERR(hdr)) { |
| 5852 | err = PTR_ERR(hdr); |
| 5853 | goto free_msg; |
| 5854 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5855 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5856 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5857 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5858 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5859 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5860 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5861 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5862 | if (err) |
| 5863 | goto free_msg; |
| 5864 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5865 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5866 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 5867 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5868 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5869 | genlmsg_end(msg, hdr); |
| 5870 | return genlmsg_reply(msg, info); |
| 5871 | } |
| 5872 | |
| 5873 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5874 | |
| 5875 | nla_put_failure: |
| 5876 | err = -ENOBUFS; |
| 5877 | free_msg: |
| 5878 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5879 | return err; |
| 5880 | } |
| 5881 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5882 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5883 | { |
| 5884 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5885 | struct net_device *dev = info->user_ptr[1]; |
| 5886 | u64 cookie; |
| 5887 | |
| 5888 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5889 | return -EINVAL; |
| 5890 | |
| 5891 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5892 | return -EOPNOTSUPP; |
| 5893 | |
| 5894 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5895 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5896 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5897 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5898 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5899 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5900 | return -EOPNOTSUPP; |
| 5901 | |
| 5902 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5903 | |
| 5904 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5905 | } |
| 5906 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5907 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5908 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5910 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5911 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5912 | u8 ps_state; |
| 5913 | bool state; |
| 5914 | int err; |
| 5915 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5916 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5917 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5918 | |
| 5919 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5920 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5921 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5922 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5923 | |
| 5924 | wdev = dev->ieee80211_ptr; |
| 5925 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5926 | if (!rdev->ops->set_power_mgmt) |
| 5927 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5928 | |
| 5929 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5930 | |
| 5931 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5932 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5933 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5934 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5935 | wdev->ps_timeout); |
| 5936 | if (!err) |
| 5937 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5938 | return err; |
| 5939 | } |
| 5940 | |
| 5941 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5942 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5943 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5944 | enum nl80211_ps_state ps_state; |
| 5945 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5946 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5947 | struct sk_buff *msg; |
| 5948 | void *hdr; |
| 5949 | int err; |
| 5950 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5951 | wdev = dev->ieee80211_ptr; |
| 5952 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5953 | if (!rdev->ops->set_power_mgmt) |
| 5954 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5955 | |
| 5956 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5957 | if (!msg) |
| 5958 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5959 | |
| 5960 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5961 | NL80211_CMD_GET_POWER_SAVE); |
| 5962 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5963 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5964 | goto free_msg; |
| 5965 | } |
| 5966 | |
| 5967 | if (wdev->ps) |
| 5968 | ps_state = NL80211_PS_ENABLED; |
| 5969 | else |
| 5970 | ps_state = NL80211_PS_DISABLED; |
| 5971 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5972 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 5973 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5974 | |
| 5975 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5976 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5977 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5978 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5979 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5980 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5981 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5982 | return err; |
| 5983 | } |
| 5984 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5985 | static struct nla_policy |
| 5986 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5987 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5988 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5989 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5990 | }; |
| 5991 | |
| 5992 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5993 | s32 threshold, u32 hysteresis) |
| 5994 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5996 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5997 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5998 | |
| 5999 | if (threshold > 0) |
| 6000 | return -EINVAL; |
| 6001 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6002 | wdev = dev->ieee80211_ptr; |
| 6003 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6004 | if (!rdev->ops->set_cqm_rssi_config) |
| 6005 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6006 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6007 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6008 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6009 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6010 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6011 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 6012 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6013 | } |
| 6014 | |
| 6015 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 6016 | { |
| 6017 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 6018 | struct nlattr *cqm; |
| 6019 | int err; |
| 6020 | |
| 6021 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 6022 | if (!cqm) { |
| 6023 | err = -EINVAL; |
| 6024 | goto out; |
| 6025 | } |
| 6026 | |
| 6027 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 6028 | nl80211_attr_cqm_policy); |
| 6029 | if (err) |
| 6030 | goto out; |
| 6031 | |
| 6032 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 6033 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 6034 | s32 threshold; |
| 6035 | u32 hysteresis; |
| 6036 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 6037 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 6038 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 6039 | } else |
| 6040 | err = -EINVAL; |
| 6041 | |
| 6042 | out: |
| 6043 | return err; |
| 6044 | } |
| 6045 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6046 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6047 | { |
| 6048 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6049 | struct net_device *dev = info->user_ptr[1]; |
| 6050 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6051 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6052 | int err; |
| 6053 | |
| 6054 | /* start with default */ |
| 6055 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6056 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6057 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6058 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6059 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6060 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6061 | if (err) |
| 6062 | return err; |
| 6063 | } |
| 6064 | |
| 6065 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 6066 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 6067 | return -EINVAL; |
| 6068 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6069 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6070 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 6071 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 6072 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6073 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 6074 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6075 | return -EINVAL; |
| 6076 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6077 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 6078 | /* parse additional setup parameters if given */ |
| 6079 | err = nl80211_parse_mesh_setup(info, &setup); |
| 6080 | if (err) |
| 6081 | return err; |
| 6082 | } |
| 6083 | |
| 6084 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 6088 | { |
| 6089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6090 | struct net_device *dev = info->user_ptr[1]; |
| 6091 | |
| 6092 | return cfg80211_leave_mesh(rdev, dev); |
| 6093 | } |
| 6094 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6095 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6096 | { |
| 6097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6098 | struct sk_buff *msg; |
| 6099 | void *hdr; |
| 6100 | |
| 6101 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6102 | return -EOPNOTSUPP; |
| 6103 | |
| 6104 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6105 | if (!msg) |
| 6106 | return -ENOMEM; |
| 6107 | |
| 6108 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6109 | NL80211_CMD_GET_WOWLAN); |
| 6110 | if (!hdr) |
| 6111 | goto nla_put_failure; |
| 6112 | |
| 6113 | if (rdev->wowlan) { |
| 6114 | struct nlattr *nl_wowlan; |
| 6115 | |
| 6116 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 6117 | if (!nl_wowlan) |
| 6118 | goto nla_put_failure; |
| 6119 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6120 | if ((rdev->wowlan->any && |
| 6121 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 6122 | (rdev->wowlan->disconnect && |
| 6123 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 6124 | (rdev->wowlan->magic_pkt && |
| 6125 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 6126 | (rdev->wowlan->gtk_rekey_failure && |
| 6127 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 6128 | (rdev->wowlan->eap_identity_req && |
| 6129 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 6130 | (rdev->wowlan->four_way_handshake && |
| 6131 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 6132 | (rdev->wowlan->rfkill_release && |
| 6133 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 6134 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6135 | if (rdev->wowlan->n_patterns) { |
| 6136 | struct nlattr *nl_pats, *nl_pat; |
| 6137 | int i, pat_len; |
| 6138 | |
| 6139 | nl_pats = nla_nest_start(msg, |
| 6140 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 6141 | if (!nl_pats) |
| 6142 | goto nla_put_failure; |
| 6143 | |
| 6144 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 6145 | nl_pat = nla_nest_start(msg, i + 1); |
| 6146 | if (!nl_pat) |
| 6147 | goto nla_put_failure; |
| 6148 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6149 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 6150 | DIV_ROUND_UP(pat_len, 8), |
| 6151 | rdev->wowlan->patterns[i].mask) || |
| 6152 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 6153 | pat_len, |
| 6154 | rdev->wowlan->patterns[i].pattern)) |
| 6155 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6156 | nla_nest_end(msg, nl_pat); |
| 6157 | } |
| 6158 | nla_nest_end(msg, nl_pats); |
| 6159 | } |
| 6160 | |
| 6161 | nla_nest_end(msg, nl_wowlan); |
| 6162 | } |
| 6163 | |
| 6164 | genlmsg_end(msg, hdr); |
| 6165 | return genlmsg_reply(msg, info); |
| 6166 | |
| 6167 | nla_put_failure: |
| 6168 | nlmsg_free(msg); |
| 6169 | return -ENOBUFS; |
| 6170 | } |
| 6171 | |
| 6172 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6173 | { |
| 6174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6175 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 6176 | struct cfg80211_wowlan no_triggers = {}; |
| 6177 | struct cfg80211_wowlan new_triggers = {}; |
| 6178 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6179 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6180 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6181 | |
| 6182 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6183 | return -EOPNOTSUPP; |
| 6184 | |
| 6185 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 6186 | goto no_triggers; |
| 6187 | |
| 6188 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6189 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6190 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6191 | nl80211_wowlan_policy); |
| 6192 | if (err) |
| 6193 | return err; |
| 6194 | |
| 6195 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6196 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6197 | return -EINVAL; |
| 6198 | new_triggers.any = true; |
| 6199 | } |
| 6200 | |
| 6201 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6202 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6203 | return -EINVAL; |
| 6204 | new_triggers.disconnect = true; |
| 6205 | } |
| 6206 | |
| 6207 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6208 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6209 | return -EINVAL; |
| 6210 | new_triggers.magic_pkt = true; |
| 6211 | } |
| 6212 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6213 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6214 | return -EINVAL; |
| 6215 | |
| 6216 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6217 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6218 | return -EINVAL; |
| 6219 | new_triggers.gtk_rekey_failure = true; |
| 6220 | } |
| 6221 | |
| 6222 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6223 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6224 | return -EINVAL; |
| 6225 | new_triggers.eap_identity_req = true; |
| 6226 | } |
| 6227 | |
| 6228 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6229 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6230 | return -EINVAL; |
| 6231 | new_triggers.four_way_handshake = true; |
| 6232 | } |
| 6233 | |
| 6234 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6235 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6236 | return -EINVAL; |
| 6237 | new_triggers.rfkill_release = true; |
| 6238 | } |
| 6239 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6240 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6241 | struct nlattr *pat; |
| 6242 | int n_patterns = 0; |
| 6243 | int rem, pat_len, mask_len; |
| 6244 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6245 | |
| 6246 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6247 | rem) |
| 6248 | n_patterns++; |
| 6249 | if (n_patterns > wowlan->n_patterns) |
| 6250 | return -EINVAL; |
| 6251 | |
| 6252 | new_triggers.patterns = kcalloc(n_patterns, |
| 6253 | sizeof(new_triggers.patterns[0]), |
| 6254 | GFP_KERNEL); |
| 6255 | if (!new_triggers.patterns) |
| 6256 | return -ENOMEM; |
| 6257 | |
| 6258 | new_triggers.n_patterns = n_patterns; |
| 6259 | i = 0; |
| 6260 | |
| 6261 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6262 | rem) { |
| 6263 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6264 | nla_data(pat), nla_len(pat), NULL); |
| 6265 | err = -EINVAL; |
| 6266 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6267 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6268 | goto error; |
| 6269 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6270 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6271 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6272 | mask_len) |
| 6273 | goto error; |
| 6274 | if (pat_len > wowlan->pattern_max_len || |
| 6275 | pat_len < wowlan->pattern_min_len) |
| 6276 | goto error; |
| 6277 | |
| 6278 | new_triggers.patterns[i].mask = |
| 6279 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6280 | if (!new_triggers.patterns[i].mask) { |
| 6281 | err = -ENOMEM; |
| 6282 | goto error; |
| 6283 | } |
| 6284 | new_triggers.patterns[i].pattern = |
| 6285 | new_triggers.patterns[i].mask + mask_len; |
| 6286 | memcpy(new_triggers.patterns[i].mask, |
| 6287 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6288 | mask_len); |
| 6289 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6290 | memcpy(new_triggers.patterns[i].pattern, |
| 6291 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6292 | pat_len); |
| 6293 | i++; |
| 6294 | } |
| 6295 | } |
| 6296 | |
| 6297 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 6298 | struct cfg80211_wowlan *ntrig; |
| 6299 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 6300 | GFP_KERNEL); |
| 6301 | if (!ntrig) { |
| 6302 | err = -ENOMEM; |
| 6303 | goto error; |
| 6304 | } |
| 6305 | cfg80211_rdev_free_wowlan(rdev); |
| 6306 | rdev->wowlan = ntrig; |
| 6307 | } else { |
| 6308 | no_triggers: |
| 6309 | cfg80211_rdev_free_wowlan(rdev); |
| 6310 | rdev->wowlan = NULL; |
| 6311 | } |
| 6312 | |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 6313 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
| 6314 | rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan); |
| 6315 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6316 | return 0; |
| 6317 | error: |
| 6318 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6319 | kfree(new_triggers.patterns[i].mask); |
| 6320 | kfree(new_triggers.patterns); |
| 6321 | return err; |
| 6322 | } |
| 6323 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6324 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6325 | { |
| 6326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6327 | struct net_device *dev = info->user_ptr[1]; |
| 6328 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6329 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6330 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6331 | int err; |
| 6332 | |
| 6333 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6334 | return -EINVAL; |
| 6335 | |
| 6336 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6337 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6338 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6339 | nl80211_rekey_policy); |
| 6340 | if (err) |
| 6341 | return err; |
| 6342 | |
| 6343 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6344 | return -ERANGE; |
| 6345 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6346 | return -ERANGE; |
| 6347 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6348 | return -ERANGE; |
| 6349 | |
| 6350 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6351 | NL80211_KEK_LEN); |
| 6352 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6353 | NL80211_KCK_LEN); |
| 6354 | memcpy(rekey_data.replay_ctr, |
| 6355 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6356 | NL80211_REPLAY_CTR_LEN); |
| 6357 | |
| 6358 | wdev_lock(wdev); |
| 6359 | if (!wdev->current_bss) { |
| 6360 | err = -ENOTCONN; |
| 6361 | goto out; |
| 6362 | } |
| 6363 | |
| 6364 | if (!rdev->ops->set_rekey_data) { |
| 6365 | err = -EOPNOTSUPP; |
| 6366 | goto out; |
| 6367 | } |
| 6368 | |
| 6369 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 6370 | out: |
| 6371 | wdev_unlock(wdev); |
| 6372 | return err; |
| 6373 | } |
| 6374 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6375 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6376 | struct genl_info *info) |
| 6377 | { |
| 6378 | struct net_device *dev = info->user_ptr[1]; |
| 6379 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6380 | |
| 6381 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6382 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6383 | return -EINVAL; |
| 6384 | |
| 6385 | if (wdev->ap_unexpected_nlpid) |
| 6386 | return -EBUSY; |
| 6387 | |
| 6388 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 6389 | return 0; |
| 6390 | } |
| 6391 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6392 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6393 | struct genl_info *info) |
| 6394 | { |
| 6395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6396 | struct net_device *dev = info->user_ptr[1]; |
| 6397 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6398 | struct sk_buff *msg; |
| 6399 | void *hdr; |
| 6400 | const u8 *addr; |
| 6401 | u64 cookie; |
| 6402 | int err; |
| 6403 | |
| 6404 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6405 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6406 | return -EOPNOTSUPP; |
| 6407 | |
| 6408 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6409 | return -EINVAL; |
| 6410 | |
| 6411 | if (!rdev->ops->probe_client) |
| 6412 | return -EOPNOTSUPP; |
| 6413 | |
| 6414 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6415 | if (!msg) |
| 6416 | return -ENOMEM; |
| 6417 | |
| 6418 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6419 | NL80211_CMD_PROBE_CLIENT); |
| 6420 | |
| 6421 | if (IS_ERR(hdr)) { |
| 6422 | err = PTR_ERR(hdr); |
| 6423 | goto free_msg; |
| 6424 | } |
| 6425 | |
| 6426 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6427 | |
| 6428 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6429 | if (err) |
| 6430 | goto free_msg; |
| 6431 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6432 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 6433 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6434 | |
| 6435 | genlmsg_end(msg, hdr); |
| 6436 | |
| 6437 | return genlmsg_reply(msg, info); |
| 6438 | |
| 6439 | nla_put_failure: |
| 6440 | err = -ENOBUFS; |
| 6441 | free_msg: |
| 6442 | nlmsg_free(msg); |
| 6443 | return err; |
| 6444 | } |
| 6445 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6446 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6447 | { |
| 6448 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6449 | |
| 6450 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6451 | return -EOPNOTSUPP; |
| 6452 | |
| 6453 | if (rdev->ap_beacons_nlpid) |
| 6454 | return -EBUSY; |
| 6455 | |
| 6456 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 6457 | |
| 6458 | return 0; |
| 6459 | } |
| 6460 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6461 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6462 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6463 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6464 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6465 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6466 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6467 | |
| 6468 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6469 | struct genl_info *info) |
| 6470 | { |
| 6471 | struct cfg80211_registered_device *rdev; |
| 6472 | struct net_device *dev; |
| 6473 | int err; |
| 6474 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6475 | |
| 6476 | if (rtnl) |
| 6477 | rtnl_lock(); |
| 6478 | |
| 6479 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 6480 | rdev = cfg80211_get_dev_from_info(info); |
| 6481 | if (IS_ERR(rdev)) { |
| 6482 | if (rtnl) |
| 6483 | rtnl_unlock(); |
| 6484 | return PTR_ERR(rdev); |
| 6485 | } |
| 6486 | info->user_ptr[0] = rdev; |
| 6487 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6488 | err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs, |
| 6489 | &rdev, &dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6490 | if (err) { |
| 6491 | if (rtnl) |
| 6492 | rtnl_unlock(); |
| 6493 | return err; |
| 6494 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6495 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 6496 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 6497 | cfg80211_unlock_rdev(rdev); |
| 6498 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6499 | if (rtnl) |
| 6500 | rtnl_unlock(); |
| 6501 | return -ENETDOWN; |
| 6502 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6503 | info->user_ptr[0] = rdev; |
| 6504 | info->user_ptr[1] = dev; |
| 6505 | } |
| 6506 | |
| 6507 | return 0; |
| 6508 | } |
| 6509 | |
| 6510 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6511 | struct genl_info *info) |
| 6512 | { |
| 6513 | if (info->user_ptr[0]) |
| 6514 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 6515 | if (info->user_ptr[1]) |
| 6516 | dev_put(info->user_ptr[1]); |
| 6517 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6518 | rtnl_unlock(); |
| 6519 | } |
| 6520 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6521 | static struct genl_ops nl80211_ops[] = { |
| 6522 | { |
| 6523 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6524 | .doit = nl80211_get_wiphy, |
| 6525 | .dumpit = nl80211_dump_wiphy, |
| 6526 | .policy = nl80211_policy, |
| 6527 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6528 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6529 | }, |
| 6530 | { |
| 6531 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6532 | .doit = nl80211_set_wiphy, |
| 6533 | .policy = nl80211_policy, |
| 6534 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6535 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6536 | }, |
| 6537 | { |
| 6538 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6539 | .doit = nl80211_get_interface, |
| 6540 | .dumpit = nl80211_dump_interface, |
| 6541 | .policy = nl80211_policy, |
| 6542 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6543 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6544 | }, |
| 6545 | { |
| 6546 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6547 | .doit = nl80211_set_interface, |
| 6548 | .policy = nl80211_policy, |
| 6549 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6550 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6551 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6552 | }, |
| 6553 | { |
| 6554 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6555 | .doit = nl80211_new_interface, |
| 6556 | .policy = nl80211_policy, |
| 6557 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6558 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6559 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6560 | }, |
| 6561 | { |
| 6562 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6563 | .doit = nl80211_del_interface, |
| 6564 | .policy = nl80211_policy, |
| 6565 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6566 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6567 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6568 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6569 | { |
| 6570 | .cmd = NL80211_CMD_GET_KEY, |
| 6571 | .doit = nl80211_get_key, |
| 6572 | .policy = nl80211_policy, |
| 6573 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6574 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6575 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6576 | }, |
| 6577 | { |
| 6578 | .cmd = NL80211_CMD_SET_KEY, |
| 6579 | .doit = nl80211_set_key, |
| 6580 | .policy = nl80211_policy, |
| 6581 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6582 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6583 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6584 | }, |
| 6585 | { |
| 6586 | .cmd = NL80211_CMD_NEW_KEY, |
| 6587 | .doit = nl80211_new_key, |
| 6588 | .policy = nl80211_policy, |
| 6589 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6591 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6592 | }, |
| 6593 | { |
| 6594 | .cmd = NL80211_CMD_DEL_KEY, |
| 6595 | .doit = nl80211_del_key, |
| 6596 | .policy = nl80211_policy, |
| 6597 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6598 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6599 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6600 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6601 | { |
| 6602 | .cmd = NL80211_CMD_SET_BEACON, |
| 6603 | .policy = nl80211_policy, |
| 6604 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6605 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6606 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6607 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6608 | }, |
| 6609 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6610 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6611 | .policy = nl80211_policy, |
| 6612 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6613 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6614 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6615 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6616 | }, |
| 6617 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6618 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6619 | .policy = nl80211_policy, |
| 6620 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6621 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +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, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6624 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6625 | { |
| 6626 | .cmd = NL80211_CMD_GET_STATION, |
| 6627 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6628 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6629 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6630 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6631 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6632 | }, |
| 6633 | { |
| 6634 | .cmd = NL80211_CMD_SET_STATION, |
| 6635 | .doit = nl80211_set_station, |
| 6636 | .policy = nl80211_policy, |
| 6637 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6638 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6639 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6640 | }, |
| 6641 | { |
| 6642 | .cmd = NL80211_CMD_NEW_STATION, |
| 6643 | .doit = nl80211_new_station, |
| 6644 | .policy = nl80211_policy, |
| 6645 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6646 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6647 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6648 | }, |
| 6649 | { |
| 6650 | .cmd = NL80211_CMD_DEL_STATION, |
| 6651 | .doit = nl80211_del_station, |
| 6652 | .policy = nl80211_policy, |
| 6653 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6654 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6655 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6656 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6657 | { |
| 6658 | .cmd = NL80211_CMD_GET_MPATH, |
| 6659 | .doit = nl80211_get_mpath, |
| 6660 | .dumpit = nl80211_dump_mpath, |
| 6661 | .policy = nl80211_policy, |
| 6662 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6663 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6664 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6665 | }, |
| 6666 | { |
| 6667 | .cmd = NL80211_CMD_SET_MPATH, |
| 6668 | .doit = nl80211_set_mpath, |
| 6669 | .policy = nl80211_policy, |
| 6670 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6672 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6673 | }, |
| 6674 | { |
| 6675 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6676 | .doit = nl80211_new_mpath, |
| 6677 | .policy = nl80211_policy, |
| 6678 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6679 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6680 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6681 | }, |
| 6682 | { |
| 6683 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6684 | .doit = nl80211_del_mpath, |
| 6685 | .policy = nl80211_policy, |
| 6686 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6687 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6688 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6689 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6690 | { |
| 6691 | .cmd = NL80211_CMD_SET_BSS, |
| 6692 | .doit = nl80211_set_bss, |
| 6693 | .policy = nl80211_policy, |
| 6694 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6695 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6696 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6697 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6698 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6699 | .cmd = NL80211_CMD_GET_REG, |
| 6700 | .doit = nl80211_get_reg, |
| 6701 | .policy = nl80211_policy, |
| 6702 | /* can be retrieved by unprivileged users */ |
| 6703 | }, |
| 6704 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6705 | .cmd = NL80211_CMD_SET_REG, |
| 6706 | .doit = nl80211_set_reg, |
| 6707 | .policy = nl80211_policy, |
| 6708 | .flags = GENL_ADMIN_PERM, |
| 6709 | }, |
| 6710 | { |
| 6711 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6712 | .doit = nl80211_req_set_reg, |
| 6713 | .policy = nl80211_policy, |
| 6714 | .flags = GENL_ADMIN_PERM, |
| 6715 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6716 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6717 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6718 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6719 | .policy = nl80211_policy, |
| 6720 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6721 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6722 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6723 | }, |
| 6724 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6725 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6726 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6727 | .policy = nl80211_policy, |
| 6728 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6729 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6730 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6731 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6732 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6733 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6734 | .doit = nl80211_trigger_scan, |
| 6735 | .policy = nl80211_policy, |
| 6736 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6737 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6738 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6739 | }, |
| 6740 | { |
| 6741 | .cmd = NL80211_CMD_GET_SCAN, |
| 6742 | .policy = nl80211_policy, |
| 6743 | .dumpit = nl80211_dump_scan, |
| 6744 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6745 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6746 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6747 | .doit = nl80211_start_sched_scan, |
| 6748 | .policy = nl80211_policy, |
| 6749 | .flags = GENL_ADMIN_PERM, |
| 6750 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6751 | NL80211_FLAG_NEED_RTNL, |
| 6752 | }, |
| 6753 | { |
| 6754 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6755 | .doit = nl80211_stop_sched_scan, |
| 6756 | .policy = nl80211_policy, |
| 6757 | .flags = GENL_ADMIN_PERM, |
| 6758 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6759 | NL80211_FLAG_NEED_RTNL, |
| 6760 | }, |
| 6761 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6762 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6763 | .doit = nl80211_authenticate, |
| 6764 | .policy = nl80211_policy, |
| 6765 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6766 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6767 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6768 | }, |
| 6769 | { |
| 6770 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6771 | .doit = nl80211_associate, |
| 6772 | .policy = nl80211_policy, |
| 6773 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6774 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6775 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6776 | }, |
| 6777 | { |
| 6778 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6779 | .doit = nl80211_deauthenticate, |
| 6780 | .policy = nl80211_policy, |
| 6781 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6782 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6783 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6784 | }, |
| 6785 | { |
| 6786 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6787 | .doit = nl80211_disassociate, |
| 6788 | .policy = nl80211_policy, |
| 6789 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6790 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6791 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6792 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6793 | { |
| 6794 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6795 | .doit = nl80211_join_ibss, |
| 6796 | .policy = nl80211_policy, |
| 6797 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6798 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6799 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6800 | }, |
| 6801 | { |
| 6802 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6803 | .doit = nl80211_leave_ibss, |
| 6804 | .policy = nl80211_policy, |
| 6805 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6806 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6807 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6808 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6809 | #ifdef CONFIG_NL80211_TESTMODE |
| 6810 | { |
| 6811 | .cmd = NL80211_CMD_TESTMODE, |
| 6812 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6813 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6814 | .policy = nl80211_policy, |
| 6815 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6816 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6817 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6818 | }, |
| 6819 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6820 | { |
| 6821 | .cmd = NL80211_CMD_CONNECT, |
| 6822 | .doit = nl80211_connect, |
| 6823 | .policy = nl80211_policy, |
| 6824 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6825 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6826 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6827 | }, |
| 6828 | { |
| 6829 | .cmd = NL80211_CMD_DISCONNECT, |
| 6830 | .doit = nl80211_disconnect, |
| 6831 | .policy = nl80211_policy, |
| 6832 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6833 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6834 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6835 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6836 | { |
| 6837 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6838 | .doit = nl80211_wiphy_netns, |
| 6839 | .policy = nl80211_policy, |
| 6840 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6841 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6842 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6843 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6844 | { |
| 6845 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6846 | .policy = nl80211_policy, |
| 6847 | .dumpit = nl80211_dump_survey, |
| 6848 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6849 | { |
| 6850 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6851 | .doit = nl80211_setdel_pmksa, |
| 6852 | .policy = nl80211_policy, |
| 6853 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6854 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6855 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6856 | }, |
| 6857 | { |
| 6858 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6859 | .doit = nl80211_setdel_pmksa, |
| 6860 | .policy = nl80211_policy, |
| 6861 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6862 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6863 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6864 | }, |
| 6865 | { |
| 6866 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6867 | .doit = nl80211_flush_pmksa, |
| 6868 | .policy = nl80211_policy, |
| 6869 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 6870 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6871 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6872 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6873 | { |
| 6874 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6875 | .doit = nl80211_remain_on_channel, |
| 6876 | .policy = nl80211_policy, |
| 6877 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6878 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6879 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6880 | }, |
| 6881 | { |
| 6882 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6883 | .doit = nl80211_cancel_remain_on_channel, |
| 6884 | .policy = nl80211_policy, |
| 6885 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6886 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6887 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6888 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6889 | { |
| 6890 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6891 | .doit = nl80211_set_tx_bitrate_mask, |
| 6892 | .policy = nl80211_policy, |
| 6893 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6894 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6895 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6896 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6897 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6898 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6899 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6900 | .policy = nl80211_policy, |
| 6901 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6902 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6903 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6904 | }, |
| 6905 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6906 | .cmd = NL80211_CMD_FRAME, |
| 6907 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6908 | .policy = nl80211_policy, |
| 6909 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6910 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6911 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6912 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6913 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6914 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6915 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6916 | .policy = nl80211_policy, |
| 6917 | .flags = GENL_ADMIN_PERM, |
| 6918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6919 | NL80211_FLAG_NEED_RTNL, |
| 6920 | }, |
| 6921 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6922 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6923 | .doit = nl80211_set_power_save, |
| 6924 | .policy = nl80211_policy, |
| 6925 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6926 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6927 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6928 | }, |
| 6929 | { |
| 6930 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6931 | .doit = nl80211_get_power_save, |
| 6932 | .policy = nl80211_policy, |
| 6933 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6934 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6935 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6936 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6937 | { |
| 6938 | .cmd = NL80211_CMD_SET_CQM, |
| 6939 | .doit = nl80211_set_cqm, |
| 6940 | .policy = nl80211_policy, |
| 6941 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6942 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6943 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6944 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6945 | { |
| 6946 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6947 | .doit = nl80211_set_channel, |
| 6948 | .policy = nl80211_policy, |
| 6949 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6950 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6951 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6952 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6953 | { |
| 6954 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6955 | .doit = nl80211_set_wds_peer, |
| 6956 | .policy = nl80211_policy, |
| 6957 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6958 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6959 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6960 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6961 | { |
| 6962 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6963 | .doit = nl80211_join_mesh, |
| 6964 | .policy = nl80211_policy, |
| 6965 | .flags = GENL_ADMIN_PERM, |
| 6966 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6967 | NL80211_FLAG_NEED_RTNL, |
| 6968 | }, |
| 6969 | { |
| 6970 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6971 | .doit = nl80211_leave_mesh, |
| 6972 | .policy = nl80211_policy, |
| 6973 | .flags = GENL_ADMIN_PERM, |
| 6974 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6975 | NL80211_FLAG_NEED_RTNL, |
| 6976 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6977 | { |
| 6978 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6979 | .doit = nl80211_get_wowlan, |
| 6980 | .policy = nl80211_policy, |
| 6981 | /* can be retrieved by unprivileged users */ |
| 6982 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6983 | NL80211_FLAG_NEED_RTNL, |
| 6984 | }, |
| 6985 | { |
| 6986 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6987 | .doit = nl80211_set_wowlan, |
| 6988 | .policy = nl80211_policy, |
| 6989 | .flags = GENL_ADMIN_PERM, |
| 6990 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6991 | NL80211_FLAG_NEED_RTNL, |
| 6992 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6993 | { |
| 6994 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6995 | .doit = nl80211_set_rekey_data, |
| 6996 | .policy = nl80211_policy, |
| 6997 | .flags = GENL_ADMIN_PERM, |
| 6998 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6999 | NL80211_FLAG_NEED_RTNL, |
| 7000 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7001 | { |
| 7002 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 7003 | .doit = nl80211_tdls_mgmt, |
| 7004 | .policy = nl80211_policy, |
| 7005 | .flags = GENL_ADMIN_PERM, |
| 7006 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7007 | NL80211_FLAG_NEED_RTNL, |
| 7008 | }, |
| 7009 | { |
| 7010 | .cmd = NL80211_CMD_TDLS_OPER, |
| 7011 | .doit = nl80211_tdls_oper, |
| 7012 | .policy = nl80211_policy, |
| 7013 | .flags = GENL_ADMIN_PERM, |
| 7014 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 7015 | NL80211_FLAG_NEED_RTNL, |
| 7016 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7017 | { |
| 7018 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 7019 | .doit = nl80211_register_unexpected_frame, |
| 7020 | .policy = nl80211_policy, |
| 7021 | .flags = GENL_ADMIN_PERM, |
| 7022 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7023 | NL80211_FLAG_NEED_RTNL, |
| 7024 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7025 | { |
| 7026 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 7027 | .doit = nl80211_probe_client, |
| 7028 | .policy = nl80211_policy, |
| 7029 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 7030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7031 | NL80211_FLAG_NEED_RTNL, |
| 7032 | }, |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7033 | { |
| 7034 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 7035 | .doit = nl80211_register_beacons, |
| 7036 | .policy = nl80211_policy, |
| 7037 | .flags = GENL_ADMIN_PERM, |
| 7038 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 7039 | NL80211_FLAG_NEED_RTNL, |
| 7040 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 7041 | { |
| 7042 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 7043 | .doit = nl80211_set_noack_map, |
| 7044 | .policy = nl80211_policy, |
| 7045 | .flags = GENL_ADMIN_PERM, |
| 7046 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 7047 | NL80211_FLAG_NEED_RTNL, |
| 7048 | }, |
| 7049 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7050 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7051 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7052 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 7053 | .name = "mlme", |
| 7054 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7055 | |
| 7056 | /* multicast groups */ |
| 7057 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 7058 | .name = "config", |
| 7059 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7060 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 7061 | .name = "scan", |
| 7062 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7063 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 7064 | .name = "regulatory", |
| 7065 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7066 | |
| 7067 | /* notification functions */ |
| 7068 | |
| 7069 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 7070 | { |
| 7071 | struct sk_buff *msg; |
| 7072 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7073 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7074 | if (!msg) |
| 7075 | return; |
| 7076 | |
| 7077 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 7078 | nlmsg_free(msg); |
| 7079 | return; |
| 7080 | } |
| 7081 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7082 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7083 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7084 | } |
| 7085 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7086 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 7087 | struct cfg80211_registered_device *rdev) |
| 7088 | { |
| 7089 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 7090 | struct nlattr *nest; |
| 7091 | int i; |
| 7092 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7093 | ASSERT_RDEV_LOCK(rdev); |
| 7094 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7095 | if (WARN_ON(!req)) |
| 7096 | return 0; |
| 7097 | |
| 7098 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 7099 | if (!nest) |
| 7100 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7101 | for (i = 0; i < req->n_ssids; i++) { |
| 7102 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 7103 | goto nla_put_failure; |
| 7104 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7105 | nla_nest_end(msg, nest); |
| 7106 | |
| 7107 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 7108 | if (!nest) |
| 7109 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7110 | for (i = 0; i < req->n_channels; i++) { |
| 7111 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 7112 | goto nla_put_failure; |
| 7113 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7114 | nla_nest_end(msg, nest); |
| 7115 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7116 | if (req->ie && |
| 7117 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 7118 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7119 | |
| 7120 | return 0; |
| 7121 | nla_put_failure: |
| 7122 | return -ENOBUFS; |
| 7123 | } |
| 7124 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7125 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 7126 | struct cfg80211_registered_device *rdev, |
| 7127 | struct net_device *netdev, |
| 7128 | u32 pid, u32 seq, int flags, |
| 7129 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7130 | { |
| 7131 | void *hdr; |
| 7132 | |
| 7133 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 7134 | if (!hdr) |
| 7135 | return -1; |
| 7136 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7137 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7138 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7139 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7140 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 7141 | /* ignore errors and send incomplete event anyway */ |
| 7142 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7143 | |
| 7144 | return genlmsg_end(msg, hdr); |
| 7145 | |
| 7146 | nla_put_failure: |
| 7147 | genlmsg_cancel(msg, hdr); |
| 7148 | return -EMSGSIZE; |
| 7149 | } |
| 7150 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7151 | static int |
| 7152 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 7153 | struct cfg80211_registered_device *rdev, |
| 7154 | struct net_device *netdev, |
| 7155 | u32 pid, u32 seq, int flags, u32 cmd) |
| 7156 | { |
| 7157 | void *hdr; |
| 7158 | |
| 7159 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 7160 | if (!hdr) |
| 7161 | return -1; |
| 7162 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7163 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7164 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 7165 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7166 | |
| 7167 | return genlmsg_end(msg, hdr); |
| 7168 | |
| 7169 | nla_put_failure: |
| 7170 | genlmsg_cancel(msg, hdr); |
| 7171 | return -EMSGSIZE; |
| 7172 | } |
| 7173 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7174 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 7175 | struct net_device *netdev) |
| 7176 | { |
| 7177 | struct sk_buff *msg; |
| 7178 | |
| 7179 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7180 | if (!msg) |
| 7181 | return; |
| 7182 | |
| 7183 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7184 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7185 | nlmsg_free(msg); |
| 7186 | return; |
| 7187 | } |
| 7188 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7189 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7190 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7191 | } |
| 7192 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7193 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 7194 | struct net_device *netdev) |
| 7195 | { |
| 7196 | struct sk_buff *msg; |
| 7197 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7198 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7199 | if (!msg) |
| 7200 | return; |
| 7201 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7202 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7203 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7204 | nlmsg_free(msg); |
| 7205 | return; |
| 7206 | } |
| 7207 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7208 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7209 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7210 | } |
| 7211 | |
| 7212 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 7213 | struct net_device *netdev) |
| 7214 | { |
| 7215 | struct sk_buff *msg; |
| 7216 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7217 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7218 | if (!msg) |
| 7219 | return; |
| 7220 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7221 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7222 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7223 | nlmsg_free(msg); |
| 7224 | return; |
| 7225 | } |
| 7226 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7227 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7228 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7229 | } |
| 7230 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7231 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7232 | struct net_device *netdev) |
| 7233 | { |
| 7234 | struct sk_buff *msg; |
| 7235 | |
| 7236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7237 | if (!msg) |
| 7238 | return; |
| 7239 | |
| 7240 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7241 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7242 | nlmsg_free(msg); |
| 7243 | return; |
| 7244 | } |
| 7245 | |
| 7246 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7247 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7248 | } |
| 7249 | |
| 7250 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7251 | struct net_device *netdev, u32 cmd) |
| 7252 | { |
| 7253 | struct sk_buff *msg; |
| 7254 | |
| 7255 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7256 | if (!msg) |
| 7257 | return; |
| 7258 | |
| 7259 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7260 | nlmsg_free(msg); |
| 7261 | return; |
| 7262 | } |
| 7263 | |
| 7264 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7265 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7266 | } |
| 7267 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7268 | /* |
| 7269 | * This can happen on global regulatory changes or device specific settings |
| 7270 | * based on custom world regulatory domains. |
| 7271 | */ |
| 7272 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7273 | { |
| 7274 | struct sk_buff *msg; |
| 7275 | void *hdr; |
| 7276 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7277 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7278 | if (!msg) |
| 7279 | return; |
| 7280 | |
| 7281 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7282 | if (!hdr) { |
| 7283 | nlmsg_free(msg); |
| 7284 | return; |
| 7285 | } |
| 7286 | |
| 7287 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7288 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 7289 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7290 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7291 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 7292 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7293 | NL80211_REGDOM_TYPE_WORLD)) |
| 7294 | goto nla_put_failure; |
| 7295 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 7296 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7297 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 7298 | goto nla_put_failure; |
| 7299 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7300 | request->intersect) { |
| 7301 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7302 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 7303 | goto nla_put_failure; |
| 7304 | } else { |
| 7305 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 7306 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 7307 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 7308 | request->alpha2)) |
| 7309 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7310 | } |
| 7311 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7312 | if (wiphy_idx_valid(request->wiphy_idx) && |
| 7313 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 7314 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7315 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7316 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7317 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7318 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7319 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7320 | GFP_ATOMIC); |
| 7321 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7322 | |
| 7323 | return; |
| 7324 | |
| 7325 | nla_put_failure: |
| 7326 | genlmsg_cancel(msg, hdr); |
| 7327 | nlmsg_free(msg); |
| 7328 | } |
| 7329 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7330 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7331 | struct net_device *netdev, |
| 7332 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7333 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7334 | { |
| 7335 | struct sk_buff *msg; |
| 7336 | void *hdr; |
| 7337 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7338 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7339 | if (!msg) |
| 7340 | return; |
| 7341 | |
| 7342 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7343 | if (!hdr) { |
| 7344 | nlmsg_free(msg); |
| 7345 | return; |
| 7346 | } |
| 7347 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7348 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7349 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7350 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 7351 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7352 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7353 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7354 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7355 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7356 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7357 | return; |
| 7358 | |
| 7359 | nla_put_failure: |
| 7360 | genlmsg_cancel(msg, hdr); |
| 7361 | nlmsg_free(msg); |
| 7362 | } |
| 7363 | |
| 7364 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7365 | struct net_device *netdev, const u8 *buf, |
| 7366 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7367 | { |
| 7368 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7369 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7370 | } |
| 7371 | |
| 7372 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 7373 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7374 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7375 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7376 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7377 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7378 | } |
| 7379 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7380 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7381 | struct net_device *netdev, const u8 *buf, |
| 7382 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7383 | { |
| 7384 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7385 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7386 | } |
| 7387 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7388 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 7389 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7390 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7391 | { |
| 7392 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7393 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7394 | } |
| 7395 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7396 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7397 | struct net_device *netdev, const u8 *buf, |
| 7398 | size_t len, gfp_t gfp) |
| 7399 | { |
| 7400 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7401 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7402 | } |
| 7403 | |
| 7404 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7405 | struct net_device *netdev, const u8 *buf, |
| 7406 | size_t len, gfp_t gfp) |
| 7407 | { |
| 7408 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7409 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7410 | } |
| 7411 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7412 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7413 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7414 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7415 | { |
| 7416 | struct sk_buff *msg; |
| 7417 | void *hdr; |
| 7418 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7419 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7420 | if (!msg) |
| 7421 | return; |
| 7422 | |
| 7423 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7424 | if (!hdr) { |
| 7425 | nlmsg_free(msg); |
| 7426 | return; |
| 7427 | } |
| 7428 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7429 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7430 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7431 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 7432 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 7433 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7434 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7435 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7436 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7437 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7438 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7439 | return; |
| 7440 | |
| 7441 | nla_put_failure: |
| 7442 | genlmsg_cancel(msg, hdr); |
| 7443 | nlmsg_free(msg); |
| 7444 | } |
| 7445 | |
| 7446 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7447 | struct net_device *netdev, const u8 *addr, |
| 7448 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7449 | { |
| 7450 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7451 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7452 | } |
| 7453 | |
| 7454 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7455 | struct net_device *netdev, const u8 *addr, |
| 7456 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7457 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7458 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 7459 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7460 | } |
| 7461 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7462 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 7463 | struct net_device *netdev, const u8 *bssid, |
| 7464 | const u8 *req_ie, size_t req_ie_len, |
| 7465 | const u8 *resp_ie, size_t resp_ie_len, |
| 7466 | u16 status, gfp_t gfp) |
| 7467 | { |
| 7468 | struct sk_buff *msg; |
| 7469 | void *hdr; |
| 7470 | |
| 7471 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7472 | if (!msg) |
| 7473 | return; |
| 7474 | |
| 7475 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 7476 | if (!hdr) { |
| 7477 | nlmsg_free(msg); |
| 7478 | return; |
| 7479 | } |
| 7480 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7481 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7482 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7483 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 7484 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 7485 | (req_ie && |
| 7486 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 7487 | (resp_ie && |
| 7488 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 7489 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7490 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7491 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7492 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7493 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7494 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7495 | return; |
| 7496 | |
| 7497 | nla_put_failure: |
| 7498 | genlmsg_cancel(msg, hdr); |
| 7499 | nlmsg_free(msg); |
| 7500 | |
| 7501 | } |
| 7502 | |
| 7503 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 7504 | struct net_device *netdev, const u8 *bssid, |
| 7505 | const u8 *req_ie, size_t req_ie_len, |
| 7506 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 7507 | { |
| 7508 | struct sk_buff *msg; |
| 7509 | void *hdr; |
| 7510 | |
| 7511 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7512 | if (!msg) |
| 7513 | return; |
| 7514 | |
| 7515 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 7516 | if (!hdr) { |
| 7517 | nlmsg_free(msg); |
| 7518 | return; |
| 7519 | } |
| 7520 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7521 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7522 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7523 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 7524 | (req_ie && |
| 7525 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 7526 | (resp_ie && |
| 7527 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 7528 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7529 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7530 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7531 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7532 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7533 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7534 | return; |
| 7535 | |
| 7536 | nla_put_failure: |
| 7537 | genlmsg_cancel(msg, hdr); |
| 7538 | nlmsg_free(msg); |
| 7539 | |
| 7540 | } |
| 7541 | |
| 7542 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 7543 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7544 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7545 | { |
| 7546 | struct sk_buff *msg; |
| 7547 | void *hdr; |
| 7548 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7549 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7550 | if (!msg) |
| 7551 | return; |
| 7552 | |
| 7553 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7554 | if (!hdr) { |
| 7555 | nlmsg_free(msg); |
| 7556 | return; |
| 7557 | } |
| 7558 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7559 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7560 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7561 | (from_ap && reason && |
| 7562 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 7563 | (from_ap && |
| 7564 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 7565 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 7566 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7567 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7568 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7569 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7570 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7571 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7572 | return; |
| 7573 | |
| 7574 | nla_put_failure: |
| 7575 | genlmsg_cancel(msg, hdr); |
| 7576 | nlmsg_free(msg); |
| 7577 | |
| 7578 | } |
| 7579 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7580 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7581 | struct net_device *netdev, const u8 *bssid, |
| 7582 | gfp_t gfp) |
| 7583 | { |
| 7584 | struct sk_buff *msg; |
| 7585 | void *hdr; |
| 7586 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7587 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7588 | if (!msg) |
| 7589 | return; |
| 7590 | |
| 7591 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7592 | if (!hdr) { |
| 7593 | nlmsg_free(msg); |
| 7594 | return; |
| 7595 | } |
| 7596 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7597 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7598 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7599 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 7600 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7601 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7602 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7603 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7604 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7605 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7606 | return; |
| 7607 | |
| 7608 | nla_put_failure: |
| 7609 | genlmsg_cancel(msg, hdr); |
| 7610 | nlmsg_free(msg); |
| 7611 | } |
| 7612 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7613 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7614 | struct net_device *netdev, |
| 7615 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7616 | gfp_t gfp) |
| 7617 | { |
| 7618 | struct sk_buff *msg; |
| 7619 | void *hdr; |
| 7620 | |
| 7621 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7622 | if (!msg) |
| 7623 | return; |
| 7624 | |
| 7625 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7626 | if (!hdr) { |
| 7627 | nlmsg_free(msg); |
| 7628 | return; |
| 7629 | } |
| 7630 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7631 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7632 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7633 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || |
| 7634 | (ie_len && ie && |
| 7635 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 7636 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7637 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7638 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7639 | |
| 7640 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7641 | nl80211_mlme_mcgrp.id, gfp); |
| 7642 | return; |
| 7643 | |
| 7644 | nla_put_failure: |
| 7645 | genlmsg_cancel(msg, hdr); |
| 7646 | nlmsg_free(msg); |
| 7647 | } |
| 7648 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7649 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7650 | struct net_device *netdev, const u8 *addr, |
| 7651 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7652 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7653 | { |
| 7654 | struct sk_buff *msg; |
| 7655 | void *hdr; |
| 7656 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7657 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7658 | if (!msg) |
| 7659 | return; |
| 7660 | |
| 7661 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7662 | if (!hdr) { |
| 7663 | nlmsg_free(msg); |
| 7664 | return; |
| 7665 | } |
| 7666 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7667 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7668 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7669 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 7670 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 7671 | (key_id != -1 && |
| 7672 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 7673 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 7674 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7675 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7676 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7677 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7678 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7679 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7680 | return; |
| 7681 | |
| 7682 | nla_put_failure: |
| 7683 | genlmsg_cancel(msg, hdr); |
| 7684 | nlmsg_free(msg); |
| 7685 | } |
| 7686 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7687 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7688 | struct ieee80211_channel *channel_before, |
| 7689 | struct ieee80211_channel *channel_after) |
| 7690 | { |
| 7691 | struct sk_buff *msg; |
| 7692 | void *hdr; |
| 7693 | struct nlattr *nl_freq; |
| 7694 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7695 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7696 | if (!msg) |
| 7697 | return; |
| 7698 | |
| 7699 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7700 | if (!hdr) { |
| 7701 | nlmsg_free(msg); |
| 7702 | return; |
| 7703 | } |
| 7704 | |
| 7705 | /* |
| 7706 | * Since we are applying the beacon hint to a wiphy we know its |
| 7707 | * wiphy_idx is valid |
| 7708 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7709 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7710 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7711 | |
| 7712 | /* Before */ |
| 7713 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7714 | if (!nl_freq) |
| 7715 | goto nla_put_failure; |
| 7716 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7717 | goto nla_put_failure; |
| 7718 | nla_nest_end(msg, nl_freq); |
| 7719 | |
| 7720 | /* After */ |
| 7721 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7722 | if (!nl_freq) |
| 7723 | goto nla_put_failure; |
| 7724 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7725 | goto nla_put_failure; |
| 7726 | nla_nest_end(msg, nl_freq); |
| 7727 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7728 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7729 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7730 | rcu_read_lock(); |
| 7731 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7732 | GFP_ATOMIC); |
| 7733 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7734 | |
| 7735 | return; |
| 7736 | |
| 7737 | nla_put_failure: |
| 7738 | genlmsg_cancel(msg, hdr); |
| 7739 | nlmsg_free(msg); |
| 7740 | } |
| 7741 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7742 | static void nl80211_send_remain_on_chan_event( |
| 7743 | int cmd, struct cfg80211_registered_device *rdev, |
| 7744 | struct net_device *netdev, u64 cookie, |
| 7745 | struct ieee80211_channel *chan, |
| 7746 | enum nl80211_channel_type channel_type, |
| 7747 | unsigned int duration, gfp_t gfp) |
| 7748 | { |
| 7749 | struct sk_buff *msg; |
| 7750 | void *hdr; |
| 7751 | |
| 7752 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7753 | if (!msg) |
| 7754 | return; |
| 7755 | |
| 7756 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7757 | if (!hdr) { |
| 7758 | nlmsg_free(msg); |
| 7759 | return; |
| 7760 | } |
| 7761 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7762 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7763 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7764 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
| 7765 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) || |
| 7766 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7767 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7768 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7769 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 7770 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 7771 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7772 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7773 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7774 | |
| 7775 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7776 | nl80211_mlme_mcgrp.id, gfp); |
| 7777 | return; |
| 7778 | |
| 7779 | nla_put_failure: |
| 7780 | genlmsg_cancel(msg, hdr); |
| 7781 | nlmsg_free(msg); |
| 7782 | } |
| 7783 | |
| 7784 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7785 | struct net_device *netdev, u64 cookie, |
| 7786 | struct ieee80211_channel *chan, |
| 7787 | enum nl80211_channel_type channel_type, |
| 7788 | unsigned int duration, gfp_t gfp) |
| 7789 | { |
| 7790 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7791 | rdev, netdev, cookie, chan, |
| 7792 | channel_type, duration, gfp); |
| 7793 | } |
| 7794 | |
| 7795 | void nl80211_send_remain_on_channel_cancel( |
| 7796 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7797 | u64 cookie, struct ieee80211_channel *chan, |
| 7798 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7799 | { |
| 7800 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7801 | rdev, netdev, cookie, chan, |
| 7802 | channel_type, 0, gfp); |
| 7803 | } |
| 7804 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7805 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7806 | struct net_device *dev, const u8 *mac_addr, |
| 7807 | struct station_info *sinfo, gfp_t gfp) |
| 7808 | { |
| 7809 | struct sk_buff *msg; |
| 7810 | |
| 7811 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7812 | if (!msg) |
| 7813 | return; |
| 7814 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 7815 | if (nl80211_send_station(msg, 0, 0, 0, |
| 7816 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7817 | nlmsg_free(msg); |
| 7818 | return; |
| 7819 | } |
| 7820 | |
| 7821 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7822 | nl80211_mlme_mcgrp.id, gfp); |
| 7823 | } |
| 7824 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7825 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7826 | struct net_device *dev, const u8 *mac_addr, |
| 7827 | gfp_t gfp) |
| 7828 | { |
| 7829 | struct sk_buff *msg; |
| 7830 | void *hdr; |
| 7831 | |
| 7832 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7833 | if (!msg) |
| 7834 | return; |
| 7835 | |
| 7836 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7837 | if (!hdr) { |
| 7838 | nlmsg_free(msg); |
| 7839 | return; |
| 7840 | } |
| 7841 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7842 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 7843 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 7844 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7845 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7846 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7847 | |
| 7848 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7849 | nl80211_mlme_mcgrp.id, gfp); |
| 7850 | return; |
| 7851 | |
| 7852 | nla_put_failure: |
| 7853 | genlmsg_cancel(msg, hdr); |
| 7854 | nlmsg_free(msg); |
| 7855 | } |
| 7856 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7857 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 7858 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7859 | { |
| 7860 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7861 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7862 | struct sk_buff *msg; |
| 7863 | void *hdr; |
| 7864 | int err; |
| 7865 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 7866 | |
| 7867 | if (!nlpid) |
| 7868 | return false; |
| 7869 | |
| 7870 | msg = nlmsg_new(100, gfp); |
| 7871 | if (!msg) |
| 7872 | return true; |
| 7873 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7874 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7875 | if (!hdr) { |
| 7876 | nlmsg_free(msg); |
| 7877 | return true; |
| 7878 | } |
| 7879 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7880 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7881 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 7882 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 7883 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7884 | |
| 7885 | err = genlmsg_end(msg, hdr); |
| 7886 | if (err < 0) { |
| 7887 | nlmsg_free(msg); |
| 7888 | return true; |
| 7889 | } |
| 7890 | |
| 7891 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7892 | return true; |
| 7893 | |
| 7894 | nla_put_failure: |
| 7895 | genlmsg_cancel(msg, hdr); |
| 7896 | nlmsg_free(msg); |
| 7897 | return true; |
| 7898 | } |
| 7899 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7900 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 7901 | { |
| 7902 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 7903 | addr, gfp); |
| 7904 | } |
| 7905 | |
| 7906 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 7907 | const u8 *addr, gfp_t gfp) |
| 7908 | { |
| 7909 | return __nl80211_unexpected_frame(dev, |
| 7910 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 7911 | addr, gfp); |
| 7912 | } |
| 7913 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7914 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7915 | struct net_device *netdev, u32 nlpid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 7916 | int freq, int sig_dbm, |
| 7917 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7918 | { |
| 7919 | struct sk_buff *msg; |
| 7920 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7921 | |
| 7922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7923 | if (!msg) |
| 7924 | return -ENOMEM; |
| 7925 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7926 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7927 | if (!hdr) { |
| 7928 | nlmsg_free(msg); |
| 7929 | return -ENOMEM; |
| 7930 | } |
| 7931 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7932 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7933 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7934 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 7935 | (sig_dbm && |
| 7936 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 7937 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 7938 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7939 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7940 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7941 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7942 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7943 | |
| 7944 | nla_put_failure: |
| 7945 | genlmsg_cancel(msg, hdr); |
| 7946 | nlmsg_free(msg); |
| 7947 | return -ENOBUFS; |
| 7948 | } |
| 7949 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7950 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7951 | struct net_device *netdev, u64 cookie, |
| 7952 | const u8 *buf, size_t len, bool ack, |
| 7953 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7954 | { |
| 7955 | struct sk_buff *msg; |
| 7956 | void *hdr; |
| 7957 | |
| 7958 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7959 | if (!msg) |
| 7960 | return; |
| 7961 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7962 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7963 | if (!hdr) { |
| 7964 | nlmsg_free(msg); |
| 7965 | return; |
| 7966 | } |
| 7967 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 7969 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 7970 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 7971 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 7972 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 7973 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7974 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7975 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7976 | |
| 7977 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7978 | return; |
| 7979 | |
| 7980 | nla_put_failure: |
| 7981 | genlmsg_cancel(msg, hdr); |
| 7982 | nlmsg_free(msg); |
| 7983 | } |
| 7984 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7985 | void |
| 7986 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7987 | struct net_device *netdev, |
| 7988 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7989 | gfp_t gfp) |
| 7990 | { |
| 7991 | struct sk_buff *msg; |
| 7992 | struct nlattr *pinfoattr; |
| 7993 | void *hdr; |
| 7994 | |
| 7995 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7996 | if (!msg) |
| 7997 | return; |
| 7998 | |
| 7999 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8000 | if (!hdr) { |
| 8001 | nlmsg_free(msg); |
| 8002 | return; |
| 8003 | } |
| 8004 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8005 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8006 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8007 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8008 | |
| 8009 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8010 | if (!pinfoattr) |
| 8011 | goto nla_put_failure; |
| 8012 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8013 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 8014 | rssi_event)) |
| 8015 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8016 | |
| 8017 | nla_nest_end(msg, pinfoattr); |
| 8018 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8019 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8020 | |
| 8021 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8022 | nl80211_mlme_mcgrp.id, gfp); |
| 8023 | return; |
| 8024 | |
| 8025 | nla_put_failure: |
| 8026 | genlmsg_cancel(msg, hdr); |
| 8027 | nlmsg_free(msg); |
| 8028 | } |
| 8029 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8030 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 8031 | struct net_device *netdev, const u8 *bssid, |
| 8032 | const u8 *replay_ctr, gfp_t gfp) |
| 8033 | { |
| 8034 | struct sk_buff *msg; |
| 8035 | struct nlattr *rekey_attr; |
| 8036 | void *hdr; |
| 8037 | |
| 8038 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8039 | if (!msg) |
| 8040 | return; |
| 8041 | |
| 8042 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 8043 | if (!hdr) { |
| 8044 | nlmsg_free(msg); |
| 8045 | return; |
| 8046 | } |
| 8047 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8048 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8049 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8050 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 8051 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8052 | |
| 8053 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 8054 | if (!rekey_attr) |
| 8055 | goto nla_put_failure; |
| 8056 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8057 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 8058 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 8059 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8060 | |
| 8061 | nla_nest_end(msg, rekey_attr); |
| 8062 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8063 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8064 | |
| 8065 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8066 | nl80211_mlme_mcgrp.id, gfp); |
| 8067 | return; |
| 8068 | |
| 8069 | nla_put_failure: |
| 8070 | genlmsg_cancel(msg, hdr); |
| 8071 | nlmsg_free(msg); |
| 8072 | } |
| 8073 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8074 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 8075 | struct net_device *netdev, int index, |
| 8076 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 8077 | { |
| 8078 | struct sk_buff *msg; |
| 8079 | struct nlattr *attr; |
| 8080 | void *hdr; |
| 8081 | |
| 8082 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8083 | if (!msg) |
| 8084 | return; |
| 8085 | |
| 8086 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 8087 | if (!hdr) { |
| 8088 | nlmsg_free(msg); |
| 8089 | return; |
| 8090 | } |
| 8091 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8092 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8093 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 8094 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8095 | |
| 8096 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 8097 | if (!attr) |
| 8098 | goto nla_put_failure; |
| 8099 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8100 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 8101 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 8102 | (preauth && |
| 8103 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 8104 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8105 | |
| 8106 | nla_nest_end(msg, attr); |
| 8107 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8108 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 8109 | |
| 8110 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8111 | nl80211_mlme_mcgrp.id, gfp); |
| 8112 | return; |
| 8113 | |
| 8114 | nla_put_failure: |
| 8115 | genlmsg_cancel(msg, hdr); |
| 8116 | nlmsg_free(msg); |
| 8117 | } |
| 8118 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8119 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 8120 | struct net_device *netdev, int freq, |
| 8121 | enum nl80211_channel_type type, gfp_t gfp) |
| 8122 | { |
| 8123 | struct sk_buff *msg; |
| 8124 | void *hdr; |
| 8125 | |
| 8126 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8127 | if (!msg) |
| 8128 | return; |
| 8129 | |
| 8130 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 8131 | if (!hdr) { |
| 8132 | nlmsg_free(msg); |
| 8133 | return; |
| 8134 | } |
| 8135 | |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 8136 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8137 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8138 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type)) |
| 8139 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 8140 | |
| 8141 | genlmsg_end(msg, hdr); |
| 8142 | |
| 8143 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8144 | nl80211_mlme_mcgrp.id, gfp); |
| 8145 | return; |
| 8146 | |
| 8147 | nla_put_failure: |
| 8148 | genlmsg_cancel(msg, hdr); |
| 8149 | nlmsg_free(msg); |
| 8150 | } |
| 8151 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8152 | void |
| 8153 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 8154 | struct net_device *netdev, const u8 *peer, |
| 8155 | u32 num_packets, gfp_t gfp) |
| 8156 | { |
| 8157 | struct sk_buff *msg; |
| 8158 | struct nlattr *pinfoattr; |
| 8159 | void *hdr; |
| 8160 | |
| 8161 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8162 | if (!msg) |
| 8163 | return; |
| 8164 | |
| 8165 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 8166 | if (!hdr) { |
| 8167 | nlmsg_free(msg); |
| 8168 | return; |
| 8169 | } |
| 8170 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8171 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8172 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 8173 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 8174 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8175 | |
| 8176 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 8177 | if (!pinfoattr) |
| 8178 | goto nla_put_failure; |
| 8179 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8180 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 8181 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8182 | |
| 8183 | nla_nest_end(msg, pinfoattr); |
| 8184 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 8185 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 8186 | |
| 8187 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8188 | nl80211_mlme_mcgrp.id, gfp); |
| 8189 | return; |
| 8190 | |
| 8191 | nla_put_failure: |
| 8192 | genlmsg_cancel(msg, hdr); |
| 8193 | nlmsg_free(msg); |
| 8194 | } |
| 8195 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8196 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 8197 | u64 cookie, bool acked, gfp_t gfp) |
| 8198 | { |
| 8199 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8200 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 8201 | struct sk_buff *msg; |
| 8202 | void *hdr; |
| 8203 | int err; |
| 8204 | |
| 8205 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 8206 | if (!msg) |
| 8207 | return; |
| 8208 | |
| 8209 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 8210 | if (!hdr) { |
| 8211 | nlmsg_free(msg); |
| 8212 | return; |
| 8213 | } |
| 8214 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8215 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8216 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 8217 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8218 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 8219 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 8220 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 8221 | |
| 8222 | err = genlmsg_end(msg, hdr); |
| 8223 | if (err < 0) { |
| 8224 | nlmsg_free(msg); |
| 8225 | return; |
| 8226 | } |
| 8227 | |
| 8228 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8229 | nl80211_mlme_mcgrp.id, gfp); |
| 8230 | return; |
| 8231 | |
| 8232 | nla_put_failure: |
| 8233 | genlmsg_cancel(msg, hdr); |
| 8234 | nlmsg_free(msg); |
| 8235 | } |
| 8236 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 8237 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8238 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 8239 | const u8 *frame, size_t len, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8240 | int freq, int sig_dbm, gfp_t gfp) |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8241 | { |
| 8242 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 8243 | struct sk_buff *msg; |
| 8244 | void *hdr; |
| 8245 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 8246 | |
| 8247 | if (!nlpid) |
| 8248 | return; |
| 8249 | |
| 8250 | msg = nlmsg_new(len + 100, gfp); |
| 8251 | if (!msg) |
| 8252 | return; |
| 8253 | |
| 8254 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 8255 | if (!hdr) { |
| 8256 | nlmsg_free(msg); |
| 8257 | return; |
| 8258 | } |
| 8259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8260 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 8261 | (freq && |
| 8262 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 8263 | (sig_dbm && |
| 8264 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 8265 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 8266 | goto nla_put_failure; |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8267 | |
| 8268 | genlmsg_end(msg, hdr); |
| 8269 | |
| 8270 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 8271 | return; |
| 8272 | |
| 8273 | nla_put_failure: |
| 8274 | genlmsg_cancel(msg, hdr); |
| 8275 | nlmsg_free(msg); |
| 8276 | } |
| 8277 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 8278 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8279 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 8280 | unsigned long state, |
| 8281 | void *_notify) |
| 8282 | { |
| 8283 | struct netlink_notify *notify = _notify; |
| 8284 | struct cfg80211_registered_device *rdev; |
| 8285 | struct wireless_dev *wdev; |
| 8286 | |
| 8287 | if (state != NETLINK_URELEASE) |
| 8288 | return NOTIFY_DONE; |
| 8289 | |
| 8290 | rcu_read_lock(); |
| 8291 | |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8292 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8293 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8294 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e760230 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8295 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 8296 | rdev->ap_beacons_nlpid = 0; |
| 8297 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8298 | |
| 8299 | rcu_read_unlock(); |
| 8300 | |
| 8301 | return NOTIFY_DONE; |
| 8302 | } |
| 8303 | |
| 8304 | static struct notifier_block nl80211_netlink_notifier = { |
| 8305 | .notifier_call = nl80211_netlink_notify, |
| 8306 | }; |
| 8307 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8308 | /* initialisation/exit functions */ |
| 8309 | |
| 8310 | int nl80211_init(void) |
| 8311 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8312 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8313 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8314 | err = genl_register_family_with_ops(&nl80211_fam, |
| 8315 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8316 | if (err) |
| 8317 | return err; |
| 8318 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8319 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 8320 | if (err) |
| 8321 | goto err_out; |
| 8322 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8323 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 8324 | if (err) |
| 8325 | goto err_out; |
| 8326 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8327 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 8328 | if (err) |
| 8329 | goto err_out; |
| 8330 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8331 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 8332 | if (err) |
| 8333 | goto err_out; |
| 8334 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8335 | #ifdef CONFIG_NL80211_TESTMODE |
| 8336 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 8337 | if (err) |
| 8338 | goto err_out; |
| 8339 | #endif |
| 8340 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8341 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 8342 | if (err) |
| 8343 | goto err_out; |
| 8344 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8345 | return 0; |
| 8346 | err_out: |
| 8347 | genl_unregister_family(&nl80211_fam); |
| 8348 | return err; |
| 8349 | } |
| 8350 | |
| 8351 | void nl80211_exit(void) |
| 8352 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8353 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8354 | genl_unregister_family(&nl80211_fam); |
| 8355 | } |