Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 26 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
| 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 49 | /* internal helper: get rdev and dev */ |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 50 | static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs, |
| 51 | struct cfg80211_registered_device **rdev, |
| 52 | struct net_device **dev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | { |
| 54 | int ifindex; |
| 55 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 56 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 57 | return -EINVAL; |
| 58 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 59 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 60 | *dev = dev_get_by_index(netns, ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 61 | if (!*dev) |
| 62 | return -ENODEV; |
| 63 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 64 | *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 65 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 66 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 67 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 74 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 75 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 76 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 77 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 78 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 79 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 80 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 81 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 82 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 83 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 84 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 85 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 86 | |
| 87 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 88 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 89 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 90 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 91 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 92 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 93 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 94 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 95 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 96 | .len = WLAN_MAX_KEY_LEN }, |
| 97 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 98 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 99 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 100 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 101 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 102 | |
| 103 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 104 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 105 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 106 | .len = IEEE80211_MAX_DATA_LEN }, |
| 107 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 108 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 109 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 110 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 111 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 112 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 113 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 114 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 115 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 116 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 117 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 118 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 119 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 120 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 121 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 122 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 123 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 124 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 125 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 126 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 127 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 128 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 129 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 130 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 131 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 132 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 133 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 134 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 135 | |
| 136 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 137 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 138 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 139 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 140 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 141 | |
| 142 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 143 | .len = IEEE80211_MAX_SSID_LEN }, |
| 144 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 145 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 146 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 147 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_STA_FLAGS2] = { |
| 150 | .len = sizeof(struct nl80211_sta_flag_update), |
| 151 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 152 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 153 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 154 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 155 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 156 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 157 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 158 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 159 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 160 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 161 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 162 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 163 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 164 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 166 | .len = IEEE80211_MAX_DATA_LEN }, |
| 167 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 168 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 169 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 170 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 171 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 172 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 173 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 174 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 175 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 176 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 177 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 178 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 179 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 180 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 181 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 182 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 183 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 184 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 185 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 186 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 187 | .len = IEEE80211_MAX_DATA_LEN }, |
| 188 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 189 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 190 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 191 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 192 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 193 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 194 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 195 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 196 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 197 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 198 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 199 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 200 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 201 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 202 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 203 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 204 | .len = NL80211_HT_CAPABILITY_LEN |
| 205 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 206 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 207 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
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 | { |
| 359 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 360 | chan->center_freq); |
| 361 | |
| 362 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 363 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 364 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 365 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 366 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 367 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 368 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 369 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 370 | |
| 371 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 372 | DBM_TO_MBM(chan->max_power)); |
| 373 | |
| 374 | return 0; |
| 375 | |
| 376 | nla_put_failure: |
| 377 | return -ENOBUFS; |
| 378 | } |
| 379 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 380 | /* netlink command implementations */ |
| 381 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 382 | struct key_parse { |
| 383 | struct key_params p; |
| 384 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 385 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 386 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 387 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 391 | { |
| 392 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 393 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 394 | nl80211_key_policy); |
| 395 | if (err) |
| 396 | return err; |
| 397 | |
| 398 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 399 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 400 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 401 | if (k->def) { |
| 402 | k->def_uni = true; |
| 403 | k->def_multi = true; |
| 404 | } |
| 405 | if (k->defmgmt) |
| 406 | k->def_multi = true; |
| 407 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 408 | if (tb[NL80211_KEY_IDX]) |
| 409 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 410 | |
| 411 | if (tb[NL80211_KEY_DATA]) { |
| 412 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 413 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 414 | } |
| 415 | |
| 416 | if (tb[NL80211_KEY_SEQ]) { |
| 417 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 418 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 419 | } |
| 420 | |
| 421 | if (tb[NL80211_KEY_CIPHER]) |
| 422 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 423 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 424 | if (tb[NL80211_KEY_TYPE]) { |
| 425 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 426 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 427 | return -EINVAL; |
| 428 | } |
| 429 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 430 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 431 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 432 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 433 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 434 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 435 | if (err) |
| 436 | return err; |
| 437 | |
| 438 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 439 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 440 | } |
| 441 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 446 | { |
| 447 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 448 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 449 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 450 | } |
| 451 | |
| 452 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 453 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 454 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 455 | } |
| 456 | |
| 457 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 458 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 459 | |
| 460 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 461 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 462 | |
| 463 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 464 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 465 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 466 | if (k->def) { |
| 467 | k->def_uni = true; |
| 468 | k->def_multi = true; |
| 469 | } |
| 470 | if (k->defmgmt) |
| 471 | k->def_multi = true; |
| 472 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 473 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 474 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 475 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 476 | return -EINVAL; |
| 477 | } |
| 478 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 479 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 480 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 481 | int err = nla_parse_nested( |
| 482 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 483 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 484 | nl80211_key_default_policy); |
| 485 | if (err) |
| 486 | return err; |
| 487 | |
| 488 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 489 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 490 | } |
| 491 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 496 | { |
| 497 | int err; |
| 498 | |
| 499 | memset(k, 0, sizeof(*k)); |
| 500 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 501 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 502 | |
| 503 | if (info->attrs[NL80211_ATTR_KEY]) |
| 504 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 505 | else |
| 506 | err = nl80211_parse_key_old(info, k); |
| 507 | |
| 508 | if (err) |
| 509 | return err; |
| 510 | |
| 511 | if (k->def && k->defmgmt) |
| 512 | return -EINVAL; |
| 513 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 514 | if (k->defmgmt) { |
| 515 | if (k->def_uni || !k->def_multi) |
| 516 | return -EINVAL; |
| 517 | } |
| 518 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 519 | if (k->idx != -1) { |
| 520 | if (k->defmgmt) { |
| 521 | if (k->idx < 4 || k->idx > 5) |
| 522 | return -EINVAL; |
| 523 | } else if (k->def) { |
| 524 | if (k->idx < 0 || k->idx > 3) |
| 525 | return -EINVAL; |
| 526 | } else { |
| 527 | if (k->idx < 0 || k->idx > 5) |
| 528 | return -EINVAL; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 535 | static struct cfg80211_cached_keys * |
| 536 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 537 | struct nlattr *keys) |
| 538 | { |
| 539 | struct key_parse parse; |
| 540 | struct nlattr *key; |
| 541 | struct cfg80211_cached_keys *result; |
| 542 | int rem, err, def = 0; |
| 543 | |
| 544 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 545 | if (!result) |
| 546 | return ERR_PTR(-ENOMEM); |
| 547 | |
| 548 | result->def = -1; |
| 549 | result->defmgmt = -1; |
| 550 | |
| 551 | nla_for_each_nested(key, keys, rem) { |
| 552 | memset(&parse, 0, sizeof(parse)); |
| 553 | parse.idx = -1; |
| 554 | |
| 555 | err = nl80211_parse_key_new(key, &parse); |
| 556 | if (err) |
| 557 | goto error; |
| 558 | err = -EINVAL; |
| 559 | if (!parse.p.key) |
| 560 | goto error; |
| 561 | if (parse.idx < 0 || parse.idx > 4) |
| 562 | goto error; |
| 563 | if (parse.def) { |
| 564 | if (def) |
| 565 | goto error; |
| 566 | def = 1; |
| 567 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 568 | if (!parse.def_uni || !parse.def_multi) |
| 569 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 570 | } else if (parse.defmgmt) |
| 571 | goto error; |
| 572 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 573 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 574 | if (err) |
| 575 | goto error; |
| 576 | result->params[parse.idx].cipher = parse.p.cipher; |
| 577 | result->params[parse.idx].key_len = parse.p.key_len; |
| 578 | result->params[parse.idx].key = result->data[parse.idx]; |
| 579 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 580 | } |
| 581 | |
| 582 | return result; |
| 583 | error: |
| 584 | kfree(result); |
| 585 | return ERR_PTR(err); |
| 586 | } |
| 587 | |
| 588 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 589 | { |
| 590 | ASSERT_WDEV_LOCK(wdev); |
| 591 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 592 | switch (wdev->iftype) { |
| 593 | case NL80211_IFTYPE_AP: |
| 594 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 595 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 596 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 597 | break; |
| 598 | case NL80211_IFTYPE_ADHOC: |
| 599 | if (!wdev->current_bss) |
| 600 | return -ENOLINK; |
| 601 | break; |
| 602 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 603 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 604 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 605 | return -ENOLINK; |
| 606 | break; |
| 607 | default: |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 614 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 615 | { |
| 616 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 617 | int i; |
| 618 | |
| 619 | if (!nl_modes) |
| 620 | goto nla_put_failure; |
| 621 | |
| 622 | i = 0; |
| 623 | while (ifmodes) { |
| 624 | if (ifmodes & 1) |
| 625 | NLA_PUT_FLAG(msg, i); |
| 626 | ifmodes >>= 1; |
| 627 | i++; |
| 628 | } |
| 629 | |
| 630 | nla_nest_end(msg, nl_modes); |
| 631 | return 0; |
| 632 | |
| 633 | nla_put_failure: |
| 634 | return -ENOBUFS; |
| 635 | } |
| 636 | |
| 637 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 638 | struct sk_buff *msg) |
| 639 | { |
| 640 | struct nlattr *nl_combis; |
| 641 | int i, j; |
| 642 | |
| 643 | nl_combis = nla_nest_start(msg, |
| 644 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 645 | if (!nl_combis) |
| 646 | goto nla_put_failure; |
| 647 | |
| 648 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 649 | const struct ieee80211_iface_combination *c; |
| 650 | struct nlattr *nl_combi, *nl_limits; |
| 651 | |
| 652 | c = &wiphy->iface_combinations[i]; |
| 653 | |
| 654 | nl_combi = nla_nest_start(msg, i + 1); |
| 655 | if (!nl_combi) |
| 656 | goto nla_put_failure; |
| 657 | |
| 658 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 659 | if (!nl_limits) |
| 660 | goto nla_put_failure; |
| 661 | |
| 662 | for (j = 0; j < c->n_limits; j++) { |
| 663 | struct nlattr *nl_limit; |
| 664 | |
| 665 | nl_limit = nla_nest_start(msg, j + 1); |
| 666 | if (!nl_limit) |
| 667 | goto nla_put_failure; |
| 668 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 669 | c->limits[j].max); |
| 670 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 671 | c->limits[j].types)) |
| 672 | goto nla_put_failure; |
| 673 | nla_nest_end(msg, nl_limit); |
| 674 | } |
| 675 | |
| 676 | nla_nest_end(msg, nl_limits); |
| 677 | |
| 678 | if (c->beacon_int_infra_match) |
| 679 | NLA_PUT_FLAG(msg, |
| 680 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 681 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 682 | c->num_different_channels); |
| 683 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 684 | c->max_interfaces); |
| 685 | |
| 686 | nla_nest_end(msg, nl_combi); |
| 687 | } |
| 688 | |
| 689 | nla_nest_end(msg, nl_combis); |
| 690 | |
| 691 | return 0; |
| 692 | nla_put_failure: |
| 693 | return -ENOBUFS; |
| 694 | } |
| 695 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 696 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 697 | struct cfg80211_registered_device *dev) |
| 698 | { |
| 699 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 700 | struct nlattr *nl_bands, *nl_band; |
| 701 | struct nlattr *nl_freqs, *nl_freq; |
| 702 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 703 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 704 | enum ieee80211_band band; |
| 705 | struct ieee80211_channel *chan; |
| 706 | struct ieee80211_rate *rate; |
| 707 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 708 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 709 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 710 | |
| 711 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 712 | if (!hdr) |
| 713 | return -1; |
| 714 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 715 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 716 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 717 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 718 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 719 | cfg80211_rdev_list_generation); |
| 720 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 721 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 722 | dev->wiphy.retry_short); |
| 723 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 724 | dev->wiphy.retry_long); |
| 725 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 726 | dev->wiphy.frag_threshold); |
| 727 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 728 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 729 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 730 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 731 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 732 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 733 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 734 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 735 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 736 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 737 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 738 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 739 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 740 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 741 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 742 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 743 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 744 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 745 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 746 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 747 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 748 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 749 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 750 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) |
| 751 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT); |
| 752 | if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) |
| 753 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 754 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 755 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 756 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 757 | dev->wiphy.cipher_suites); |
| 758 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 759 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 760 | dev->wiphy.max_num_pmkids); |
| 761 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 762 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 763 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 764 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 765 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 766 | dev->wiphy.available_antennas_tx); |
| 767 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 768 | dev->wiphy.available_antennas_rx); |
| 769 | |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 770 | if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) |
| 771 | NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 772 | dev->wiphy.probe_resp_offload); |
| 773 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 774 | if ((dev->wiphy.available_antennas_tx || |
| 775 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 776 | u32 tx_ant = 0, rx_ant = 0; |
| 777 | int res; |
| 778 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 779 | if (!res) { |
| 780 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 781 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 782 | } |
| 783 | } |
| 784 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 785 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 786 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 787 | goto nla_put_failure; |
| 788 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 789 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 790 | if (!nl_bands) |
| 791 | goto nla_put_failure; |
| 792 | |
| 793 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 794 | if (!dev->wiphy.bands[band]) |
| 795 | continue; |
| 796 | |
| 797 | nl_band = nla_nest_start(msg, band); |
| 798 | if (!nl_band) |
| 799 | goto nla_put_failure; |
| 800 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 801 | /* add HT info */ |
| 802 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 803 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 804 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 805 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 806 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 807 | dev->wiphy.bands[band]->ht_cap.cap); |
| 808 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 809 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 810 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 811 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 812 | } |
| 813 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 814 | /* add frequencies */ |
| 815 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 816 | if (!nl_freqs) |
| 817 | goto nla_put_failure; |
| 818 | |
| 819 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 820 | nl_freq = nla_nest_start(msg, i); |
| 821 | if (!nl_freq) |
| 822 | goto nla_put_failure; |
| 823 | |
| 824 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 825 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 826 | if (nl80211_msg_put_channel(msg, chan)) |
| 827 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 828 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 829 | nla_nest_end(msg, nl_freq); |
| 830 | } |
| 831 | |
| 832 | nla_nest_end(msg, nl_freqs); |
| 833 | |
| 834 | /* add bitrates */ |
| 835 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 836 | if (!nl_rates) |
| 837 | goto nla_put_failure; |
| 838 | |
| 839 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 840 | nl_rate = nla_nest_start(msg, i); |
| 841 | if (!nl_rate) |
| 842 | goto nla_put_failure; |
| 843 | |
| 844 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 845 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 846 | rate->bitrate); |
| 847 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 848 | NLA_PUT_FLAG(msg, |
| 849 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 850 | |
| 851 | nla_nest_end(msg, nl_rate); |
| 852 | } |
| 853 | |
| 854 | nla_nest_end(msg, nl_rates); |
| 855 | |
| 856 | nla_nest_end(msg, nl_band); |
| 857 | } |
| 858 | nla_nest_end(msg, nl_bands); |
| 859 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 860 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 861 | if (!nl_cmds) |
| 862 | goto nla_put_failure; |
| 863 | |
| 864 | i = 0; |
| 865 | #define CMD(op, n) \ |
| 866 | do { \ |
| 867 | if (dev->ops->op) { \ |
| 868 | i++; \ |
| 869 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 870 | } \ |
| 871 | } while (0) |
| 872 | |
| 873 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 874 | CMD(change_virtual_intf, SET_INTERFACE); |
| 875 | CMD(add_key, NEW_KEY); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 876 | CMD(start_ap, START_AP); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 877 | CMD(add_station, NEW_STATION); |
| 878 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 879 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 880 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 881 | CMD(auth, AUTHENTICATE); |
| 882 | CMD(assoc, ASSOCIATE); |
| 883 | CMD(deauth, DEAUTHENTICATE); |
| 884 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 885 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 886 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 887 | CMD(set_pmksa, SET_PMKSA); |
| 888 | CMD(del_pmksa, DEL_PMKSA); |
| 889 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 890 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 891 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 892 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 893 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 894 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 895 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 896 | i++; |
| 897 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 898 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 899 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 900 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 901 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 902 | CMD(tdls_mgmt, TDLS_MGMT); |
| 903 | CMD(tdls_oper, TDLS_OPER); |
| 904 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 905 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 906 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 907 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 908 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 909 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 910 | i++; |
| 911 | NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS); |
| 912 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 913 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 914 | #ifdef CONFIG_NL80211_TESTMODE |
| 915 | CMD(testmode_cmd, TESTMODE); |
| 916 | #endif |
| 917 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 918 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 919 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 920 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 921 | i++; |
| 922 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 923 | } |
| 924 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 925 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 926 | i++; |
| 927 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 928 | } |
| 929 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 930 | nla_nest_end(msg, nl_cmds); |
| 931 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 932 | if (dev->ops->remain_on_channel && |
| 933 | dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 934 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 935 | dev->wiphy.max_remain_on_channel_duration); |
| 936 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 937 | if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 938 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 939 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 940 | if (mgmt_stypes) { |
| 941 | u16 stypes; |
| 942 | struct nlattr *nl_ftypes, *nl_ifs; |
| 943 | enum nl80211_iftype ift; |
| 944 | |
| 945 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 946 | if (!nl_ifs) |
| 947 | goto nla_put_failure; |
| 948 | |
| 949 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 950 | nl_ftypes = nla_nest_start(msg, ift); |
| 951 | if (!nl_ftypes) |
| 952 | goto nla_put_failure; |
| 953 | i = 0; |
| 954 | stypes = mgmt_stypes[ift].tx; |
| 955 | while (stypes) { |
| 956 | if (stypes & 1) |
| 957 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 958 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 959 | stypes >>= 1; |
| 960 | i++; |
| 961 | } |
| 962 | nla_nest_end(msg, nl_ftypes); |
| 963 | } |
| 964 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 965 | nla_nest_end(msg, nl_ifs); |
| 966 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 967 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 968 | if (!nl_ifs) |
| 969 | goto nla_put_failure; |
| 970 | |
| 971 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 972 | nl_ftypes = nla_nest_start(msg, ift); |
| 973 | if (!nl_ftypes) |
| 974 | goto nla_put_failure; |
| 975 | i = 0; |
| 976 | stypes = mgmt_stypes[ift].rx; |
| 977 | while (stypes) { |
| 978 | if (stypes & 1) |
| 979 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 980 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 981 | stypes >>= 1; |
| 982 | i++; |
| 983 | } |
| 984 | nla_nest_end(msg, nl_ftypes); |
| 985 | } |
| 986 | nla_nest_end(msg, nl_ifs); |
| 987 | } |
| 988 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 989 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 990 | struct nlattr *nl_wowlan; |
| 991 | |
| 992 | nl_wowlan = nla_nest_start(msg, |
| 993 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 994 | if (!nl_wowlan) |
| 995 | goto nla_put_failure; |
| 996 | |
| 997 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 998 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 999 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 1000 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 1001 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 1002 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 1003 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 1004 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 1005 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 1006 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 1007 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 1008 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 1009 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 1010 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 1011 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 1012 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1013 | if (dev->wiphy.wowlan.n_patterns) { |
| 1014 | struct nl80211_wowlan_pattern_support pat = { |
| 1015 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1016 | .min_pattern_len = |
| 1017 | dev->wiphy.wowlan.pattern_min_len, |
| 1018 | .max_pattern_len = |
| 1019 | dev->wiphy.wowlan.pattern_max_len, |
| 1020 | }; |
| 1021 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1022 | sizeof(pat), &pat); |
| 1023 | } |
| 1024 | |
| 1025 | nla_nest_end(msg, nl_wowlan); |
| 1026 | } |
| 1027 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1028 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1029 | dev->wiphy.software_iftypes)) |
| 1030 | goto nla_put_failure; |
| 1031 | |
| 1032 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1033 | goto nla_put_failure; |
| 1034 | |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1035 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) |
| 1036 | NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1037 | dev->wiphy.ap_sme_capa); |
| 1038 | |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1039 | NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features); |
| 1040 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1041 | if (dev->wiphy.ht_capa_mod_mask) |
| 1042 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1043 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1044 | dev->wiphy.ht_capa_mod_mask); |
| 1045 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1046 | return genlmsg_end(msg, hdr); |
| 1047 | |
| 1048 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1049 | genlmsg_cancel(msg, hdr); |
| 1050 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1054 | { |
| 1055 | int idx = 0; |
| 1056 | int start = cb->args[0]; |
| 1057 | struct cfg80211_registered_device *dev; |
| 1058 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1059 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1060 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1061 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1062 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1063 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1064 | continue; |
| 1065 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1066 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1067 | dev) < 0) { |
| 1068 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1069 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1070 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1071 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1072 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1073 | |
| 1074 | cb->args[0] = idx; |
| 1075 | |
| 1076 | return skb->len; |
| 1077 | } |
| 1078 | |
| 1079 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1080 | { |
| 1081 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1082 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1083 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1084 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1085 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1086 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1088 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1089 | nlmsg_free(msg); |
| 1090 | return -ENOBUFS; |
| 1091 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1092 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1093 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1094 | } |
| 1095 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1096 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1097 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1098 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1099 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1100 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1101 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1102 | }; |
| 1103 | |
| 1104 | static int parse_txq_params(struct nlattr *tb[], |
| 1105 | struct ieee80211_txq_params *txq_params) |
| 1106 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1107 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1108 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1109 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1110 | return -EINVAL; |
| 1111 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1112 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1113 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1114 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1115 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1116 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1117 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1118 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1119 | return -EINVAL; |
| 1120 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1121 | return 0; |
| 1122 | } |
| 1123 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1124 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1125 | { |
| 1126 | /* |
| 1127 | * You can only set the channel explicitly for AP, mesh |
| 1128 | * and WDS type interfaces; all others have their channel |
| 1129 | * managed via their respective "establish a connection" |
| 1130 | * command (connect, join, ...) |
| 1131 | * |
| 1132 | * Monitors are special as they are normally slaved to |
| 1133 | * whatever else is going on, so they behave as though |
| 1134 | * you tried setting the wiphy channel itself. |
| 1135 | */ |
| 1136 | return !wdev || |
| 1137 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1138 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1139 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1140 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1141 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1145 | struct wireless_dev *wdev, |
| 1146 | struct genl_info *info) |
| 1147 | { |
| 1148 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1149 | u32 freq; |
| 1150 | int result; |
| 1151 | |
| 1152 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1153 | return -EINVAL; |
| 1154 | |
| 1155 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1156 | return -EOPNOTSUPP; |
| 1157 | |
| 1158 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1159 | channel_type = nla_get_u32(info->attrs[ |
| 1160 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1161 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1162 | channel_type != NL80211_CHAN_HT20 && |
| 1163 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1164 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1165 | return -EINVAL; |
| 1166 | } |
| 1167 | |
| 1168 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1169 | |
| 1170 | mutex_lock(&rdev->devlist_mtx); |
| 1171 | if (wdev) { |
| 1172 | wdev_lock(wdev); |
| 1173 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1174 | wdev_unlock(wdev); |
| 1175 | } else { |
| 1176 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1177 | } |
| 1178 | mutex_unlock(&rdev->devlist_mtx); |
| 1179 | |
| 1180 | return result; |
| 1181 | } |
| 1182 | |
| 1183 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1184 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1185 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1186 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1187 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1188 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1189 | } |
| 1190 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1191 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1192 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1194 | struct net_device *dev = info->user_ptr[1]; |
| 1195 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1196 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1197 | |
| 1198 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1199 | return -EINVAL; |
| 1200 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1201 | if (netif_running(dev)) |
| 1202 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1203 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1204 | if (!rdev->ops->set_wds_peer) |
| 1205 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1206 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1207 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1208 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1209 | |
| 1210 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1211 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1215 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1216 | { |
| 1217 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1218 | struct net_device *netdev = NULL; |
| 1219 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1220 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1221 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1222 | u32 changed; |
| 1223 | u8 retry_short = 0, retry_long = 0; |
| 1224 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1225 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1226 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1227 | /* |
| 1228 | * Try to find the wiphy and netdev. Normally this |
| 1229 | * function shouldn't need the netdev, but this is |
| 1230 | * done for backward compatibility -- previously |
| 1231 | * setting the channel was done per wiphy, but now |
| 1232 | * it is per netdev. Previous userland like hostapd |
| 1233 | * also passed a netdev to set_wiphy, so that it is |
| 1234 | * possible to let that go to the right netdev! |
| 1235 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1236 | mutex_lock(&cfg80211_mutex); |
| 1237 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1238 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1239 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1240 | |
| 1241 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1242 | if (netdev && netdev->ieee80211_ptr) { |
| 1243 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1244 | mutex_lock(&rdev->mtx); |
| 1245 | } else |
| 1246 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1247 | } |
| 1248 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1249 | if (!netdev) { |
| 1250 | rdev = __cfg80211_rdev_from_info(info); |
| 1251 | if (IS_ERR(rdev)) { |
| 1252 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1253 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1254 | } |
| 1255 | wdev = NULL; |
| 1256 | netdev = NULL; |
| 1257 | result = 0; |
| 1258 | |
| 1259 | mutex_lock(&rdev->mtx); |
| 1260 | } else if (netif_running(netdev) && |
| 1261 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1262 | wdev = netdev->ieee80211_ptr; |
| 1263 | else |
| 1264 | wdev = NULL; |
| 1265 | |
| 1266 | /* |
| 1267 | * end workaround code, by now the rdev is available |
| 1268 | * and locked, and wdev may or may not be NULL. |
| 1269 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1270 | |
| 1271 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1272 | result = cfg80211_dev_rename( |
| 1273 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1274 | |
| 1275 | mutex_unlock(&cfg80211_mutex); |
| 1276 | |
| 1277 | if (result) |
| 1278 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1279 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1280 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1281 | struct ieee80211_txq_params txq_params; |
| 1282 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1283 | |
| 1284 | if (!rdev->ops->set_txq_params) { |
| 1285 | result = -EOPNOTSUPP; |
| 1286 | goto bad_res; |
| 1287 | } |
| 1288 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1289 | if (!netdev) { |
| 1290 | result = -EINVAL; |
| 1291 | goto bad_res; |
| 1292 | } |
| 1293 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1294 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1295 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1296 | result = -EINVAL; |
| 1297 | goto bad_res; |
| 1298 | } |
| 1299 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1300 | nla_for_each_nested(nl_txq_params, |
| 1301 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1302 | rem_txq_params) { |
| 1303 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1304 | nla_data(nl_txq_params), |
| 1305 | nla_len(nl_txq_params), |
| 1306 | txq_params_policy); |
| 1307 | result = parse_txq_params(tb, &txq_params); |
| 1308 | if (result) |
| 1309 | goto bad_res; |
| 1310 | |
| 1311 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1312 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1313 | &txq_params); |
| 1314 | if (result) |
| 1315 | goto bad_res; |
| 1316 | } |
| 1317 | } |
| 1318 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1319 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1320 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1321 | if (result) |
| 1322 | goto bad_res; |
| 1323 | } |
| 1324 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1325 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1326 | enum nl80211_tx_power_setting type; |
| 1327 | int idx, mbm = 0; |
| 1328 | |
| 1329 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1330 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1331 | goto bad_res; |
| 1332 | } |
| 1333 | |
| 1334 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1335 | type = nla_get_u32(info->attrs[idx]); |
| 1336 | |
| 1337 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1338 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1339 | result = -EINVAL; |
| 1340 | goto bad_res; |
| 1341 | } |
| 1342 | |
| 1343 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1344 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1345 | mbm = nla_get_u32(info->attrs[idx]); |
| 1346 | } |
| 1347 | |
| 1348 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1349 | if (result) |
| 1350 | goto bad_res; |
| 1351 | } |
| 1352 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1353 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1354 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1355 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1356 | if ((!rdev->wiphy.available_antennas_tx && |
| 1357 | !rdev->wiphy.available_antennas_rx) || |
| 1358 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1359 | result = -EOPNOTSUPP; |
| 1360 | goto bad_res; |
| 1361 | } |
| 1362 | |
| 1363 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1364 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1365 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1366 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1367 | * available antenna masks, except for the "all" mask */ |
| 1368 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1369 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1370 | result = -EINVAL; |
| 1371 | goto bad_res; |
| 1372 | } |
| 1373 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1374 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1375 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1376 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1377 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1378 | if (result) |
| 1379 | goto bad_res; |
| 1380 | } |
| 1381 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1382 | changed = 0; |
| 1383 | |
| 1384 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1385 | retry_short = nla_get_u8( |
| 1386 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1387 | if (retry_short == 0) { |
| 1388 | result = -EINVAL; |
| 1389 | goto bad_res; |
| 1390 | } |
| 1391 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1392 | } |
| 1393 | |
| 1394 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1395 | retry_long = nla_get_u8( |
| 1396 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1397 | if (retry_long == 0) { |
| 1398 | result = -EINVAL; |
| 1399 | goto bad_res; |
| 1400 | } |
| 1401 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1402 | } |
| 1403 | |
| 1404 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1405 | frag_threshold = nla_get_u32( |
| 1406 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1407 | if (frag_threshold < 256) { |
| 1408 | result = -EINVAL; |
| 1409 | goto bad_res; |
| 1410 | } |
| 1411 | if (frag_threshold != (u32) -1) { |
| 1412 | /* |
| 1413 | * Fragments (apart from the last one) are required to |
| 1414 | * have even length. Make the fragmentation code |
| 1415 | * simpler by stripping LSB should someone try to use |
| 1416 | * odd threshold value. |
| 1417 | */ |
| 1418 | frag_threshold &= ~0x1; |
| 1419 | } |
| 1420 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1421 | } |
| 1422 | |
| 1423 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1424 | rts_threshold = nla_get_u32( |
| 1425 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1426 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1427 | } |
| 1428 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1429 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1430 | coverage_class = nla_get_u8( |
| 1431 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1432 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1433 | } |
| 1434 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1435 | if (changed) { |
| 1436 | u8 old_retry_short, old_retry_long; |
| 1437 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1438 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1439 | |
| 1440 | if (!rdev->ops->set_wiphy_params) { |
| 1441 | result = -EOPNOTSUPP; |
| 1442 | goto bad_res; |
| 1443 | } |
| 1444 | |
| 1445 | old_retry_short = rdev->wiphy.retry_short; |
| 1446 | old_retry_long = rdev->wiphy.retry_long; |
| 1447 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1448 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1449 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1450 | |
| 1451 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1452 | rdev->wiphy.retry_short = retry_short; |
| 1453 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1454 | rdev->wiphy.retry_long = retry_long; |
| 1455 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1456 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1457 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1458 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1459 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1460 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1461 | |
| 1462 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1463 | if (result) { |
| 1464 | rdev->wiphy.retry_short = old_retry_short; |
| 1465 | rdev->wiphy.retry_long = old_retry_long; |
| 1466 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1467 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1468 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1469 | } |
| 1470 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1471 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1472 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1473 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1474 | if (netdev) |
| 1475 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1476 | return result; |
| 1477 | } |
| 1478 | |
| 1479 | |
| 1480 | 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] | 1481 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1482 | struct net_device *dev) |
| 1483 | { |
| 1484 | void *hdr; |
| 1485 | |
| 1486 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1487 | if (!hdr) |
| 1488 | return -1; |
| 1489 | |
| 1490 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1491 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1492 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1493 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1494 | |
| 1495 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1496 | rdev->devlist_generation ^ |
| 1497 | (cfg80211_rdev_list_generation << 2)); |
| 1498 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1499 | return genlmsg_end(msg, hdr); |
| 1500 | |
| 1501 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1502 | genlmsg_cancel(msg, hdr); |
| 1503 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1507 | { |
| 1508 | int wp_idx = 0; |
| 1509 | int if_idx = 0; |
| 1510 | int wp_start = cb->args[0]; |
| 1511 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1512 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1513 | struct wireless_dev *wdev; |
| 1514 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1515 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1516 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1517 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1518 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1519 | if (wp_idx < wp_start) { |
| 1520 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1521 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1522 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1523 | if_idx = 0; |
| 1524 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1525 | mutex_lock(&rdev->devlist_mtx); |
| 1526 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1527 | if (if_idx < if_start) { |
| 1528 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1529 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1530 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1531 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1532 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1533 | rdev, wdev->netdev) < 0) { |
| 1534 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1535 | goto out; |
| 1536 | } |
| 1537 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1538 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1539 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1540 | |
| 1541 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1542 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1543 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1544 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1545 | |
| 1546 | cb->args[0] = wp_idx; |
| 1547 | cb->args[1] = if_idx; |
| 1548 | |
| 1549 | return skb->len; |
| 1550 | } |
| 1551 | |
| 1552 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1553 | { |
| 1554 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1555 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1556 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1557 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1558 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1559 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1560 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1561 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1562 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1563 | dev, netdev) < 0) { |
| 1564 | nlmsg_free(msg); |
| 1565 | return -ENOBUFS; |
| 1566 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1567 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1568 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1569 | } |
| 1570 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1571 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1572 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1573 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1574 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1575 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1576 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1577 | }; |
| 1578 | |
| 1579 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1580 | { |
| 1581 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1582 | int flag; |
| 1583 | |
| 1584 | *mntrflags = 0; |
| 1585 | |
| 1586 | if (!nla) |
| 1587 | return -EINVAL; |
| 1588 | |
| 1589 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1590 | nla, mntr_flags_policy)) |
| 1591 | return -EINVAL; |
| 1592 | |
| 1593 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1594 | if (flags[flag]) |
| 1595 | *mntrflags |= (1<<flag); |
| 1596 | |
| 1597 | return 0; |
| 1598 | } |
| 1599 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1600 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1601 | struct net_device *netdev, u8 use_4addr, |
| 1602 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1603 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1604 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1605 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1606 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1607 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1608 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1609 | |
| 1610 | switch (iftype) { |
| 1611 | case NL80211_IFTYPE_AP_VLAN: |
| 1612 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1613 | return 0; |
| 1614 | break; |
| 1615 | case NL80211_IFTYPE_STATION: |
| 1616 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1617 | return 0; |
| 1618 | break; |
| 1619 | default: |
| 1620 | break; |
| 1621 | } |
| 1622 | |
| 1623 | return -EOPNOTSUPP; |
| 1624 | } |
| 1625 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1626 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1627 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1628 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1629 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1630 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1631 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1632 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1633 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1634 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1635 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1636 | memset(¶ms, 0, sizeof(params)); |
| 1637 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1638 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1639 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1640 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1641 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1642 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1643 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1644 | if (ntype > NL80211_IFTYPE_MAX) |
| 1645 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1646 | } |
| 1647 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1648 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1649 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1650 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1651 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1652 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1653 | if (netif_running(dev)) |
| 1654 | return -EBUSY; |
| 1655 | |
| 1656 | wdev_lock(wdev); |
| 1657 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1658 | IEEE80211_MAX_MESH_ID_LEN); |
| 1659 | wdev->mesh_id_up_len = |
| 1660 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1661 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1662 | wdev->mesh_id_up_len); |
| 1663 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1664 | } |
| 1665 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1666 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1667 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1668 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1669 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1670 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1671 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1672 | } else { |
| 1673 | params.use_4addr = -1; |
| 1674 | } |
| 1675 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1676 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1677 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1678 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1679 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1680 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1681 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1682 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1683 | |
| 1684 | flags = &_flags; |
| 1685 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1686 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1687 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1688 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1689 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1690 | else |
| 1691 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1692 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1693 | if (!err && params.use_4addr != -1) |
| 1694 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1695 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1696 | return err; |
| 1697 | } |
| 1698 | |
| 1699 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1700 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1702 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1703 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1704 | int err; |
| 1705 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1706 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1707 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1708 | memset(¶ms, 0, sizeof(params)); |
| 1709 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1710 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1711 | return -EINVAL; |
| 1712 | |
| 1713 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1714 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1715 | if (type > NL80211_IFTYPE_MAX) |
| 1716 | return -EINVAL; |
| 1717 | } |
| 1718 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1719 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1720 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1721 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1722 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1723 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1724 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1725 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1726 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1727 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1728 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1729 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1730 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1731 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1732 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1733 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1734 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1735 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1736 | if (IS_ERR(dev)) |
| 1737 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1738 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1739 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1740 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1741 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1742 | |
| 1743 | wdev_lock(wdev); |
| 1744 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1745 | IEEE80211_MAX_MESH_ID_LEN); |
| 1746 | wdev->mesh_id_up_len = |
| 1747 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1748 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1749 | wdev->mesh_id_up_len); |
| 1750 | wdev_unlock(wdev); |
| 1751 | } |
| 1752 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1753 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1757 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1759 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1761 | if (!rdev->ops->del_virtual_intf) |
| 1762 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1763 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1764 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1765 | } |
| 1766 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1767 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 1768 | { |
| 1769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1770 | struct net_device *dev = info->user_ptr[1]; |
| 1771 | u16 noack_map; |
| 1772 | |
| 1773 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 1774 | return -EINVAL; |
| 1775 | |
| 1776 | if (!rdev->ops->set_noack_map) |
| 1777 | return -EOPNOTSUPP; |
| 1778 | |
| 1779 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 1780 | |
| 1781 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 1782 | } |
| 1783 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1784 | struct get_key_cookie { |
| 1785 | struct sk_buff *msg; |
| 1786 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1787 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1788 | }; |
| 1789 | |
| 1790 | static void get_key_callback(void *c, struct key_params *params) |
| 1791 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1792 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1793 | struct get_key_cookie *cookie = c; |
| 1794 | |
| 1795 | if (params->key) |
| 1796 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1797 | params->key_len, params->key); |
| 1798 | |
| 1799 | if (params->seq) |
| 1800 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1801 | params->seq_len, params->seq); |
| 1802 | |
| 1803 | if (params->cipher) |
| 1804 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1805 | params->cipher); |
| 1806 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1807 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1808 | if (!key) |
| 1809 | goto nla_put_failure; |
| 1810 | |
| 1811 | if (params->key) |
| 1812 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1813 | params->key_len, params->key); |
| 1814 | |
| 1815 | if (params->seq) |
| 1816 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1817 | params->seq_len, params->seq); |
| 1818 | |
| 1819 | if (params->cipher) |
| 1820 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1821 | params->cipher); |
| 1822 | |
| 1823 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1824 | |
| 1825 | nla_nest_end(cookie->msg, key); |
| 1826 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1827 | return; |
| 1828 | nla_put_failure: |
| 1829 | cookie->error = 1; |
| 1830 | } |
| 1831 | |
| 1832 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1833 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1835 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1836 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1837 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1838 | const u8 *mac_addr = NULL; |
| 1839 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1840 | struct get_key_cookie cookie = { |
| 1841 | .error = 0, |
| 1842 | }; |
| 1843 | void *hdr; |
| 1844 | struct sk_buff *msg; |
| 1845 | |
| 1846 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1847 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1848 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1849 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1850 | return -EINVAL; |
| 1851 | |
| 1852 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1853 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1854 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1855 | pairwise = !!mac_addr; |
| 1856 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1857 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1858 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1859 | return -EINVAL; |
| 1860 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1861 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1862 | return -EINVAL; |
| 1863 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1864 | } |
| 1865 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1866 | if (!rdev->ops->get_key) |
| 1867 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1868 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1869 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1870 | if (!msg) |
| 1871 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1872 | |
| 1873 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1874 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1875 | if (IS_ERR(hdr)) |
| 1876 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1877 | |
| 1878 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1879 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1880 | |
| 1881 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1882 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1883 | if (mac_addr) |
| 1884 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1885 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1886 | if (pairwise && mac_addr && |
| 1887 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1888 | return -ENOENT; |
| 1889 | |
| 1890 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1891 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1892 | |
| 1893 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1894 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1895 | |
| 1896 | if (cookie.error) |
| 1897 | goto nla_put_failure; |
| 1898 | |
| 1899 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1900 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1901 | |
| 1902 | nla_put_failure: |
| 1903 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1904 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1905 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1906 | return err; |
| 1907 | } |
| 1908 | |
| 1909 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1910 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1912 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1913 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1914 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1915 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1916 | err = nl80211_parse_key(info, &key); |
| 1917 | if (err) |
| 1918 | return err; |
| 1919 | |
| 1920 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1921 | return -EINVAL; |
| 1922 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1923 | /* only support setting default key */ |
| 1924 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1925 | return -EINVAL; |
| 1926 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1927 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1928 | |
| 1929 | if (key.def) { |
| 1930 | if (!rdev->ops->set_default_key) { |
| 1931 | err = -EOPNOTSUPP; |
| 1932 | goto out; |
| 1933 | } |
| 1934 | |
| 1935 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1936 | if (err) |
| 1937 | goto out; |
| 1938 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1939 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1940 | key.def_uni, key.def_multi); |
| 1941 | |
| 1942 | if (err) |
| 1943 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1944 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1945 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1946 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1947 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1948 | } else { |
| 1949 | if (key.def_uni || !key.def_multi) { |
| 1950 | err = -EINVAL; |
| 1951 | goto out; |
| 1952 | } |
| 1953 | |
| 1954 | if (!rdev->ops->set_default_mgmt_key) { |
| 1955 | err = -EOPNOTSUPP; |
| 1956 | goto out; |
| 1957 | } |
| 1958 | |
| 1959 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1960 | if (err) |
| 1961 | goto out; |
| 1962 | |
| 1963 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1964 | dev, key.idx); |
| 1965 | if (err) |
| 1966 | goto out; |
| 1967 | |
| 1968 | #ifdef CONFIG_CFG80211_WEXT |
| 1969 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1970 | #endif |
| 1971 | } |
| 1972 | |
| 1973 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1974 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1975 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1976 | return err; |
| 1977 | } |
| 1978 | |
| 1979 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1980 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1982 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1983 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1984 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1985 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1986 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1987 | err = nl80211_parse_key(info, &key); |
| 1988 | if (err) |
| 1989 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1990 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1991 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1992 | return -EINVAL; |
| 1993 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1994 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1995 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1996 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1997 | if (key.type == -1) { |
| 1998 | if (mac_addr) |
| 1999 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2000 | else |
| 2001 | key.type = NL80211_KEYTYPE_GROUP; |
| 2002 | } |
| 2003 | |
| 2004 | /* for now */ |
| 2005 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2006 | key.type != NL80211_KEYTYPE_GROUP) |
| 2007 | return -EINVAL; |
| 2008 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2009 | if (!rdev->ops->add_key) |
| 2010 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2011 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2012 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2013 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2014 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2015 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2016 | |
| 2017 | wdev_lock(dev->ieee80211_ptr); |
| 2018 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2019 | if (!err) |
| 2020 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2021 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2022 | mac_addr, &key.p); |
| 2023 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2024 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2025 | return err; |
| 2026 | } |
| 2027 | |
| 2028 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2029 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2031 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2032 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2033 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2034 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2035 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2036 | err = nl80211_parse_key(info, &key); |
| 2037 | if (err) |
| 2038 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2039 | |
| 2040 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2041 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2042 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2043 | if (key.type == -1) { |
| 2044 | if (mac_addr) |
| 2045 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2046 | else |
| 2047 | key.type = NL80211_KEYTYPE_GROUP; |
| 2048 | } |
| 2049 | |
| 2050 | /* for now */ |
| 2051 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2052 | key.type != NL80211_KEYTYPE_GROUP) |
| 2053 | return -EINVAL; |
| 2054 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2055 | if (!rdev->ops->del_key) |
| 2056 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2057 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2058 | wdev_lock(dev->ieee80211_ptr); |
| 2059 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2060 | |
| 2061 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2062 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2063 | err = -ENOENT; |
| 2064 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2065 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2066 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2067 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2068 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2069 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2070 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2071 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2072 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2073 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2074 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2075 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2076 | } |
| 2077 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2078 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2079 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2080 | return err; |
| 2081 | } |
| 2082 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2083 | static int nl80211_parse_beacon(struct genl_info *info, |
| 2084 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2085 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2086 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2087 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2088 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2089 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2090 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2091 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2092 | return -EINVAL; |
| 2093 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2094 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2095 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2096 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2097 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2098 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2099 | if (!bcn->head_len) |
| 2100 | return -EINVAL; |
| 2101 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2105 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2106 | bcn->tail_len = |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2107 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2108 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2109 | } |
| 2110 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2111 | if (!haveinfo) |
| 2112 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2113 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2114 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2115 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2116 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2120 | bcn->proberesp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2121 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2122 | bcn->proberesp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2123 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2124 | } |
| 2125 | |
| 2126 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2127 | bcn->assocresp_ies = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2128 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2129 | bcn->assocresp_ies_len = |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2130 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2131 | } |
| 2132 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2133 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2134 | bcn->probe_resp = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2135 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2136 | bcn->probe_resp_len = |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2137 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2138 | } |
| 2139 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2140 | return 0; |
| 2141 | } |
| 2142 | |
| 2143 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 2144 | { |
| 2145 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2146 | struct net_device *dev = info->user_ptr[1]; |
| 2147 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2148 | struct cfg80211_ap_settings params; |
| 2149 | int err; |
| 2150 | |
| 2151 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2152 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2153 | return -EOPNOTSUPP; |
| 2154 | |
| 2155 | if (!rdev->ops->start_ap) |
| 2156 | return -EOPNOTSUPP; |
| 2157 | |
| 2158 | if (wdev->beacon_interval) |
| 2159 | return -EALREADY; |
| 2160 | |
| 2161 | memset(¶ms, 0, sizeof(params)); |
| 2162 | |
| 2163 | /* these are required for START_AP */ |
| 2164 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2165 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 2166 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2167 | return -EINVAL; |
| 2168 | |
| 2169 | err = nl80211_parse_beacon(info, ¶ms.beacon); |
| 2170 | if (err) |
| 2171 | return err; |
| 2172 | |
| 2173 | params.beacon_interval = |
| 2174 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2175 | params.dtim_period = |
| 2176 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2177 | |
| 2178 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 2179 | if (err) |
| 2180 | return err; |
| 2181 | |
| 2182 | /* |
| 2183 | * In theory, some of these attributes should be required here |
| 2184 | * but since they were not used when the command was originally |
| 2185 | * added, keep them optional for old user space programs to let |
| 2186 | * them continue to work with drivers that do not need the |
| 2187 | * additional information -- drivers must check! |
| 2188 | */ |
| 2189 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2190 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2191 | params.ssid_len = |
| 2192 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2193 | if (params.ssid_len == 0 || |
| 2194 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2195 | return -EINVAL; |
| 2196 | } |
| 2197 | |
| 2198 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2199 | params.hidden_ssid = nla_get_u32( |
| 2200 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2201 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2202 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2203 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2204 | return -EINVAL; |
| 2205 | } |
| 2206 | |
| 2207 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2208 | |
| 2209 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2210 | params.auth_type = nla_get_u32( |
| 2211 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2212 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2213 | return -EINVAL; |
| 2214 | } else |
| 2215 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2216 | |
| 2217 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2218 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2219 | if (err) |
| 2220 | return err; |
| 2221 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 2222 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 2223 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 2224 | return -EOPNOTSUPP; |
| 2225 | params.inactivity_timeout = nla_get_u16( |
| 2226 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 2227 | } |
| 2228 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2229 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
| 2230 | if (!err) |
| 2231 | wdev->beacon_interval = params.beacon_interval; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2232 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2233 | } |
| 2234 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2235 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2236 | { |
| 2237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2238 | struct net_device *dev = info->user_ptr[1]; |
| 2239 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2240 | struct cfg80211_beacon_data params; |
| 2241 | int err; |
| 2242 | |
| 2243 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 2244 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2245 | return -EOPNOTSUPP; |
| 2246 | |
| 2247 | if (!rdev->ops->change_beacon) |
| 2248 | return -EOPNOTSUPP; |
| 2249 | |
| 2250 | if (!wdev->beacon_interval) |
| 2251 | return -EINVAL; |
| 2252 | |
| 2253 | err = nl80211_parse_beacon(info, ¶ms); |
| 2254 | if (err) |
| 2255 | return err; |
| 2256 | |
| 2257 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); |
| 2258 | } |
| 2259 | |
| 2260 | 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] | 2261 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2262 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2263 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2264 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2265 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2266 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2267 | if (!rdev->ops->stop_ap) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2268 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2269 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2270 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2271 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2272 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2273 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 2274 | if (!wdev->beacon_interval) |
| 2275 | return -ENOENT; |
| 2276 | |
| 2277 | err = rdev->ops->stop_ap(&rdev->wiphy, dev); |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2278 | if (!err) |
| 2279 | wdev->beacon_interval = 0; |
| 2280 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2281 | } |
| 2282 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2283 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2284 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2285 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2286 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2287 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2288 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2289 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2290 | }; |
| 2291 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2292 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2293 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2294 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2295 | { |
| 2296 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2297 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2298 | int flag; |
| 2299 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2300 | /* |
| 2301 | * Try parsing the new attribute first so userspace |
| 2302 | * can specify both for older kernels. |
| 2303 | */ |
| 2304 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2305 | if (nla) { |
| 2306 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2307 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2308 | sta_flags = nla_data(nla); |
| 2309 | params->sta_flags_mask = sta_flags->mask; |
| 2310 | params->sta_flags_set = sta_flags->set; |
| 2311 | if ((params->sta_flags_mask | |
| 2312 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2313 | return -EINVAL; |
| 2314 | return 0; |
| 2315 | } |
| 2316 | |
| 2317 | /* if present, parse the old attribute */ |
| 2318 | |
| 2319 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2320 | if (!nla) |
| 2321 | return 0; |
| 2322 | |
| 2323 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2324 | nla, sta_flags_policy)) |
| 2325 | return -EINVAL; |
| 2326 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2327 | /* |
| 2328 | * Only allow certain flags for interface types so that |
| 2329 | * other attributes are silently ignored. Remember that |
| 2330 | * this is backward compatibility code with old userspace |
| 2331 | * and shouldn't be hit in other cases anyway. |
| 2332 | */ |
| 2333 | switch (iftype) { |
| 2334 | case NL80211_IFTYPE_AP: |
| 2335 | case NL80211_IFTYPE_AP_VLAN: |
| 2336 | case NL80211_IFTYPE_P2P_GO: |
| 2337 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2338 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2339 | BIT(NL80211_STA_FLAG_WME) | |
| 2340 | BIT(NL80211_STA_FLAG_MFP); |
| 2341 | break; |
| 2342 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2343 | case NL80211_IFTYPE_STATION: |
| 2344 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2345 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2346 | break; |
| 2347 | case NL80211_IFTYPE_MESH_POINT: |
| 2348 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2349 | BIT(NL80211_STA_FLAG_MFP) | |
| 2350 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2351 | default: |
| 2352 | return -EINVAL; |
| 2353 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2354 | |
| 2355 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2356 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2357 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2358 | |
| 2359 | return 0; |
| 2360 | } |
| 2361 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2362 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2363 | int attr) |
| 2364 | { |
| 2365 | struct nlattr *rate; |
| 2366 | u16 bitrate; |
| 2367 | |
| 2368 | rate = nla_nest_start(msg, attr); |
| 2369 | if (!rate) |
| 2370 | goto nla_put_failure; |
| 2371 | |
| 2372 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2373 | bitrate = cfg80211_calculate_bitrate(info); |
| 2374 | if (bitrate > 0) |
| 2375 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2376 | |
| 2377 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2378 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2379 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2380 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2381 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2382 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2383 | |
| 2384 | nla_nest_end(msg, rate); |
| 2385 | return true; |
| 2386 | |
| 2387 | nla_put_failure: |
| 2388 | return false; |
| 2389 | } |
| 2390 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2391 | 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] | 2392 | int flags, |
| 2393 | struct cfg80211_registered_device *rdev, |
| 2394 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2395 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2396 | { |
| 2397 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2398 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2399 | |
| 2400 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2401 | if (!hdr) |
| 2402 | return -1; |
| 2403 | |
| 2404 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2405 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2406 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2407 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2408 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2409 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2410 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2411 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2412 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2413 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2414 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2415 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2416 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2417 | sinfo->inactive_time); |
| 2418 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2419 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2420 | sinfo->rx_bytes); |
| 2421 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2422 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2423 | sinfo->tx_bytes); |
| 2424 | if (sinfo->filled & STATION_INFO_LLID) |
| 2425 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2426 | sinfo->llid); |
| 2427 | if (sinfo->filled & STATION_INFO_PLID) |
| 2428 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2429 | sinfo->plid); |
| 2430 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2431 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2432 | sinfo->plink_state); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2433 | switch (rdev->wiphy.signal_type) { |
| 2434 | case CFG80211_SIGNAL_TYPE_MBM: |
| 2435 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2436 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2437 | sinfo->signal); |
| 2438 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2439 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2440 | sinfo->signal_avg); |
| 2441 | break; |
| 2442 | default: |
| 2443 | break; |
| 2444 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2445 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2446 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2447 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2448 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2449 | } |
| 2450 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2451 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2452 | NL80211_STA_INFO_RX_BITRATE)) |
| 2453 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2454 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2455 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2456 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2457 | sinfo->rx_packets); |
| 2458 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2459 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2460 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2461 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2462 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2463 | sinfo->tx_retries); |
| 2464 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2465 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2466 | sinfo->tx_failed); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2467 | if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) |
| 2468 | NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2469 | sinfo->beacon_loss_count); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2470 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2471 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2472 | if (!bss_param) |
| 2473 | goto nla_put_failure; |
| 2474 | |
| 2475 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2476 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2477 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2478 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2479 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2480 | NLA_PUT_FLAG(msg, |
| 2481 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2482 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2483 | sinfo->bss_param.dtim_period); |
| 2484 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2485 | sinfo->bss_param.beacon_interval); |
| 2486 | |
| 2487 | nla_nest_end(msg, bss_param); |
| 2488 | } |
Helmut Schaa | bb6e753 | 2011-10-13 16:30:39 +0200 | [diff] [blame] | 2489 | if (sinfo->filled & STATION_INFO_STA_FLAGS) |
| 2490 | NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2491 | sizeof(struct nl80211_sta_flag_update), |
| 2492 | &sinfo->sta_flags); |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 2493 | if (sinfo->filled & STATION_INFO_T_OFFSET) |
| 2494 | NLA_PUT_U64(msg, NL80211_STA_INFO_T_OFFSET, |
| 2495 | sinfo->t_offset); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2496 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2497 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2498 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2499 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2500 | sinfo->assoc_req_ies); |
| 2501 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2502 | return genlmsg_end(msg, hdr); |
| 2503 | |
| 2504 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2505 | genlmsg_cancel(msg, hdr); |
| 2506 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2507 | } |
| 2508 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2509 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2510 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2511 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2512 | struct station_info sinfo; |
| 2513 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2514 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2515 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2516 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2517 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2518 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2519 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2520 | if (err) |
| 2521 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2522 | |
| 2523 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2524 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2525 | goto out_err; |
| 2526 | } |
| 2527 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2528 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2529 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2530 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2531 | mac_addr, &sinfo); |
| 2532 | if (err == -ENOENT) |
| 2533 | break; |
| 2534 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2535 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2536 | |
| 2537 | if (nl80211_send_station(skb, |
| 2538 | NETLINK_CB(cb->skb).pid, |
| 2539 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 2540 | dev, netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2541 | &sinfo) < 0) |
| 2542 | goto out; |
| 2543 | |
| 2544 | sta_idx++; |
| 2545 | } |
| 2546 | |
| 2547 | |
| 2548 | out: |
| 2549 | cb->args[1] = sta_idx; |
| 2550 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2551 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2552 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2553 | |
| 2554 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2555 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2556 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2557 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2558 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2560 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2561 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2562 | struct sk_buff *msg; |
| 2563 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2564 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2565 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2566 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2567 | |
| 2568 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2569 | return -EINVAL; |
| 2570 | |
| 2571 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2572 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2573 | if (!rdev->ops->get_station) |
| 2574 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2575 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2576 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2577 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2578 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2579 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2580 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2581 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2582 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2583 | |
| 2584 | 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] | 2585 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2586 | nlmsg_free(msg); |
| 2587 | return -ENOBUFS; |
| 2588 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2589 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2590 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2594 | * 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] | 2595 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2596 | static struct net_device *get_vlan(struct genl_info *info, |
| 2597 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2598 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2599 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2600 | struct net_device *v; |
| 2601 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2602 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2603 | if (!vlanattr) |
| 2604 | return NULL; |
| 2605 | |
| 2606 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 2607 | if (!v) |
| 2608 | return ERR_PTR(-ENODEV); |
| 2609 | |
| 2610 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 2611 | ret = -EINVAL; |
| 2612 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2613 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2614 | |
| 2615 | if (!netif_running(v)) { |
| 2616 | ret = -ENETDOWN; |
| 2617 | goto error; |
| 2618 | } |
| 2619 | |
| 2620 | return v; |
| 2621 | error: |
| 2622 | dev_put(v); |
| 2623 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2627 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2628 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2629 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2630 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2631 | struct station_parameters params; |
| 2632 | u8 *mac_addr = NULL; |
| 2633 | |
| 2634 | memset(¶ms, 0, sizeof(params)); |
| 2635 | |
| 2636 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2637 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2638 | |
| 2639 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2640 | return -EINVAL; |
| 2641 | |
| 2642 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2643 | return -EINVAL; |
| 2644 | |
| 2645 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2646 | |
| 2647 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2648 | params.supported_rates = |
| 2649 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2650 | params.supported_rates_len = |
| 2651 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2652 | } |
| 2653 | |
| 2654 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2655 | params.listen_interval = |
| 2656 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2657 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2658 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2659 | params.ht_capa = |
| 2660 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2661 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2662 | if (!rdev->ops->change_station) |
| 2663 | return -EOPNOTSUPP; |
| 2664 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2665 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2666 | return -EINVAL; |
| 2667 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2668 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2669 | params.plink_action = |
| 2670 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2671 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2672 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2673 | params.plink_state = |
| 2674 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2675 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2676 | switch (dev->ieee80211_ptr->iftype) { |
| 2677 | case NL80211_IFTYPE_AP: |
| 2678 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2679 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2680 | /* disallow mesh-specific things */ |
| 2681 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2682 | return -EINVAL; |
| 2683 | |
| 2684 | /* TDLS can't be set, ... */ |
| 2685 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 2686 | return -EINVAL; |
| 2687 | /* |
| 2688 | * ... but don't bother the driver with it. This works around |
| 2689 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 2690 | * TLDS_PEER flag in the mask even for AP mode. |
| 2691 | */ |
| 2692 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2693 | |
| 2694 | /* accept only the listed bits */ |
| 2695 | if (params.sta_flags_mask & |
| 2696 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2697 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2698 | BIT(NL80211_STA_FLAG_WME) | |
| 2699 | BIT(NL80211_STA_FLAG_MFP))) |
| 2700 | return -EINVAL; |
| 2701 | |
| 2702 | /* must be last in here for error handling */ |
| 2703 | params.vlan = get_vlan(info, rdev); |
| 2704 | if (IS_ERR(params.vlan)) |
| 2705 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2706 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2707 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2708 | case NL80211_IFTYPE_STATION: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2709 | /* |
| 2710 | * Don't allow userspace to change the TDLS_PEER flag, |
| 2711 | * but silently ignore attempts to change it since we |
| 2712 | * don't have state here to verify that it doesn't try |
| 2713 | * to change the flag. |
| 2714 | */ |
| 2715 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 2716 | /* fall through */ |
| 2717 | case NL80211_IFTYPE_ADHOC: |
| 2718 | /* disallow things sta doesn't support */ |
| 2719 | if (params.plink_action) |
| 2720 | return -EINVAL; |
| 2721 | if (params.ht_capa) |
| 2722 | return -EINVAL; |
| 2723 | if (params.listen_interval >= 0) |
| 2724 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2725 | /* reject any changes other than AUTHORIZED */ |
| 2726 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2727 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2728 | break; |
| 2729 | case NL80211_IFTYPE_MESH_POINT: |
| 2730 | /* disallow things mesh doesn't support */ |
| 2731 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2732 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2733 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2734 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2735 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2736 | return -EINVAL; |
| 2737 | /* |
| 2738 | * No special handling for TDLS here -- the userspace |
| 2739 | * mesh code doesn't have this bug. |
| 2740 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2741 | if (params.sta_flags_mask & |
| 2742 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2743 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2744 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2745 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2746 | break; |
| 2747 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2748 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2749 | } |
| 2750 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2751 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2752 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2753 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2754 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2755 | if (params.vlan) |
| 2756 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2757 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2758 | return err; |
| 2759 | } |
| 2760 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2761 | static struct nla_policy |
| 2762 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2763 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2764 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2765 | }; |
| 2766 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2767 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2768 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2770 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2771 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2772 | struct station_parameters params; |
| 2773 | u8 *mac_addr = NULL; |
| 2774 | |
| 2775 | memset(¶ms, 0, sizeof(params)); |
| 2776 | |
| 2777 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2778 | return -EINVAL; |
| 2779 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2780 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2781 | return -EINVAL; |
| 2782 | |
| 2783 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2784 | return -EINVAL; |
| 2785 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2786 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2787 | return -EINVAL; |
| 2788 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2789 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2790 | params.supported_rates = |
| 2791 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2792 | params.supported_rates_len = |
| 2793 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2794 | params.listen_interval = |
| 2795 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2796 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2797 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2798 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2799 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2800 | |
Jouni Malinen | 36aedc9 | 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]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2804 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2805 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2806 | params.plink_action = |
| 2807 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2808 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2809 | if (!rdev->ops->add_station) |
| 2810 | return -EOPNOTSUPP; |
| 2811 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2812 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2813 | return -EINVAL; |
| 2814 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2815 | switch (dev->ieee80211_ptr->iftype) { |
| 2816 | case NL80211_IFTYPE_AP: |
| 2817 | case NL80211_IFTYPE_AP_VLAN: |
| 2818 | case NL80211_IFTYPE_P2P_GO: |
| 2819 | /* parse WME attributes if sta is WME capable */ |
| 2820 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 2821 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 2822 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2823 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2824 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2825 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2826 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2827 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2828 | nl80211_sta_wme_policy); |
| 2829 | if (err) |
| 2830 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2831 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2832 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2833 | params.uapsd_queues = |
| 2834 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 2835 | if (params.uapsd_queues & |
| 2836 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2837 | return -EINVAL; |
| 2838 | |
| 2839 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2840 | params.max_sp = |
| 2841 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 2842 | |
| 2843 | if (params.max_sp & |
| 2844 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2845 | return -EINVAL; |
| 2846 | |
| 2847 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 2848 | } |
| 2849 | /* TDLS peers cannot be added */ |
| 2850 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2851 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2852 | /* but don't bother the driver with it */ |
| 2853 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2854 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2855 | /* must be last in here for error handling */ |
| 2856 | params.vlan = get_vlan(info, rdev); |
| 2857 | if (IS_ERR(params.vlan)) |
| 2858 | return PTR_ERR(params.vlan); |
| 2859 | break; |
| 2860 | case NL80211_IFTYPE_MESH_POINT: |
| 2861 | /* TDLS peers cannot be added */ |
| 2862 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2863 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2864 | break; |
| 2865 | case NL80211_IFTYPE_STATION: |
| 2866 | /* Only TDLS peers can be added */ |
| 2867 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 2868 | return -EINVAL; |
| 2869 | /* Can only add if TDLS ... */ |
| 2870 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 2871 | return -EOPNOTSUPP; |
| 2872 | /* ... with external setup is supported */ |
| 2873 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 2874 | return -EOPNOTSUPP; |
| 2875 | break; |
| 2876 | default: |
| 2877 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2878 | } |
| 2879 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2880 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2881 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2882 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2883 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2884 | if (params.vlan) |
| 2885 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2886 | return err; |
| 2887 | } |
| 2888 | |
| 2889 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2890 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2891 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2892 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2893 | u8 *mac_addr = NULL; |
| 2894 | |
| 2895 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2896 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2897 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2898 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2899 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2900 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2901 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2902 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2903 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2904 | if (!rdev->ops->del_station) |
| 2905 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2906 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2907 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2908 | } |
| 2909 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2910 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2911 | int flags, struct net_device *dev, |
| 2912 | u8 *dst, u8 *next_hop, |
| 2913 | struct mpath_info *pinfo) |
| 2914 | { |
| 2915 | void *hdr; |
| 2916 | struct nlattr *pinfoattr; |
| 2917 | |
| 2918 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2919 | if (!hdr) |
| 2920 | return -1; |
| 2921 | |
| 2922 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2923 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2924 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2925 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2926 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2927 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2928 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2929 | if (!pinfoattr) |
| 2930 | goto nla_put_failure; |
| 2931 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2932 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2933 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2934 | if (pinfo->filled & MPATH_INFO_SN) |
| 2935 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2936 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2937 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2938 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2939 | pinfo->metric); |
| 2940 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2941 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2942 | pinfo->exptime); |
| 2943 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2944 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2945 | pinfo->flags); |
| 2946 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2947 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2948 | pinfo->discovery_timeout); |
| 2949 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2950 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2951 | pinfo->discovery_retries); |
| 2952 | |
| 2953 | nla_nest_end(msg, pinfoattr); |
| 2954 | |
| 2955 | return genlmsg_end(msg, hdr); |
| 2956 | |
| 2957 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2958 | genlmsg_cancel(msg, hdr); |
| 2959 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2960 | } |
| 2961 | |
| 2962 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2963 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2964 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2965 | struct mpath_info pinfo; |
| 2966 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2967 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2968 | u8 dst[ETH_ALEN]; |
| 2969 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2970 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2971 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2972 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2973 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2974 | if (err) |
| 2975 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2976 | |
| 2977 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2978 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2979 | goto out_err; |
| 2980 | } |
| 2981 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2982 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2983 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2984 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2985 | } |
| 2986 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2987 | while (1) { |
| 2988 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2989 | dst, next_hop, &pinfo); |
| 2990 | if (err == -ENOENT) |
| 2991 | break; |
| 2992 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2993 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2994 | |
| 2995 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2996 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2997 | netdev, dst, next_hop, |
| 2998 | &pinfo) < 0) |
| 2999 | goto out; |
| 3000 | |
| 3001 | path_idx++; |
| 3002 | } |
| 3003 | |
| 3004 | |
| 3005 | out: |
| 3006 | cb->args[1] = path_idx; |
| 3007 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3008 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3009 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3010 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3014 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3015 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3016 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3017 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3018 | struct mpath_info pinfo; |
| 3019 | struct sk_buff *msg; |
| 3020 | u8 *dst = NULL; |
| 3021 | u8 next_hop[ETH_ALEN]; |
| 3022 | |
| 3023 | memset(&pinfo, 0, sizeof(pinfo)); |
| 3024 | |
| 3025 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3026 | return -EINVAL; |
| 3027 | |
| 3028 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3029 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3030 | if (!rdev->ops->get_mpath) |
| 3031 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3032 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3033 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3034 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3035 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3036 | 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] | 3037 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3038 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3039 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3040 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3041 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3042 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3043 | |
| 3044 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3045 | dev, dst, next_hop, &pinfo) < 0) { |
| 3046 | nlmsg_free(msg); |
| 3047 | return -ENOBUFS; |
| 3048 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3049 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3050 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3054 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3056 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3057 | u8 *dst = NULL; |
| 3058 | u8 *next_hop = NULL; |
| 3059 | |
| 3060 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3061 | return -EINVAL; |
| 3062 | |
| 3063 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3064 | return -EINVAL; |
| 3065 | |
| 3066 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3067 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3068 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3069 | if (!rdev->ops->change_mpath) |
| 3070 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3071 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3072 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3073 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3074 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3075 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3076 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3077 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3078 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3079 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3080 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3081 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3082 | u8 *dst = NULL; |
| 3083 | u8 *next_hop = NULL; |
| 3084 | |
| 3085 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3086 | return -EINVAL; |
| 3087 | |
| 3088 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3089 | return -EINVAL; |
| 3090 | |
| 3091 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3092 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3093 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3094 | if (!rdev->ops->add_mpath) |
| 3095 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3096 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3097 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3098 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3099 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3100 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3104 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3106 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3107 | u8 *dst = NULL; |
| 3108 | |
| 3109 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3110 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3111 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3112 | if (!rdev->ops->del_mpath) |
| 3113 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3114 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3115 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3116 | } |
| 3117 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3118 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3119 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3121 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3122 | struct bss_parameters params; |
| 3123 | |
| 3124 | memset(¶ms, 0, sizeof(params)); |
| 3125 | /* default to not changing parameters */ |
| 3126 | params.use_cts_prot = -1; |
| 3127 | params.use_short_preamble = -1; |
| 3128 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3129 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3130 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3131 | |
| 3132 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3133 | params.use_cts_prot = |
| 3134 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3135 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3136 | params.use_short_preamble = |
| 3137 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3138 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3139 | params.use_short_slot_time = |
| 3140 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3141 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3142 | params.basic_rates = |
| 3143 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3144 | params.basic_rates_len = |
| 3145 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3146 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3147 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3148 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3149 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3150 | params.ht_opmode = |
| 3151 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3152 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3153 | if (!rdev->ops->change_bss) |
| 3154 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3155 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3156 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3157 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3158 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3159 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3160 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3161 | } |
| 3162 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3163 | 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] | 3164 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3165 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3166 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3167 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3168 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3169 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3170 | }; |
| 3171 | |
| 3172 | static int parse_reg_rule(struct nlattr *tb[], |
| 3173 | struct ieee80211_reg_rule *reg_rule) |
| 3174 | { |
| 3175 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3176 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3177 | |
| 3178 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3179 | return -EINVAL; |
| 3180 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3181 | return -EINVAL; |
| 3182 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3183 | return -EINVAL; |
| 3184 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3185 | return -EINVAL; |
| 3186 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3187 | return -EINVAL; |
| 3188 | |
| 3189 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3190 | |
| 3191 | freq_range->start_freq_khz = |
| 3192 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3193 | freq_range->end_freq_khz = |
| 3194 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3195 | freq_range->max_bandwidth_khz = |
| 3196 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3197 | |
| 3198 | power_rule->max_eirp = |
| 3199 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3200 | |
| 3201 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3202 | power_rule->max_antenna_gain = |
| 3203 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3204 | |
| 3205 | return 0; |
| 3206 | } |
| 3207 | |
| 3208 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3209 | { |
| 3210 | int r; |
| 3211 | char *data = NULL; |
| 3212 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3213 | /* |
| 3214 | * You should only get this when cfg80211 hasn't yet initialized |
| 3215 | * completely when built-in to the kernel right between the time |
| 3216 | * window between nl80211_init() and regulatory_init(), if that is |
| 3217 | * even possible. |
| 3218 | */ |
| 3219 | mutex_lock(&cfg80211_mutex); |
| 3220 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3221 | mutex_unlock(&cfg80211_mutex); |
| 3222 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3223 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3224 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3225 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3226 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3227 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3228 | |
| 3229 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3230 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3231 | r = regulatory_hint_user(data); |
| 3232 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3233 | return r; |
| 3234 | } |
| 3235 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3236 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3237 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3238 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3239 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3240 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3241 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3242 | struct mesh_config cur_params; |
| 3243 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3244 | void *hdr; |
| 3245 | struct nlattr *pinfoattr; |
| 3246 | struct sk_buff *msg; |
| 3247 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3248 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3249 | return -EOPNOTSUPP; |
| 3250 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3251 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3252 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3253 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3254 | wdev_lock(wdev); |
| 3255 | /* If not connected, get default parameters */ |
| 3256 | if (!wdev->mesh_id_len) |
| 3257 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3258 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3259 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3260 | &cur_params); |
| 3261 | wdev_unlock(wdev); |
| 3262 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3263 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3264 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3265 | |
| 3266 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3267 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3268 | if (!msg) |
| 3269 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3270 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3271 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3272 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3273 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3274 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3275 | if (!pinfoattr) |
| 3276 | goto nla_put_failure; |
| 3277 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3278 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3279 | cur_params.dot11MeshRetryTimeout); |
| 3280 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3281 | cur_params.dot11MeshConfirmTimeout); |
| 3282 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3283 | cur_params.dot11MeshHoldingTimeout); |
| 3284 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3285 | cur_params.dot11MeshMaxPeerLinks); |
| 3286 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3287 | cur_params.dot11MeshMaxRetries); |
| 3288 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3289 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3290 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3291 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3292 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3293 | cur_params.auto_open_plinks); |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3294 | NLA_PUT_U32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3295 | cur_params.dot11MeshNbrOffsetMaxNeighbor); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3296 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3297 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3298 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3299 | cur_params.path_refresh_time); |
| 3300 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3301 | cur_params.min_discovery_timeout); |
| 3302 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3303 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3304 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3305 | cur_params.dot11MeshHWMPpreqMinInterval); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3306 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3307 | cur_params.dot11MeshHWMPperrMinInterval); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3308 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3309 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3310 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3311 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3312 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3313 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3314 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3315 | cur_params.dot11MeshGateAnnouncementProtocol); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3316 | NLA_PUT_U8(msg, NL80211_MESHCONF_FORWARDING, |
| 3317 | cur_params.dot11MeshForwarding); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3318 | NLA_PUT_U32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 3319 | cur_params.rssi_threshold); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3320 | nla_nest_end(msg, pinfoattr); |
| 3321 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3322 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3323 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3324 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3325 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3326 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3327 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3328 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3329 | } |
| 3330 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3331 | 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] | 3332 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3333 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3334 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3335 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3336 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3337 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3338 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3339 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3340 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3341 | |
| 3342 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3343 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3344 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3345 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3346 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3347 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3348 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3349 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3350 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3351 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3352 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3353 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32}, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3354 | }; |
| 3355 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3356 | static const struct nla_policy |
| 3357 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3358 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3359 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3360 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3361 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3362 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3363 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3364 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3365 | }; |
| 3366 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3367 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3368 | struct mesh_config *cfg, |
| 3369 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3370 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3371 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3372 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3373 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3374 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3375 | do {\ |
| 3376 | if (table[attr_num]) {\ |
| 3377 | cfg->param = nla_fn(table[attr_num]); \ |
| 3378 | mask |= (1 << (attr_num - 1)); \ |
| 3379 | } \ |
| 3380 | } while (0);\ |
| 3381 | |
| 3382 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3383 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3384 | return -EINVAL; |
| 3385 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3386 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3387 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3388 | return -EINVAL; |
| 3389 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3390 | /* This makes sure that there aren't more than 32 mesh config |
| 3391 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3392 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3393 | |
| 3394 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3395 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3396 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3397 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3398 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3399 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3400 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3401 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3402 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3403 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3404 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3405 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3406 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3407 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3408 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3409 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3410 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3411 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 3412 | mask, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 3413 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3414 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3415 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3416 | nla_get_u8); |
| 3417 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3418 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3419 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3420 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3421 | nla_get_u16); |
| 3422 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3423 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3424 | nla_get_u32); |
| 3425 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3426 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3427 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3428 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
| 3429 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3430 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3431 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3432 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3433 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3434 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3435 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3436 | dot11MeshHWMPRootMode, mask, |
| 3437 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3438 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3439 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3440 | dot11MeshHWMPRannInterval, mask, |
| 3441 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3442 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3443 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3444 | dot11MeshGateAnnouncementProtocol, mask, |
| 3445 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3446 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3447 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
| 3448 | mask, NL80211_MESHCONF_FORWARDING, nla_get_u8); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 3449 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
| 3450 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3451 | if (mask_out) |
| 3452 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3453 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3454 | return 0; |
| 3455 | |
| 3456 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3457 | } |
| 3458 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3459 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3460 | struct mesh_setup *setup) |
| 3461 | { |
| 3462 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3463 | |
| 3464 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3465 | return -EINVAL; |
| 3466 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3467 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3468 | nl80211_mesh_setup_params_policy)) |
| 3469 | return -EINVAL; |
| 3470 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 3471 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 3472 | setup->sync_method = |
| 3473 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 3474 | IEEE80211_SYNC_METHOD_VENDOR : |
| 3475 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 3476 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3477 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3478 | setup->path_sel_proto = |
| 3479 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3480 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3481 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3482 | |
| 3483 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3484 | setup->path_metric = |
| 3485 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3486 | IEEE80211_PATH_METRIC_VENDOR : |
| 3487 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3488 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3489 | |
| 3490 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3491 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3492 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3493 | if (!is_valid_ie_attr(ieattr)) |
| 3494 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3495 | setup->ie = nla_data(ieattr); |
| 3496 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3497 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3498 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3499 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3500 | |
| 3501 | return 0; |
| 3502 | } |
| 3503 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3504 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3505 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3506 | { |
| 3507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3508 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3509 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3510 | struct mesh_config cfg; |
| 3511 | u32 mask; |
| 3512 | int err; |
| 3513 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3514 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3515 | return -EOPNOTSUPP; |
| 3516 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3517 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3518 | return -EOPNOTSUPP; |
| 3519 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3520 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3521 | if (err) |
| 3522 | return err; |
| 3523 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3524 | wdev_lock(wdev); |
| 3525 | if (!wdev->mesh_id_len) |
| 3526 | err = -ENOLINK; |
| 3527 | |
| 3528 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3529 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3530 | mask, &cfg); |
| 3531 | |
| 3532 | wdev_unlock(wdev); |
| 3533 | |
| 3534 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3537 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3538 | { |
| 3539 | struct sk_buff *msg; |
| 3540 | void *hdr = NULL; |
| 3541 | struct nlattr *nl_reg_rules; |
| 3542 | unsigned int i; |
| 3543 | int err = -EINVAL; |
| 3544 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3545 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3546 | |
| 3547 | if (!cfg80211_regdomain) |
| 3548 | goto out; |
| 3549 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3550 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3551 | if (!msg) { |
| 3552 | err = -ENOBUFS; |
| 3553 | goto out; |
| 3554 | } |
| 3555 | |
| 3556 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3557 | NL80211_CMD_GET_REG); |
| 3558 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3559 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3560 | |
| 3561 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3562 | cfg80211_regdomain->alpha2); |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3563 | if (cfg80211_regdomain->dfs_region) |
| 3564 | NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION, |
| 3565 | cfg80211_regdomain->dfs_region); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3566 | |
| 3567 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3568 | if (!nl_reg_rules) |
| 3569 | goto nla_put_failure; |
| 3570 | |
| 3571 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3572 | struct nlattr *nl_reg_rule; |
| 3573 | const struct ieee80211_reg_rule *reg_rule; |
| 3574 | const struct ieee80211_freq_range *freq_range; |
| 3575 | const struct ieee80211_power_rule *power_rule; |
| 3576 | |
| 3577 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3578 | freq_range = ®_rule->freq_range; |
| 3579 | power_rule = ®_rule->power_rule; |
| 3580 | |
| 3581 | nl_reg_rule = nla_nest_start(msg, i); |
| 3582 | if (!nl_reg_rule) |
| 3583 | goto nla_put_failure; |
| 3584 | |
| 3585 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3586 | reg_rule->flags); |
| 3587 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3588 | freq_range->start_freq_khz); |
| 3589 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3590 | freq_range->end_freq_khz); |
| 3591 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3592 | freq_range->max_bandwidth_khz); |
| 3593 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3594 | power_rule->max_antenna_gain); |
| 3595 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3596 | power_rule->max_eirp); |
| 3597 | |
| 3598 | nla_nest_end(msg, nl_reg_rule); |
| 3599 | } |
| 3600 | |
| 3601 | nla_nest_end(msg, nl_reg_rules); |
| 3602 | |
| 3603 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3604 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3605 | goto out; |
| 3606 | |
| 3607 | nla_put_failure: |
| 3608 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3609 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3610 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3611 | err = -EMSGSIZE; |
| 3612 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3613 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3614 | return err; |
| 3615 | } |
| 3616 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3617 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3618 | { |
| 3619 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3620 | struct nlattr *nl_reg_rule; |
| 3621 | char *alpha2 = NULL; |
| 3622 | int rem_reg_rules = 0, r = 0; |
| 3623 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3624 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3625 | struct ieee80211_regdomain *rd = NULL; |
| 3626 | |
| 3627 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3628 | return -EINVAL; |
| 3629 | |
| 3630 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3631 | return -EINVAL; |
| 3632 | |
| 3633 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3634 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3635 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 3636 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 3637 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3638 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3639 | rem_reg_rules) { |
| 3640 | num_rules++; |
| 3641 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3642 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3645 | mutex_lock(&cfg80211_mutex); |
| 3646 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3647 | if (!reg_is_valid_request(alpha2)) { |
| 3648 | r = -EINVAL; |
| 3649 | goto bad_reg; |
| 3650 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3651 | |
| 3652 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3653 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3654 | |
| 3655 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3656 | if (!rd) { |
| 3657 | r = -ENOMEM; |
| 3658 | goto bad_reg; |
| 3659 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3660 | |
| 3661 | rd->n_reg_rules = num_rules; |
| 3662 | rd->alpha2[0] = alpha2[0]; |
| 3663 | rd->alpha2[1] = alpha2[1]; |
| 3664 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3665 | /* |
| 3666 | * Disable DFS master mode if the DFS region was |
| 3667 | * not supported or known on this kernel. |
| 3668 | */ |
| 3669 | if (reg_supported_dfs_region(dfs_region)) |
| 3670 | rd->dfs_region = dfs_region; |
| 3671 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3672 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3673 | rem_reg_rules) { |
| 3674 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3675 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3676 | reg_rule_policy); |
| 3677 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3678 | if (r) |
| 3679 | goto bad_reg; |
| 3680 | |
| 3681 | rule_idx++; |
| 3682 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3683 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3684 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3685 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3686 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | BUG_ON(rule_idx != num_rules); |
| 3690 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3691 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3692 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3693 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3694 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3695 | return r; |
| 3696 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3697 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3698 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3699 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3700 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3703 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3704 | { |
| 3705 | struct nlattr *attr1, *attr2; |
| 3706 | int n_channels = 0, tmp1, tmp2; |
| 3707 | |
| 3708 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3709 | n_channels++; |
| 3710 | /* |
| 3711 | * Some hardware has a limited channel list for |
| 3712 | * scanning, and it is pretty much nonsensical |
| 3713 | * to scan for a channel twice, so disallow that |
| 3714 | * and don't require drivers to check that the |
| 3715 | * channel list they get isn't longer than what |
| 3716 | * they can scan, as long as they can scan all |
| 3717 | * the channels they registered at once. |
| 3718 | */ |
| 3719 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3720 | if (attr1 != attr2 && |
| 3721 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3722 | return 0; |
| 3723 | } |
| 3724 | |
| 3725 | return n_channels; |
| 3726 | } |
| 3727 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3728 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3729 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3730 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3731 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3732 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3733 | struct nlattr *attr; |
| 3734 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3735 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3736 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3737 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3738 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3739 | return -EINVAL; |
| 3740 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3741 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3742 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3743 | if (!rdev->ops->scan) |
| 3744 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3745 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3746 | if (rdev->scan_req) |
| 3747 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3748 | |
| 3749 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3750 | n_channels = validate_scan_freqs( |
| 3751 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3752 | if (!n_channels) |
| 3753 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3754 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3755 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3756 | n_channels = 0; |
| 3757 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3758 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3759 | if (wiphy->bands[band]) |
| 3760 | n_channels += wiphy->bands[band]->n_channels; |
| 3761 | } |
| 3762 | |
| 3763 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3764 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3765 | n_ssids++; |
| 3766 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3767 | if (n_ssids > wiphy->max_scan_ssids) |
| 3768 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3769 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3770 | if (info->attrs[NL80211_ATTR_IE]) |
| 3771 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3772 | else |
| 3773 | ie_len = 0; |
| 3774 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3775 | if (ie_len > wiphy->max_scan_ie_len) |
| 3776 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3777 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3778 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3779 | + sizeof(*request->ssids) * n_ssids |
| 3780 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3781 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3782 | if (!request) |
| 3783 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3784 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3785 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3786 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3787 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3788 | if (ie_len) { |
| 3789 | if (request->ssids) |
| 3790 | request->ie = (void *)(request->ssids + n_ssids); |
| 3791 | else |
| 3792 | request->ie = (void *)(request->channels + n_channels); |
| 3793 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3794 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3795 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3796 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3797 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3798 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3799 | struct ieee80211_channel *chan; |
| 3800 | |
| 3801 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3802 | |
| 3803 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3804 | err = -EINVAL; |
| 3805 | goto out_free; |
| 3806 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3807 | |
| 3808 | /* ignore disabled channels */ |
| 3809 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3810 | continue; |
| 3811 | |
| 3812 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3813 | i++; |
| 3814 | } |
| 3815 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3816 | enum ieee80211_band band; |
| 3817 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3818 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3819 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3820 | int j; |
| 3821 | if (!wiphy->bands[band]) |
| 3822 | continue; |
| 3823 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3824 | struct ieee80211_channel *chan; |
| 3825 | |
| 3826 | chan = &wiphy->bands[band]->channels[j]; |
| 3827 | |
| 3828 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3829 | continue; |
| 3830 | |
| 3831 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3832 | i++; |
| 3833 | } |
| 3834 | } |
| 3835 | } |
| 3836 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3837 | if (!i) { |
| 3838 | err = -EINVAL; |
| 3839 | goto out_free; |
| 3840 | } |
| 3841 | |
| 3842 | request->n_channels = i; |
| 3843 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3844 | i = 0; |
| 3845 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3846 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3847 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3848 | err = -EINVAL; |
| 3849 | goto out_free; |
| 3850 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3851 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3852 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3853 | i++; |
| 3854 | } |
| 3855 | } |
| 3856 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3857 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3858 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3859 | memcpy((void *)request->ie, |
| 3860 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3861 | request->ie_len); |
| 3862 | } |
| 3863 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3864 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3865 | if (wiphy->bands[i]) |
| 3866 | request->rates[i] = |
| 3867 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3868 | |
| 3869 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3870 | nla_for_each_nested(attr, |
| 3871 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3872 | tmp) { |
| 3873 | enum ieee80211_band band = nla_type(attr); |
| 3874 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3875 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3876 | err = -EINVAL; |
| 3877 | goto out_free; |
| 3878 | } |
| 3879 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3880 | nla_data(attr), |
| 3881 | nla_len(attr), |
| 3882 | &request->rates[band]); |
| 3883 | if (err) |
| 3884 | goto out_free; |
| 3885 | } |
| 3886 | } |
| 3887 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3888 | request->no_cck = |
| 3889 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3890 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3891 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3892 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3893 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3894 | rdev->scan_req = request; |
| 3895 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3896 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3897 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3898 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3899 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3900 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3901 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3902 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3903 | kfree(request); |
| 3904 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3905 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3906 | return err; |
| 3907 | } |
| 3908 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3909 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3910 | struct genl_info *info) |
| 3911 | { |
| 3912 | struct cfg80211_sched_scan_request *request; |
| 3913 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3914 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3915 | struct nlattr *attr; |
| 3916 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3917 | 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] | 3918 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3919 | enum ieee80211_band band; |
| 3920 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3921 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3922 | |
| 3923 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3924 | !rdev->ops->sched_scan_start) |
| 3925 | return -EOPNOTSUPP; |
| 3926 | |
| 3927 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3928 | return -EINVAL; |
| 3929 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3930 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3931 | return -EINVAL; |
| 3932 | |
| 3933 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3934 | if (interval == 0) |
| 3935 | return -EINVAL; |
| 3936 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3937 | wiphy = &rdev->wiphy; |
| 3938 | |
| 3939 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3940 | n_channels = validate_scan_freqs( |
| 3941 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3942 | if (!n_channels) |
| 3943 | return -EINVAL; |
| 3944 | } else { |
| 3945 | n_channels = 0; |
| 3946 | |
| 3947 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3948 | if (wiphy->bands[band]) |
| 3949 | n_channels += wiphy->bands[band]->n_channels; |
| 3950 | } |
| 3951 | |
| 3952 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3953 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3954 | tmp) |
| 3955 | n_ssids++; |
| 3956 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3957 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3958 | return -EINVAL; |
| 3959 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3960 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3961 | nla_for_each_nested(attr, |
| 3962 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3963 | tmp) |
| 3964 | n_match_sets++; |
| 3965 | |
| 3966 | if (n_match_sets > wiphy->max_match_sets) |
| 3967 | return -EINVAL; |
| 3968 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3969 | if (info->attrs[NL80211_ATTR_IE]) |
| 3970 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3971 | else |
| 3972 | ie_len = 0; |
| 3973 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3974 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3975 | return -EINVAL; |
| 3976 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3977 | mutex_lock(&rdev->sched_scan_mtx); |
| 3978 | |
| 3979 | if (rdev->sched_scan_req) { |
| 3980 | err = -EINPROGRESS; |
| 3981 | goto out; |
| 3982 | } |
| 3983 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3984 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3985 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3986 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3987 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3988 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3989 | if (!request) { |
| 3990 | err = -ENOMEM; |
| 3991 | goto out; |
| 3992 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3993 | |
| 3994 | if (n_ssids) |
| 3995 | request->ssids = (void *)&request->channels[n_channels]; |
| 3996 | request->n_ssids = n_ssids; |
| 3997 | if (ie_len) { |
| 3998 | if (request->ssids) |
| 3999 | request->ie = (void *)(request->ssids + n_ssids); |
| 4000 | else |
| 4001 | request->ie = (void *)(request->channels + n_channels); |
| 4002 | } |
| 4003 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4004 | if (n_match_sets) { |
| 4005 | if (request->ie) |
| 4006 | request->match_sets = (void *)(request->ie + ie_len); |
| 4007 | else if (request->ssids) |
| 4008 | request->match_sets = |
| 4009 | (void *)(request->ssids + n_ssids); |
| 4010 | else |
| 4011 | request->match_sets = |
| 4012 | (void *)(request->channels + n_channels); |
| 4013 | } |
| 4014 | request->n_match_sets = n_match_sets; |
| 4015 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4016 | i = 0; |
| 4017 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 4018 | /* user specified, bail out if channel not found */ |
| 4019 | nla_for_each_nested(attr, |
| 4020 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 4021 | tmp) { |
| 4022 | struct ieee80211_channel *chan; |
| 4023 | |
| 4024 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 4025 | |
| 4026 | if (!chan) { |
| 4027 | err = -EINVAL; |
| 4028 | goto out_free; |
| 4029 | } |
| 4030 | |
| 4031 | /* ignore disabled channels */ |
| 4032 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4033 | continue; |
| 4034 | |
| 4035 | request->channels[i] = chan; |
| 4036 | i++; |
| 4037 | } |
| 4038 | } else { |
| 4039 | /* all channels */ |
| 4040 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4041 | int j; |
| 4042 | if (!wiphy->bands[band]) |
| 4043 | continue; |
| 4044 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 4045 | struct ieee80211_channel *chan; |
| 4046 | |
| 4047 | chan = &wiphy->bands[band]->channels[j]; |
| 4048 | |
| 4049 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 4050 | continue; |
| 4051 | |
| 4052 | request->channels[i] = chan; |
| 4053 | i++; |
| 4054 | } |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | if (!i) { |
| 4059 | err = -EINVAL; |
| 4060 | goto out_free; |
| 4061 | } |
| 4062 | |
| 4063 | request->n_channels = i; |
| 4064 | |
| 4065 | i = 0; |
| 4066 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 4067 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 4068 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4069 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4070 | err = -EINVAL; |
| 4071 | goto out_free; |
| 4072 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4073 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4074 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4075 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4076 | i++; |
| 4077 | } |
| 4078 | } |
| 4079 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4080 | i = 0; |
| 4081 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4082 | nla_for_each_nested(attr, |
| 4083 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4084 | tmp) { |
| 4085 | struct nlattr *ssid; |
| 4086 | |
| 4087 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4088 | nla_data(attr), nla_len(attr), |
| 4089 | nl80211_match_policy); |
| 4090 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 4091 | if (ssid) { |
| 4092 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4093 | err = -EINVAL; |
| 4094 | goto out_free; |
| 4095 | } |
| 4096 | memcpy(request->match_sets[i].ssid.ssid, |
| 4097 | nla_data(ssid), nla_len(ssid)); |
| 4098 | request->match_sets[i].ssid.ssid_len = |
| 4099 | nla_len(ssid); |
| 4100 | } |
| 4101 | i++; |
| 4102 | } |
| 4103 | } |
| 4104 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4105 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4106 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4107 | memcpy((void *)request->ie, |
| 4108 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4109 | request->ie_len); |
| 4110 | } |
| 4111 | |
| 4112 | request->dev = dev; |
| 4113 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4114 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4115 | |
| 4116 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 4117 | if (!err) { |
| 4118 | rdev->sched_scan_req = request; |
| 4119 | nl80211_send_sched_scan(rdev, dev, |
| 4120 | NL80211_CMD_START_SCHED_SCAN); |
| 4121 | goto out; |
| 4122 | } |
| 4123 | |
| 4124 | out_free: |
| 4125 | kfree(request); |
| 4126 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4127 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4128 | return err; |
| 4129 | } |
| 4130 | |
| 4131 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4132 | struct genl_info *info) |
| 4133 | { |
| 4134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4135 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4136 | |
| 4137 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4138 | !rdev->ops->sched_scan_stop) |
| 4139 | return -EOPNOTSUPP; |
| 4140 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4141 | mutex_lock(&rdev->sched_scan_mtx); |
| 4142 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4143 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4144 | |
| 4145 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4146 | } |
| 4147 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4148 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4149 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4150 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4151 | struct wireless_dev *wdev, |
| 4152 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4153 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4154 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4155 | void *hdr; |
| 4156 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4157 | |
| 4158 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4159 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4160 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4161 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4162 | if (!hdr) |
| 4163 | return -1; |
| 4164 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4165 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4166 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4167 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4168 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4169 | |
| 4170 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4171 | if (!bss) |
| 4172 | goto nla_put_failure; |
| 4173 | if (!is_zero_ether_addr(res->bssid)) |
| 4174 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 4175 | if (res->information_elements && res->len_information_elements) |
| 4176 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4177 | res->len_information_elements, |
| 4178 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 4179 | if (res->beacon_ies && res->len_beacon_ies && |
| 4180 | res->beacon_ies != res->information_elements) |
| 4181 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 4182 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4183 | if (res->tsf) |
| 4184 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 4185 | if (res->beacon_interval) |
| 4186 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 4187 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 4188 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 4189 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4190 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4191 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4192 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4193 | case CFG80211_SIGNAL_TYPE_MBM: |
| 4194 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 4195 | break; |
| 4196 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 4197 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 4198 | break; |
| 4199 | default: |
| 4200 | break; |
| 4201 | } |
| 4202 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4203 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4204 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4205 | case NL80211_IFTYPE_STATION: |
| 4206 | if (intbss == wdev->current_bss) |
| 4207 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4208 | NL80211_BSS_STATUS_ASSOCIATED); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4209 | break; |
| 4210 | case NL80211_IFTYPE_ADHOC: |
| 4211 | if (intbss == wdev->current_bss) |
| 4212 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4213 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 4214 | break; |
| 4215 | default: |
| 4216 | break; |
| 4217 | } |
| 4218 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4219 | nla_nest_end(msg, bss); |
| 4220 | |
| 4221 | return genlmsg_end(msg, hdr); |
| 4222 | |
| 4223 | nla_put_failure: |
| 4224 | genlmsg_cancel(msg, hdr); |
| 4225 | return -EMSGSIZE; |
| 4226 | } |
| 4227 | |
| 4228 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4229 | struct netlink_callback *cb) |
| 4230 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4231 | struct cfg80211_registered_device *rdev; |
| 4232 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4233 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4234 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4235 | int start = cb->args[1], idx = 0; |
| 4236 | int err; |
| 4237 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4238 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4239 | if (err) |
| 4240 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4241 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4242 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4243 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4244 | wdev_lock(wdev); |
| 4245 | spin_lock_bh(&rdev->bss_lock); |
| 4246 | cfg80211_bss_expire(rdev); |
| 4247 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4248 | cb->seq = rdev->bss_generation; |
| 4249 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4250 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4251 | if (++idx <= start) |
| 4252 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4253 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4254 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4255 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4256 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4257 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4258 | } |
| 4259 | } |
| 4260 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4261 | spin_unlock_bh(&rdev->bss_lock); |
| 4262 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4263 | |
| 4264 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4265 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4266 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4267 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4268 | } |
| 4269 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4270 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4271 | int flags, struct net_device *dev, |
| 4272 | struct survey_info *survey) |
| 4273 | { |
| 4274 | void *hdr; |
| 4275 | struct nlattr *infoattr; |
| 4276 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4277 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4278 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4279 | if (!hdr) |
| 4280 | return -ENOMEM; |
| 4281 | |
| 4282 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4283 | |
| 4284 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4285 | if (!infoattr) |
| 4286 | goto nla_put_failure; |
| 4287 | |
| 4288 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4289 | survey->channel->center_freq); |
| 4290 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4291 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4292 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4293 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4294 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4295 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4296 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4297 | survey->channel_time); |
| 4298 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4299 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4300 | survey->channel_time_busy); |
| 4301 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4302 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4303 | survey->channel_time_ext_busy); |
| 4304 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4305 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4306 | survey->channel_time_rx); |
| 4307 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4308 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4309 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4310 | |
| 4311 | nla_nest_end(msg, infoattr); |
| 4312 | |
| 4313 | return genlmsg_end(msg, hdr); |
| 4314 | |
| 4315 | nla_put_failure: |
| 4316 | genlmsg_cancel(msg, hdr); |
| 4317 | return -EMSGSIZE; |
| 4318 | } |
| 4319 | |
| 4320 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4321 | struct netlink_callback *cb) |
| 4322 | { |
| 4323 | struct survey_info survey; |
| 4324 | struct cfg80211_registered_device *dev; |
| 4325 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4326 | int survey_idx = cb->args[1]; |
| 4327 | int res; |
| 4328 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4329 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4330 | if (res) |
| 4331 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4332 | |
| 4333 | if (!dev->ops->dump_survey) { |
| 4334 | res = -EOPNOTSUPP; |
| 4335 | goto out_err; |
| 4336 | } |
| 4337 | |
| 4338 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4339 | struct ieee80211_channel *chan; |
| 4340 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4341 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4342 | &survey); |
| 4343 | if (res == -ENOENT) |
| 4344 | break; |
| 4345 | if (res) |
| 4346 | goto out_err; |
| 4347 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4348 | /* Survey without a channel doesn't make sense */ |
| 4349 | if (!survey.channel) { |
| 4350 | res = -EINVAL; |
| 4351 | goto out; |
| 4352 | } |
| 4353 | |
| 4354 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4355 | survey.channel->center_freq); |
| 4356 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4357 | survey_idx++; |
| 4358 | continue; |
| 4359 | } |
| 4360 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4361 | if (nl80211_send_survey(skb, |
| 4362 | NETLINK_CB(cb->skb).pid, |
| 4363 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4364 | netdev, |
| 4365 | &survey) < 0) |
| 4366 | goto out; |
| 4367 | survey_idx++; |
| 4368 | } |
| 4369 | |
| 4370 | out: |
| 4371 | cb->args[1] = survey_idx; |
| 4372 | res = skb->len; |
| 4373 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4374 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4375 | return res; |
| 4376 | } |
| 4377 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4378 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4379 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4380 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4381 | } |
| 4382 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4383 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4384 | { |
| 4385 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4386 | NL80211_WPA_VERSION_2)); |
| 4387 | } |
| 4388 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4389 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4390 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4392 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4393 | struct ieee80211_channel *chan; |
| 4394 | const u8 *bssid, *ssid, *ie = NULL; |
| 4395 | int err, ssid_len, ie_len = 0; |
| 4396 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4397 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4398 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4399 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4400 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4401 | return -EINVAL; |
| 4402 | |
| 4403 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4404 | return -EINVAL; |
| 4405 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4406 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4407 | return -EINVAL; |
| 4408 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4409 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4410 | return -EINVAL; |
| 4411 | |
| 4412 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4413 | return -EINVAL; |
| 4414 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4415 | err = nl80211_parse_key(info, &key); |
| 4416 | if (err) |
| 4417 | return err; |
| 4418 | |
| 4419 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4420 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4421 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4422 | if (!key.p.key || !key.p.key_len) |
| 4423 | return -EINVAL; |
| 4424 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4425 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4426 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4427 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4428 | return -EINVAL; |
| 4429 | if (key.idx > 4) |
| 4430 | return -EINVAL; |
| 4431 | } else { |
| 4432 | key.p.key_len = 0; |
| 4433 | key.p.key = NULL; |
| 4434 | } |
| 4435 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4436 | if (key.idx >= 0) { |
| 4437 | int i; |
| 4438 | bool ok = false; |
| 4439 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4440 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4441 | ok = true; |
| 4442 | break; |
| 4443 | } |
| 4444 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4445 | if (!ok) |
| 4446 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4447 | } |
| 4448 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4449 | if (!rdev->ops->auth) |
| 4450 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4451 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4452 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4453 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4454 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4455 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4456 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4457 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4458 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4459 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4460 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4461 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4462 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4463 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4464 | |
| 4465 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4466 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4467 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4468 | } |
| 4469 | |
| 4470 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4471 | if (!nl80211_valid_auth_type(auth_type)) |
| 4472 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4473 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4474 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4475 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4476 | /* |
| 4477 | * Since we no longer track auth state, ignore |
| 4478 | * requests to only change local state. |
| 4479 | */ |
| 4480 | if (local_state_change) |
| 4481 | return 0; |
| 4482 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4483 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4484 | ssid, ssid_len, ie, ie_len, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 4485 | key.p.key, key.p.key_len, key.idx); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4486 | } |
| 4487 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4488 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4489 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4490 | struct cfg80211_crypto_settings *settings, |
| 4491 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4492 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4493 | memset(settings, 0, sizeof(*settings)); |
| 4494 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4495 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4496 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4497 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4498 | u16 proto; |
| 4499 | proto = nla_get_u16( |
| 4500 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4501 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4502 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4503 | proto != ETH_P_PAE) |
| 4504 | return -EINVAL; |
| 4505 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4506 | settings->control_port_no_encrypt = true; |
| 4507 | } else |
| 4508 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4509 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4510 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4511 | void *data; |
| 4512 | int len, i; |
| 4513 | |
| 4514 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4515 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4516 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4517 | |
| 4518 | if (len % sizeof(u32)) |
| 4519 | return -EINVAL; |
| 4520 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4521 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4522 | return -EINVAL; |
| 4523 | |
| 4524 | memcpy(settings->ciphers_pairwise, data, len); |
| 4525 | |
| 4526 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4527 | if (!cfg80211_supported_cipher_suite( |
| 4528 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4529 | settings->ciphers_pairwise[i])) |
| 4530 | return -EINVAL; |
| 4531 | } |
| 4532 | |
| 4533 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4534 | settings->cipher_group = |
| 4535 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4536 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4537 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4538 | return -EINVAL; |
| 4539 | } |
| 4540 | |
| 4541 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4542 | settings->wpa_versions = |
| 4543 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4544 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4545 | return -EINVAL; |
| 4546 | } |
| 4547 | |
| 4548 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4549 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4550 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4551 | |
| 4552 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4553 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4554 | settings->n_akm_suites = len / sizeof(u32); |
| 4555 | |
| 4556 | if (len % sizeof(u32)) |
| 4557 | return -EINVAL; |
| 4558 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4559 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4560 | return -EINVAL; |
| 4561 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4562 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4563 | } |
| 4564 | |
| 4565 | return 0; |
| 4566 | } |
| 4567 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4568 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4569 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4571 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4572 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4573 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4574 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4575 | int err, ssid_len, ie_len = 0; |
| 4576 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4577 | u32 flags = 0; |
| 4578 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 4579 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4580 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4581 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4582 | return -EINVAL; |
| 4583 | |
| 4584 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4585 | !info->attrs[NL80211_ATTR_SSID] || |
| 4586 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4587 | return -EINVAL; |
| 4588 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4589 | if (!rdev->ops->assoc) |
| 4590 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4591 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4592 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4593 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4594 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4595 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4596 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4597 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4598 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4599 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4600 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4601 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4602 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4603 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4604 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4605 | |
| 4606 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4607 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4608 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4609 | } |
| 4610 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4611 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4612 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4613 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4614 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4615 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4616 | else if (mfp != NL80211_MFP_NO) |
| 4617 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4618 | } |
| 4619 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4620 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4621 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4622 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4623 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 4624 | flags |= ASSOC_REQ_DISABLE_HT; |
| 4625 | |
| 4626 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 4627 | ht_capa_mask = |
| 4628 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 4629 | |
| 4630 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 4631 | if (!ht_capa_mask) |
| 4632 | return -EINVAL; |
| 4633 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4634 | } |
| 4635 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4636 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4637 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4638 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4639 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4640 | &crypto, flags, ht_capa, |
| 4641 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4642 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4643 | return err; |
| 4644 | } |
| 4645 | |
| 4646 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4647 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4649 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4650 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4651 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4652 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4653 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4654 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4655 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4656 | return -EINVAL; |
| 4657 | |
| 4658 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4659 | return -EINVAL; |
| 4660 | |
| 4661 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4662 | return -EINVAL; |
| 4663 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4664 | if (!rdev->ops->deauth) |
| 4665 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4666 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4667 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4668 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4669 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4670 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4671 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4672 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4673 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4674 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4675 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4676 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4677 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4678 | |
| 4679 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4680 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4681 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4682 | } |
| 4683 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4684 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4685 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4686 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4687 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4691 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4693 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4694 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4695 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4696 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4697 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4698 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4699 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4700 | return -EINVAL; |
| 4701 | |
| 4702 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4703 | return -EINVAL; |
| 4704 | |
| 4705 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4706 | return -EINVAL; |
| 4707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4708 | if (!rdev->ops->disassoc) |
| 4709 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4710 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4711 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4712 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4713 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4714 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4715 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4716 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4717 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4718 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4719 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4720 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4721 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4722 | |
| 4723 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4724 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4725 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4726 | } |
| 4727 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4728 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4729 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4730 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4731 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4732 | } |
| 4733 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4734 | static bool |
| 4735 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4736 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4737 | int rateval) |
| 4738 | { |
| 4739 | struct wiphy *wiphy = &rdev->wiphy; |
| 4740 | bool found = false; |
| 4741 | int band, i; |
| 4742 | |
| 4743 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4744 | struct ieee80211_supported_band *sband; |
| 4745 | |
| 4746 | sband = wiphy->bands[band]; |
| 4747 | if (!sband) |
| 4748 | continue; |
| 4749 | |
| 4750 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4751 | if (sband->bitrates[i].bitrate == rateval) { |
| 4752 | mcast_rate[band] = i + 1; |
| 4753 | found = true; |
| 4754 | break; |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | |
| 4759 | return found; |
| 4760 | } |
| 4761 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4762 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4763 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4765 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4766 | struct cfg80211_ibss_params ibss; |
| 4767 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4768 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4769 | int err; |
| 4770 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4771 | memset(&ibss, 0, sizeof(ibss)); |
| 4772 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4773 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4774 | return -EINVAL; |
| 4775 | |
| 4776 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4777 | !info->attrs[NL80211_ATTR_SSID] || |
| 4778 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4779 | return -EINVAL; |
| 4780 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4781 | ibss.beacon_interval = 100; |
| 4782 | |
| 4783 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4784 | ibss.beacon_interval = |
| 4785 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4786 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4787 | return -EINVAL; |
| 4788 | } |
| 4789 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4790 | if (!rdev->ops->join_ibss) |
| 4791 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4792 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4793 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4794 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4795 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4796 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4797 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4798 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4799 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4800 | |
| 4801 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4802 | return -EINVAL; |
| 4803 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4804 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4805 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4806 | |
| 4807 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4808 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4809 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4810 | } |
| 4811 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 4812 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4813 | enum nl80211_channel_type channel_type; |
| 4814 | |
| 4815 | channel_type = nla_get_u32( |
| 4816 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4817 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4818 | channel_type != NL80211_CHAN_HT20 && |
| 4819 | channel_type != NL80211_CHAN_HT40MINUS && |
| 4820 | channel_type != NL80211_CHAN_HT40PLUS) |
| 4821 | return -EINVAL; |
| 4822 | |
| 4823 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4824 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 4825 | return -EINVAL; |
| 4826 | |
| 4827 | ibss.channel_type = channel_type; |
| 4828 | } else { |
| 4829 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 4830 | } |
| 4831 | |
| 4832 | ibss.channel = rdev_freq_to_chan(rdev, |
| 4833 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 4834 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4835 | if (!ibss.channel || |
| 4836 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4837 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4838 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4839 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 4840 | /* Both channels should be able to initiate communication */ |
| 4841 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 4842 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 4843 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 4844 | ibss.channel_type)) |
| 4845 | return -EINVAL; |
| 4846 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4847 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4848 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4849 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4850 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4851 | u8 *rates = |
| 4852 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4853 | int n_rates = |
| 4854 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4855 | struct ieee80211_supported_band *sband = |
| 4856 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4857 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4858 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4859 | &ibss.basic_rates); |
| 4860 | if (err) |
| 4861 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4862 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4863 | |
| 4864 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4865 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4866 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4867 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4868 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4869 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4870 | connkeys = nl80211_parse_connkeys(rdev, |
| 4871 | info->attrs[NL80211_ATTR_KEYS]); |
| 4872 | if (IS_ERR(connkeys)) |
| 4873 | return PTR_ERR(connkeys); |
| 4874 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4875 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4876 | ibss.control_port = |
| 4877 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 4878 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4879 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4880 | if (err) |
| 4881 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4882 | return err; |
| 4883 | } |
| 4884 | |
| 4885 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4886 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4888 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4889 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4890 | if (!rdev->ops->leave_ibss) |
| 4891 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4892 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4894 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4895 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4896 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4897 | } |
| 4898 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4899 | #ifdef CONFIG_NL80211_TESTMODE |
| 4900 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4901 | .name = "testmode", |
| 4902 | }; |
| 4903 | |
| 4904 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4905 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4907 | int err; |
| 4908 | |
| 4909 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4910 | return -EINVAL; |
| 4911 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4912 | err = -EOPNOTSUPP; |
| 4913 | if (rdev->ops->testmode_cmd) { |
| 4914 | rdev->testmode_info = info; |
| 4915 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4916 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4917 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4918 | rdev->testmode_info = NULL; |
| 4919 | } |
| 4920 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4921 | return err; |
| 4922 | } |
| 4923 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4924 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4925 | struct netlink_callback *cb) |
| 4926 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4927 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4928 | int err; |
| 4929 | long phy_idx; |
| 4930 | void *data = NULL; |
| 4931 | int data_len = 0; |
| 4932 | |
| 4933 | if (cb->args[0]) { |
| 4934 | /* |
| 4935 | * 0 is a valid index, but not valid for args[0], |
| 4936 | * so we need to offset by 1. |
| 4937 | */ |
| 4938 | phy_idx = cb->args[0] - 1; |
| 4939 | } else { |
| 4940 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4941 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4942 | nl80211_policy); |
| 4943 | if (err) |
| 4944 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4945 | if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) { |
| 4946 | phy_idx = nla_get_u32( |
| 4947 | nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4948 | } else { |
| 4949 | struct net_device *netdev; |
| 4950 | |
| 4951 | err = get_rdev_dev_by_ifindex(sock_net(skb->sk), |
| 4952 | nl80211_fam.attrbuf, |
| 4953 | &rdev, &netdev); |
| 4954 | if (err) |
| 4955 | return err; |
| 4956 | dev_put(netdev); |
| 4957 | phy_idx = rdev->wiphy_idx; |
| 4958 | cfg80211_unlock_rdev(rdev); |
| 4959 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4960 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4961 | cb->args[1] = |
| 4962 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4963 | } |
| 4964 | |
| 4965 | if (cb->args[1]) { |
| 4966 | data = nla_data((void *)cb->args[1]); |
| 4967 | data_len = nla_len((void *)cb->args[1]); |
| 4968 | } |
| 4969 | |
| 4970 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4971 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4972 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4973 | mutex_unlock(&cfg80211_mutex); |
| 4974 | return -ENOENT; |
| 4975 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4976 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4977 | mutex_unlock(&cfg80211_mutex); |
| 4978 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4979 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4980 | err = -EOPNOTSUPP; |
| 4981 | goto out_err; |
| 4982 | } |
| 4983 | |
| 4984 | while (1) { |
| 4985 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4986 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4987 | NL80211_CMD_TESTMODE); |
| 4988 | struct nlattr *tmdata; |
| 4989 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4990 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4991 | genlmsg_cancel(skb, hdr); |
| 4992 | break; |
| 4993 | } |
| 4994 | |
| 4995 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4996 | if (!tmdata) { |
| 4997 | genlmsg_cancel(skb, hdr); |
| 4998 | break; |
| 4999 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5000 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
| 5001 | data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5002 | nla_nest_end(skb, tmdata); |
| 5003 | |
| 5004 | if (err == -ENOBUFS || err == -ENOENT) { |
| 5005 | genlmsg_cancel(skb, hdr); |
| 5006 | break; |
| 5007 | } else if (err) { |
| 5008 | genlmsg_cancel(skb, hdr); |
| 5009 | goto out_err; |
| 5010 | } |
| 5011 | |
| 5012 | genlmsg_end(skb, hdr); |
| 5013 | } |
| 5014 | |
| 5015 | err = skb->len; |
| 5016 | /* see above */ |
| 5017 | cb->args[0] = phy_idx + 1; |
| 5018 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 5019 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 5020 | return err; |
| 5021 | } |
| 5022 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 5023 | static struct sk_buff * |
| 5024 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 5025 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 5026 | { |
| 5027 | struct sk_buff *skb; |
| 5028 | void *hdr; |
| 5029 | struct nlattr *data; |
| 5030 | |
| 5031 | skb = nlmsg_new(approxlen + 100, gfp); |
| 5032 | if (!skb) |
| 5033 | return NULL; |
| 5034 | |
| 5035 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 5036 | if (!hdr) { |
| 5037 | kfree_skb(skb); |
| 5038 | return NULL; |
| 5039 | } |
| 5040 | |
| 5041 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 5042 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 5043 | |
| 5044 | ((void **)skb->cb)[0] = rdev; |
| 5045 | ((void **)skb->cb)[1] = hdr; |
| 5046 | ((void **)skb->cb)[2] = data; |
| 5047 | |
| 5048 | return skb; |
| 5049 | |
| 5050 | nla_put_failure: |
| 5051 | kfree_skb(skb); |
| 5052 | return NULL; |
| 5053 | } |
| 5054 | |
| 5055 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 5056 | int approxlen) |
| 5057 | { |
| 5058 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5059 | |
| 5060 | if (WARN_ON(!rdev->testmode_info)) |
| 5061 | return NULL; |
| 5062 | |
| 5063 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 5064 | rdev->testmode_info->snd_pid, |
| 5065 | rdev->testmode_info->snd_seq, |
| 5066 | GFP_KERNEL); |
| 5067 | } |
| 5068 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 5069 | |
| 5070 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 5071 | { |
| 5072 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 5073 | void *hdr = ((void **)skb->cb)[1]; |
| 5074 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5075 | |
| 5076 | if (WARN_ON(!rdev->testmode_info)) { |
| 5077 | kfree_skb(skb); |
| 5078 | return -EINVAL; |
| 5079 | } |
| 5080 | |
| 5081 | nla_nest_end(skb, data); |
| 5082 | genlmsg_end(skb, hdr); |
| 5083 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5084 | } |
| 5085 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5086 | |
| 5087 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5088 | int approxlen, gfp_t gfp) |
| 5089 | { |
| 5090 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5091 | |
| 5092 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5093 | } |
| 5094 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5095 | |
| 5096 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5097 | { |
| 5098 | void *hdr = ((void **)skb->cb)[1]; |
| 5099 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5100 | |
| 5101 | nla_nest_end(skb, data); |
| 5102 | genlmsg_end(skb, hdr); |
| 5103 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5104 | } |
| 5105 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5106 | #endif |
| 5107 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5108 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5109 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5110 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5111 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5112 | struct cfg80211_connect_params connect; |
| 5113 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5114 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5115 | int err; |
| 5116 | |
| 5117 | memset(&connect, 0, sizeof(connect)); |
| 5118 | |
| 5119 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5120 | return -EINVAL; |
| 5121 | |
| 5122 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5123 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5124 | return -EINVAL; |
| 5125 | |
| 5126 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5127 | connect.auth_type = |
| 5128 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 5129 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 5130 | return -EINVAL; |
| 5131 | } else |
| 5132 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5133 | |
| 5134 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5135 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5136 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5137 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5138 | if (err) |
| 5139 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5140 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5141 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5142 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5143 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5144 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5145 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5146 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 5147 | connect.bg_scan_period = -1; |
| 5148 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 5149 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 5150 | connect.bg_scan_period = |
| 5151 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 5152 | } |
| 5153 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5154 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5155 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5156 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5157 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5158 | |
| 5159 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5160 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5161 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5162 | } |
| 5163 | |
| 5164 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5165 | connect.channel = |
| 5166 | ieee80211_get_channel(wiphy, |
| 5167 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5168 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5169 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5170 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5171 | } |
| 5172 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5173 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5174 | connkeys = nl80211_parse_connkeys(rdev, |
| 5175 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5176 | if (IS_ERR(connkeys)) |
| 5177 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5178 | } |
| 5179 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5180 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5181 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5182 | |
| 5183 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5184 | memcpy(&connect.ht_capa_mask, |
| 5185 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5186 | sizeof(connect.ht_capa_mask)); |
| 5187 | |
| 5188 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5189 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5190 | return -EINVAL; |
| 5191 | memcpy(&connect.ht_capa, |
| 5192 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5193 | sizeof(connect.ht_capa)); |
| 5194 | } |
| 5195 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5196 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5197 | if (err) |
| 5198 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5199 | return err; |
| 5200 | } |
| 5201 | |
| 5202 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5203 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5204 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5205 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5206 | u16 reason; |
| 5207 | |
| 5208 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5209 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5210 | else |
| 5211 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5212 | |
| 5213 | if (reason == 0) |
| 5214 | return -EINVAL; |
| 5215 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5216 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5217 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5218 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5219 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5220 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5221 | } |
| 5222 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5223 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5224 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5226 | struct net *net; |
| 5227 | int err; |
| 5228 | u32 pid; |
| 5229 | |
| 5230 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5231 | return -EINVAL; |
| 5232 | |
| 5233 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5234 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5235 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5236 | if (IS_ERR(net)) |
| 5237 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5238 | |
| 5239 | err = 0; |
| 5240 | |
| 5241 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5242 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5243 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5244 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5245 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5246 | return err; |
| 5247 | } |
| 5248 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5249 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5250 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5251 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5252 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5253 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5254 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5255 | struct cfg80211_pmksa pmksa; |
| 5256 | |
| 5257 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5258 | |
| 5259 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5260 | return -EINVAL; |
| 5261 | |
| 5262 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5263 | return -EINVAL; |
| 5264 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5265 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5266 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5267 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5268 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5269 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5270 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5271 | |
| 5272 | switch (info->genlhdr->cmd) { |
| 5273 | case NL80211_CMD_SET_PMKSA: |
| 5274 | rdev_ops = rdev->ops->set_pmksa; |
| 5275 | break; |
| 5276 | case NL80211_CMD_DEL_PMKSA: |
| 5277 | rdev_ops = rdev->ops->del_pmksa; |
| 5278 | break; |
| 5279 | default: |
| 5280 | WARN_ON(1); |
| 5281 | break; |
| 5282 | } |
| 5283 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5284 | if (!rdev_ops) |
| 5285 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5286 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5287 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5291 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5292 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5293 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5294 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5295 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5296 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5297 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5298 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5299 | if (!rdev->ops->flush_pmksa) |
| 5300 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5301 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5302 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5303 | } |
| 5304 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5305 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5306 | { |
| 5307 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5308 | struct net_device *dev = info->user_ptr[1]; |
| 5309 | u8 action_code, dialog_token; |
| 5310 | u16 status_code; |
| 5311 | u8 *peer; |
| 5312 | |
| 5313 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5314 | !rdev->ops->tdls_mgmt) |
| 5315 | return -EOPNOTSUPP; |
| 5316 | |
| 5317 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5318 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5319 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5320 | !info->attrs[NL80211_ATTR_IE] || |
| 5321 | !info->attrs[NL80211_ATTR_MAC]) |
| 5322 | return -EINVAL; |
| 5323 | |
| 5324 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5325 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5326 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5327 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5328 | |
| 5329 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5330 | dialog_token, status_code, |
| 5331 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5332 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5333 | } |
| 5334 | |
| 5335 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5336 | { |
| 5337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5338 | struct net_device *dev = info->user_ptr[1]; |
| 5339 | enum nl80211_tdls_operation operation; |
| 5340 | u8 *peer; |
| 5341 | |
| 5342 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5343 | !rdev->ops->tdls_oper) |
| 5344 | return -EOPNOTSUPP; |
| 5345 | |
| 5346 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5347 | !info->attrs[NL80211_ATTR_MAC]) |
| 5348 | return -EINVAL; |
| 5349 | |
| 5350 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5351 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5352 | |
| 5353 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5354 | } |
| 5355 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5356 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5357 | struct genl_info *info) |
| 5358 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5359 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5360 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5361 | struct ieee80211_channel *chan; |
| 5362 | struct sk_buff *msg; |
| 5363 | void *hdr; |
| 5364 | u64 cookie; |
| 5365 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5366 | u32 freq, duration; |
| 5367 | int err; |
| 5368 | |
| 5369 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5370 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5371 | return -EINVAL; |
| 5372 | |
| 5373 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5374 | |
| 5375 | /* |
| 5376 | * We should be on that channel for at least one jiffie, |
| 5377 | * and more than 5 seconds seems excessive. |
| 5378 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5379 | if (!duration || !msecs_to_jiffies(duration) || |
| 5380 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5381 | return -EINVAL; |
| 5382 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5383 | if (!rdev->ops->remain_on_channel || |
| 5384 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5385 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5386 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5387 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5388 | channel_type = nla_get_u32( |
| 5389 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5390 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5391 | channel_type != NL80211_CHAN_HT20 && |
| 5392 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5393 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5394 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5398 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5399 | if (chan == NULL) |
| 5400 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5401 | |
| 5402 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5403 | if (!msg) |
| 5404 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5405 | |
| 5406 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5407 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5408 | |
| 5409 | if (IS_ERR(hdr)) { |
| 5410 | err = PTR_ERR(hdr); |
| 5411 | goto free_msg; |
| 5412 | } |
| 5413 | |
| 5414 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5415 | channel_type, duration, &cookie); |
| 5416 | |
| 5417 | if (err) |
| 5418 | goto free_msg; |
| 5419 | |
| 5420 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5421 | |
| 5422 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5423 | |
| 5424 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5425 | |
| 5426 | nla_put_failure: |
| 5427 | err = -ENOBUFS; |
| 5428 | free_msg: |
| 5429 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5430 | return err; |
| 5431 | } |
| 5432 | |
| 5433 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5434 | struct genl_info *info) |
| 5435 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5437 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5438 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5439 | |
| 5440 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5441 | return -EINVAL; |
| 5442 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5443 | if (!rdev->ops->cancel_remain_on_channel) |
| 5444 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5445 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5446 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5447 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5448 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5449 | } |
| 5450 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5451 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5452 | u8 *rates, u8 rates_len) |
| 5453 | { |
| 5454 | u8 i; |
| 5455 | u32 mask = 0; |
| 5456 | |
| 5457 | for (i = 0; i < rates_len; i++) { |
| 5458 | int rate = (rates[i] & 0x7f) * 5; |
| 5459 | int ridx; |
| 5460 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5461 | struct ieee80211_rate *srate = |
| 5462 | &sband->bitrates[ridx]; |
| 5463 | if (rate == srate->bitrate) { |
| 5464 | mask |= 1 << ridx; |
| 5465 | break; |
| 5466 | } |
| 5467 | } |
| 5468 | if (ridx == sband->n_bitrates) |
| 5469 | return 0; /* rate not found */ |
| 5470 | } |
| 5471 | |
| 5472 | return mask; |
| 5473 | } |
| 5474 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5475 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5476 | u8 *rates, u8 rates_len, |
| 5477 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 5478 | { |
| 5479 | u8 i; |
| 5480 | |
| 5481 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 5482 | |
| 5483 | for (i = 0; i < rates_len; i++) { |
| 5484 | int ridx, rbit; |
| 5485 | |
| 5486 | ridx = rates[i] / 8; |
| 5487 | rbit = BIT(rates[i] % 8); |
| 5488 | |
| 5489 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 5490 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5491 | return false; |
| 5492 | |
| 5493 | /* check availability */ |
| 5494 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 5495 | mcs[ridx] |= rbit; |
| 5496 | else |
| 5497 | return false; |
| 5498 | } |
| 5499 | |
| 5500 | return true; |
| 5501 | } |
| 5502 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5503 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5504 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5505 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5506 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 5507 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5508 | }; |
| 5509 | |
| 5510 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5511 | struct genl_info *info) |
| 5512 | { |
| 5513 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5514 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5515 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5516 | int rem, i; |
| 5517 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5518 | struct nlattr *tx_rates; |
| 5519 | struct ieee80211_supported_band *sband; |
| 5520 | |
| 5521 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5522 | return -EINVAL; |
| 5523 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5524 | if (!rdev->ops->set_bitrate_mask) |
| 5525 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5526 | |
| 5527 | memset(&mask, 0, sizeof(mask)); |
| 5528 | /* Default to all rates enabled */ |
| 5529 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5530 | sband = rdev->wiphy.bands[i]; |
| 5531 | mask.control[i].legacy = |
| 5532 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5533 | if (sband) |
| 5534 | memcpy(mask.control[i].mcs, |
| 5535 | sband->ht_cap.mcs.rx_mask, |
| 5536 | sizeof(mask.control[i].mcs)); |
| 5537 | else |
| 5538 | memset(mask.control[i].mcs, 0, |
| 5539 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | /* |
| 5543 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5544 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5545 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5546 | 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] | 5547 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5548 | { |
| 5549 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5550 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5551 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5552 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5553 | if (sband == NULL) |
| 5554 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5555 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5556 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5557 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5558 | mask.control[band].legacy = rateset_to_mask( |
| 5559 | sband, |
| 5560 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5561 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5562 | } |
| 5563 | if (tb[NL80211_TXRATE_MCS]) { |
| 5564 | if (!ht_rateset_to_mask( |
| 5565 | sband, |
| 5566 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 5567 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 5568 | mask.control[band].mcs)) |
| 5569 | return -EINVAL; |
| 5570 | } |
| 5571 | |
| 5572 | if (mask.control[band].legacy == 0) { |
| 5573 | /* don't allow empty legacy rates if HT |
| 5574 | * is not even supported. */ |
| 5575 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 5576 | return -EINVAL; |
| 5577 | |
| 5578 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5579 | if (mask.control[band].mcs[i]) |
| 5580 | break; |
| 5581 | |
| 5582 | /* legacy and mcs rates may not be both empty */ |
| 5583 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5584 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5588 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5589 | } |
| 5590 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5591 | 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] | 5592 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5593 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5594 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5595 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5596 | |
| 5597 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5598 | return -EINVAL; |
| 5599 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5600 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5601 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5602 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5603 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5604 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5605 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5606 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5607 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5608 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5609 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5610 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5611 | |
| 5612 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5613 | if (!rdev->ops->mgmt_tx) |
| 5614 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5616 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5617 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5618 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5619 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5620 | } |
| 5621 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5622 | 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] | 5623 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5625 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5626 | struct ieee80211_channel *chan; |
| 5627 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5628 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5629 | u32 freq; |
| 5630 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 5631 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5632 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5633 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5634 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5635 | bool offchan, no_cck, dont_wait_for_ack; |
| 5636 | |
| 5637 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5638 | |
| 5639 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5640 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5641 | return -EINVAL; |
| 5642 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5643 | if (!rdev->ops->mgmt_tx) |
| 5644 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5645 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5646 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5647 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5648 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5649 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5650 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5651 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5652 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5653 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5654 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5655 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5656 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5657 | return -EINVAL; |
| 5658 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5659 | } |
| 5660 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5661 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5662 | channel_type = nla_get_u32( |
| 5663 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5664 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5665 | channel_type != NL80211_CHAN_HT20 && |
| 5666 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5667 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5668 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5669 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5670 | } |
| 5671 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5672 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5673 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5674 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 5675 | return -EINVAL; |
| 5676 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5677 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5678 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5679 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5680 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5681 | if (chan == NULL) |
| 5682 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5683 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5684 | if (!dont_wait_for_ack) { |
| 5685 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5686 | if (!msg) |
| 5687 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5688 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5689 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5690 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5691 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5692 | if (IS_ERR(hdr)) { |
| 5693 | err = PTR_ERR(hdr); |
| 5694 | goto free_msg; |
| 5695 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5696 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5697 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5698 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5699 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5700 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5701 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5702 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5703 | if (err) |
| 5704 | goto free_msg; |
| 5705 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5706 | if (msg) { |
| 5707 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5708 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5709 | genlmsg_end(msg, hdr); |
| 5710 | return genlmsg_reply(msg, info); |
| 5711 | } |
| 5712 | |
| 5713 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5714 | |
| 5715 | nla_put_failure: |
| 5716 | err = -ENOBUFS; |
| 5717 | free_msg: |
| 5718 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5719 | return err; |
| 5720 | } |
| 5721 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5722 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5723 | { |
| 5724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5725 | struct net_device *dev = info->user_ptr[1]; |
| 5726 | u64 cookie; |
| 5727 | |
| 5728 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5729 | return -EINVAL; |
| 5730 | |
| 5731 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5732 | return -EOPNOTSUPP; |
| 5733 | |
| 5734 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5735 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5736 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5737 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5738 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5739 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5740 | return -EOPNOTSUPP; |
| 5741 | |
| 5742 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5743 | |
| 5744 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5745 | } |
| 5746 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5747 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5748 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5750 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5751 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5752 | u8 ps_state; |
| 5753 | bool state; |
| 5754 | int err; |
| 5755 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5756 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5757 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5758 | |
| 5759 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5761 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5762 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5763 | |
| 5764 | wdev = dev->ieee80211_ptr; |
| 5765 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5766 | if (!rdev->ops->set_power_mgmt) |
| 5767 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5768 | |
| 5769 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5770 | |
| 5771 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5772 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5773 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5774 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5775 | wdev->ps_timeout); |
| 5776 | if (!err) |
| 5777 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5778 | return err; |
| 5779 | } |
| 5780 | |
| 5781 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5782 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5783 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5784 | enum nl80211_ps_state ps_state; |
| 5785 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5786 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5787 | struct sk_buff *msg; |
| 5788 | void *hdr; |
| 5789 | int err; |
| 5790 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5791 | wdev = dev->ieee80211_ptr; |
| 5792 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5793 | if (!rdev->ops->set_power_mgmt) |
| 5794 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5795 | |
| 5796 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5797 | if (!msg) |
| 5798 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5799 | |
| 5800 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5801 | NL80211_CMD_GET_POWER_SAVE); |
| 5802 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5803 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5804 | goto free_msg; |
| 5805 | } |
| 5806 | |
| 5807 | if (wdev->ps) |
| 5808 | ps_state = NL80211_PS_ENABLED; |
| 5809 | else |
| 5810 | ps_state = NL80211_PS_DISABLED; |
| 5811 | |
| 5812 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5813 | |
| 5814 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5815 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5816 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5817 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5818 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5819 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5820 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5821 | return err; |
| 5822 | } |
| 5823 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5824 | static struct nla_policy |
| 5825 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5826 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5827 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5828 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5829 | }; |
| 5830 | |
| 5831 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5832 | s32 threshold, u32 hysteresis) |
| 5833 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5835 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5836 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5837 | |
| 5838 | if (threshold > 0) |
| 5839 | return -EINVAL; |
| 5840 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5841 | wdev = dev->ieee80211_ptr; |
| 5842 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5843 | if (!rdev->ops->set_cqm_rssi_config) |
| 5844 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5845 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5846 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5847 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5848 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5849 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5850 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5851 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5855 | { |
| 5856 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5857 | struct nlattr *cqm; |
| 5858 | int err; |
| 5859 | |
| 5860 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5861 | if (!cqm) { |
| 5862 | err = -EINVAL; |
| 5863 | goto out; |
| 5864 | } |
| 5865 | |
| 5866 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5867 | nl80211_attr_cqm_policy); |
| 5868 | if (err) |
| 5869 | goto out; |
| 5870 | |
| 5871 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5872 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5873 | s32 threshold; |
| 5874 | u32 hysteresis; |
| 5875 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5876 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5877 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5878 | } else |
| 5879 | err = -EINVAL; |
| 5880 | |
| 5881 | out: |
| 5882 | return err; |
| 5883 | } |
| 5884 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5885 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5886 | { |
| 5887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5888 | struct net_device *dev = info->user_ptr[1]; |
| 5889 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5890 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5891 | int err; |
| 5892 | |
| 5893 | /* start with default */ |
| 5894 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5895 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5896 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5897 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5898 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5899 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5900 | if (err) |
| 5901 | return err; |
| 5902 | } |
| 5903 | |
| 5904 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5905 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5906 | return -EINVAL; |
| 5907 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5908 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5909 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5910 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 5911 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5912 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 5913 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5914 | return -EINVAL; |
| 5915 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5916 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5917 | /* parse additional setup parameters if given */ |
| 5918 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5919 | if (err) |
| 5920 | return err; |
| 5921 | } |
| 5922 | |
| 5923 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5927 | { |
| 5928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5929 | struct net_device *dev = info->user_ptr[1]; |
| 5930 | |
| 5931 | return cfg80211_leave_mesh(rdev, dev); |
| 5932 | } |
| 5933 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5934 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5935 | { |
| 5936 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5937 | struct sk_buff *msg; |
| 5938 | void *hdr; |
| 5939 | |
| 5940 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5941 | return -EOPNOTSUPP; |
| 5942 | |
| 5943 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5944 | if (!msg) |
| 5945 | return -ENOMEM; |
| 5946 | |
| 5947 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5948 | NL80211_CMD_GET_WOWLAN); |
| 5949 | if (!hdr) |
| 5950 | goto nla_put_failure; |
| 5951 | |
| 5952 | if (rdev->wowlan) { |
| 5953 | struct nlattr *nl_wowlan; |
| 5954 | |
| 5955 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5956 | if (!nl_wowlan) |
| 5957 | goto nla_put_failure; |
| 5958 | |
| 5959 | if (rdev->wowlan->any) |
| 5960 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5961 | if (rdev->wowlan->disconnect) |
| 5962 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5963 | if (rdev->wowlan->magic_pkt) |
| 5964 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5965 | if (rdev->wowlan->gtk_rekey_failure) |
| 5966 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5967 | if (rdev->wowlan->eap_identity_req) |
| 5968 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5969 | if (rdev->wowlan->four_way_handshake) |
| 5970 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5971 | if (rdev->wowlan->rfkill_release) |
| 5972 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5973 | if (rdev->wowlan->n_patterns) { |
| 5974 | struct nlattr *nl_pats, *nl_pat; |
| 5975 | int i, pat_len; |
| 5976 | |
| 5977 | nl_pats = nla_nest_start(msg, |
| 5978 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5979 | if (!nl_pats) |
| 5980 | goto nla_put_failure; |
| 5981 | |
| 5982 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5983 | nl_pat = nla_nest_start(msg, i + 1); |
| 5984 | if (!nl_pat) |
| 5985 | goto nla_put_failure; |
| 5986 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5987 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5988 | DIV_ROUND_UP(pat_len, 8), |
| 5989 | rdev->wowlan->patterns[i].mask); |
| 5990 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5991 | pat_len, |
| 5992 | rdev->wowlan->patterns[i].pattern); |
| 5993 | nla_nest_end(msg, nl_pat); |
| 5994 | } |
| 5995 | nla_nest_end(msg, nl_pats); |
| 5996 | } |
| 5997 | |
| 5998 | nla_nest_end(msg, nl_wowlan); |
| 5999 | } |
| 6000 | |
| 6001 | genlmsg_end(msg, hdr); |
| 6002 | return genlmsg_reply(msg, info); |
| 6003 | |
| 6004 | nla_put_failure: |
| 6005 | nlmsg_free(msg); |
| 6006 | return -ENOBUFS; |
| 6007 | } |
| 6008 | |
| 6009 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 6010 | { |
| 6011 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6012 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 6013 | struct cfg80211_wowlan no_triggers = {}; |
| 6014 | struct cfg80211_wowlan new_triggers = {}; |
| 6015 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 6016 | int err, i; |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame^] | 6017 | bool prev_enabled = rdev->wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6018 | |
| 6019 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 6020 | return -EOPNOTSUPP; |
| 6021 | |
| 6022 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 6023 | goto no_triggers; |
| 6024 | |
| 6025 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 6026 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6027 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 6028 | nl80211_wowlan_policy); |
| 6029 | if (err) |
| 6030 | return err; |
| 6031 | |
| 6032 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 6033 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 6034 | return -EINVAL; |
| 6035 | new_triggers.any = true; |
| 6036 | } |
| 6037 | |
| 6038 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 6039 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 6040 | return -EINVAL; |
| 6041 | new_triggers.disconnect = true; |
| 6042 | } |
| 6043 | |
| 6044 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 6045 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 6046 | return -EINVAL; |
| 6047 | new_triggers.magic_pkt = true; |
| 6048 | } |
| 6049 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 6050 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 6051 | return -EINVAL; |
| 6052 | |
| 6053 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 6054 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 6055 | return -EINVAL; |
| 6056 | new_triggers.gtk_rekey_failure = true; |
| 6057 | } |
| 6058 | |
| 6059 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 6060 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 6061 | return -EINVAL; |
| 6062 | new_triggers.eap_identity_req = true; |
| 6063 | } |
| 6064 | |
| 6065 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 6066 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 6067 | return -EINVAL; |
| 6068 | new_triggers.four_way_handshake = true; |
| 6069 | } |
| 6070 | |
| 6071 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 6072 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 6073 | return -EINVAL; |
| 6074 | new_triggers.rfkill_release = true; |
| 6075 | } |
| 6076 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6077 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 6078 | struct nlattr *pat; |
| 6079 | int n_patterns = 0; |
| 6080 | int rem, pat_len, mask_len; |
| 6081 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6082 | |
| 6083 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6084 | rem) |
| 6085 | n_patterns++; |
| 6086 | if (n_patterns > wowlan->n_patterns) |
| 6087 | return -EINVAL; |
| 6088 | |
| 6089 | new_triggers.patterns = kcalloc(n_patterns, |
| 6090 | sizeof(new_triggers.patterns[0]), |
| 6091 | GFP_KERNEL); |
| 6092 | if (!new_triggers.patterns) |
| 6093 | return -ENOMEM; |
| 6094 | |
| 6095 | new_triggers.n_patterns = n_patterns; |
| 6096 | i = 0; |
| 6097 | |
| 6098 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6099 | rem) { |
| 6100 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6101 | nla_data(pat), nla_len(pat), NULL); |
| 6102 | err = -EINVAL; |
| 6103 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6104 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6105 | goto error; |
| 6106 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6107 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6108 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6109 | mask_len) |
| 6110 | goto error; |
| 6111 | if (pat_len > wowlan->pattern_max_len || |
| 6112 | pat_len < wowlan->pattern_min_len) |
| 6113 | goto error; |
| 6114 | |
| 6115 | new_triggers.patterns[i].mask = |
| 6116 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6117 | if (!new_triggers.patterns[i].mask) { |
| 6118 | err = -ENOMEM; |
| 6119 | goto error; |
| 6120 | } |
| 6121 | new_triggers.patterns[i].pattern = |
| 6122 | new_triggers.patterns[i].mask + mask_len; |
| 6123 | memcpy(new_triggers.patterns[i].mask, |
| 6124 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6125 | mask_len); |
| 6126 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6127 | memcpy(new_triggers.patterns[i].pattern, |
| 6128 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6129 | pat_len); |
| 6130 | i++; |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 6135 | struct cfg80211_wowlan *ntrig; |
| 6136 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 6137 | GFP_KERNEL); |
| 6138 | if (!ntrig) { |
| 6139 | err = -ENOMEM; |
| 6140 | goto error; |
| 6141 | } |
| 6142 | cfg80211_rdev_free_wowlan(rdev); |
| 6143 | rdev->wowlan = ntrig; |
| 6144 | } else { |
| 6145 | no_triggers: |
| 6146 | cfg80211_rdev_free_wowlan(rdev); |
| 6147 | rdev->wowlan = NULL; |
| 6148 | } |
| 6149 | |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame^] | 6150 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
| 6151 | rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan); |
| 6152 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6153 | return 0; |
| 6154 | error: |
| 6155 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6156 | kfree(new_triggers.patterns[i].mask); |
| 6157 | kfree(new_triggers.patterns); |
| 6158 | return err; |
| 6159 | } |
| 6160 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6161 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6162 | { |
| 6163 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6164 | struct net_device *dev = info->user_ptr[1]; |
| 6165 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6166 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6167 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6168 | int err; |
| 6169 | |
| 6170 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6171 | return -EINVAL; |
| 6172 | |
| 6173 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6174 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6175 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6176 | nl80211_rekey_policy); |
| 6177 | if (err) |
| 6178 | return err; |
| 6179 | |
| 6180 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6181 | return -ERANGE; |
| 6182 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6183 | return -ERANGE; |
| 6184 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6185 | return -ERANGE; |
| 6186 | |
| 6187 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6188 | NL80211_KEK_LEN); |
| 6189 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6190 | NL80211_KCK_LEN); |
| 6191 | memcpy(rekey_data.replay_ctr, |
| 6192 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6193 | NL80211_REPLAY_CTR_LEN); |
| 6194 | |
| 6195 | wdev_lock(wdev); |
| 6196 | if (!wdev->current_bss) { |
| 6197 | err = -ENOTCONN; |
| 6198 | goto out; |
| 6199 | } |
| 6200 | |
| 6201 | if (!rdev->ops->set_rekey_data) { |
| 6202 | err = -EOPNOTSUPP; |
| 6203 | goto out; |
| 6204 | } |
| 6205 | |
| 6206 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 6207 | out: |
| 6208 | wdev_unlock(wdev); |
| 6209 | return err; |
| 6210 | } |
| 6211 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6212 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6213 | struct genl_info *info) |
| 6214 | { |
| 6215 | struct net_device *dev = info->user_ptr[1]; |
| 6216 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6217 | |
| 6218 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6219 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6220 | return -EINVAL; |
| 6221 | |
| 6222 | if (wdev->ap_unexpected_nlpid) |
| 6223 | return -EBUSY; |
| 6224 | |
| 6225 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 6226 | return 0; |
| 6227 | } |
| 6228 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6229 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6230 | struct genl_info *info) |
| 6231 | { |
| 6232 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6233 | struct net_device *dev = info->user_ptr[1]; |
| 6234 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6235 | struct sk_buff *msg; |
| 6236 | void *hdr; |
| 6237 | const u8 *addr; |
| 6238 | u64 cookie; |
| 6239 | int err; |
| 6240 | |
| 6241 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6242 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6243 | return -EOPNOTSUPP; |
| 6244 | |
| 6245 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6246 | return -EINVAL; |
| 6247 | |
| 6248 | if (!rdev->ops->probe_client) |
| 6249 | return -EOPNOTSUPP; |
| 6250 | |
| 6251 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6252 | if (!msg) |
| 6253 | return -ENOMEM; |
| 6254 | |
| 6255 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6256 | NL80211_CMD_PROBE_CLIENT); |
| 6257 | |
| 6258 | if (IS_ERR(hdr)) { |
| 6259 | err = PTR_ERR(hdr); |
| 6260 | goto free_msg; |
| 6261 | } |
| 6262 | |
| 6263 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6264 | |
| 6265 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6266 | if (err) |
| 6267 | goto free_msg; |
| 6268 | |
| 6269 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6270 | |
| 6271 | genlmsg_end(msg, hdr); |
| 6272 | |
| 6273 | return genlmsg_reply(msg, info); |
| 6274 | |
| 6275 | nla_put_failure: |
| 6276 | err = -ENOBUFS; |
| 6277 | free_msg: |
| 6278 | nlmsg_free(msg); |
| 6279 | return err; |
| 6280 | } |
| 6281 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6282 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6283 | { |
| 6284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6285 | |
| 6286 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6287 | return -EOPNOTSUPP; |
| 6288 | |
| 6289 | if (rdev->ap_beacons_nlpid) |
| 6290 | return -EBUSY; |
| 6291 | |
| 6292 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 6293 | |
| 6294 | return 0; |
| 6295 | } |
| 6296 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6297 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6298 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6299 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6300 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6301 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6302 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6303 | |
| 6304 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6305 | struct genl_info *info) |
| 6306 | { |
| 6307 | struct cfg80211_registered_device *rdev; |
| 6308 | struct net_device *dev; |
| 6309 | int err; |
| 6310 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6311 | |
| 6312 | if (rtnl) |
| 6313 | rtnl_lock(); |
| 6314 | |
| 6315 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 6316 | rdev = cfg80211_get_dev_from_info(info); |
| 6317 | if (IS_ERR(rdev)) { |
| 6318 | if (rtnl) |
| 6319 | rtnl_unlock(); |
| 6320 | return PTR_ERR(rdev); |
| 6321 | } |
| 6322 | info->user_ptr[0] = rdev; |
| 6323 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6324 | err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs, |
| 6325 | &rdev, &dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6326 | if (err) { |
| 6327 | if (rtnl) |
| 6328 | rtnl_unlock(); |
| 6329 | return err; |
| 6330 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6331 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 6332 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 6333 | cfg80211_unlock_rdev(rdev); |
| 6334 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6335 | if (rtnl) |
| 6336 | rtnl_unlock(); |
| 6337 | return -ENETDOWN; |
| 6338 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6339 | info->user_ptr[0] = rdev; |
| 6340 | info->user_ptr[1] = dev; |
| 6341 | } |
| 6342 | |
| 6343 | return 0; |
| 6344 | } |
| 6345 | |
| 6346 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6347 | struct genl_info *info) |
| 6348 | { |
| 6349 | if (info->user_ptr[0]) |
| 6350 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 6351 | if (info->user_ptr[1]) |
| 6352 | dev_put(info->user_ptr[1]); |
| 6353 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6354 | rtnl_unlock(); |
| 6355 | } |
| 6356 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6357 | static struct genl_ops nl80211_ops[] = { |
| 6358 | { |
| 6359 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6360 | .doit = nl80211_get_wiphy, |
| 6361 | .dumpit = nl80211_dump_wiphy, |
| 6362 | .policy = nl80211_policy, |
| 6363 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6364 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6365 | }, |
| 6366 | { |
| 6367 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6368 | .doit = nl80211_set_wiphy, |
| 6369 | .policy = nl80211_policy, |
| 6370 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6371 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6372 | }, |
| 6373 | { |
| 6374 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6375 | .doit = nl80211_get_interface, |
| 6376 | .dumpit = nl80211_dump_interface, |
| 6377 | .policy = nl80211_policy, |
| 6378 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6379 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6380 | }, |
| 6381 | { |
| 6382 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6383 | .doit = nl80211_set_interface, |
| 6384 | .policy = nl80211_policy, |
| 6385 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6386 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6387 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6388 | }, |
| 6389 | { |
| 6390 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6391 | .doit = nl80211_new_interface, |
| 6392 | .policy = nl80211_policy, |
| 6393 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6394 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6395 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6396 | }, |
| 6397 | { |
| 6398 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6399 | .doit = nl80211_del_interface, |
| 6400 | .policy = nl80211_policy, |
| 6401 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6402 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6403 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6404 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6405 | { |
| 6406 | .cmd = NL80211_CMD_GET_KEY, |
| 6407 | .doit = nl80211_get_key, |
| 6408 | .policy = nl80211_policy, |
| 6409 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6410 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6411 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6412 | }, |
| 6413 | { |
| 6414 | .cmd = NL80211_CMD_SET_KEY, |
| 6415 | .doit = nl80211_set_key, |
| 6416 | .policy = nl80211_policy, |
| 6417 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6419 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6420 | }, |
| 6421 | { |
| 6422 | .cmd = NL80211_CMD_NEW_KEY, |
| 6423 | .doit = nl80211_new_key, |
| 6424 | .policy = nl80211_policy, |
| 6425 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6427 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6428 | }, |
| 6429 | { |
| 6430 | .cmd = NL80211_CMD_DEL_KEY, |
| 6431 | .doit = nl80211_del_key, |
| 6432 | .policy = nl80211_policy, |
| 6433 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6435 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6436 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6437 | { |
| 6438 | .cmd = NL80211_CMD_SET_BEACON, |
| 6439 | .policy = nl80211_policy, |
| 6440 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6441 | .doit = nl80211_set_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6442 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6443 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6444 | }, |
| 6445 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6446 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6447 | .policy = nl80211_policy, |
| 6448 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6449 | .doit = nl80211_start_ap, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6450 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6451 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6452 | }, |
| 6453 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6454 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6455 | .policy = nl80211_policy, |
| 6456 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 6457 | .doit = nl80211_stop_ap, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6458 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6459 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6460 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6461 | { |
| 6462 | .cmd = NL80211_CMD_GET_STATION, |
| 6463 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6464 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6465 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6466 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6467 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6468 | }, |
| 6469 | { |
| 6470 | .cmd = NL80211_CMD_SET_STATION, |
| 6471 | .doit = nl80211_set_station, |
| 6472 | .policy = nl80211_policy, |
| 6473 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6474 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6475 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6476 | }, |
| 6477 | { |
| 6478 | .cmd = NL80211_CMD_NEW_STATION, |
| 6479 | .doit = nl80211_new_station, |
| 6480 | .policy = nl80211_policy, |
| 6481 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6482 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6483 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6484 | }, |
| 6485 | { |
| 6486 | .cmd = NL80211_CMD_DEL_STATION, |
| 6487 | .doit = nl80211_del_station, |
| 6488 | .policy = nl80211_policy, |
| 6489 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6490 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6491 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6492 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6493 | { |
| 6494 | .cmd = NL80211_CMD_GET_MPATH, |
| 6495 | .doit = nl80211_get_mpath, |
| 6496 | .dumpit = nl80211_dump_mpath, |
| 6497 | .policy = nl80211_policy, |
| 6498 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6500 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6501 | }, |
| 6502 | { |
| 6503 | .cmd = NL80211_CMD_SET_MPATH, |
| 6504 | .doit = nl80211_set_mpath, |
| 6505 | .policy = nl80211_policy, |
| 6506 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6507 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6508 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6509 | }, |
| 6510 | { |
| 6511 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6512 | .doit = nl80211_new_mpath, |
| 6513 | .policy = nl80211_policy, |
| 6514 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6515 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6516 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6517 | }, |
| 6518 | { |
| 6519 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6520 | .doit = nl80211_del_mpath, |
| 6521 | .policy = nl80211_policy, |
| 6522 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6523 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6524 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6525 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6526 | { |
| 6527 | .cmd = NL80211_CMD_SET_BSS, |
| 6528 | .doit = nl80211_set_bss, |
| 6529 | .policy = nl80211_policy, |
| 6530 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6531 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6532 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6533 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6534 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6535 | .cmd = NL80211_CMD_GET_REG, |
| 6536 | .doit = nl80211_get_reg, |
| 6537 | .policy = nl80211_policy, |
| 6538 | /* can be retrieved by unprivileged users */ |
| 6539 | }, |
| 6540 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6541 | .cmd = NL80211_CMD_SET_REG, |
| 6542 | .doit = nl80211_set_reg, |
| 6543 | .policy = nl80211_policy, |
| 6544 | .flags = GENL_ADMIN_PERM, |
| 6545 | }, |
| 6546 | { |
| 6547 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6548 | .doit = nl80211_req_set_reg, |
| 6549 | .policy = nl80211_policy, |
| 6550 | .flags = GENL_ADMIN_PERM, |
| 6551 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6552 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6553 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6554 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6555 | .policy = nl80211_policy, |
| 6556 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6557 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6558 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6559 | }, |
| 6560 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6561 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6562 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6563 | .policy = nl80211_policy, |
| 6564 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6565 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6566 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6567 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6568 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6569 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6570 | .doit = nl80211_trigger_scan, |
| 6571 | .policy = nl80211_policy, |
| 6572 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6573 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6574 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6575 | }, |
| 6576 | { |
| 6577 | .cmd = NL80211_CMD_GET_SCAN, |
| 6578 | .policy = nl80211_policy, |
| 6579 | .dumpit = nl80211_dump_scan, |
| 6580 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6581 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6582 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6583 | .doit = nl80211_start_sched_scan, |
| 6584 | .policy = nl80211_policy, |
| 6585 | .flags = GENL_ADMIN_PERM, |
| 6586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6587 | NL80211_FLAG_NEED_RTNL, |
| 6588 | }, |
| 6589 | { |
| 6590 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6591 | .doit = nl80211_stop_sched_scan, |
| 6592 | .policy = nl80211_policy, |
| 6593 | .flags = GENL_ADMIN_PERM, |
| 6594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6595 | NL80211_FLAG_NEED_RTNL, |
| 6596 | }, |
| 6597 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6598 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6599 | .doit = nl80211_authenticate, |
| 6600 | .policy = nl80211_policy, |
| 6601 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6603 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6604 | }, |
| 6605 | { |
| 6606 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6607 | .doit = nl80211_associate, |
| 6608 | .policy = nl80211_policy, |
| 6609 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6611 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6612 | }, |
| 6613 | { |
| 6614 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6615 | .doit = nl80211_deauthenticate, |
| 6616 | .policy = nl80211_policy, |
| 6617 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6618 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6619 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6620 | }, |
| 6621 | { |
| 6622 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6623 | .doit = nl80211_disassociate, |
| 6624 | .policy = nl80211_policy, |
| 6625 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6626 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6627 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6628 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6629 | { |
| 6630 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6631 | .doit = nl80211_join_ibss, |
| 6632 | .policy = nl80211_policy, |
| 6633 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6634 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6635 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6636 | }, |
| 6637 | { |
| 6638 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6639 | .doit = nl80211_leave_ibss, |
| 6640 | .policy = nl80211_policy, |
| 6641 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6642 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6643 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6644 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6645 | #ifdef CONFIG_NL80211_TESTMODE |
| 6646 | { |
| 6647 | .cmd = NL80211_CMD_TESTMODE, |
| 6648 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6649 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6650 | .policy = nl80211_policy, |
| 6651 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6652 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6653 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6654 | }, |
| 6655 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6656 | { |
| 6657 | .cmd = NL80211_CMD_CONNECT, |
| 6658 | .doit = nl80211_connect, |
| 6659 | .policy = nl80211_policy, |
| 6660 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6661 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6662 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6663 | }, |
| 6664 | { |
| 6665 | .cmd = NL80211_CMD_DISCONNECT, |
| 6666 | .doit = nl80211_disconnect, |
| 6667 | .policy = nl80211_policy, |
| 6668 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6669 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6670 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6671 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6672 | { |
| 6673 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6674 | .doit = nl80211_wiphy_netns, |
| 6675 | .policy = nl80211_policy, |
| 6676 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6677 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6678 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6679 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6680 | { |
| 6681 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6682 | .policy = nl80211_policy, |
| 6683 | .dumpit = nl80211_dump_survey, |
| 6684 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6685 | { |
| 6686 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6687 | .doit = nl80211_setdel_pmksa, |
| 6688 | .policy = nl80211_policy, |
| 6689 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6690 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6691 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6692 | }, |
| 6693 | { |
| 6694 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6695 | .doit = nl80211_setdel_pmksa, |
| 6696 | .policy = nl80211_policy, |
| 6697 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6698 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6699 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6700 | }, |
| 6701 | { |
| 6702 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6703 | .doit = nl80211_flush_pmksa, |
| 6704 | .policy = nl80211_policy, |
| 6705 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6706 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6707 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6708 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6709 | { |
| 6710 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6711 | .doit = nl80211_remain_on_channel, |
| 6712 | .policy = nl80211_policy, |
| 6713 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6714 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6715 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6716 | }, |
| 6717 | { |
| 6718 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6719 | .doit = nl80211_cancel_remain_on_channel, |
| 6720 | .policy = nl80211_policy, |
| 6721 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6722 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6723 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6724 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6725 | { |
| 6726 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6727 | .doit = nl80211_set_tx_bitrate_mask, |
| 6728 | .policy = nl80211_policy, |
| 6729 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6730 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6731 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6732 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6733 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6734 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6735 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6736 | .policy = nl80211_policy, |
| 6737 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6738 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6739 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6740 | }, |
| 6741 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6742 | .cmd = NL80211_CMD_FRAME, |
| 6743 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6744 | .policy = nl80211_policy, |
| 6745 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6746 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6747 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6748 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6749 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6750 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6751 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6752 | .policy = nl80211_policy, |
| 6753 | .flags = GENL_ADMIN_PERM, |
| 6754 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6755 | NL80211_FLAG_NEED_RTNL, |
| 6756 | }, |
| 6757 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6758 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6759 | .doit = nl80211_set_power_save, |
| 6760 | .policy = nl80211_policy, |
| 6761 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6762 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6763 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6764 | }, |
| 6765 | { |
| 6766 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6767 | .doit = nl80211_get_power_save, |
| 6768 | .policy = nl80211_policy, |
| 6769 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6770 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6771 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6772 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6773 | { |
| 6774 | .cmd = NL80211_CMD_SET_CQM, |
| 6775 | .doit = nl80211_set_cqm, |
| 6776 | .policy = nl80211_policy, |
| 6777 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6778 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6779 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6780 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6781 | { |
| 6782 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6783 | .doit = nl80211_set_channel, |
| 6784 | .policy = nl80211_policy, |
| 6785 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6786 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6787 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6788 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6789 | { |
| 6790 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6791 | .doit = nl80211_set_wds_peer, |
| 6792 | .policy = nl80211_policy, |
| 6793 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6794 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6795 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6796 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6797 | { |
| 6798 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6799 | .doit = nl80211_join_mesh, |
| 6800 | .policy = nl80211_policy, |
| 6801 | .flags = GENL_ADMIN_PERM, |
| 6802 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6803 | NL80211_FLAG_NEED_RTNL, |
| 6804 | }, |
| 6805 | { |
| 6806 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6807 | .doit = nl80211_leave_mesh, |
| 6808 | .policy = nl80211_policy, |
| 6809 | .flags = GENL_ADMIN_PERM, |
| 6810 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6811 | NL80211_FLAG_NEED_RTNL, |
| 6812 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6813 | { |
| 6814 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6815 | .doit = nl80211_get_wowlan, |
| 6816 | .policy = nl80211_policy, |
| 6817 | /* can be retrieved by unprivileged users */ |
| 6818 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6819 | NL80211_FLAG_NEED_RTNL, |
| 6820 | }, |
| 6821 | { |
| 6822 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6823 | .doit = nl80211_set_wowlan, |
| 6824 | .policy = nl80211_policy, |
| 6825 | .flags = GENL_ADMIN_PERM, |
| 6826 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6827 | NL80211_FLAG_NEED_RTNL, |
| 6828 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6829 | { |
| 6830 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6831 | .doit = nl80211_set_rekey_data, |
| 6832 | .policy = nl80211_policy, |
| 6833 | .flags = GENL_ADMIN_PERM, |
| 6834 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6835 | NL80211_FLAG_NEED_RTNL, |
| 6836 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6837 | { |
| 6838 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 6839 | .doit = nl80211_tdls_mgmt, |
| 6840 | .policy = nl80211_policy, |
| 6841 | .flags = GENL_ADMIN_PERM, |
| 6842 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6843 | NL80211_FLAG_NEED_RTNL, |
| 6844 | }, |
| 6845 | { |
| 6846 | .cmd = NL80211_CMD_TDLS_OPER, |
| 6847 | .doit = nl80211_tdls_oper, |
| 6848 | .policy = nl80211_policy, |
| 6849 | .flags = GENL_ADMIN_PERM, |
| 6850 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6851 | NL80211_FLAG_NEED_RTNL, |
| 6852 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6853 | { |
| 6854 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 6855 | .doit = nl80211_register_unexpected_frame, |
| 6856 | .policy = nl80211_policy, |
| 6857 | .flags = GENL_ADMIN_PERM, |
| 6858 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6859 | NL80211_FLAG_NEED_RTNL, |
| 6860 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6861 | { |
| 6862 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 6863 | .doit = nl80211_probe_client, |
| 6864 | .policy = nl80211_policy, |
| 6865 | .flags = GENL_ADMIN_PERM, |
| 6866 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6867 | NL80211_FLAG_NEED_RTNL, |
| 6868 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6869 | { |
| 6870 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 6871 | .doit = nl80211_register_beacons, |
| 6872 | .policy = nl80211_policy, |
| 6873 | .flags = GENL_ADMIN_PERM, |
| 6874 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6875 | NL80211_FLAG_NEED_RTNL, |
| 6876 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 6877 | { |
| 6878 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 6879 | .doit = nl80211_set_noack_map, |
| 6880 | .policy = nl80211_policy, |
| 6881 | .flags = GENL_ADMIN_PERM, |
| 6882 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6883 | NL80211_FLAG_NEED_RTNL, |
| 6884 | }, |
| 6885 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6886 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6887 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6888 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6889 | .name = "mlme", |
| 6890 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6891 | |
| 6892 | /* multicast groups */ |
| 6893 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6894 | .name = "config", |
| 6895 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6896 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6897 | .name = "scan", |
| 6898 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6899 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6900 | .name = "regulatory", |
| 6901 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6902 | |
| 6903 | /* notification functions */ |
| 6904 | |
| 6905 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6906 | { |
| 6907 | struct sk_buff *msg; |
| 6908 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6909 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6910 | if (!msg) |
| 6911 | return; |
| 6912 | |
| 6913 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6914 | nlmsg_free(msg); |
| 6915 | return; |
| 6916 | } |
| 6917 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6918 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6919 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6920 | } |
| 6921 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6922 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6923 | struct cfg80211_registered_device *rdev) |
| 6924 | { |
| 6925 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6926 | struct nlattr *nest; |
| 6927 | int i; |
| 6928 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6929 | ASSERT_RDEV_LOCK(rdev); |
| 6930 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6931 | if (WARN_ON(!req)) |
| 6932 | return 0; |
| 6933 | |
| 6934 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6935 | if (!nest) |
| 6936 | goto nla_put_failure; |
| 6937 | for (i = 0; i < req->n_ssids; i++) |
| 6938 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6939 | nla_nest_end(msg, nest); |
| 6940 | |
| 6941 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6942 | if (!nest) |
| 6943 | goto nla_put_failure; |
| 6944 | for (i = 0; i < req->n_channels; i++) |
| 6945 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6946 | nla_nest_end(msg, nest); |
| 6947 | |
| 6948 | if (req->ie) |
| 6949 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6950 | |
| 6951 | return 0; |
| 6952 | nla_put_failure: |
| 6953 | return -ENOBUFS; |
| 6954 | } |
| 6955 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6956 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6957 | struct cfg80211_registered_device *rdev, |
| 6958 | struct net_device *netdev, |
| 6959 | u32 pid, u32 seq, int flags, |
| 6960 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6961 | { |
| 6962 | void *hdr; |
| 6963 | |
| 6964 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6965 | if (!hdr) |
| 6966 | return -1; |
| 6967 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6968 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6969 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6970 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6971 | /* ignore errors and send incomplete event anyway */ |
| 6972 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6973 | |
| 6974 | return genlmsg_end(msg, hdr); |
| 6975 | |
| 6976 | nla_put_failure: |
| 6977 | genlmsg_cancel(msg, hdr); |
| 6978 | return -EMSGSIZE; |
| 6979 | } |
| 6980 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6981 | static int |
| 6982 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6983 | struct cfg80211_registered_device *rdev, |
| 6984 | struct net_device *netdev, |
| 6985 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6986 | { |
| 6987 | void *hdr; |
| 6988 | |
| 6989 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6990 | if (!hdr) |
| 6991 | return -1; |
| 6992 | |
| 6993 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6994 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6995 | |
| 6996 | return genlmsg_end(msg, hdr); |
| 6997 | |
| 6998 | nla_put_failure: |
| 6999 | genlmsg_cancel(msg, hdr); |
| 7000 | return -EMSGSIZE; |
| 7001 | } |
| 7002 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7003 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 7004 | struct net_device *netdev) |
| 7005 | { |
| 7006 | struct sk_buff *msg; |
| 7007 | |
| 7008 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7009 | if (!msg) |
| 7010 | return; |
| 7011 | |
| 7012 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7013 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 7014 | nlmsg_free(msg); |
| 7015 | return; |
| 7016 | } |
| 7017 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7018 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7019 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7020 | } |
| 7021 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7022 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 7023 | struct net_device *netdev) |
| 7024 | { |
| 7025 | struct sk_buff *msg; |
| 7026 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7027 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7028 | if (!msg) |
| 7029 | return; |
| 7030 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7031 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7032 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7033 | nlmsg_free(msg); |
| 7034 | return; |
| 7035 | } |
| 7036 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7037 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7038 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 7042 | struct net_device *netdev) |
| 7043 | { |
| 7044 | struct sk_buff *msg; |
| 7045 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7046 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7047 | if (!msg) |
| 7048 | return; |
| 7049 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 7050 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7051 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7052 | nlmsg_free(msg); |
| 7053 | return; |
| 7054 | } |
| 7055 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7056 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7057 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7058 | } |
| 7059 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7060 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 7061 | struct net_device *netdev) |
| 7062 | { |
| 7063 | struct sk_buff *msg; |
| 7064 | |
| 7065 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7066 | if (!msg) |
| 7067 | return; |
| 7068 | |
| 7069 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 7070 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 7071 | nlmsg_free(msg); |
| 7072 | return; |
| 7073 | } |
| 7074 | |
| 7075 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7076 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7077 | } |
| 7078 | |
| 7079 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 7080 | struct net_device *netdev, u32 cmd) |
| 7081 | { |
| 7082 | struct sk_buff *msg; |
| 7083 | |
| 7084 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7085 | if (!msg) |
| 7086 | return; |
| 7087 | |
| 7088 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7089 | nlmsg_free(msg); |
| 7090 | return; |
| 7091 | } |
| 7092 | |
| 7093 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7094 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7095 | } |
| 7096 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7097 | /* |
| 7098 | * This can happen on global regulatory changes or device specific settings |
| 7099 | * based on custom world regulatory domains. |
| 7100 | */ |
| 7101 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7102 | { |
| 7103 | struct sk_buff *msg; |
| 7104 | void *hdr; |
| 7105 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7106 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7107 | if (!msg) |
| 7108 | return; |
| 7109 | |
| 7110 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7111 | if (!hdr) { |
| 7112 | nlmsg_free(msg); |
| 7113 | return; |
| 7114 | } |
| 7115 | |
| 7116 | /* Userspace can always count this one always being set */ |
| 7117 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 7118 | |
| 7119 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 7120 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7121 | NL80211_REGDOM_TYPE_WORLD); |
| 7122 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 7123 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7124 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 7125 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7126 | request->intersect) |
| 7127 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7128 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 7129 | else { |
| 7130 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7131 | NL80211_REGDOM_TYPE_COUNTRY); |
| 7132 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 7133 | } |
| 7134 | |
| 7135 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 7136 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 7137 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7138 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7139 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7140 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7141 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7142 | GFP_ATOMIC); |
| 7143 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7144 | |
| 7145 | return; |
| 7146 | |
| 7147 | nla_put_failure: |
| 7148 | genlmsg_cancel(msg, hdr); |
| 7149 | nlmsg_free(msg); |
| 7150 | } |
| 7151 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7152 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7153 | struct net_device *netdev, |
| 7154 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7155 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7156 | { |
| 7157 | struct sk_buff *msg; |
| 7158 | void *hdr; |
| 7159 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7160 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7161 | if (!msg) |
| 7162 | return; |
| 7163 | |
| 7164 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7165 | if (!hdr) { |
| 7166 | nlmsg_free(msg); |
| 7167 | return; |
| 7168 | } |
| 7169 | |
| 7170 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7171 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7172 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7173 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7174 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7175 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7176 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7177 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7178 | return; |
| 7179 | |
| 7180 | nla_put_failure: |
| 7181 | genlmsg_cancel(msg, hdr); |
| 7182 | nlmsg_free(msg); |
| 7183 | } |
| 7184 | |
| 7185 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7186 | struct net_device *netdev, const u8 *buf, |
| 7187 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7188 | { |
| 7189 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7190 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 7194 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7195 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7196 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7197 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7198 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7199 | } |
| 7200 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7201 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7202 | struct net_device *netdev, const u8 *buf, |
| 7203 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7204 | { |
| 7205 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7206 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7207 | } |
| 7208 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7209 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 7210 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7211 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7212 | { |
| 7213 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7214 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7215 | } |
| 7216 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7217 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7218 | struct net_device *netdev, const u8 *buf, |
| 7219 | size_t len, gfp_t gfp) |
| 7220 | { |
| 7221 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7222 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7223 | } |
| 7224 | |
| 7225 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7226 | struct net_device *netdev, const u8 *buf, |
| 7227 | size_t len, gfp_t gfp) |
| 7228 | { |
| 7229 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7230 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7231 | } |
| 7232 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7233 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7234 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7235 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7236 | { |
| 7237 | struct sk_buff *msg; |
| 7238 | void *hdr; |
| 7239 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7240 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7241 | if (!msg) |
| 7242 | return; |
| 7243 | |
| 7244 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7245 | if (!hdr) { |
| 7246 | nlmsg_free(msg); |
| 7247 | return; |
| 7248 | } |
| 7249 | |
| 7250 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7251 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7252 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 7253 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7254 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7255 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7256 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7257 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7258 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7259 | return; |
| 7260 | |
| 7261 | nla_put_failure: |
| 7262 | genlmsg_cancel(msg, hdr); |
| 7263 | nlmsg_free(msg); |
| 7264 | } |
| 7265 | |
| 7266 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7267 | struct net_device *netdev, const u8 *addr, |
| 7268 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7269 | { |
| 7270 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7271 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7272 | } |
| 7273 | |
| 7274 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7275 | struct net_device *netdev, const u8 *addr, |
| 7276 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7277 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7278 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 7279 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7280 | } |
| 7281 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7282 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 7283 | struct net_device *netdev, const u8 *bssid, |
| 7284 | const u8 *req_ie, size_t req_ie_len, |
| 7285 | const u8 *resp_ie, size_t resp_ie_len, |
| 7286 | u16 status, gfp_t gfp) |
| 7287 | { |
| 7288 | struct sk_buff *msg; |
| 7289 | void *hdr; |
| 7290 | |
| 7291 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7292 | if (!msg) |
| 7293 | return; |
| 7294 | |
| 7295 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 7296 | if (!hdr) { |
| 7297 | nlmsg_free(msg); |
| 7298 | return; |
| 7299 | } |
| 7300 | |
| 7301 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7302 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7303 | if (bssid) |
| 7304 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7305 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 7306 | if (req_ie) |
| 7307 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 7308 | if (resp_ie) |
| 7309 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 7310 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7311 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7312 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7313 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7314 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7315 | return; |
| 7316 | |
| 7317 | nla_put_failure: |
| 7318 | genlmsg_cancel(msg, hdr); |
| 7319 | nlmsg_free(msg); |
| 7320 | |
| 7321 | } |
| 7322 | |
| 7323 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 7324 | struct net_device *netdev, const u8 *bssid, |
| 7325 | const u8 *req_ie, size_t req_ie_len, |
| 7326 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 7327 | { |
| 7328 | struct sk_buff *msg; |
| 7329 | void *hdr; |
| 7330 | |
| 7331 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7332 | if (!msg) |
| 7333 | return; |
| 7334 | |
| 7335 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 7336 | if (!hdr) { |
| 7337 | nlmsg_free(msg); |
| 7338 | return; |
| 7339 | } |
| 7340 | |
| 7341 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7342 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7343 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7344 | if (req_ie) |
| 7345 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 7346 | if (resp_ie) |
| 7347 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 7348 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7349 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7350 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7351 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7352 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7353 | return; |
| 7354 | |
| 7355 | nla_put_failure: |
| 7356 | genlmsg_cancel(msg, hdr); |
| 7357 | nlmsg_free(msg); |
| 7358 | |
| 7359 | } |
| 7360 | |
| 7361 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 7362 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7363 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7364 | { |
| 7365 | struct sk_buff *msg; |
| 7366 | void *hdr; |
| 7367 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7368 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7369 | if (!msg) |
| 7370 | return; |
| 7371 | |
| 7372 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7373 | if (!hdr) { |
| 7374 | nlmsg_free(msg); |
| 7375 | return; |
| 7376 | } |
| 7377 | |
| 7378 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7379 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7380 | if (from_ap && reason) |
| 7381 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 7382 | if (from_ap) |
| 7383 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 7384 | if (ie) |
| 7385 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 7386 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7387 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7388 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7389 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7390 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7391 | return; |
| 7392 | |
| 7393 | nla_put_failure: |
| 7394 | genlmsg_cancel(msg, hdr); |
| 7395 | nlmsg_free(msg); |
| 7396 | |
| 7397 | } |
| 7398 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7399 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7400 | struct net_device *netdev, const u8 *bssid, |
| 7401 | gfp_t gfp) |
| 7402 | { |
| 7403 | struct sk_buff *msg; |
| 7404 | void *hdr; |
| 7405 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7406 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7407 | if (!msg) |
| 7408 | return; |
| 7409 | |
| 7410 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7411 | if (!hdr) { |
| 7412 | nlmsg_free(msg); |
| 7413 | return; |
| 7414 | } |
| 7415 | |
| 7416 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7417 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7418 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7419 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7420 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7421 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7422 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7423 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7424 | return; |
| 7425 | |
| 7426 | nla_put_failure: |
| 7427 | genlmsg_cancel(msg, hdr); |
| 7428 | nlmsg_free(msg); |
| 7429 | } |
| 7430 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7431 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7432 | struct net_device *netdev, |
| 7433 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7434 | gfp_t gfp) |
| 7435 | { |
| 7436 | struct sk_buff *msg; |
| 7437 | void *hdr; |
| 7438 | |
| 7439 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7440 | if (!msg) |
| 7441 | return; |
| 7442 | |
| 7443 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7444 | if (!hdr) { |
| 7445 | nlmsg_free(msg); |
| 7446 | return; |
| 7447 | } |
| 7448 | |
| 7449 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7450 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7451 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 7452 | if (ie_len && ie) |
| 7453 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 7454 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7455 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7456 | |
| 7457 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7458 | nl80211_mlme_mcgrp.id, gfp); |
| 7459 | return; |
| 7460 | |
| 7461 | nla_put_failure: |
| 7462 | genlmsg_cancel(msg, hdr); |
| 7463 | nlmsg_free(msg); |
| 7464 | } |
| 7465 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7466 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7467 | struct net_device *netdev, const u8 *addr, |
| 7468 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7469 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7470 | { |
| 7471 | struct sk_buff *msg; |
| 7472 | void *hdr; |
| 7473 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7474 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7475 | if (!msg) |
| 7476 | return; |
| 7477 | |
| 7478 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7479 | if (!hdr) { |
| 7480 | nlmsg_free(msg); |
| 7481 | return; |
| 7482 | } |
| 7483 | |
| 7484 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7485 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7486 | if (addr) |
| 7487 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7488 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 7489 | if (key_id != -1) |
| 7490 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7491 | if (tsc) |
| 7492 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 7493 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7494 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7495 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7496 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7497 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7498 | return; |
| 7499 | |
| 7500 | nla_put_failure: |
| 7501 | genlmsg_cancel(msg, hdr); |
| 7502 | nlmsg_free(msg); |
| 7503 | } |
| 7504 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7505 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7506 | struct ieee80211_channel *channel_before, |
| 7507 | struct ieee80211_channel *channel_after) |
| 7508 | { |
| 7509 | struct sk_buff *msg; |
| 7510 | void *hdr; |
| 7511 | struct nlattr *nl_freq; |
| 7512 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7513 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7514 | if (!msg) |
| 7515 | return; |
| 7516 | |
| 7517 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7518 | if (!hdr) { |
| 7519 | nlmsg_free(msg); |
| 7520 | return; |
| 7521 | } |
| 7522 | |
| 7523 | /* |
| 7524 | * Since we are applying the beacon hint to a wiphy we know its |
| 7525 | * wiphy_idx is valid |
| 7526 | */ |
| 7527 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 7528 | |
| 7529 | /* Before */ |
| 7530 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7531 | if (!nl_freq) |
| 7532 | goto nla_put_failure; |
| 7533 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7534 | goto nla_put_failure; |
| 7535 | nla_nest_end(msg, nl_freq); |
| 7536 | |
| 7537 | /* After */ |
| 7538 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7539 | if (!nl_freq) |
| 7540 | goto nla_put_failure; |
| 7541 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7542 | goto nla_put_failure; |
| 7543 | nla_nest_end(msg, nl_freq); |
| 7544 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7545 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7546 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7547 | rcu_read_lock(); |
| 7548 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7549 | GFP_ATOMIC); |
| 7550 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7551 | |
| 7552 | return; |
| 7553 | |
| 7554 | nla_put_failure: |
| 7555 | genlmsg_cancel(msg, hdr); |
| 7556 | nlmsg_free(msg); |
| 7557 | } |
| 7558 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7559 | static void nl80211_send_remain_on_chan_event( |
| 7560 | int cmd, struct cfg80211_registered_device *rdev, |
| 7561 | struct net_device *netdev, u64 cookie, |
| 7562 | struct ieee80211_channel *chan, |
| 7563 | enum nl80211_channel_type channel_type, |
| 7564 | unsigned int duration, gfp_t gfp) |
| 7565 | { |
| 7566 | struct sk_buff *msg; |
| 7567 | void *hdr; |
| 7568 | |
| 7569 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7570 | if (!msg) |
| 7571 | return; |
| 7572 | |
| 7573 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7574 | if (!hdr) { |
| 7575 | nlmsg_free(msg); |
| 7576 | return; |
| 7577 | } |
| 7578 | |
| 7579 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7580 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7581 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7582 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7583 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7584 | |
| 7585 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7586 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7587 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7588 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7589 | |
| 7590 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7591 | nl80211_mlme_mcgrp.id, gfp); |
| 7592 | return; |
| 7593 | |
| 7594 | nla_put_failure: |
| 7595 | genlmsg_cancel(msg, hdr); |
| 7596 | nlmsg_free(msg); |
| 7597 | } |
| 7598 | |
| 7599 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7600 | struct net_device *netdev, u64 cookie, |
| 7601 | struct ieee80211_channel *chan, |
| 7602 | enum nl80211_channel_type channel_type, |
| 7603 | unsigned int duration, gfp_t gfp) |
| 7604 | { |
| 7605 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7606 | rdev, netdev, cookie, chan, |
| 7607 | channel_type, duration, gfp); |
| 7608 | } |
| 7609 | |
| 7610 | void nl80211_send_remain_on_channel_cancel( |
| 7611 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7612 | u64 cookie, struct ieee80211_channel *chan, |
| 7613 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7614 | { |
| 7615 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7616 | rdev, netdev, cookie, chan, |
| 7617 | channel_type, 0, gfp); |
| 7618 | } |
| 7619 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7620 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7621 | struct net_device *dev, const u8 *mac_addr, |
| 7622 | struct station_info *sinfo, gfp_t gfp) |
| 7623 | { |
| 7624 | struct sk_buff *msg; |
| 7625 | |
| 7626 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7627 | if (!msg) |
| 7628 | return; |
| 7629 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 7630 | if (nl80211_send_station(msg, 0, 0, 0, |
| 7631 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7632 | nlmsg_free(msg); |
| 7633 | return; |
| 7634 | } |
| 7635 | |
| 7636 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7637 | nl80211_mlme_mcgrp.id, gfp); |
| 7638 | } |
| 7639 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7640 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7641 | struct net_device *dev, const u8 *mac_addr, |
| 7642 | gfp_t gfp) |
| 7643 | { |
| 7644 | struct sk_buff *msg; |
| 7645 | void *hdr; |
| 7646 | |
| 7647 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7648 | if (!msg) |
| 7649 | return; |
| 7650 | |
| 7651 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7652 | if (!hdr) { |
| 7653 | nlmsg_free(msg); |
| 7654 | return; |
| 7655 | } |
| 7656 | |
| 7657 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7658 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7659 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7660 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7661 | |
| 7662 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7663 | nl80211_mlme_mcgrp.id, gfp); |
| 7664 | return; |
| 7665 | |
| 7666 | nla_put_failure: |
| 7667 | genlmsg_cancel(msg, hdr); |
| 7668 | nlmsg_free(msg); |
| 7669 | } |
| 7670 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7671 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 7672 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7673 | { |
| 7674 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7675 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7676 | struct sk_buff *msg; |
| 7677 | void *hdr; |
| 7678 | int err; |
| 7679 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 7680 | |
| 7681 | if (!nlpid) |
| 7682 | return false; |
| 7683 | |
| 7684 | msg = nlmsg_new(100, gfp); |
| 7685 | if (!msg) |
| 7686 | return true; |
| 7687 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7688 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7689 | if (!hdr) { |
| 7690 | nlmsg_free(msg); |
| 7691 | return true; |
| 7692 | } |
| 7693 | |
| 7694 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7695 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7696 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7697 | |
| 7698 | err = genlmsg_end(msg, hdr); |
| 7699 | if (err < 0) { |
| 7700 | nlmsg_free(msg); |
| 7701 | return true; |
| 7702 | } |
| 7703 | |
| 7704 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7705 | return true; |
| 7706 | |
| 7707 | nla_put_failure: |
| 7708 | genlmsg_cancel(msg, hdr); |
| 7709 | nlmsg_free(msg); |
| 7710 | return true; |
| 7711 | } |
| 7712 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7713 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 7714 | { |
| 7715 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 7716 | addr, gfp); |
| 7717 | } |
| 7718 | |
| 7719 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 7720 | const u8 *addr, gfp_t gfp) |
| 7721 | { |
| 7722 | return __nl80211_unexpected_frame(dev, |
| 7723 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 7724 | addr, gfp); |
| 7725 | } |
| 7726 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7727 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7728 | struct net_device *netdev, u32 nlpid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 7729 | int freq, int sig_dbm, |
| 7730 | const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7731 | { |
| 7732 | struct sk_buff *msg; |
| 7733 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7734 | |
| 7735 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7736 | if (!msg) |
| 7737 | return -ENOMEM; |
| 7738 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7739 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7740 | if (!hdr) { |
| 7741 | nlmsg_free(msg); |
| 7742 | return -ENOMEM; |
| 7743 | } |
| 7744 | |
| 7745 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7746 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7747 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 7748 | if (sig_dbm) |
| 7749 | NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7750 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7751 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7752 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7753 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7754 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7755 | |
| 7756 | nla_put_failure: |
| 7757 | genlmsg_cancel(msg, hdr); |
| 7758 | nlmsg_free(msg); |
| 7759 | return -ENOBUFS; |
| 7760 | } |
| 7761 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7762 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7763 | struct net_device *netdev, u64 cookie, |
| 7764 | const u8 *buf, size_t len, bool ack, |
| 7765 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7766 | { |
| 7767 | struct sk_buff *msg; |
| 7768 | void *hdr; |
| 7769 | |
| 7770 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7771 | if (!msg) |
| 7772 | return; |
| 7773 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7774 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7775 | if (!hdr) { |
| 7776 | nlmsg_free(msg); |
| 7777 | return; |
| 7778 | } |
| 7779 | |
| 7780 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7781 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7782 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7783 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7784 | if (ack) |
| 7785 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7786 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7787 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7788 | |
| 7789 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7790 | return; |
| 7791 | |
| 7792 | nla_put_failure: |
| 7793 | genlmsg_cancel(msg, hdr); |
| 7794 | nlmsg_free(msg); |
| 7795 | } |
| 7796 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7797 | void |
| 7798 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7799 | struct net_device *netdev, |
| 7800 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7801 | gfp_t gfp) |
| 7802 | { |
| 7803 | struct sk_buff *msg; |
| 7804 | struct nlattr *pinfoattr; |
| 7805 | void *hdr; |
| 7806 | |
| 7807 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7808 | if (!msg) |
| 7809 | return; |
| 7810 | |
| 7811 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7812 | if (!hdr) { |
| 7813 | nlmsg_free(msg); |
| 7814 | return; |
| 7815 | } |
| 7816 | |
| 7817 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7818 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7819 | |
| 7820 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7821 | if (!pinfoattr) |
| 7822 | goto nla_put_failure; |
| 7823 | |
| 7824 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7825 | rssi_event); |
| 7826 | |
| 7827 | nla_nest_end(msg, pinfoattr); |
| 7828 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7829 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7830 | |
| 7831 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7832 | nl80211_mlme_mcgrp.id, gfp); |
| 7833 | return; |
| 7834 | |
| 7835 | nla_put_failure: |
| 7836 | genlmsg_cancel(msg, hdr); |
| 7837 | nlmsg_free(msg); |
| 7838 | } |
| 7839 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7840 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7841 | struct net_device *netdev, const u8 *bssid, |
| 7842 | const u8 *replay_ctr, gfp_t gfp) |
| 7843 | { |
| 7844 | struct sk_buff *msg; |
| 7845 | struct nlattr *rekey_attr; |
| 7846 | void *hdr; |
| 7847 | |
| 7848 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7849 | if (!msg) |
| 7850 | return; |
| 7851 | |
| 7852 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7853 | if (!hdr) { |
| 7854 | nlmsg_free(msg); |
| 7855 | return; |
| 7856 | } |
| 7857 | |
| 7858 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7859 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7860 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7861 | |
| 7862 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7863 | if (!rekey_attr) |
| 7864 | goto nla_put_failure; |
| 7865 | |
| 7866 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7867 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7868 | |
| 7869 | nla_nest_end(msg, rekey_attr); |
| 7870 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7871 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7872 | |
| 7873 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7874 | nl80211_mlme_mcgrp.id, gfp); |
| 7875 | return; |
| 7876 | |
| 7877 | nla_put_failure: |
| 7878 | genlmsg_cancel(msg, hdr); |
| 7879 | nlmsg_free(msg); |
| 7880 | } |
| 7881 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7882 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7883 | struct net_device *netdev, int index, |
| 7884 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7885 | { |
| 7886 | struct sk_buff *msg; |
| 7887 | struct nlattr *attr; |
| 7888 | void *hdr; |
| 7889 | |
| 7890 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7891 | if (!msg) |
| 7892 | return; |
| 7893 | |
| 7894 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7895 | if (!hdr) { |
| 7896 | nlmsg_free(msg); |
| 7897 | return; |
| 7898 | } |
| 7899 | |
| 7900 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7901 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7902 | |
| 7903 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7904 | if (!attr) |
| 7905 | goto nla_put_failure; |
| 7906 | |
| 7907 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7908 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7909 | if (preauth) |
| 7910 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7911 | |
| 7912 | nla_nest_end(msg, attr); |
| 7913 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7914 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7915 | |
| 7916 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7917 | nl80211_mlme_mcgrp.id, gfp); |
| 7918 | return; |
| 7919 | |
| 7920 | nla_put_failure: |
| 7921 | genlmsg_cancel(msg, hdr); |
| 7922 | nlmsg_free(msg); |
| 7923 | } |
| 7924 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7925 | void |
| 7926 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7927 | struct net_device *netdev, const u8 *peer, |
| 7928 | u32 num_packets, gfp_t gfp) |
| 7929 | { |
| 7930 | struct sk_buff *msg; |
| 7931 | struct nlattr *pinfoattr; |
| 7932 | void *hdr; |
| 7933 | |
| 7934 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7935 | if (!msg) |
| 7936 | return; |
| 7937 | |
| 7938 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7939 | if (!hdr) { |
| 7940 | nlmsg_free(msg); |
| 7941 | return; |
| 7942 | } |
| 7943 | |
| 7944 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7945 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7946 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7947 | |
| 7948 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7949 | if (!pinfoattr) |
| 7950 | goto nla_put_failure; |
| 7951 | |
| 7952 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7953 | |
| 7954 | nla_nest_end(msg, pinfoattr); |
| 7955 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7956 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7957 | |
| 7958 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7959 | nl80211_mlme_mcgrp.id, gfp); |
| 7960 | return; |
| 7961 | |
| 7962 | nla_put_failure: |
| 7963 | genlmsg_cancel(msg, hdr); |
| 7964 | nlmsg_free(msg); |
| 7965 | } |
| 7966 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7967 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 7968 | u64 cookie, bool acked, gfp_t gfp) |
| 7969 | { |
| 7970 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7971 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7972 | struct sk_buff *msg; |
| 7973 | void *hdr; |
| 7974 | int err; |
| 7975 | |
| 7976 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7977 | if (!msg) |
| 7978 | return; |
| 7979 | |
| 7980 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 7981 | if (!hdr) { |
| 7982 | nlmsg_free(msg); |
| 7983 | return; |
| 7984 | } |
| 7985 | |
| 7986 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7987 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7988 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7989 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7990 | if (acked) |
| 7991 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7992 | |
| 7993 | err = genlmsg_end(msg, hdr); |
| 7994 | if (err < 0) { |
| 7995 | nlmsg_free(msg); |
| 7996 | return; |
| 7997 | } |
| 7998 | |
| 7999 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 8000 | nl80211_mlme_mcgrp.id, gfp); |
| 8001 | return; |
| 8002 | |
| 8003 | nla_put_failure: |
| 8004 | genlmsg_cancel(msg, hdr); |
| 8005 | nlmsg_free(msg); |
| 8006 | } |
| 8007 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 8008 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8009 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 8010 | const u8 *frame, size_t len, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8011 | int freq, int sig_dbm, gfp_t gfp) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8012 | { |
| 8013 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 8014 | struct sk_buff *msg; |
| 8015 | void *hdr; |
| 8016 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 8017 | |
| 8018 | if (!nlpid) |
| 8019 | return; |
| 8020 | |
| 8021 | msg = nlmsg_new(len + 100, gfp); |
| 8022 | if (!msg) |
| 8023 | return; |
| 8024 | |
| 8025 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 8026 | if (!hdr) { |
| 8027 | nlmsg_free(msg); |
| 8028 | return; |
| 8029 | } |
| 8030 | |
| 8031 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 8032 | if (freq) |
| 8033 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 8034 | if (sig_dbm) |
| 8035 | NLA_PUT_U32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8036 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame); |
| 8037 | |
| 8038 | genlmsg_end(msg, hdr); |
| 8039 | |
| 8040 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 8041 | return; |
| 8042 | |
| 8043 | nla_put_failure: |
| 8044 | genlmsg_cancel(msg, hdr); |
| 8045 | nlmsg_free(msg); |
| 8046 | } |
| 8047 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 8048 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8049 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 8050 | unsigned long state, |
| 8051 | void *_notify) |
| 8052 | { |
| 8053 | struct netlink_notify *notify = _notify; |
| 8054 | struct cfg80211_registered_device *rdev; |
| 8055 | struct wireless_dev *wdev; |
| 8056 | |
| 8057 | if (state != NETLINK_URELEASE) |
| 8058 | return NOTIFY_DONE; |
| 8059 | |
| 8060 | rcu_read_lock(); |
| 8061 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8062 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8063 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8064 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 8065 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 8066 | rdev->ap_beacons_nlpid = 0; |
| 8067 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8068 | |
| 8069 | rcu_read_unlock(); |
| 8070 | |
| 8071 | return NOTIFY_DONE; |
| 8072 | } |
| 8073 | |
| 8074 | static struct notifier_block nl80211_netlink_notifier = { |
| 8075 | .notifier_call = nl80211_netlink_notify, |
| 8076 | }; |
| 8077 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8078 | /* initialisation/exit functions */ |
| 8079 | |
| 8080 | int nl80211_init(void) |
| 8081 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8082 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8083 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 8084 | err = genl_register_family_with_ops(&nl80211_fam, |
| 8085 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8086 | if (err) |
| 8087 | return err; |
| 8088 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8089 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 8090 | if (err) |
| 8091 | goto err_out; |
| 8092 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8093 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 8094 | if (err) |
| 8095 | goto err_out; |
| 8096 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8097 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 8098 | if (err) |
| 8099 | goto err_out; |
| 8100 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8101 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 8102 | if (err) |
| 8103 | goto err_out; |
| 8104 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8105 | #ifdef CONFIG_NL80211_TESTMODE |
| 8106 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 8107 | if (err) |
| 8108 | goto err_out; |
| 8109 | #endif |
| 8110 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8111 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 8112 | if (err) |
| 8113 | goto err_out; |
| 8114 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8115 | return 0; |
| 8116 | err_out: |
| 8117 | genl_unregister_family(&nl80211_fam); |
| 8118 | return err; |
| 8119 | } |
| 8120 | |
| 8121 | void nl80211_exit(void) |
| 8122 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8123 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8124 | genl_unregister_family(&nl80211_fam); |
| 8125 | } |