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 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 207 | }; |
| 208 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 209 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 210 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 211 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 212 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 213 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 214 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 215 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 216 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 217 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 218 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 219 | }; |
| 220 | |
| 221 | /* policy for the key default flags */ |
| 222 | static const struct nla_policy |
| 223 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 224 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 225 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 226 | }; |
| 227 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 228 | /* policy for WoWLAN attributes */ |
| 229 | static const struct nla_policy |
| 230 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 231 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 232 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 233 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 234 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 235 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 236 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 237 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 238 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 239 | }; |
| 240 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 241 | /* policy for GTK rekey offload attributes */ |
| 242 | static const struct nla_policy |
| 243 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 244 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 245 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 246 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 247 | }; |
| 248 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 249 | static const struct nla_policy |
| 250 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 251 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 252 | .len = IEEE80211_MAX_SSID_LEN }, |
| 253 | }; |
| 254 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 255 | /* ifidx get helper */ |
| 256 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 257 | { |
| 258 | int res; |
| 259 | |
| 260 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 261 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 262 | nl80211_policy); |
| 263 | if (res) |
| 264 | return res; |
| 265 | |
| 266 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 267 | return -EINVAL; |
| 268 | |
| 269 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 270 | if (!res) |
| 271 | return -EINVAL; |
| 272 | return res; |
| 273 | } |
| 274 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 275 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 276 | struct netlink_callback *cb, |
| 277 | struct cfg80211_registered_device **rdev, |
| 278 | struct net_device **dev) |
| 279 | { |
| 280 | int ifidx = cb->args[0]; |
| 281 | int err; |
| 282 | |
| 283 | if (!ifidx) |
| 284 | ifidx = nl80211_get_ifidx(cb); |
| 285 | if (ifidx < 0) |
| 286 | return ifidx; |
| 287 | |
| 288 | cb->args[0] = ifidx; |
| 289 | |
| 290 | rtnl_lock(); |
| 291 | |
| 292 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 293 | if (!*dev) { |
| 294 | err = -ENODEV; |
| 295 | goto out_rtnl; |
| 296 | } |
| 297 | |
| 298 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 299 | if (IS_ERR(*rdev)) { |
| 300 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 301 | goto out_rtnl; |
| 302 | } |
| 303 | |
| 304 | return 0; |
| 305 | out_rtnl: |
| 306 | rtnl_unlock(); |
| 307 | return err; |
| 308 | } |
| 309 | |
| 310 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 311 | { |
| 312 | cfg80211_unlock_rdev(rdev); |
| 313 | rtnl_unlock(); |
| 314 | } |
| 315 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 316 | /* IE validation */ |
| 317 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 318 | { |
| 319 | const u8 *pos; |
| 320 | int len; |
| 321 | |
| 322 | if (!attr) |
| 323 | return true; |
| 324 | |
| 325 | pos = nla_data(attr); |
| 326 | len = nla_len(attr); |
| 327 | |
| 328 | while (len) { |
| 329 | u8 elemlen; |
| 330 | |
| 331 | if (len < 2) |
| 332 | return false; |
| 333 | len -= 2; |
| 334 | |
| 335 | elemlen = pos[1]; |
| 336 | if (elemlen > len) |
| 337 | return false; |
| 338 | |
| 339 | len -= elemlen; |
| 340 | pos += 2 + elemlen; |
| 341 | } |
| 342 | |
| 343 | return true; |
| 344 | } |
| 345 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 346 | /* message building helper */ |
| 347 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 348 | int flags, u8 cmd) |
| 349 | { |
| 350 | /* since there is no private header just add the generic one */ |
| 351 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 352 | } |
| 353 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 354 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 355 | struct ieee80211_channel *chan) |
| 356 | { |
| 357 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 358 | chan->center_freq); |
| 359 | |
| 360 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 361 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 362 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 363 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 364 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 365 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 366 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 367 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 368 | |
| 369 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 370 | DBM_TO_MBM(chan->max_power)); |
| 371 | |
| 372 | return 0; |
| 373 | |
| 374 | nla_put_failure: |
| 375 | return -ENOBUFS; |
| 376 | } |
| 377 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 378 | /* netlink command implementations */ |
| 379 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 380 | struct key_parse { |
| 381 | struct key_params p; |
| 382 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 383 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 384 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 385 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 389 | { |
| 390 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 391 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 392 | nl80211_key_policy); |
| 393 | if (err) |
| 394 | return err; |
| 395 | |
| 396 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 397 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 398 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 399 | if (k->def) { |
| 400 | k->def_uni = true; |
| 401 | k->def_multi = true; |
| 402 | } |
| 403 | if (k->defmgmt) |
| 404 | k->def_multi = true; |
| 405 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 406 | if (tb[NL80211_KEY_IDX]) |
| 407 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 408 | |
| 409 | if (tb[NL80211_KEY_DATA]) { |
| 410 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 411 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 412 | } |
| 413 | |
| 414 | if (tb[NL80211_KEY_SEQ]) { |
| 415 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 416 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 417 | } |
| 418 | |
| 419 | if (tb[NL80211_KEY_CIPHER]) |
| 420 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 421 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 422 | if (tb[NL80211_KEY_TYPE]) { |
| 423 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 424 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 425 | return -EINVAL; |
| 426 | } |
| 427 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 428 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 429 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 430 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 431 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 432 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 433 | if (err) |
| 434 | return err; |
| 435 | |
| 436 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 437 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 438 | } |
| 439 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 444 | { |
| 445 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 446 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 447 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 448 | } |
| 449 | |
| 450 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 451 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 452 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 453 | } |
| 454 | |
| 455 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 456 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 457 | |
| 458 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 459 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 460 | |
| 461 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 462 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 463 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 464 | if (k->def) { |
| 465 | k->def_uni = true; |
| 466 | k->def_multi = true; |
| 467 | } |
| 468 | if (k->defmgmt) |
| 469 | k->def_multi = true; |
| 470 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 471 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 472 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 473 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 474 | return -EINVAL; |
| 475 | } |
| 476 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 477 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 478 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 479 | int err = nla_parse_nested( |
| 480 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 481 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 482 | nl80211_key_default_policy); |
| 483 | if (err) |
| 484 | return err; |
| 485 | |
| 486 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 487 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 488 | } |
| 489 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 494 | { |
| 495 | int err; |
| 496 | |
| 497 | memset(k, 0, sizeof(*k)); |
| 498 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 499 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 500 | |
| 501 | if (info->attrs[NL80211_ATTR_KEY]) |
| 502 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 503 | else |
| 504 | err = nl80211_parse_key_old(info, k); |
| 505 | |
| 506 | if (err) |
| 507 | return err; |
| 508 | |
| 509 | if (k->def && k->defmgmt) |
| 510 | return -EINVAL; |
| 511 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 512 | if (k->defmgmt) { |
| 513 | if (k->def_uni || !k->def_multi) |
| 514 | return -EINVAL; |
| 515 | } |
| 516 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 517 | if (k->idx != -1) { |
| 518 | if (k->defmgmt) { |
| 519 | if (k->idx < 4 || k->idx > 5) |
| 520 | return -EINVAL; |
| 521 | } else if (k->def) { |
| 522 | if (k->idx < 0 || k->idx > 3) |
| 523 | return -EINVAL; |
| 524 | } else { |
| 525 | if (k->idx < 0 || k->idx > 5) |
| 526 | return -EINVAL; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 533 | static struct cfg80211_cached_keys * |
| 534 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 535 | struct nlattr *keys) |
| 536 | { |
| 537 | struct key_parse parse; |
| 538 | struct nlattr *key; |
| 539 | struct cfg80211_cached_keys *result; |
| 540 | int rem, err, def = 0; |
| 541 | |
| 542 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 543 | if (!result) |
| 544 | return ERR_PTR(-ENOMEM); |
| 545 | |
| 546 | result->def = -1; |
| 547 | result->defmgmt = -1; |
| 548 | |
| 549 | nla_for_each_nested(key, keys, rem) { |
| 550 | memset(&parse, 0, sizeof(parse)); |
| 551 | parse.idx = -1; |
| 552 | |
| 553 | err = nl80211_parse_key_new(key, &parse); |
| 554 | if (err) |
| 555 | goto error; |
| 556 | err = -EINVAL; |
| 557 | if (!parse.p.key) |
| 558 | goto error; |
| 559 | if (parse.idx < 0 || parse.idx > 4) |
| 560 | goto error; |
| 561 | if (parse.def) { |
| 562 | if (def) |
| 563 | goto error; |
| 564 | def = 1; |
| 565 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 566 | if (!parse.def_uni || !parse.def_multi) |
| 567 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 568 | } else if (parse.defmgmt) |
| 569 | goto error; |
| 570 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 571 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 572 | if (err) |
| 573 | goto error; |
| 574 | result->params[parse.idx].cipher = parse.p.cipher; |
| 575 | result->params[parse.idx].key_len = parse.p.key_len; |
| 576 | result->params[parse.idx].key = result->data[parse.idx]; |
| 577 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 578 | } |
| 579 | |
| 580 | return result; |
| 581 | error: |
| 582 | kfree(result); |
| 583 | return ERR_PTR(err); |
| 584 | } |
| 585 | |
| 586 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 587 | { |
| 588 | ASSERT_WDEV_LOCK(wdev); |
| 589 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 590 | switch (wdev->iftype) { |
| 591 | case NL80211_IFTYPE_AP: |
| 592 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 593 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 594 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 595 | break; |
| 596 | case NL80211_IFTYPE_ADHOC: |
| 597 | if (!wdev->current_bss) |
| 598 | return -ENOLINK; |
| 599 | break; |
| 600 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 601 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 602 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 603 | return -ENOLINK; |
| 604 | break; |
| 605 | default: |
| 606 | return -EINVAL; |
| 607 | } |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 612 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 613 | { |
| 614 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 615 | int i; |
| 616 | |
| 617 | if (!nl_modes) |
| 618 | goto nla_put_failure; |
| 619 | |
| 620 | i = 0; |
| 621 | while (ifmodes) { |
| 622 | if (ifmodes & 1) |
| 623 | NLA_PUT_FLAG(msg, i); |
| 624 | ifmodes >>= 1; |
| 625 | i++; |
| 626 | } |
| 627 | |
| 628 | nla_nest_end(msg, nl_modes); |
| 629 | return 0; |
| 630 | |
| 631 | nla_put_failure: |
| 632 | return -ENOBUFS; |
| 633 | } |
| 634 | |
| 635 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 636 | struct sk_buff *msg) |
| 637 | { |
| 638 | struct nlattr *nl_combis; |
| 639 | int i, j; |
| 640 | |
| 641 | nl_combis = nla_nest_start(msg, |
| 642 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 643 | if (!nl_combis) |
| 644 | goto nla_put_failure; |
| 645 | |
| 646 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 647 | const struct ieee80211_iface_combination *c; |
| 648 | struct nlattr *nl_combi, *nl_limits; |
| 649 | |
| 650 | c = &wiphy->iface_combinations[i]; |
| 651 | |
| 652 | nl_combi = nla_nest_start(msg, i + 1); |
| 653 | if (!nl_combi) |
| 654 | goto nla_put_failure; |
| 655 | |
| 656 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 657 | if (!nl_limits) |
| 658 | goto nla_put_failure; |
| 659 | |
| 660 | for (j = 0; j < c->n_limits; j++) { |
| 661 | struct nlattr *nl_limit; |
| 662 | |
| 663 | nl_limit = nla_nest_start(msg, j + 1); |
| 664 | if (!nl_limit) |
| 665 | goto nla_put_failure; |
| 666 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 667 | c->limits[j].max); |
| 668 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 669 | c->limits[j].types)) |
| 670 | goto nla_put_failure; |
| 671 | nla_nest_end(msg, nl_limit); |
| 672 | } |
| 673 | |
| 674 | nla_nest_end(msg, nl_limits); |
| 675 | |
| 676 | if (c->beacon_int_infra_match) |
| 677 | NLA_PUT_FLAG(msg, |
| 678 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 679 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 680 | c->num_different_channels); |
| 681 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 682 | c->max_interfaces); |
| 683 | |
| 684 | nla_nest_end(msg, nl_combi); |
| 685 | } |
| 686 | |
| 687 | nla_nest_end(msg, nl_combis); |
| 688 | |
| 689 | return 0; |
| 690 | nla_put_failure: |
| 691 | return -ENOBUFS; |
| 692 | } |
| 693 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 694 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 695 | struct cfg80211_registered_device *dev) |
| 696 | { |
| 697 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 698 | struct nlattr *nl_bands, *nl_band; |
| 699 | struct nlattr *nl_freqs, *nl_freq; |
| 700 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 701 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 702 | enum ieee80211_band band; |
| 703 | struct ieee80211_channel *chan; |
| 704 | struct ieee80211_rate *rate; |
| 705 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 706 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 707 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 708 | |
| 709 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 710 | if (!hdr) |
| 711 | return -1; |
| 712 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 713 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 714 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 715 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 716 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 717 | cfg80211_rdev_list_generation); |
| 718 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 719 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 720 | dev->wiphy.retry_short); |
| 721 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 722 | dev->wiphy.retry_long); |
| 723 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 724 | dev->wiphy.frag_threshold); |
| 725 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 726 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 727 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 728 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 729 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 730 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 731 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 732 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 733 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 734 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 735 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 736 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 737 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 738 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 739 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 740 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 741 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 742 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 743 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 744 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 745 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 746 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 747 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 748 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) |
| 749 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT); |
| 750 | if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) |
| 751 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 752 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 753 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 754 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 755 | dev->wiphy.cipher_suites); |
| 756 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 757 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 758 | dev->wiphy.max_num_pmkids); |
| 759 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 760 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 761 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 762 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 763 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 764 | dev->wiphy.available_antennas_tx); |
| 765 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 766 | dev->wiphy.available_antennas_rx); |
| 767 | |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 768 | if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) |
| 769 | NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 770 | dev->wiphy.probe_resp_offload); |
| 771 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 772 | if ((dev->wiphy.available_antennas_tx || |
| 773 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 774 | u32 tx_ant = 0, rx_ant = 0; |
| 775 | int res; |
| 776 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 777 | if (!res) { |
| 778 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 779 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 780 | } |
| 781 | } |
| 782 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 783 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 784 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 785 | goto nla_put_failure; |
| 786 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 787 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 788 | if (!nl_bands) |
| 789 | goto nla_put_failure; |
| 790 | |
| 791 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 792 | if (!dev->wiphy.bands[band]) |
| 793 | continue; |
| 794 | |
| 795 | nl_band = nla_nest_start(msg, band); |
| 796 | if (!nl_band) |
| 797 | goto nla_put_failure; |
| 798 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 799 | /* add HT info */ |
| 800 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 801 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 802 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 803 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 804 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 805 | dev->wiphy.bands[band]->ht_cap.cap); |
| 806 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 807 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 808 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 809 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 810 | } |
| 811 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 812 | /* add frequencies */ |
| 813 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 814 | if (!nl_freqs) |
| 815 | goto nla_put_failure; |
| 816 | |
| 817 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 818 | nl_freq = nla_nest_start(msg, i); |
| 819 | if (!nl_freq) |
| 820 | goto nla_put_failure; |
| 821 | |
| 822 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 823 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 824 | if (nl80211_msg_put_channel(msg, chan)) |
| 825 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 826 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 827 | nla_nest_end(msg, nl_freq); |
| 828 | } |
| 829 | |
| 830 | nla_nest_end(msg, nl_freqs); |
| 831 | |
| 832 | /* add bitrates */ |
| 833 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 834 | if (!nl_rates) |
| 835 | goto nla_put_failure; |
| 836 | |
| 837 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 838 | nl_rate = nla_nest_start(msg, i); |
| 839 | if (!nl_rate) |
| 840 | goto nla_put_failure; |
| 841 | |
| 842 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 843 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 844 | rate->bitrate); |
| 845 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 846 | NLA_PUT_FLAG(msg, |
| 847 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 848 | |
| 849 | nla_nest_end(msg, nl_rate); |
| 850 | } |
| 851 | |
| 852 | nla_nest_end(msg, nl_rates); |
| 853 | |
| 854 | nla_nest_end(msg, nl_band); |
| 855 | } |
| 856 | nla_nest_end(msg, nl_bands); |
| 857 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 858 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 859 | if (!nl_cmds) |
| 860 | goto nla_put_failure; |
| 861 | |
| 862 | i = 0; |
| 863 | #define CMD(op, n) \ |
| 864 | do { \ |
| 865 | if (dev->ops->op) { \ |
| 866 | i++; \ |
| 867 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 868 | } \ |
| 869 | } while (0) |
| 870 | |
| 871 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 872 | CMD(change_virtual_intf, SET_INTERFACE); |
| 873 | CMD(add_key, NEW_KEY); |
| 874 | CMD(add_beacon, NEW_BEACON); |
| 875 | CMD(add_station, NEW_STATION); |
| 876 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 877 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 878 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 879 | CMD(auth, AUTHENTICATE); |
| 880 | CMD(assoc, ASSOCIATE); |
| 881 | CMD(deauth, DEAUTHENTICATE); |
| 882 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 883 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 884 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 885 | CMD(set_pmksa, SET_PMKSA); |
| 886 | CMD(del_pmksa, DEL_PMKSA); |
| 887 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 888 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 889 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 890 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 891 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 892 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 893 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 894 | i++; |
| 895 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 896 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 897 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 898 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 899 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 900 | CMD(tdls_mgmt, TDLS_MGMT); |
| 901 | CMD(tdls_oper, TDLS_OPER); |
| 902 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 903 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 904 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 905 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 906 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 907 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 908 | i++; |
| 909 | NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS); |
| 910 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 911 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 912 | #ifdef CONFIG_NL80211_TESTMODE |
| 913 | CMD(testmode_cmd, TESTMODE); |
| 914 | #endif |
| 915 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 916 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 917 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 918 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 919 | i++; |
| 920 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 921 | } |
| 922 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 923 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 924 | i++; |
| 925 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 926 | } |
| 927 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 928 | nla_nest_end(msg, nl_cmds); |
| 929 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 930 | if (dev->ops->remain_on_channel && |
| 931 | dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 932 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 933 | dev->wiphy.max_remain_on_channel_duration); |
| 934 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 935 | if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 936 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 937 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 938 | if (mgmt_stypes) { |
| 939 | u16 stypes; |
| 940 | struct nlattr *nl_ftypes, *nl_ifs; |
| 941 | enum nl80211_iftype ift; |
| 942 | |
| 943 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 944 | if (!nl_ifs) |
| 945 | goto nla_put_failure; |
| 946 | |
| 947 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 948 | nl_ftypes = nla_nest_start(msg, ift); |
| 949 | if (!nl_ftypes) |
| 950 | goto nla_put_failure; |
| 951 | i = 0; |
| 952 | stypes = mgmt_stypes[ift].tx; |
| 953 | while (stypes) { |
| 954 | if (stypes & 1) |
| 955 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 956 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 957 | stypes >>= 1; |
| 958 | i++; |
| 959 | } |
| 960 | nla_nest_end(msg, nl_ftypes); |
| 961 | } |
| 962 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 963 | nla_nest_end(msg, nl_ifs); |
| 964 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 965 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 966 | if (!nl_ifs) |
| 967 | goto nla_put_failure; |
| 968 | |
| 969 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 970 | nl_ftypes = nla_nest_start(msg, ift); |
| 971 | if (!nl_ftypes) |
| 972 | goto nla_put_failure; |
| 973 | i = 0; |
| 974 | stypes = mgmt_stypes[ift].rx; |
| 975 | while (stypes) { |
| 976 | if (stypes & 1) |
| 977 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 978 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 979 | stypes >>= 1; |
| 980 | i++; |
| 981 | } |
| 982 | nla_nest_end(msg, nl_ftypes); |
| 983 | } |
| 984 | nla_nest_end(msg, nl_ifs); |
| 985 | } |
| 986 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 987 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 988 | struct nlattr *nl_wowlan; |
| 989 | |
| 990 | nl_wowlan = nla_nest_start(msg, |
| 991 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 992 | if (!nl_wowlan) |
| 993 | goto nla_put_failure; |
| 994 | |
| 995 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 996 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 997 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 998 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 999 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 1000 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 1001 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 1002 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 1003 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 1004 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 1005 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 1006 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 1007 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 1008 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 1009 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 1010 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1011 | if (dev->wiphy.wowlan.n_patterns) { |
| 1012 | struct nl80211_wowlan_pattern_support pat = { |
| 1013 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1014 | .min_pattern_len = |
| 1015 | dev->wiphy.wowlan.pattern_min_len, |
| 1016 | .max_pattern_len = |
| 1017 | dev->wiphy.wowlan.pattern_max_len, |
| 1018 | }; |
| 1019 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1020 | sizeof(pat), &pat); |
| 1021 | } |
| 1022 | |
| 1023 | nla_nest_end(msg, nl_wowlan); |
| 1024 | } |
| 1025 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1026 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1027 | dev->wiphy.software_iftypes)) |
| 1028 | goto nla_put_failure; |
| 1029 | |
| 1030 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1031 | goto nla_put_failure; |
| 1032 | |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1033 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) |
| 1034 | NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1035 | dev->wiphy.ap_sme_capa); |
| 1036 | |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1037 | NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features); |
| 1038 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1039 | if (dev->wiphy.ht_capa_mod_mask) |
| 1040 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1041 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1042 | dev->wiphy.ht_capa_mod_mask); |
| 1043 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1044 | return genlmsg_end(msg, hdr); |
| 1045 | |
| 1046 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1047 | genlmsg_cancel(msg, hdr); |
| 1048 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1052 | { |
| 1053 | int idx = 0; |
| 1054 | int start = cb->args[0]; |
| 1055 | struct cfg80211_registered_device *dev; |
| 1056 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1057 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1058 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1059 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1060 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1061 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1062 | continue; |
| 1063 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1064 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1065 | dev) < 0) { |
| 1066 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1067 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1068 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1069 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1070 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1071 | |
| 1072 | cb->args[0] = idx; |
| 1073 | |
| 1074 | return skb->len; |
| 1075 | } |
| 1076 | |
| 1077 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1078 | { |
| 1079 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1080 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1081 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1082 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1083 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1084 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1085 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1086 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1087 | nlmsg_free(msg); |
| 1088 | return -ENOBUFS; |
| 1089 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1090 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1091 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1092 | } |
| 1093 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1094 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1095 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1096 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1097 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1098 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1099 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1100 | }; |
| 1101 | |
| 1102 | static int parse_txq_params(struct nlattr *tb[], |
| 1103 | struct ieee80211_txq_params *txq_params) |
| 1104 | { |
| 1105 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1106 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1107 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1108 | return -EINVAL; |
| 1109 | |
| 1110 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1111 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1112 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1113 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1114 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1119 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1120 | { |
| 1121 | /* |
| 1122 | * You can only set the channel explicitly for AP, mesh |
| 1123 | * and WDS type interfaces; all others have their channel |
| 1124 | * managed via their respective "establish a connection" |
| 1125 | * command (connect, join, ...) |
| 1126 | * |
| 1127 | * Monitors are special as they are normally slaved to |
| 1128 | * whatever else is going on, so they behave as though |
| 1129 | * you tried setting the wiphy channel itself. |
| 1130 | */ |
| 1131 | return !wdev || |
| 1132 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1133 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1134 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1135 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1136 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1140 | struct wireless_dev *wdev, |
| 1141 | struct genl_info *info) |
| 1142 | { |
| 1143 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1144 | u32 freq; |
| 1145 | int result; |
| 1146 | |
| 1147 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1148 | return -EINVAL; |
| 1149 | |
| 1150 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1151 | return -EOPNOTSUPP; |
| 1152 | |
| 1153 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1154 | channel_type = nla_get_u32(info->attrs[ |
| 1155 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1156 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1157 | channel_type != NL80211_CHAN_HT20 && |
| 1158 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1159 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1160 | return -EINVAL; |
| 1161 | } |
| 1162 | |
| 1163 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1164 | |
| 1165 | mutex_lock(&rdev->devlist_mtx); |
| 1166 | if (wdev) { |
| 1167 | wdev_lock(wdev); |
| 1168 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1169 | wdev_unlock(wdev); |
| 1170 | } else { |
| 1171 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1172 | } |
| 1173 | mutex_unlock(&rdev->devlist_mtx); |
| 1174 | |
| 1175 | return result; |
| 1176 | } |
| 1177 | |
| 1178 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1179 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1181 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1182 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1183 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1186 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1187 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1189 | struct net_device *dev = info->user_ptr[1]; |
| 1190 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1191 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1192 | |
| 1193 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1194 | return -EINVAL; |
| 1195 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1196 | if (netif_running(dev)) |
| 1197 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1198 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1199 | if (!rdev->ops->set_wds_peer) |
| 1200 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1201 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1202 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1203 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1204 | |
| 1205 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1206 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1210 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1211 | { |
| 1212 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1213 | struct net_device *netdev = NULL; |
| 1214 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1215 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1216 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1217 | u32 changed; |
| 1218 | u8 retry_short = 0, retry_long = 0; |
| 1219 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1220 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1221 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1222 | /* |
| 1223 | * Try to find the wiphy and netdev. Normally this |
| 1224 | * function shouldn't need the netdev, but this is |
| 1225 | * done for backward compatibility -- previously |
| 1226 | * setting the channel was done per wiphy, but now |
| 1227 | * it is per netdev. Previous userland like hostapd |
| 1228 | * also passed a netdev to set_wiphy, so that it is |
| 1229 | * possible to let that go to the right netdev! |
| 1230 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1231 | mutex_lock(&cfg80211_mutex); |
| 1232 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1233 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1234 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1235 | |
| 1236 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1237 | if (netdev && netdev->ieee80211_ptr) { |
| 1238 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1239 | mutex_lock(&rdev->mtx); |
| 1240 | } else |
| 1241 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1242 | } |
| 1243 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1244 | if (!netdev) { |
| 1245 | rdev = __cfg80211_rdev_from_info(info); |
| 1246 | if (IS_ERR(rdev)) { |
| 1247 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1248 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1249 | } |
| 1250 | wdev = NULL; |
| 1251 | netdev = NULL; |
| 1252 | result = 0; |
| 1253 | |
| 1254 | mutex_lock(&rdev->mtx); |
| 1255 | } else if (netif_running(netdev) && |
| 1256 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1257 | wdev = netdev->ieee80211_ptr; |
| 1258 | else |
| 1259 | wdev = NULL; |
| 1260 | |
| 1261 | /* |
| 1262 | * end workaround code, by now the rdev is available |
| 1263 | * and locked, and wdev may or may not be NULL. |
| 1264 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1265 | |
| 1266 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1267 | result = cfg80211_dev_rename( |
| 1268 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1269 | |
| 1270 | mutex_unlock(&cfg80211_mutex); |
| 1271 | |
| 1272 | if (result) |
| 1273 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1274 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1275 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1276 | struct ieee80211_txq_params txq_params; |
| 1277 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1278 | |
| 1279 | if (!rdev->ops->set_txq_params) { |
| 1280 | result = -EOPNOTSUPP; |
| 1281 | goto bad_res; |
| 1282 | } |
| 1283 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1284 | if (!netdev) { |
| 1285 | result = -EINVAL; |
| 1286 | goto bad_res; |
| 1287 | } |
| 1288 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1289 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1290 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1291 | result = -EINVAL; |
| 1292 | goto bad_res; |
| 1293 | } |
| 1294 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1295 | nla_for_each_nested(nl_txq_params, |
| 1296 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1297 | rem_txq_params) { |
| 1298 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1299 | nla_data(nl_txq_params), |
| 1300 | nla_len(nl_txq_params), |
| 1301 | txq_params_policy); |
| 1302 | result = parse_txq_params(tb, &txq_params); |
| 1303 | if (result) |
| 1304 | goto bad_res; |
| 1305 | |
| 1306 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1307 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1308 | &txq_params); |
| 1309 | if (result) |
| 1310 | goto bad_res; |
| 1311 | } |
| 1312 | } |
| 1313 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1314 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1315 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1316 | if (result) |
| 1317 | goto bad_res; |
| 1318 | } |
| 1319 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1320 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1321 | enum nl80211_tx_power_setting type; |
| 1322 | int idx, mbm = 0; |
| 1323 | |
| 1324 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1325 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1326 | goto bad_res; |
| 1327 | } |
| 1328 | |
| 1329 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1330 | type = nla_get_u32(info->attrs[idx]); |
| 1331 | |
| 1332 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1333 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1334 | result = -EINVAL; |
| 1335 | goto bad_res; |
| 1336 | } |
| 1337 | |
| 1338 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1339 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1340 | mbm = nla_get_u32(info->attrs[idx]); |
| 1341 | } |
| 1342 | |
| 1343 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1344 | if (result) |
| 1345 | goto bad_res; |
| 1346 | } |
| 1347 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1348 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1349 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1350 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1351 | if ((!rdev->wiphy.available_antennas_tx && |
| 1352 | !rdev->wiphy.available_antennas_rx) || |
| 1353 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1354 | result = -EOPNOTSUPP; |
| 1355 | goto bad_res; |
| 1356 | } |
| 1357 | |
| 1358 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1359 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1360 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1361 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1362 | * available antenna masks, except for the "all" mask */ |
| 1363 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1364 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1365 | result = -EINVAL; |
| 1366 | goto bad_res; |
| 1367 | } |
| 1368 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1369 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1370 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1371 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1372 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1373 | if (result) |
| 1374 | goto bad_res; |
| 1375 | } |
| 1376 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1377 | changed = 0; |
| 1378 | |
| 1379 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1380 | retry_short = nla_get_u8( |
| 1381 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1382 | if (retry_short == 0) { |
| 1383 | result = -EINVAL; |
| 1384 | goto bad_res; |
| 1385 | } |
| 1386 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1387 | } |
| 1388 | |
| 1389 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1390 | retry_long = nla_get_u8( |
| 1391 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1392 | if (retry_long == 0) { |
| 1393 | result = -EINVAL; |
| 1394 | goto bad_res; |
| 1395 | } |
| 1396 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1397 | } |
| 1398 | |
| 1399 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1400 | frag_threshold = nla_get_u32( |
| 1401 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1402 | if (frag_threshold < 256) { |
| 1403 | result = -EINVAL; |
| 1404 | goto bad_res; |
| 1405 | } |
| 1406 | if (frag_threshold != (u32) -1) { |
| 1407 | /* |
| 1408 | * Fragments (apart from the last one) are required to |
| 1409 | * have even length. Make the fragmentation code |
| 1410 | * simpler by stripping LSB should someone try to use |
| 1411 | * odd threshold value. |
| 1412 | */ |
| 1413 | frag_threshold &= ~0x1; |
| 1414 | } |
| 1415 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1416 | } |
| 1417 | |
| 1418 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1419 | rts_threshold = nla_get_u32( |
| 1420 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1421 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1422 | } |
| 1423 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1424 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1425 | coverage_class = nla_get_u8( |
| 1426 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1427 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1428 | } |
| 1429 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1430 | if (changed) { |
| 1431 | u8 old_retry_short, old_retry_long; |
| 1432 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1433 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1434 | |
| 1435 | if (!rdev->ops->set_wiphy_params) { |
| 1436 | result = -EOPNOTSUPP; |
| 1437 | goto bad_res; |
| 1438 | } |
| 1439 | |
| 1440 | old_retry_short = rdev->wiphy.retry_short; |
| 1441 | old_retry_long = rdev->wiphy.retry_long; |
| 1442 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1443 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1444 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1445 | |
| 1446 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1447 | rdev->wiphy.retry_short = retry_short; |
| 1448 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1449 | rdev->wiphy.retry_long = retry_long; |
| 1450 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1451 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1452 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1453 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1454 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1455 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1456 | |
| 1457 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1458 | if (result) { |
| 1459 | rdev->wiphy.retry_short = old_retry_short; |
| 1460 | rdev->wiphy.retry_long = old_retry_long; |
| 1461 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1462 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1463 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1464 | } |
| 1465 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1466 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1467 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1468 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1469 | if (netdev) |
| 1470 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1471 | return result; |
| 1472 | } |
| 1473 | |
| 1474 | |
| 1475 | 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] | 1476 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1477 | struct net_device *dev) |
| 1478 | { |
| 1479 | void *hdr; |
| 1480 | |
| 1481 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1482 | if (!hdr) |
| 1483 | return -1; |
| 1484 | |
| 1485 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1486 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1487 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1488 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1489 | |
| 1490 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1491 | rdev->devlist_generation ^ |
| 1492 | (cfg80211_rdev_list_generation << 2)); |
| 1493 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1494 | return genlmsg_end(msg, hdr); |
| 1495 | |
| 1496 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1497 | genlmsg_cancel(msg, hdr); |
| 1498 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1502 | { |
| 1503 | int wp_idx = 0; |
| 1504 | int if_idx = 0; |
| 1505 | int wp_start = cb->args[0]; |
| 1506 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1507 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1508 | struct wireless_dev *wdev; |
| 1509 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1510 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1511 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1512 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1513 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1514 | if (wp_idx < wp_start) { |
| 1515 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1516 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1517 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1518 | if_idx = 0; |
| 1519 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1520 | mutex_lock(&rdev->devlist_mtx); |
| 1521 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1522 | if (if_idx < if_start) { |
| 1523 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1524 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1525 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1526 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1527 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1528 | rdev, wdev->netdev) < 0) { |
| 1529 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1530 | goto out; |
| 1531 | } |
| 1532 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1533 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1534 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1535 | |
| 1536 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1537 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1538 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1539 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1540 | |
| 1541 | cb->args[0] = wp_idx; |
| 1542 | cb->args[1] = if_idx; |
| 1543 | |
| 1544 | return skb->len; |
| 1545 | } |
| 1546 | |
| 1547 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1548 | { |
| 1549 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1550 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1551 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1552 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1553 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1554 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1555 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1556 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1557 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1558 | dev, netdev) < 0) { |
| 1559 | nlmsg_free(msg); |
| 1560 | return -ENOBUFS; |
| 1561 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1562 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1563 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1566 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1567 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1568 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1569 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1570 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1571 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1572 | }; |
| 1573 | |
| 1574 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1575 | { |
| 1576 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1577 | int flag; |
| 1578 | |
| 1579 | *mntrflags = 0; |
| 1580 | |
| 1581 | if (!nla) |
| 1582 | return -EINVAL; |
| 1583 | |
| 1584 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1585 | nla, mntr_flags_policy)) |
| 1586 | return -EINVAL; |
| 1587 | |
| 1588 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1589 | if (flags[flag]) |
| 1590 | *mntrflags |= (1<<flag); |
| 1591 | |
| 1592 | return 0; |
| 1593 | } |
| 1594 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1595 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1596 | struct net_device *netdev, u8 use_4addr, |
| 1597 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1598 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1599 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1600 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1601 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1602 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1603 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1604 | |
| 1605 | switch (iftype) { |
| 1606 | case NL80211_IFTYPE_AP_VLAN: |
| 1607 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1608 | return 0; |
| 1609 | break; |
| 1610 | case NL80211_IFTYPE_STATION: |
| 1611 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1612 | return 0; |
| 1613 | break; |
| 1614 | default: |
| 1615 | break; |
| 1616 | } |
| 1617 | |
| 1618 | return -EOPNOTSUPP; |
| 1619 | } |
| 1620 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1621 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1622 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1623 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1624 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1625 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1626 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1627 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1628 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1629 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1630 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1631 | memset(¶ms, 0, sizeof(params)); |
| 1632 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1633 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1634 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1635 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1636 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1637 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1638 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1639 | if (ntype > NL80211_IFTYPE_MAX) |
| 1640 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1641 | } |
| 1642 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1643 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1644 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1645 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1646 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1647 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1648 | if (netif_running(dev)) |
| 1649 | return -EBUSY; |
| 1650 | |
| 1651 | wdev_lock(wdev); |
| 1652 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1653 | IEEE80211_MAX_MESH_ID_LEN); |
| 1654 | wdev->mesh_id_up_len = |
| 1655 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1656 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1657 | wdev->mesh_id_up_len); |
| 1658 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1659 | } |
| 1660 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1661 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1662 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1663 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1664 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1665 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1666 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1667 | } else { |
| 1668 | params.use_4addr = -1; |
| 1669 | } |
| 1670 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1671 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1672 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1673 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1674 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1675 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1676 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1677 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1678 | |
| 1679 | flags = &_flags; |
| 1680 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1681 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1682 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1683 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1684 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1685 | else |
| 1686 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1687 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1688 | if (!err && params.use_4addr != -1) |
| 1689 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1690 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1691 | return err; |
| 1692 | } |
| 1693 | |
| 1694 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1695 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1697 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1698 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1699 | int err; |
| 1700 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1701 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1702 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1703 | memset(¶ms, 0, sizeof(params)); |
| 1704 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1705 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1706 | return -EINVAL; |
| 1707 | |
| 1708 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1709 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1710 | if (type > NL80211_IFTYPE_MAX) |
| 1711 | return -EINVAL; |
| 1712 | } |
| 1713 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1714 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1715 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1716 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1717 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1718 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1719 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1720 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1721 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1722 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1723 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1724 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1725 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1726 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1727 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1728 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1729 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1730 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1731 | if (IS_ERR(dev)) |
| 1732 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1733 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1734 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1735 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1736 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1737 | |
| 1738 | wdev_lock(wdev); |
| 1739 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1740 | IEEE80211_MAX_MESH_ID_LEN); |
| 1741 | wdev->mesh_id_up_len = |
| 1742 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1743 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1744 | wdev->mesh_id_up_len); |
| 1745 | wdev_unlock(wdev); |
| 1746 | } |
| 1747 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1748 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1752 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1753 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1754 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1755 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1756 | if (!rdev->ops->del_virtual_intf) |
| 1757 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1758 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1759 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1760 | } |
| 1761 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1762 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 1763 | { |
| 1764 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1765 | struct net_device *dev = info->user_ptr[1]; |
| 1766 | u16 noack_map; |
| 1767 | |
| 1768 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 1769 | return -EINVAL; |
| 1770 | |
| 1771 | if (!rdev->ops->set_noack_map) |
| 1772 | return -EOPNOTSUPP; |
| 1773 | |
| 1774 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 1775 | |
| 1776 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 1777 | } |
| 1778 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1779 | struct get_key_cookie { |
| 1780 | struct sk_buff *msg; |
| 1781 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1782 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1783 | }; |
| 1784 | |
| 1785 | static void get_key_callback(void *c, struct key_params *params) |
| 1786 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1787 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1788 | struct get_key_cookie *cookie = c; |
| 1789 | |
| 1790 | if (params->key) |
| 1791 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1792 | params->key_len, params->key); |
| 1793 | |
| 1794 | if (params->seq) |
| 1795 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1796 | params->seq_len, params->seq); |
| 1797 | |
| 1798 | if (params->cipher) |
| 1799 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1800 | params->cipher); |
| 1801 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1802 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1803 | if (!key) |
| 1804 | goto nla_put_failure; |
| 1805 | |
| 1806 | if (params->key) |
| 1807 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1808 | params->key_len, params->key); |
| 1809 | |
| 1810 | if (params->seq) |
| 1811 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1812 | params->seq_len, params->seq); |
| 1813 | |
| 1814 | if (params->cipher) |
| 1815 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1816 | params->cipher); |
| 1817 | |
| 1818 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1819 | |
| 1820 | nla_nest_end(cookie->msg, key); |
| 1821 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1822 | return; |
| 1823 | nla_put_failure: |
| 1824 | cookie->error = 1; |
| 1825 | } |
| 1826 | |
| 1827 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1828 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1830 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1831 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1832 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1833 | const u8 *mac_addr = NULL; |
| 1834 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1835 | struct get_key_cookie cookie = { |
| 1836 | .error = 0, |
| 1837 | }; |
| 1838 | void *hdr; |
| 1839 | struct sk_buff *msg; |
| 1840 | |
| 1841 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1842 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1843 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1844 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1845 | return -EINVAL; |
| 1846 | |
| 1847 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1848 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1849 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1850 | pairwise = !!mac_addr; |
| 1851 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1852 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1853 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1854 | return -EINVAL; |
| 1855 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1856 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1857 | return -EINVAL; |
| 1858 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1859 | } |
| 1860 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1861 | if (!rdev->ops->get_key) |
| 1862 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1863 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1864 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1865 | if (!msg) |
| 1866 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1867 | |
| 1868 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1869 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1870 | if (IS_ERR(hdr)) |
| 1871 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1872 | |
| 1873 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1874 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1875 | |
| 1876 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1877 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1878 | if (mac_addr) |
| 1879 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1880 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1881 | if (pairwise && mac_addr && |
| 1882 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1883 | return -ENOENT; |
| 1884 | |
| 1885 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1886 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1887 | |
| 1888 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1889 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1890 | |
| 1891 | if (cookie.error) |
| 1892 | goto nla_put_failure; |
| 1893 | |
| 1894 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1895 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1896 | |
| 1897 | nla_put_failure: |
| 1898 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1899 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1900 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1901 | return err; |
| 1902 | } |
| 1903 | |
| 1904 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1905 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1907 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1908 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1909 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1910 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1911 | err = nl80211_parse_key(info, &key); |
| 1912 | if (err) |
| 1913 | return err; |
| 1914 | |
| 1915 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1916 | return -EINVAL; |
| 1917 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1918 | /* only support setting default key */ |
| 1919 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1920 | return -EINVAL; |
| 1921 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1922 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1923 | |
| 1924 | if (key.def) { |
| 1925 | if (!rdev->ops->set_default_key) { |
| 1926 | err = -EOPNOTSUPP; |
| 1927 | goto out; |
| 1928 | } |
| 1929 | |
| 1930 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1931 | if (err) |
| 1932 | goto out; |
| 1933 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1934 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1935 | key.def_uni, key.def_multi); |
| 1936 | |
| 1937 | if (err) |
| 1938 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1939 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1940 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1941 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1942 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1943 | } else { |
| 1944 | if (key.def_uni || !key.def_multi) { |
| 1945 | err = -EINVAL; |
| 1946 | goto out; |
| 1947 | } |
| 1948 | |
| 1949 | if (!rdev->ops->set_default_mgmt_key) { |
| 1950 | err = -EOPNOTSUPP; |
| 1951 | goto out; |
| 1952 | } |
| 1953 | |
| 1954 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1955 | if (err) |
| 1956 | goto out; |
| 1957 | |
| 1958 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1959 | dev, key.idx); |
| 1960 | if (err) |
| 1961 | goto out; |
| 1962 | |
| 1963 | #ifdef CONFIG_CFG80211_WEXT |
| 1964 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1965 | #endif |
| 1966 | } |
| 1967 | |
| 1968 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1969 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1970 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1971 | return err; |
| 1972 | } |
| 1973 | |
| 1974 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1975 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1977 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1978 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1979 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1980 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1981 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1982 | err = nl80211_parse_key(info, &key); |
| 1983 | if (err) |
| 1984 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1985 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1986 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1987 | return -EINVAL; |
| 1988 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1989 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1990 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1991 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1992 | if (key.type == -1) { |
| 1993 | if (mac_addr) |
| 1994 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1995 | else |
| 1996 | key.type = NL80211_KEYTYPE_GROUP; |
| 1997 | } |
| 1998 | |
| 1999 | /* for now */ |
| 2000 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2001 | key.type != NL80211_KEYTYPE_GROUP) |
| 2002 | return -EINVAL; |
| 2003 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2004 | if (!rdev->ops->add_key) |
| 2005 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2006 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2007 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2008 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2009 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2010 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2011 | |
| 2012 | wdev_lock(dev->ieee80211_ptr); |
| 2013 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2014 | if (!err) |
| 2015 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2016 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2017 | mac_addr, &key.p); |
| 2018 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2019 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2020 | return err; |
| 2021 | } |
| 2022 | |
| 2023 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2024 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2025 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2026 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2027 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2028 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2029 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2030 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2031 | err = nl80211_parse_key(info, &key); |
| 2032 | if (err) |
| 2033 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2034 | |
| 2035 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2036 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2037 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2038 | if (key.type == -1) { |
| 2039 | if (mac_addr) |
| 2040 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2041 | else |
| 2042 | key.type = NL80211_KEYTYPE_GROUP; |
| 2043 | } |
| 2044 | |
| 2045 | /* for now */ |
| 2046 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2047 | key.type != NL80211_KEYTYPE_GROUP) |
| 2048 | return -EINVAL; |
| 2049 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2050 | if (!rdev->ops->del_key) |
| 2051 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2052 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2053 | wdev_lock(dev->ieee80211_ptr); |
| 2054 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2055 | |
| 2056 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2057 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2058 | err = -ENOENT; |
| 2059 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2060 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2061 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2062 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2063 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2064 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2065 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2066 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2067 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2068 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2069 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2070 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2071 | } |
| 2072 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2073 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2074 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2075 | return err; |
| 2076 | } |
| 2077 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2078 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2079 | { |
| 2080 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 2081 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2082 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2083 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2084 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2085 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2086 | int haveinfo = 0, err; |
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 | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2094 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2095 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2096 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2097 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2098 | memset(¶ms, 0, sizeof(params)); |
| 2099 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2100 | switch (info->genlhdr->cmd) { |
| 2101 | case NL80211_CMD_NEW_BEACON: |
| 2102 | /* these are required for NEW_BEACON */ |
| 2103 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2104 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2105 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2106 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2107 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2108 | params.interval = |
| 2109 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2110 | params.dtim_period = |
| 2111 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2112 | |
| 2113 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2114 | if (err) |
| 2115 | return err; |
| 2116 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2117 | /* |
| 2118 | * In theory, some of these attributes could be required for |
| 2119 | * NEW_BEACON, but since they were not used when the command was |
| 2120 | * originally added, keep them optional for old user space |
| 2121 | * programs to work with drivers that do not need the additional |
| 2122 | * information. |
| 2123 | */ |
| 2124 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2125 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2126 | params.ssid_len = |
| 2127 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2128 | if (params.ssid_len == 0 || |
| 2129 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2130 | return -EINVAL; |
| 2131 | } |
| 2132 | |
| 2133 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2134 | params.hidden_ssid = nla_get_u32( |
| 2135 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2136 | if (params.hidden_ssid != |
| 2137 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2138 | params.hidden_ssid != |
| 2139 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2140 | params.hidden_ssid != |
| 2141 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2142 | return -EINVAL; |
| 2143 | } |
| 2144 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2145 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2146 | |
| 2147 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2148 | params.auth_type = nla_get_u32( |
| 2149 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2150 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2151 | return -EINVAL; |
| 2152 | } else |
| 2153 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2154 | |
| 2155 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2156 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2157 | if (err) |
| 2158 | return err; |
| 2159 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2160 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2161 | break; |
| 2162 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2163 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2164 | break; |
| 2165 | default: |
| 2166 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2167 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2168 | } |
| 2169 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2170 | if (!call) |
| 2171 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2172 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2173 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2174 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2175 | params.head_len = |
| 2176 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2177 | haveinfo = 1; |
| 2178 | } |
| 2179 | |
| 2180 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2181 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2182 | params.tail_len = |
| 2183 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2184 | haveinfo = 1; |
| 2185 | } |
| 2186 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2187 | if (!haveinfo) |
| 2188 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2189 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2190 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2191 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2192 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2193 | } |
| 2194 | |
| 2195 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2196 | params.proberesp_ies = |
| 2197 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2198 | params.proberesp_ies_len = |
| 2199 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2200 | } |
| 2201 | |
| 2202 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2203 | params.assocresp_ies = |
| 2204 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2205 | params.assocresp_ies_len = |
| 2206 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2207 | } |
| 2208 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2209 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
| 2210 | params.probe_resp = |
| 2211 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2212 | params.probe_resp_len = |
| 2213 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2214 | } |
| 2215 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2216 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2217 | if (!err && params.interval) |
| 2218 | wdev->beacon_interval = params.interval; |
| 2219 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2223 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2224 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2225 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2226 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2227 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2228 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2229 | if (!rdev->ops->del_beacon) |
| 2230 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2231 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2232 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2233 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2234 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2235 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2236 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2237 | if (!err) |
| 2238 | wdev->beacon_interval = 0; |
| 2239 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2240 | } |
| 2241 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2242 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2243 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2244 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2245 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2246 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2247 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 2248 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2249 | }; |
| 2250 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2251 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2252 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2253 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2254 | { |
| 2255 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2256 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2257 | int flag; |
| 2258 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2259 | /* |
| 2260 | * Try parsing the new attribute first so userspace |
| 2261 | * can specify both for older kernels. |
| 2262 | */ |
| 2263 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2264 | if (nla) { |
| 2265 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2266 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2267 | sta_flags = nla_data(nla); |
| 2268 | params->sta_flags_mask = sta_flags->mask; |
| 2269 | params->sta_flags_set = sta_flags->set; |
| 2270 | if ((params->sta_flags_mask | |
| 2271 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2272 | return -EINVAL; |
| 2273 | return 0; |
| 2274 | } |
| 2275 | |
| 2276 | /* if present, parse the old attribute */ |
| 2277 | |
| 2278 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2279 | if (!nla) |
| 2280 | return 0; |
| 2281 | |
| 2282 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2283 | nla, sta_flags_policy)) |
| 2284 | return -EINVAL; |
| 2285 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2286 | /* |
| 2287 | * Only allow certain flags for interface types so that |
| 2288 | * other attributes are silently ignored. Remember that |
| 2289 | * this is backward compatibility code with old userspace |
| 2290 | * and shouldn't be hit in other cases anyway. |
| 2291 | */ |
| 2292 | switch (iftype) { |
| 2293 | case NL80211_IFTYPE_AP: |
| 2294 | case NL80211_IFTYPE_AP_VLAN: |
| 2295 | case NL80211_IFTYPE_P2P_GO: |
| 2296 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2297 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2298 | BIT(NL80211_STA_FLAG_WME) | |
| 2299 | BIT(NL80211_STA_FLAG_MFP); |
| 2300 | break; |
| 2301 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2302 | case NL80211_IFTYPE_STATION: |
| 2303 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2304 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2305 | break; |
| 2306 | case NL80211_IFTYPE_MESH_POINT: |
| 2307 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 2308 | BIT(NL80211_STA_FLAG_MFP) | |
| 2309 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 2310 | default: |
| 2311 | return -EINVAL; |
| 2312 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2313 | |
| 2314 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2315 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2316 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2317 | |
| 2318 | return 0; |
| 2319 | } |
| 2320 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2321 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2322 | int attr) |
| 2323 | { |
| 2324 | struct nlattr *rate; |
| 2325 | u16 bitrate; |
| 2326 | |
| 2327 | rate = nla_nest_start(msg, attr); |
| 2328 | if (!rate) |
| 2329 | goto nla_put_failure; |
| 2330 | |
| 2331 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2332 | bitrate = cfg80211_calculate_bitrate(info); |
| 2333 | if (bitrate > 0) |
| 2334 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2335 | |
| 2336 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2337 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2338 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2339 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2340 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2341 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2342 | |
| 2343 | nla_nest_end(msg, rate); |
| 2344 | return true; |
| 2345 | |
| 2346 | nla_put_failure: |
| 2347 | return false; |
| 2348 | } |
| 2349 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2350 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2351 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2352 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2353 | { |
| 2354 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2355 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2356 | |
| 2357 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2358 | if (!hdr) |
| 2359 | return -1; |
| 2360 | |
| 2361 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2362 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2363 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2364 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2365 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2366 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2367 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2368 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2369 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2370 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2371 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2372 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2373 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2374 | sinfo->inactive_time); |
| 2375 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2376 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2377 | sinfo->rx_bytes); |
| 2378 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2379 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2380 | sinfo->tx_bytes); |
| 2381 | if (sinfo->filled & STATION_INFO_LLID) |
| 2382 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2383 | sinfo->llid); |
| 2384 | if (sinfo->filled & STATION_INFO_PLID) |
| 2385 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2386 | sinfo->plid); |
| 2387 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2388 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2389 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2390 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2391 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2392 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2393 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2394 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2395 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2396 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2397 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2398 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2399 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2400 | } |
| 2401 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2402 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2403 | NL80211_STA_INFO_RX_BITRATE)) |
| 2404 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2405 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2406 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2407 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2408 | sinfo->rx_packets); |
| 2409 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2410 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2411 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2412 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2413 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2414 | sinfo->tx_retries); |
| 2415 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2416 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2417 | sinfo->tx_failed); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 2418 | if (sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) |
| 2419 | NLA_PUT_U32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 2420 | sinfo->beacon_loss_count); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2421 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2422 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2423 | if (!bss_param) |
| 2424 | goto nla_put_failure; |
| 2425 | |
| 2426 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2427 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2428 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2429 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2430 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2431 | NLA_PUT_FLAG(msg, |
| 2432 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2433 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2434 | sinfo->bss_param.dtim_period); |
| 2435 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2436 | sinfo->bss_param.beacon_interval); |
| 2437 | |
| 2438 | nla_nest_end(msg, bss_param); |
| 2439 | } |
Helmut Schaa | bb6e753 | 2011-10-13 16:30:39 +0200 | [diff] [blame] | 2440 | if (sinfo->filled & STATION_INFO_STA_FLAGS) |
| 2441 | NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2442 | sizeof(struct nl80211_sta_flag_update), |
| 2443 | &sinfo->sta_flags); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2444 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2445 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2446 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2447 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2448 | sinfo->assoc_req_ies); |
| 2449 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2450 | return genlmsg_end(msg, hdr); |
| 2451 | |
| 2452 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2453 | genlmsg_cancel(msg, hdr); |
| 2454 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2455 | } |
| 2456 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2457 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2458 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2459 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2460 | struct station_info sinfo; |
| 2461 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2462 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2463 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2464 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2465 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2466 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2467 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2468 | if (err) |
| 2469 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2470 | |
| 2471 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2472 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2473 | goto out_err; |
| 2474 | } |
| 2475 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2476 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2477 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2478 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2479 | mac_addr, &sinfo); |
| 2480 | if (err == -ENOENT) |
| 2481 | break; |
| 2482 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2483 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2484 | |
| 2485 | if (nl80211_send_station(skb, |
| 2486 | NETLINK_CB(cb->skb).pid, |
| 2487 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2488 | netdev, mac_addr, |
| 2489 | &sinfo) < 0) |
| 2490 | goto out; |
| 2491 | |
| 2492 | sta_idx++; |
| 2493 | } |
| 2494 | |
| 2495 | |
| 2496 | out: |
| 2497 | cb->args[1] = sta_idx; |
| 2498 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2499 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2500 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2501 | |
| 2502 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2503 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2504 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2505 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2506 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2508 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2509 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2510 | struct sk_buff *msg; |
| 2511 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2512 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2513 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2514 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2515 | |
| 2516 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2517 | return -EINVAL; |
| 2518 | |
| 2519 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2520 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2521 | if (!rdev->ops->get_station) |
| 2522 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2523 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2524 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2525 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2526 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2527 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2529 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2530 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2531 | |
| 2532 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2533 | dev, mac_addr, &sinfo) < 0) { |
| 2534 | nlmsg_free(msg); |
| 2535 | return -ENOBUFS; |
| 2536 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2538 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2542 | * 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] | 2543 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2544 | static struct net_device *get_vlan(struct genl_info *info, |
| 2545 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2546 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2547 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2548 | struct net_device *v; |
| 2549 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2550 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2551 | if (!vlanattr) |
| 2552 | return NULL; |
| 2553 | |
| 2554 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 2555 | if (!v) |
| 2556 | return ERR_PTR(-ENODEV); |
| 2557 | |
| 2558 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 2559 | ret = -EINVAL; |
| 2560 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2561 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2562 | |
| 2563 | if (!netif_running(v)) { |
| 2564 | ret = -ENETDOWN; |
| 2565 | goto error; |
| 2566 | } |
| 2567 | |
| 2568 | return v; |
| 2569 | error: |
| 2570 | dev_put(v); |
| 2571 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2575 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2576 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2577 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2578 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2579 | struct station_parameters params; |
| 2580 | u8 *mac_addr = NULL; |
| 2581 | |
| 2582 | memset(¶ms, 0, sizeof(params)); |
| 2583 | |
| 2584 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2585 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2586 | |
| 2587 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2588 | return -EINVAL; |
| 2589 | |
| 2590 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2591 | return -EINVAL; |
| 2592 | |
| 2593 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2594 | |
| 2595 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2596 | params.supported_rates = |
| 2597 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2598 | params.supported_rates_len = |
| 2599 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2600 | } |
| 2601 | |
| 2602 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2603 | params.listen_interval = |
| 2604 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2605 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2606 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2607 | params.ht_capa = |
| 2608 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2609 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2610 | if (!rdev->ops->change_station) |
| 2611 | return -EOPNOTSUPP; |
| 2612 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2613 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2614 | return -EINVAL; |
| 2615 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2616 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2617 | params.plink_action = |
| 2618 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2619 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2620 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2621 | params.plink_state = |
| 2622 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2623 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2624 | switch (dev->ieee80211_ptr->iftype) { |
| 2625 | case NL80211_IFTYPE_AP: |
| 2626 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2627 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2628 | /* disallow mesh-specific things */ |
| 2629 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2630 | return -EINVAL; |
| 2631 | |
| 2632 | /* TDLS can't be set, ... */ |
| 2633 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 2634 | return -EINVAL; |
| 2635 | /* |
| 2636 | * ... but don't bother the driver with it. This works around |
| 2637 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 2638 | * TLDS_PEER flag in the mask even for AP mode. |
| 2639 | */ |
| 2640 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2641 | |
| 2642 | /* accept only the listed bits */ |
| 2643 | if (params.sta_flags_mask & |
| 2644 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2645 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 2646 | BIT(NL80211_STA_FLAG_WME) | |
| 2647 | BIT(NL80211_STA_FLAG_MFP))) |
| 2648 | return -EINVAL; |
| 2649 | |
| 2650 | /* must be last in here for error handling */ |
| 2651 | params.vlan = get_vlan(info, rdev); |
| 2652 | if (IS_ERR(params.vlan)) |
| 2653 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2654 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2655 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2656 | case NL80211_IFTYPE_STATION: |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2657 | /* disallow things sta doesn't support */ |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2658 | if (params.plink_action) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2659 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2660 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2661 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2662 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2663 | return -EINVAL; |
| 2664 | /* |
| 2665 | * Don't allow userspace to change the TDLS_PEER flag, |
| 2666 | * but silently ignore attempts to change it since we |
| 2667 | * don't have state here to verify that it doesn't try |
| 2668 | * to change the flag. |
| 2669 | */ |
| 2670 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 2671 | |
| 2672 | /* reject any changes other than AUTHORIZED */ |
| 2673 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2674 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2675 | break; |
| 2676 | case NL80211_IFTYPE_MESH_POINT: |
| 2677 | /* disallow things mesh doesn't support */ |
| 2678 | if (params.vlan) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2679 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2680 | if (params.ht_capa) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2681 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2682 | if (params.listen_interval >= 0) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2683 | return -EINVAL; |
| 2684 | /* |
| 2685 | * No special handling for TDLS here -- the userspace |
| 2686 | * mesh code doesn't have this bug. |
| 2687 | */ |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2688 | if (params.sta_flags_mask & |
| 2689 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2690 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2691 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2692 | return -EINVAL; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2693 | break; |
| 2694 | default: |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2695 | return -EOPNOTSUPP; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2696 | } |
| 2697 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2698 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2699 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2700 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2701 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2702 | if (params.vlan) |
| 2703 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2704 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2705 | return err; |
| 2706 | } |
| 2707 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2708 | static struct nla_policy |
| 2709 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2710 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2711 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2712 | }; |
| 2713 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2714 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2715 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2717 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2718 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2719 | struct station_parameters params; |
| 2720 | u8 *mac_addr = NULL; |
| 2721 | |
| 2722 | memset(¶ms, 0, sizeof(params)); |
| 2723 | |
| 2724 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2725 | return -EINVAL; |
| 2726 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2727 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2728 | return -EINVAL; |
| 2729 | |
| 2730 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2731 | return -EINVAL; |
| 2732 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2733 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2734 | return -EINVAL; |
| 2735 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2736 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2737 | params.supported_rates = |
| 2738 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2739 | params.supported_rates_len = |
| 2740 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2741 | params.listen_interval = |
| 2742 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2743 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2744 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2745 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2746 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2747 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2748 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2749 | params.ht_capa = |
| 2750 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2751 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2752 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2753 | params.plink_action = |
| 2754 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2755 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2756 | if (!rdev->ops->add_station) |
| 2757 | return -EOPNOTSUPP; |
| 2758 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 2759 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2760 | return -EINVAL; |
| 2761 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2762 | switch (dev->ieee80211_ptr->iftype) { |
| 2763 | case NL80211_IFTYPE_AP: |
| 2764 | case NL80211_IFTYPE_AP_VLAN: |
| 2765 | case NL80211_IFTYPE_P2P_GO: |
| 2766 | /* parse WME attributes if sta is WME capable */ |
| 2767 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 2768 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
| 2769 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2770 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2771 | struct nlattr *nla; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2772 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2773 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2774 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2775 | nl80211_sta_wme_policy); |
| 2776 | if (err) |
| 2777 | return err; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2778 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2779 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2780 | params.uapsd_queues = |
| 2781 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 2782 | if (params.uapsd_queues & |
| 2783 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2784 | return -EINVAL; |
| 2785 | |
| 2786 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2787 | params.max_sp = |
| 2788 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 2789 | |
| 2790 | if (params.max_sp & |
| 2791 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2792 | return -EINVAL; |
| 2793 | |
| 2794 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 2795 | } |
| 2796 | /* TDLS peers cannot be added */ |
| 2797 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2798 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2799 | /* but don't bother the driver with it */ |
| 2800 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2801 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2802 | /* must be last in here for error handling */ |
| 2803 | params.vlan = get_vlan(info, rdev); |
| 2804 | if (IS_ERR(params.vlan)) |
| 2805 | return PTR_ERR(params.vlan); |
| 2806 | break; |
| 2807 | case NL80211_IFTYPE_MESH_POINT: |
| 2808 | /* TDLS peers cannot be added */ |
| 2809 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2810 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2811 | break; |
| 2812 | case NL80211_IFTYPE_STATION: |
| 2813 | /* Only TDLS peers can be added */ |
| 2814 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 2815 | return -EINVAL; |
| 2816 | /* Can only add if TDLS ... */ |
| 2817 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 2818 | return -EOPNOTSUPP; |
| 2819 | /* ... with external setup is supported */ |
| 2820 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 2821 | return -EOPNOTSUPP; |
| 2822 | break; |
| 2823 | default: |
| 2824 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2825 | } |
| 2826 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 2827 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2828 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2829 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2830 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2831 | if (params.vlan) |
| 2832 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2833 | return err; |
| 2834 | } |
| 2835 | |
| 2836 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2837 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2839 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2840 | u8 *mac_addr = NULL; |
| 2841 | |
| 2842 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2843 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2844 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2845 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2846 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2847 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2848 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2849 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2850 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2851 | if (!rdev->ops->del_station) |
| 2852 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2854 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2855 | } |
| 2856 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2857 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2858 | int flags, struct net_device *dev, |
| 2859 | u8 *dst, u8 *next_hop, |
| 2860 | struct mpath_info *pinfo) |
| 2861 | { |
| 2862 | void *hdr; |
| 2863 | struct nlattr *pinfoattr; |
| 2864 | |
| 2865 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2866 | if (!hdr) |
| 2867 | return -1; |
| 2868 | |
| 2869 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2870 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2871 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2872 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2873 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2874 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2875 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2876 | if (!pinfoattr) |
| 2877 | goto nla_put_failure; |
| 2878 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2879 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2880 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2881 | if (pinfo->filled & MPATH_INFO_SN) |
| 2882 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2883 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2884 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2885 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2886 | pinfo->metric); |
| 2887 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2888 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2889 | pinfo->exptime); |
| 2890 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2891 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2892 | pinfo->flags); |
| 2893 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2894 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2895 | pinfo->discovery_timeout); |
| 2896 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2897 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2898 | pinfo->discovery_retries); |
| 2899 | |
| 2900 | nla_nest_end(msg, pinfoattr); |
| 2901 | |
| 2902 | return genlmsg_end(msg, hdr); |
| 2903 | |
| 2904 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2905 | genlmsg_cancel(msg, hdr); |
| 2906 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2910 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2911 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2912 | struct mpath_info pinfo; |
| 2913 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2914 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2915 | u8 dst[ETH_ALEN]; |
| 2916 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2917 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2918 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2919 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2920 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2921 | if (err) |
| 2922 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2923 | |
| 2924 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2925 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2926 | goto out_err; |
| 2927 | } |
| 2928 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2929 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2930 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2931 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2932 | } |
| 2933 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2934 | while (1) { |
| 2935 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2936 | dst, next_hop, &pinfo); |
| 2937 | if (err == -ENOENT) |
| 2938 | break; |
| 2939 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2940 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2941 | |
| 2942 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2943 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2944 | netdev, dst, next_hop, |
| 2945 | &pinfo) < 0) |
| 2946 | goto out; |
| 2947 | |
| 2948 | path_idx++; |
| 2949 | } |
| 2950 | |
| 2951 | |
| 2952 | out: |
| 2953 | cb->args[1] = path_idx; |
| 2954 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2955 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2956 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2957 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2961 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2963 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2964 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2965 | struct mpath_info pinfo; |
| 2966 | struct sk_buff *msg; |
| 2967 | u8 *dst = NULL; |
| 2968 | u8 next_hop[ETH_ALEN]; |
| 2969 | |
| 2970 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2971 | |
| 2972 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2973 | return -EINVAL; |
| 2974 | |
| 2975 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2976 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2977 | if (!rdev->ops->get_mpath) |
| 2978 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2979 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2980 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2981 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2982 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2983 | 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] | 2984 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2985 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2986 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2987 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2988 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2989 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2990 | |
| 2991 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2992 | dev, dst, next_hop, &pinfo) < 0) { |
| 2993 | nlmsg_free(msg); |
| 2994 | return -ENOBUFS; |
| 2995 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2996 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2997 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3001 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3002 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3003 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3004 | u8 *dst = NULL; |
| 3005 | u8 *next_hop = NULL; |
| 3006 | |
| 3007 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3008 | return -EINVAL; |
| 3009 | |
| 3010 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3011 | return -EINVAL; |
| 3012 | |
| 3013 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3014 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3015 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3016 | if (!rdev->ops->change_mpath) |
| 3017 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3018 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3019 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3020 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3021 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3022 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3023 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3024 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3025 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3028 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3029 | u8 *dst = NULL; |
| 3030 | u8 *next_hop = NULL; |
| 3031 | |
| 3032 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3033 | return -EINVAL; |
| 3034 | |
| 3035 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 3036 | return -EINVAL; |
| 3037 | |
| 3038 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3039 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 3040 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3041 | if (!rdev->ops->add_mpath) |
| 3042 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3043 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3044 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3045 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3046 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3047 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
| 3050 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 3051 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3052 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3053 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3054 | u8 *dst = NULL; |
| 3055 | |
| 3056 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3057 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3058 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3059 | if (!rdev->ops->del_mpath) |
| 3060 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3061 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3062 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3063 | } |
| 3064 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3065 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3066 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3068 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3069 | struct bss_parameters params; |
| 3070 | |
| 3071 | memset(¶ms, 0, sizeof(params)); |
| 3072 | /* default to not changing parameters */ |
| 3073 | params.use_cts_prot = -1; |
| 3074 | params.use_short_preamble = -1; |
| 3075 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3076 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3077 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3078 | |
| 3079 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3080 | params.use_cts_prot = |
| 3081 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3082 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3083 | params.use_short_preamble = |
| 3084 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3085 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3086 | params.use_short_slot_time = |
| 3087 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3088 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3089 | params.basic_rates = |
| 3090 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3091 | params.basic_rates_len = |
| 3092 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3093 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3094 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3095 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3096 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3097 | params.ht_opmode = |
| 3098 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3099 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3100 | if (!rdev->ops->change_bss) |
| 3101 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3102 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3103 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3104 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3105 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3106 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3107 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3108 | } |
| 3109 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3110 | 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] | 3111 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3112 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3113 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3114 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3115 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3116 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3117 | }; |
| 3118 | |
| 3119 | static int parse_reg_rule(struct nlattr *tb[], |
| 3120 | struct ieee80211_reg_rule *reg_rule) |
| 3121 | { |
| 3122 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3123 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3124 | |
| 3125 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3126 | return -EINVAL; |
| 3127 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3128 | return -EINVAL; |
| 3129 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3130 | return -EINVAL; |
| 3131 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3132 | return -EINVAL; |
| 3133 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3134 | return -EINVAL; |
| 3135 | |
| 3136 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3137 | |
| 3138 | freq_range->start_freq_khz = |
| 3139 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3140 | freq_range->end_freq_khz = |
| 3141 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3142 | freq_range->max_bandwidth_khz = |
| 3143 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3144 | |
| 3145 | power_rule->max_eirp = |
| 3146 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3147 | |
| 3148 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3149 | power_rule->max_antenna_gain = |
| 3150 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3151 | |
| 3152 | return 0; |
| 3153 | } |
| 3154 | |
| 3155 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3156 | { |
| 3157 | int r; |
| 3158 | char *data = NULL; |
| 3159 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3160 | /* |
| 3161 | * You should only get this when cfg80211 hasn't yet initialized |
| 3162 | * completely when built-in to the kernel right between the time |
| 3163 | * window between nl80211_init() and regulatory_init(), if that is |
| 3164 | * even possible. |
| 3165 | */ |
| 3166 | mutex_lock(&cfg80211_mutex); |
| 3167 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3168 | mutex_unlock(&cfg80211_mutex); |
| 3169 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3170 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3171 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3172 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3173 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3174 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3175 | |
| 3176 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3177 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3178 | r = regulatory_hint_user(data); |
| 3179 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3180 | return r; |
| 3181 | } |
| 3182 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3183 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3184 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3185 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3186 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3187 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3188 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3189 | struct mesh_config cur_params; |
| 3190 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3191 | void *hdr; |
| 3192 | struct nlattr *pinfoattr; |
| 3193 | struct sk_buff *msg; |
| 3194 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3195 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3196 | return -EOPNOTSUPP; |
| 3197 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3198 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3199 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3200 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3201 | wdev_lock(wdev); |
| 3202 | /* If not connected, get default parameters */ |
| 3203 | if (!wdev->mesh_id_len) |
| 3204 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3205 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3206 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3207 | &cur_params); |
| 3208 | wdev_unlock(wdev); |
| 3209 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3210 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3211 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3212 | |
| 3213 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3214 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3215 | if (!msg) |
| 3216 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3217 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3218 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3219 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3220 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3221 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3222 | if (!pinfoattr) |
| 3223 | goto nla_put_failure; |
| 3224 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3225 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3226 | cur_params.dot11MeshRetryTimeout); |
| 3227 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3228 | cur_params.dot11MeshConfirmTimeout); |
| 3229 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3230 | cur_params.dot11MeshHoldingTimeout); |
| 3231 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3232 | cur_params.dot11MeshMaxPeerLinks); |
| 3233 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3234 | cur_params.dot11MeshMaxRetries); |
| 3235 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3236 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3237 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3238 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3239 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3240 | cur_params.auto_open_plinks); |
| 3241 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3242 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3243 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3244 | cur_params.path_refresh_time); |
| 3245 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3246 | cur_params.min_discovery_timeout); |
| 3247 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3248 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3249 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3250 | cur_params.dot11MeshHWMPpreqMinInterval); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3251 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3252 | cur_params.dot11MeshHWMPperrMinInterval); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3253 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3254 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3255 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3256 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3257 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3258 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3259 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3260 | cur_params.dot11MeshGateAnnouncementProtocol); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3261 | NLA_PUT_U8(msg, NL80211_MESHCONF_FORWARDING, |
| 3262 | cur_params.dot11MeshForwarding); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3263 | nla_nest_end(msg, pinfoattr); |
| 3264 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3265 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3266 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3267 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3268 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3269 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3270 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3271 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3274 | 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] | 3275 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3276 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3277 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3278 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3279 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3280 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3281 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3282 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3283 | |
| 3284 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3285 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3286 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3287 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3288 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3289 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3290 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3291 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3292 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3293 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3294 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3295 | }; |
| 3296 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3297 | static const struct nla_policy |
| 3298 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3299 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3300 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3301 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3302 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3303 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3304 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3305 | }; |
| 3306 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3307 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3308 | struct mesh_config *cfg, |
| 3309 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3310 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3311 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3312 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3313 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3314 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3315 | do {\ |
| 3316 | if (table[attr_num]) {\ |
| 3317 | cfg->param = nla_fn(table[attr_num]); \ |
| 3318 | mask |= (1 << (attr_num - 1)); \ |
| 3319 | } \ |
| 3320 | } while (0);\ |
| 3321 | |
| 3322 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3323 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3324 | return -EINVAL; |
| 3325 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3326 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3327 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3328 | return -EINVAL; |
| 3329 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3330 | /* This makes sure that there aren't more than 32 mesh config |
| 3331 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3332 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3333 | |
| 3334 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3335 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3336 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3337 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3338 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3339 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3340 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3341 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3342 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3343 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3344 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3345 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3346 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3347 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3348 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3349 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3350 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3351 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3352 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3353 | nla_get_u8); |
| 3354 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3355 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3356 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3357 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3358 | nla_get_u16); |
| 3359 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3360 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3361 | nla_get_u32); |
| 3362 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3363 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3364 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3365 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
| 3366 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3367 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3368 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3369 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3370 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3371 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3372 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3373 | dot11MeshHWMPRootMode, mask, |
| 3374 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3375 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3376 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3377 | dot11MeshHWMPRannInterval, mask, |
| 3378 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3379 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3380 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3381 | dot11MeshGateAnnouncementProtocol, mask, |
| 3382 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3383 | nla_get_u8); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 3384 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
| 3385 | mask, NL80211_MESHCONF_FORWARDING, nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3386 | if (mask_out) |
| 3387 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3388 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3389 | return 0; |
| 3390 | |
| 3391 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3392 | } |
| 3393 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3394 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3395 | struct mesh_setup *setup) |
| 3396 | { |
| 3397 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3398 | |
| 3399 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3400 | return -EINVAL; |
| 3401 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3402 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3403 | nl80211_mesh_setup_params_policy)) |
| 3404 | return -EINVAL; |
| 3405 | |
| 3406 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3407 | setup->path_sel_proto = |
| 3408 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3409 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3410 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3411 | |
| 3412 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3413 | setup->path_metric = |
| 3414 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3415 | IEEE80211_PATH_METRIC_VENDOR : |
| 3416 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3417 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3418 | |
| 3419 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3420 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3421 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3422 | if (!is_valid_ie_attr(ieattr)) |
| 3423 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3424 | setup->ie = nla_data(ieattr); |
| 3425 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3426 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3427 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3428 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3429 | |
| 3430 | return 0; |
| 3431 | } |
| 3432 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3433 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3434 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3435 | { |
| 3436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3437 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3438 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3439 | struct mesh_config cfg; |
| 3440 | u32 mask; |
| 3441 | int err; |
| 3442 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3443 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3444 | return -EOPNOTSUPP; |
| 3445 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3446 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3447 | return -EOPNOTSUPP; |
| 3448 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3449 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3450 | if (err) |
| 3451 | return err; |
| 3452 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3453 | wdev_lock(wdev); |
| 3454 | if (!wdev->mesh_id_len) |
| 3455 | err = -ENOLINK; |
| 3456 | |
| 3457 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3458 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3459 | mask, &cfg); |
| 3460 | |
| 3461 | wdev_unlock(wdev); |
| 3462 | |
| 3463 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3466 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3467 | { |
| 3468 | struct sk_buff *msg; |
| 3469 | void *hdr = NULL; |
| 3470 | struct nlattr *nl_reg_rules; |
| 3471 | unsigned int i; |
| 3472 | int err = -EINVAL; |
| 3473 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3474 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3475 | |
| 3476 | if (!cfg80211_regdomain) |
| 3477 | goto out; |
| 3478 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3479 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3480 | if (!msg) { |
| 3481 | err = -ENOBUFS; |
| 3482 | goto out; |
| 3483 | } |
| 3484 | |
| 3485 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3486 | NL80211_CMD_GET_REG); |
| 3487 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3488 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3489 | |
| 3490 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3491 | cfg80211_regdomain->alpha2); |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3492 | if (cfg80211_regdomain->dfs_region) |
| 3493 | NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION, |
| 3494 | cfg80211_regdomain->dfs_region); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3495 | |
| 3496 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3497 | if (!nl_reg_rules) |
| 3498 | goto nla_put_failure; |
| 3499 | |
| 3500 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3501 | struct nlattr *nl_reg_rule; |
| 3502 | const struct ieee80211_reg_rule *reg_rule; |
| 3503 | const struct ieee80211_freq_range *freq_range; |
| 3504 | const struct ieee80211_power_rule *power_rule; |
| 3505 | |
| 3506 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3507 | freq_range = ®_rule->freq_range; |
| 3508 | power_rule = ®_rule->power_rule; |
| 3509 | |
| 3510 | nl_reg_rule = nla_nest_start(msg, i); |
| 3511 | if (!nl_reg_rule) |
| 3512 | goto nla_put_failure; |
| 3513 | |
| 3514 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3515 | reg_rule->flags); |
| 3516 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3517 | freq_range->start_freq_khz); |
| 3518 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3519 | freq_range->end_freq_khz); |
| 3520 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3521 | freq_range->max_bandwidth_khz); |
| 3522 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3523 | power_rule->max_antenna_gain); |
| 3524 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3525 | power_rule->max_eirp); |
| 3526 | |
| 3527 | nla_nest_end(msg, nl_reg_rule); |
| 3528 | } |
| 3529 | |
| 3530 | nla_nest_end(msg, nl_reg_rules); |
| 3531 | |
| 3532 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3533 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3534 | goto out; |
| 3535 | |
| 3536 | nla_put_failure: |
| 3537 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3538 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3539 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3540 | err = -EMSGSIZE; |
| 3541 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3542 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3543 | return err; |
| 3544 | } |
| 3545 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3546 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3547 | { |
| 3548 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3549 | struct nlattr *nl_reg_rule; |
| 3550 | char *alpha2 = NULL; |
| 3551 | int rem_reg_rules = 0, r = 0; |
| 3552 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3553 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3554 | struct ieee80211_regdomain *rd = NULL; |
| 3555 | |
| 3556 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3557 | return -EINVAL; |
| 3558 | |
| 3559 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3560 | return -EINVAL; |
| 3561 | |
| 3562 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3563 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3564 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 3565 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 3566 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3567 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3568 | rem_reg_rules) { |
| 3569 | num_rules++; |
| 3570 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3571 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3574 | mutex_lock(&cfg80211_mutex); |
| 3575 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3576 | if (!reg_is_valid_request(alpha2)) { |
| 3577 | r = -EINVAL; |
| 3578 | goto bad_reg; |
| 3579 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3580 | |
| 3581 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3582 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3583 | |
| 3584 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3585 | if (!rd) { |
| 3586 | r = -ENOMEM; |
| 3587 | goto bad_reg; |
| 3588 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3589 | |
| 3590 | rd->n_reg_rules = num_rules; |
| 3591 | rd->alpha2[0] = alpha2[0]; |
| 3592 | rd->alpha2[1] = alpha2[1]; |
| 3593 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3594 | /* |
| 3595 | * Disable DFS master mode if the DFS region was |
| 3596 | * not supported or known on this kernel. |
| 3597 | */ |
| 3598 | if (reg_supported_dfs_region(dfs_region)) |
| 3599 | rd->dfs_region = dfs_region; |
| 3600 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3601 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3602 | rem_reg_rules) { |
| 3603 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3604 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3605 | reg_rule_policy); |
| 3606 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3607 | if (r) |
| 3608 | goto bad_reg; |
| 3609 | |
| 3610 | rule_idx++; |
| 3611 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3612 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3613 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3614 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3615 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | BUG_ON(rule_idx != num_rules); |
| 3619 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3620 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3621 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3622 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3623 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3624 | return r; |
| 3625 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3626 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3627 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3628 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3629 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3630 | } |
| 3631 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3632 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3633 | { |
| 3634 | struct nlattr *attr1, *attr2; |
| 3635 | int n_channels = 0, tmp1, tmp2; |
| 3636 | |
| 3637 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3638 | n_channels++; |
| 3639 | /* |
| 3640 | * Some hardware has a limited channel list for |
| 3641 | * scanning, and it is pretty much nonsensical |
| 3642 | * to scan for a channel twice, so disallow that |
| 3643 | * and don't require drivers to check that the |
| 3644 | * channel list they get isn't longer than what |
| 3645 | * they can scan, as long as they can scan all |
| 3646 | * the channels they registered at once. |
| 3647 | */ |
| 3648 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3649 | if (attr1 != attr2 && |
| 3650 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3651 | return 0; |
| 3652 | } |
| 3653 | |
| 3654 | return n_channels; |
| 3655 | } |
| 3656 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3657 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3658 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3659 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3660 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3661 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3662 | struct nlattr *attr; |
| 3663 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3664 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3665 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3666 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3667 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3668 | return -EINVAL; |
| 3669 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3670 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3671 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3672 | if (!rdev->ops->scan) |
| 3673 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3674 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3675 | if (rdev->scan_req) |
| 3676 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3677 | |
| 3678 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3679 | n_channels = validate_scan_freqs( |
| 3680 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3681 | if (!n_channels) |
| 3682 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3683 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3684 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3685 | n_channels = 0; |
| 3686 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3687 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3688 | if (wiphy->bands[band]) |
| 3689 | n_channels += wiphy->bands[band]->n_channels; |
| 3690 | } |
| 3691 | |
| 3692 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3693 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3694 | n_ssids++; |
| 3695 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3696 | if (n_ssids > wiphy->max_scan_ssids) |
| 3697 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3698 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3699 | if (info->attrs[NL80211_ATTR_IE]) |
| 3700 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3701 | else |
| 3702 | ie_len = 0; |
| 3703 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3704 | if (ie_len > wiphy->max_scan_ie_len) |
| 3705 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3706 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3707 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3708 | + sizeof(*request->ssids) * n_ssids |
| 3709 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3710 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3711 | if (!request) |
| 3712 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3713 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3714 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3715 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3716 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3717 | if (ie_len) { |
| 3718 | if (request->ssids) |
| 3719 | request->ie = (void *)(request->ssids + n_ssids); |
| 3720 | else |
| 3721 | request->ie = (void *)(request->channels + n_channels); |
| 3722 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3723 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3724 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3725 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3726 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3727 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3728 | struct ieee80211_channel *chan; |
| 3729 | |
| 3730 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3731 | |
| 3732 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3733 | err = -EINVAL; |
| 3734 | goto out_free; |
| 3735 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3736 | |
| 3737 | /* ignore disabled channels */ |
| 3738 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3739 | continue; |
| 3740 | |
| 3741 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3742 | i++; |
| 3743 | } |
| 3744 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3745 | enum ieee80211_band band; |
| 3746 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3747 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3748 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3749 | int j; |
| 3750 | if (!wiphy->bands[band]) |
| 3751 | continue; |
| 3752 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3753 | struct ieee80211_channel *chan; |
| 3754 | |
| 3755 | chan = &wiphy->bands[band]->channels[j]; |
| 3756 | |
| 3757 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3758 | continue; |
| 3759 | |
| 3760 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3761 | i++; |
| 3762 | } |
| 3763 | } |
| 3764 | } |
| 3765 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3766 | if (!i) { |
| 3767 | err = -EINVAL; |
| 3768 | goto out_free; |
| 3769 | } |
| 3770 | |
| 3771 | request->n_channels = i; |
| 3772 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3773 | i = 0; |
| 3774 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3775 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3776 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3777 | err = -EINVAL; |
| 3778 | goto out_free; |
| 3779 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3780 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3781 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3782 | i++; |
| 3783 | } |
| 3784 | } |
| 3785 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3786 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3787 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3788 | memcpy((void *)request->ie, |
| 3789 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3790 | request->ie_len); |
| 3791 | } |
| 3792 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3793 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3794 | if (wiphy->bands[i]) |
| 3795 | request->rates[i] = |
| 3796 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3797 | |
| 3798 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3799 | nla_for_each_nested(attr, |
| 3800 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3801 | tmp) { |
| 3802 | enum ieee80211_band band = nla_type(attr); |
| 3803 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3804 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3805 | err = -EINVAL; |
| 3806 | goto out_free; |
| 3807 | } |
| 3808 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3809 | nla_data(attr), |
| 3810 | nla_len(attr), |
| 3811 | &request->rates[band]); |
| 3812 | if (err) |
| 3813 | goto out_free; |
| 3814 | } |
| 3815 | } |
| 3816 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3817 | request->no_cck = |
| 3818 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3819 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3820 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3821 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3822 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3823 | rdev->scan_req = request; |
| 3824 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3825 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3826 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3827 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3828 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3829 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3830 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3831 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3832 | kfree(request); |
| 3833 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3834 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3835 | return err; |
| 3836 | } |
| 3837 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3838 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3839 | struct genl_info *info) |
| 3840 | { |
| 3841 | struct cfg80211_sched_scan_request *request; |
| 3842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3843 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3844 | struct nlattr *attr; |
| 3845 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3846 | 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] | 3847 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3848 | enum ieee80211_band band; |
| 3849 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3850 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3851 | |
| 3852 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3853 | !rdev->ops->sched_scan_start) |
| 3854 | return -EOPNOTSUPP; |
| 3855 | |
| 3856 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3857 | return -EINVAL; |
| 3858 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3859 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3860 | return -EINVAL; |
| 3861 | |
| 3862 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3863 | if (interval == 0) |
| 3864 | return -EINVAL; |
| 3865 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3866 | wiphy = &rdev->wiphy; |
| 3867 | |
| 3868 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3869 | n_channels = validate_scan_freqs( |
| 3870 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3871 | if (!n_channels) |
| 3872 | return -EINVAL; |
| 3873 | } else { |
| 3874 | n_channels = 0; |
| 3875 | |
| 3876 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3877 | if (wiphy->bands[band]) |
| 3878 | n_channels += wiphy->bands[band]->n_channels; |
| 3879 | } |
| 3880 | |
| 3881 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3882 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3883 | tmp) |
| 3884 | n_ssids++; |
| 3885 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3886 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3887 | return -EINVAL; |
| 3888 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3889 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3890 | nla_for_each_nested(attr, |
| 3891 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3892 | tmp) |
| 3893 | n_match_sets++; |
| 3894 | |
| 3895 | if (n_match_sets > wiphy->max_match_sets) |
| 3896 | return -EINVAL; |
| 3897 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3898 | if (info->attrs[NL80211_ATTR_IE]) |
| 3899 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3900 | else |
| 3901 | ie_len = 0; |
| 3902 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3903 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3904 | return -EINVAL; |
| 3905 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3906 | mutex_lock(&rdev->sched_scan_mtx); |
| 3907 | |
| 3908 | if (rdev->sched_scan_req) { |
| 3909 | err = -EINPROGRESS; |
| 3910 | goto out; |
| 3911 | } |
| 3912 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3913 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3914 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3915 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3916 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3917 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3918 | if (!request) { |
| 3919 | err = -ENOMEM; |
| 3920 | goto out; |
| 3921 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3922 | |
| 3923 | if (n_ssids) |
| 3924 | request->ssids = (void *)&request->channels[n_channels]; |
| 3925 | request->n_ssids = n_ssids; |
| 3926 | if (ie_len) { |
| 3927 | if (request->ssids) |
| 3928 | request->ie = (void *)(request->ssids + n_ssids); |
| 3929 | else |
| 3930 | request->ie = (void *)(request->channels + n_channels); |
| 3931 | } |
| 3932 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3933 | if (n_match_sets) { |
| 3934 | if (request->ie) |
| 3935 | request->match_sets = (void *)(request->ie + ie_len); |
| 3936 | else if (request->ssids) |
| 3937 | request->match_sets = |
| 3938 | (void *)(request->ssids + n_ssids); |
| 3939 | else |
| 3940 | request->match_sets = |
| 3941 | (void *)(request->channels + n_channels); |
| 3942 | } |
| 3943 | request->n_match_sets = n_match_sets; |
| 3944 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3945 | i = 0; |
| 3946 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3947 | /* user specified, bail out if channel not found */ |
| 3948 | nla_for_each_nested(attr, |
| 3949 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3950 | tmp) { |
| 3951 | struct ieee80211_channel *chan; |
| 3952 | |
| 3953 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3954 | |
| 3955 | if (!chan) { |
| 3956 | err = -EINVAL; |
| 3957 | goto out_free; |
| 3958 | } |
| 3959 | |
| 3960 | /* ignore disabled channels */ |
| 3961 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3962 | continue; |
| 3963 | |
| 3964 | request->channels[i] = chan; |
| 3965 | i++; |
| 3966 | } |
| 3967 | } else { |
| 3968 | /* all channels */ |
| 3969 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3970 | int j; |
| 3971 | if (!wiphy->bands[band]) |
| 3972 | continue; |
| 3973 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3974 | struct ieee80211_channel *chan; |
| 3975 | |
| 3976 | chan = &wiphy->bands[band]->channels[j]; |
| 3977 | |
| 3978 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3979 | continue; |
| 3980 | |
| 3981 | request->channels[i] = chan; |
| 3982 | i++; |
| 3983 | } |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | if (!i) { |
| 3988 | err = -EINVAL; |
| 3989 | goto out_free; |
| 3990 | } |
| 3991 | |
| 3992 | request->n_channels = i; |
| 3993 | |
| 3994 | i = 0; |
| 3995 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3996 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3997 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3998 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3999 | err = -EINVAL; |
| 4000 | goto out_free; |
| 4001 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 4002 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4003 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 4004 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4005 | i++; |
| 4006 | } |
| 4007 | } |
| 4008 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 4009 | i = 0; |
| 4010 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 4011 | nla_for_each_nested(attr, |
| 4012 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 4013 | tmp) { |
| 4014 | struct nlattr *ssid; |
| 4015 | |
| 4016 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 4017 | nla_data(attr), nla_len(attr), |
| 4018 | nl80211_match_policy); |
| 4019 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 4020 | if (ssid) { |
| 4021 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 4022 | err = -EINVAL; |
| 4023 | goto out_free; |
| 4024 | } |
| 4025 | memcpy(request->match_sets[i].ssid.ssid, |
| 4026 | nla_data(ssid), nla_len(ssid)); |
| 4027 | request->match_sets[i].ssid.ssid_len = |
| 4028 | nla_len(ssid); |
| 4029 | } |
| 4030 | i++; |
| 4031 | } |
| 4032 | } |
| 4033 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4034 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4035 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4036 | memcpy((void *)request->ie, |
| 4037 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 4038 | request->ie_len); |
| 4039 | } |
| 4040 | |
| 4041 | request->dev = dev; |
| 4042 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 4043 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4044 | |
| 4045 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 4046 | if (!err) { |
| 4047 | rdev->sched_scan_req = request; |
| 4048 | nl80211_send_sched_scan(rdev, dev, |
| 4049 | NL80211_CMD_START_SCHED_SCAN); |
| 4050 | goto out; |
| 4051 | } |
| 4052 | |
| 4053 | out_free: |
| 4054 | kfree(request); |
| 4055 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4056 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4057 | return err; |
| 4058 | } |
| 4059 | |
| 4060 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4061 | struct genl_info *info) |
| 4062 | { |
| 4063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4064 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4065 | |
| 4066 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4067 | !rdev->ops->sched_scan_stop) |
| 4068 | return -EOPNOTSUPP; |
| 4069 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4070 | mutex_lock(&rdev->sched_scan_mtx); |
| 4071 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4072 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4073 | |
| 4074 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4075 | } |
| 4076 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4077 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4078 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4079 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4080 | struct wireless_dev *wdev, |
| 4081 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4082 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4083 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4084 | void *hdr; |
| 4085 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4086 | |
| 4087 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4088 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4089 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4090 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4091 | if (!hdr) |
| 4092 | return -1; |
| 4093 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4094 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4095 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4096 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4097 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4098 | |
| 4099 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4100 | if (!bss) |
| 4101 | goto nla_put_failure; |
| 4102 | if (!is_zero_ether_addr(res->bssid)) |
| 4103 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 4104 | if (res->information_elements && res->len_information_elements) |
| 4105 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4106 | res->len_information_elements, |
| 4107 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 4108 | if (res->beacon_ies && res->len_beacon_ies && |
| 4109 | res->beacon_ies != res->information_elements) |
| 4110 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 4111 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4112 | if (res->tsf) |
| 4113 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 4114 | if (res->beacon_interval) |
| 4115 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 4116 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 4117 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 4118 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4119 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4120 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4121 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4122 | case CFG80211_SIGNAL_TYPE_MBM: |
| 4123 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 4124 | break; |
| 4125 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 4126 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 4127 | break; |
| 4128 | default: |
| 4129 | break; |
| 4130 | } |
| 4131 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4132 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4133 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4134 | case NL80211_IFTYPE_STATION: |
| 4135 | if (intbss == wdev->current_bss) |
| 4136 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4137 | NL80211_BSS_STATUS_ASSOCIATED); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4138 | break; |
| 4139 | case NL80211_IFTYPE_ADHOC: |
| 4140 | if (intbss == wdev->current_bss) |
| 4141 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4142 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 4143 | break; |
| 4144 | default: |
| 4145 | break; |
| 4146 | } |
| 4147 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4148 | nla_nest_end(msg, bss); |
| 4149 | |
| 4150 | return genlmsg_end(msg, hdr); |
| 4151 | |
| 4152 | nla_put_failure: |
| 4153 | genlmsg_cancel(msg, hdr); |
| 4154 | return -EMSGSIZE; |
| 4155 | } |
| 4156 | |
| 4157 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4158 | struct netlink_callback *cb) |
| 4159 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4160 | struct cfg80211_registered_device *rdev; |
| 4161 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4162 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4163 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4164 | int start = cb->args[1], idx = 0; |
| 4165 | int err; |
| 4166 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4167 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4168 | if (err) |
| 4169 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4170 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4171 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4172 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4173 | wdev_lock(wdev); |
| 4174 | spin_lock_bh(&rdev->bss_lock); |
| 4175 | cfg80211_bss_expire(rdev); |
| 4176 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4177 | cb->seq = rdev->bss_generation; |
| 4178 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4179 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4180 | if (++idx <= start) |
| 4181 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4182 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4183 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4184 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4185 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4186 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4187 | } |
| 4188 | } |
| 4189 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4190 | spin_unlock_bh(&rdev->bss_lock); |
| 4191 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4192 | |
| 4193 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4194 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4195 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4196 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4197 | } |
| 4198 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4199 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4200 | int flags, struct net_device *dev, |
| 4201 | struct survey_info *survey) |
| 4202 | { |
| 4203 | void *hdr; |
| 4204 | struct nlattr *infoattr; |
| 4205 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4206 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4207 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4208 | if (!hdr) |
| 4209 | return -ENOMEM; |
| 4210 | |
| 4211 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4212 | |
| 4213 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4214 | if (!infoattr) |
| 4215 | goto nla_put_failure; |
| 4216 | |
| 4217 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4218 | survey->channel->center_freq); |
| 4219 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4220 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4221 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4222 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4223 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4224 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4225 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4226 | survey->channel_time); |
| 4227 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4228 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4229 | survey->channel_time_busy); |
| 4230 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4231 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4232 | survey->channel_time_ext_busy); |
| 4233 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4234 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4235 | survey->channel_time_rx); |
| 4236 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4237 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4238 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4239 | |
| 4240 | nla_nest_end(msg, infoattr); |
| 4241 | |
| 4242 | return genlmsg_end(msg, hdr); |
| 4243 | |
| 4244 | nla_put_failure: |
| 4245 | genlmsg_cancel(msg, hdr); |
| 4246 | return -EMSGSIZE; |
| 4247 | } |
| 4248 | |
| 4249 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4250 | struct netlink_callback *cb) |
| 4251 | { |
| 4252 | struct survey_info survey; |
| 4253 | struct cfg80211_registered_device *dev; |
| 4254 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4255 | int survey_idx = cb->args[1]; |
| 4256 | int res; |
| 4257 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4258 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4259 | if (res) |
| 4260 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4261 | |
| 4262 | if (!dev->ops->dump_survey) { |
| 4263 | res = -EOPNOTSUPP; |
| 4264 | goto out_err; |
| 4265 | } |
| 4266 | |
| 4267 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4268 | struct ieee80211_channel *chan; |
| 4269 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4270 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4271 | &survey); |
| 4272 | if (res == -ENOENT) |
| 4273 | break; |
| 4274 | if (res) |
| 4275 | goto out_err; |
| 4276 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4277 | /* Survey without a channel doesn't make sense */ |
| 4278 | if (!survey.channel) { |
| 4279 | res = -EINVAL; |
| 4280 | goto out; |
| 4281 | } |
| 4282 | |
| 4283 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4284 | survey.channel->center_freq); |
| 4285 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4286 | survey_idx++; |
| 4287 | continue; |
| 4288 | } |
| 4289 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4290 | if (nl80211_send_survey(skb, |
| 4291 | NETLINK_CB(cb->skb).pid, |
| 4292 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4293 | netdev, |
| 4294 | &survey) < 0) |
| 4295 | goto out; |
| 4296 | survey_idx++; |
| 4297 | } |
| 4298 | |
| 4299 | out: |
| 4300 | cb->args[1] = survey_idx; |
| 4301 | res = skb->len; |
| 4302 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4303 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4304 | return res; |
| 4305 | } |
| 4306 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4307 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4308 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4309 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4310 | } |
| 4311 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4312 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4313 | { |
| 4314 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4315 | NL80211_WPA_VERSION_2)); |
| 4316 | } |
| 4317 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4318 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4319 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4321 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4322 | struct ieee80211_channel *chan; |
| 4323 | const u8 *bssid, *ssid, *ie = NULL; |
| 4324 | int err, ssid_len, ie_len = 0; |
| 4325 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4326 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4327 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4328 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4329 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4330 | return -EINVAL; |
| 4331 | |
| 4332 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4333 | return -EINVAL; |
| 4334 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4335 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4336 | return -EINVAL; |
| 4337 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4338 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4339 | return -EINVAL; |
| 4340 | |
| 4341 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4342 | return -EINVAL; |
| 4343 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4344 | err = nl80211_parse_key(info, &key); |
| 4345 | if (err) |
| 4346 | return err; |
| 4347 | |
| 4348 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4349 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4350 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4351 | if (!key.p.key || !key.p.key_len) |
| 4352 | return -EINVAL; |
| 4353 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4354 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4355 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4356 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4357 | return -EINVAL; |
| 4358 | if (key.idx > 4) |
| 4359 | return -EINVAL; |
| 4360 | } else { |
| 4361 | key.p.key_len = 0; |
| 4362 | key.p.key = NULL; |
| 4363 | } |
| 4364 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4365 | if (key.idx >= 0) { |
| 4366 | int i; |
| 4367 | bool ok = false; |
| 4368 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4369 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4370 | ok = true; |
| 4371 | break; |
| 4372 | } |
| 4373 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4374 | if (!ok) |
| 4375 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4376 | } |
| 4377 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4378 | if (!rdev->ops->auth) |
| 4379 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4380 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4382 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4383 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4384 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4385 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4386 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4387 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4388 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4389 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4390 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4391 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4392 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4393 | |
| 4394 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4395 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4396 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4397 | } |
| 4398 | |
| 4399 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4400 | if (!nl80211_valid_auth_type(auth_type)) |
| 4401 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4402 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4403 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4404 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame^] | 4405 | /* |
| 4406 | * Since we no longer track auth state, ignore |
| 4407 | * requests to only change local state. |
| 4408 | */ |
| 4409 | if (local_state_change) |
| 4410 | return 0; |
| 4411 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4412 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4413 | ssid, ssid_len, ie, ie_len, |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame^] | 4414 | key.p.key, key.p.key_len, key.idx); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4415 | } |
| 4416 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4417 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4418 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4419 | struct cfg80211_crypto_settings *settings, |
| 4420 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4421 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4422 | memset(settings, 0, sizeof(*settings)); |
| 4423 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4424 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4425 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4426 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4427 | u16 proto; |
| 4428 | proto = nla_get_u16( |
| 4429 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4430 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4431 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4432 | proto != ETH_P_PAE) |
| 4433 | return -EINVAL; |
| 4434 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4435 | settings->control_port_no_encrypt = true; |
| 4436 | } else |
| 4437 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4438 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4439 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4440 | void *data; |
| 4441 | int len, i; |
| 4442 | |
| 4443 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4444 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4445 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4446 | |
| 4447 | if (len % sizeof(u32)) |
| 4448 | return -EINVAL; |
| 4449 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4450 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4451 | return -EINVAL; |
| 4452 | |
| 4453 | memcpy(settings->ciphers_pairwise, data, len); |
| 4454 | |
| 4455 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4456 | if (!cfg80211_supported_cipher_suite( |
| 4457 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4458 | settings->ciphers_pairwise[i])) |
| 4459 | return -EINVAL; |
| 4460 | } |
| 4461 | |
| 4462 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4463 | settings->cipher_group = |
| 4464 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4465 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4466 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4467 | return -EINVAL; |
| 4468 | } |
| 4469 | |
| 4470 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4471 | settings->wpa_versions = |
| 4472 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4473 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4474 | return -EINVAL; |
| 4475 | } |
| 4476 | |
| 4477 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4478 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4479 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4480 | |
| 4481 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4482 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4483 | settings->n_akm_suites = len / sizeof(u32); |
| 4484 | |
| 4485 | if (len % sizeof(u32)) |
| 4486 | return -EINVAL; |
| 4487 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4488 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4489 | return -EINVAL; |
| 4490 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4491 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4492 | } |
| 4493 | |
| 4494 | return 0; |
| 4495 | } |
| 4496 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4497 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4498 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4499 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4500 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4501 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4502 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4503 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4504 | int err, ssid_len, ie_len = 0; |
| 4505 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4506 | u32 flags = 0; |
| 4507 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 4508 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4509 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4510 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4511 | return -EINVAL; |
| 4512 | |
| 4513 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4514 | !info->attrs[NL80211_ATTR_SSID] || |
| 4515 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4516 | return -EINVAL; |
| 4517 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4518 | if (!rdev->ops->assoc) |
| 4519 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4520 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4521 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4522 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4523 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4524 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4525 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4526 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4527 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4528 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4529 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4530 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4531 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4532 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4533 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4534 | |
| 4535 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4536 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4537 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4538 | } |
| 4539 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4540 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4541 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4542 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4543 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4544 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4545 | else if (mfp != NL80211_MFP_NO) |
| 4546 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4547 | } |
| 4548 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4549 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4550 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4551 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4552 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 4553 | flags |= ASSOC_REQ_DISABLE_HT; |
| 4554 | |
| 4555 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 4556 | ht_capa_mask = |
| 4557 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 4558 | |
| 4559 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 4560 | if (!ht_capa_mask) |
| 4561 | return -EINVAL; |
| 4562 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4563 | } |
| 4564 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4565 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4566 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4567 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4568 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4569 | &crypto, flags, ht_capa, |
| 4570 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4571 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4572 | return err; |
| 4573 | } |
| 4574 | |
| 4575 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4576 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4578 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4579 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4580 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4581 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4582 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4583 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4584 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4585 | return -EINVAL; |
| 4586 | |
| 4587 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4588 | return -EINVAL; |
| 4589 | |
| 4590 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4591 | return -EINVAL; |
| 4592 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4593 | if (!rdev->ops->deauth) |
| 4594 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4595 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4596 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4597 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4598 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4599 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4600 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4601 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4602 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4603 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4604 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4605 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4606 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4607 | |
| 4608 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4609 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4610 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4611 | } |
| 4612 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4613 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4614 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4615 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4616 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4620 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4622 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4623 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4624 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4625 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4626 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4627 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4628 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4629 | return -EINVAL; |
| 4630 | |
| 4631 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4632 | return -EINVAL; |
| 4633 | |
| 4634 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4635 | return -EINVAL; |
| 4636 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4637 | if (!rdev->ops->disassoc) |
| 4638 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4639 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4640 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4641 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4642 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4643 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4644 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4645 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4646 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4647 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4648 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4649 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4650 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4651 | |
| 4652 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4653 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4654 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4655 | } |
| 4656 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4657 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4658 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4659 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4660 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4661 | } |
| 4662 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4663 | static bool |
| 4664 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4665 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4666 | int rateval) |
| 4667 | { |
| 4668 | struct wiphy *wiphy = &rdev->wiphy; |
| 4669 | bool found = false; |
| 4670 | int band, i; |
| 4671 | |
| 4672 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4673 | struct ieee80211_supported_band *sband; |
| 4674 | |
| 4675 | sband = wiphy->bands[band]; |
| 4676 | if (!sband) |
| 4677 | continue; |
| 4678 | |
| 4679 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4680 | if (sband->bitrates[i].bitrate == rateval) { |
| 4681 | mcast_rate[band] = i + 1; |
| 4682 | found = true; |
| 4683 | break; |
| 4684 | } |
| 4685 | } |
| 4686 | } |
| 4687 | |
| 4688 | return found; |
| 4689 | } |
| 4690 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4691 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4692 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4694 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4695 | struct cfg80211_ibss_params ibss; |
| 4696 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4697 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4698 | int err; |
| 4699 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4700 | memset(&ibss, 0, sizeof(ibss)); |
| 4701 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4702 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4703 | return -EINVAL; |
| 4704 | |
| 4705 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4706 | !info->attrs[NL80211_ATTR_SSID] || |
| 4707 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4708 | return -EINVAL; |
| 4709 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4710 | ibss.beacon_interval = 100; |
| 4711 | |
| 4712 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4713 | ibss.beacon_interval = |
| 4714 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4715 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4716 | return -EINVAL; |
| 4717 | } |
| 4718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4719 | if (!rdev->ops->join_ibss) |
| 4720 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4721 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4722 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4723 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4724 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4725 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4726 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4727 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4728 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4729 | |
| 4730 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4731 | return -EINVAL; |
| 4732 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4733 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4734 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4735 | |
| 4736 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4737 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4738 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4739 | } |
| 4740 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 4741 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4742 | enum nl80211_channel_type channel_type; |
| 4743 | |
| 4744 | channel_type = nla_get_u32( |
| 4745 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4746 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4747 | channel_type != NL80211_CHAN_HT20 && |
| 4748 | channel_type != NL80211_CHAN_HT40MINUS && |
| 4749 | channel_type != NL80211_CHAN_HT40PLUS) |
| 4750 | return -EINVAL; |
| 4751 | |
| 4752 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4753 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 4754 | return -EINVAL; |
| 4755 | |
| 4756 | ibss.channel_type = channel_type; |
| 4757 | } else { |
| 4758 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 4759 | } |
| 4760 | |
| 4761 | ibss.channel = rdev_freq_to_chan(rdev, |
| 4762 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 4763 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4764 | if (!ibss.channel || |
| 4765 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4766 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4767 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4768 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 4769 | /* Both channels should be able to initiate communication */ |
| 4770 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 4771 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 4772 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 4773 | ibss.channel_type)) |
| 4774 | return -EINVAL; |
| 4775 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4776 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4777 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4778 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4779 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4780 | u8 *rates = |
| 4781 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4782 | int n_rates = |
| 4783 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4784 | struct ieee80211_supported_band *sband = |
| 4785 | wiphy->bands[ibss.channel->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4786 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4787 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4788 | &ibss.basic_rates); |
| 4789 | if (err) |
| 4790 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4791 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4792 | |
| 4793 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4794 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4795 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4796 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4797 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4798 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4799 | connkeys = nl80211_parse_connkeys(rdev, |
| 4800 | info->attrs[NL80211_ATTR_KEYS]); |
| 4801 | if (IS_ERR(connkeys)) |
| 4802 | return PTR_ERR(connkeys); |
| 4803 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4804 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4805 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4806 | if (err) |
| 4807 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4808 | return err; |
| 4809 | } |
| 4810 | |
| 4811 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4812 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4814 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4815 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4816 | if (!rdev->ops->leave_ibss) |
| 4817 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4818 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4819 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4820 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4821 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4822 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4823 | } |
| 4824 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4825 | #ifdef CONFIG_NL80211_TESTMODE |
| 4826 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4827 | .name = "testmode", |
| 4828 | }; |
| 4829 | |
| 4830 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4831 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4833 | int err; |
| 4834 | |
| 4835 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4836 | return -EINVAL; |
| 4837 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4838 | err = -EOPNOTSUPP; |
| 4839 | if (rdev->ops->testmode_cmd) { |
| 4840 | rdev->testmode_info = info; |
| 4841 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4842 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4843 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4844 | rdev->testmode_info = NULL; |
| 4845 | } |
| 4846 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4847 | return err; |
| 4848 | } |
| 4849 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4850 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4851 | struct netlink_callback *cb) |
| 4852 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4853 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4854 | int err; |
| 4855 | long phy_idx; |
| 4856 | void *data = NULL; |
| 4857 | int data_len = 0; |
| 4858 | |
| 4859 | if (cb->args[0]) { |
| 4860 | /* |
| 4861 | * 0 is a valid index, but not valid for args[0], |
| 4862 | * so we need to offset by 1. |
| 4863 | */ |
| 4864 | phy_idx = cb->args[0] - 1; |
| 4865 | } else { |
| 4866 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4867 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4868 | nl80211_policy); |
| 4869 | if (err) |
| 4870 | return err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4871 | if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) { |
| 4872 | phy_idx = nla_get_u32( |
| 4873 | nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4874 | } else { |
| 4875 | struct net_device *netdev; |
| 4876 | |
| 4877 | err = get_rdev_dev_by_ifindex(sock_net(skb->sk), |
| 4878 | nl80211_fam.attrbuf, |
| 4879 | &rdev, &netdev); |
| 4880 | if (err) |
| 4881 | return err; |
| 4882 | dev_put(netdev); |
| 4883 | phy_idx = rdev->wiphy_idx; |
| 4884 | cfg80211_unlock_rdev(rdev); |
| 4885 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4886 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4887 | cb->args[1] = |
| 4888 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4889 | } |
| 4890 | |
| 4891 | if (cb->args[1]) { |
| 4892 | data = nla_data((void *)cb->args[1]); |
| 4893 | data_len = nla_len((void *)cb->args[1]); |
| 4894 | } |
| 4895 | |
| 4896 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4897 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4898 | if (!rdev) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4899 | mutex_unlock(&cfg80211_mutex); |
| 4900 | return -ENOENT; |
| 4901 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4902 | cfg80211_lock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4903 | mutex_unlock(&cfg80211_mutex); |
| 4904 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4905 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4906 | err = -EOPNOTSUPP; |
| 4907 | goto out_err; |
| 4908 | } |
| 4909 | |
| 4910 | while (1) { |
| 4911 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4912 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4913 | NL80211_CMD_TESTMODE); |
| 4914 | struct nlattr *tmdata; |
| 4915 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4916 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx) < 0) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4917 | genlmsg_cancel(skb, hdr); |
| 4918 | break; |
| 4919 | } |
| 4920 | |
| 4921 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4922 | if (!tmdata) { |
| 4923 | genlmsg_cancel(skb, hdr); |
| 4924 | break; |
| 4925 | } |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4926 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
| 4927 | data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4928 | nla_nest_end(skb, tmdata); |
| 4929 | |
| 4930 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4931 | genlmsg_cancel(skb, hdr); |
| 4932 | break; |
| 4933 | } else if (err) { |
| 4934 | genlmsg_cancel(skb, hdr); |
| 4935 | goto out_err; |
| 4936 | } |
| 4937 | |
| 4938 | genlmsg_end(skb, hdr); |
| 4939 | } |
| 4940 | |
| 4941 | err = skb->len; |
| 4942 | /* see above */ |
| 4943 | cb->args[0] = phy_idx + 1; |
| 4944 | out_err: |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 4945 | cfg80211_unlock_rdev(rdev); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4946 | return err; |
| 4947 | } |
| 4948 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4949 | static struct sk_buff * |
| 4950 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4951 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4952 | { |
| 4953 | struct sk_buff *skb; |
| 4954 | void *hdr; |
| 4955 | struct nlattr *data; |
| 4956 | |
| 4957 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4958 | if (!skb) |
| 4959 | return NULL; |
| 4960 | |
| 4961 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4962 | if (!hdr) { |
| 4963 | kfree_skb(skb); |
| 4964 | return NULL; |
| 4965 | } |
| 4966 | |
| 4967 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4968 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4969 | |
| 4970 | ((void **)skb->cb)[0] = rdev; |
| 4971 | ((void **)skb->cb)[1] = hdr; |
| 4972 | ((void **)skb->cb)[2] = data; |
| 4973 | |
| 4974 | return skb; |
| 4975 | |
| 4976 | nla_put_failure: |
| 4977 | kfree_skb(skb); |
| 4978 | return NULL; |
| 4979 | } |
| 4980 | |
| 4981 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4982 | int approxlen) |
| 4983 | { |
| 4984 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4985 | |
| 4986 | if (WARN_ON(!rdev->testmode_info)) |
| 4987 | return NULL; |
| 4988 | |
| 4989 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4990 | rdev->testmode_info->snd_pid, |
| 4991 | rdev->testmode_info->snd_seq, |
| 4992 | GFP_KERNEL); |
| 4993 | } |
| 4994 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4995 | |
| 4996 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4997 | { |
| 4998 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4999 | void *hdr = ((void **)skb->cb)[1]; |
| 5000 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5001 | |
| 5002 | if (WARN_ON(!rdev->testmode_info)) { |
| 5003 | kfree_skb(skb); |
| 5004 | return -EINVAL; |
| 5005 | } |
| 5006 | |
| 5007 | nla_nest_end(skb, data); |
| 5008 | genlmsg_end(skb, hdr); |
| 5009 | return genlmsg_reply(skb, rdev->testmode_info); |
| 5010 | } |
| 5011 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 5012 | |
| 5013 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 5014 | int approxlen, gfp_t gfp) |
| 5015 | { |
| 5016 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 5017 | |
| 5018 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 5019 | } |
| 5020 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 5021 | |
| 5022 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 5023 | { |
| 5024 | void *hdr = ((void **)skb->cb)[1]; |
| 5025 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 5026 | |
| 5027 | nla_nest_end(skb, data); |
| 5028 | genlmsg_end(skb, hdr); |
| 5029 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 5030 | } |
| 5031 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 5032 | #endif |
| 5033 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5034 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 5035 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5037 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5038 | struct cfg80211_connect_params connect; |
| 5039 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5040 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5041 | int err; |
| 5042 | |
| 5043 | memset(&connect, 0, sizeof(connect)); |
| 5044 | |
| 5045 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5046 | return -EINVAL; |
| 5047 | |
| 5048 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 5049 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 5050 | return -EINVAL; |
| 5051 | |
| 5052 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5053 | connect.auth_type = |
| 5054 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 5055 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 5056 | return -EINVAL; |
| 5057 | } else |
| 5058 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5059 | |
| 5060 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 5061 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 5062 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 5063 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5064 | if (err) |
| 5065 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5066 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5067 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5068 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5069 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5070 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5071 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5072 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5073 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5074 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5075 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5076 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5077 | |
| 5078 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5079 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5080 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5081 | } |
| 5082 | |
| 5083 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5084 | connect.channel = |
| 5085 | ieee80211_get_channel(wiphy, |
| 5086 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5087 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5088 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5089 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5090 | } |
| 5091 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5092 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5093 | connkeys = nl80211_parse_connkeys(rdev, |
| 5094 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5095 | if (IS_ERR(connkeys)) |
| 5096 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5097 | } |
| 5098 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5099 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5100 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5101 | |
| 5102 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5103 | memcpy(&connect.ht_capa_mask, |
| 5104 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5105 | sizeof(connect.ht_capa_mask)); |
| 5106 | |
| 5107 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5108 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5109 | return -EINVAL; |
| 5110 | memcpy(&connect.ht_capa, |
| 5111 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5112 | sizeof(connect.ht_capa)); |
| 5113 | } |
| 5114 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5115 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5116 | if (err) |
| 5117 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5118 | return err; |
| 5119 | } |
| 5120 | |
| 5121 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5122 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5123 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5124 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5125 | u16 reason; |
| 5126 | |
| 5127 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5128 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5129 | else |
| 5130 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5131 | |
| 5132 | if (reason == 0) |
| 5133 | return -EINVAL; |
| 5134 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5135 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5136 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5137 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5138 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5139 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5140 | } |
| 5141 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5142 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5143 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5144 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5145 | struct net *net; |
| 5146 | int err; |
| 5147 | u32 pid; |
| 5148 | |
| 5149 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5150 | return -EINVAL; |
| 5151 | |
| 5152 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5153 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5154 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5155 | if (IS_ERR(net)) |
| 5156 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5157 | |
| 5158 | err = 0; |
| 5159 | |
| 5160 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5161 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5162 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5163 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5164 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5165 | return err; |
| 5166 | } |
| 5167 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5168 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5169 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5170 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5171 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5172 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5173 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5174 | struct cfg80211_pmksa pmksa; |
| 5175 | |
| 5176 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5177 | |
| 5178 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5179 | return -EINVAL; |
| 5180 | |
| 5181 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5182 | return -EINVAL; |
| 5183 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5184 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5185 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5186 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5187 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5188 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5189 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5190 | |
| 5191 | switch (info->genlhdr->cmd) { |
| 5192 | case NL80211_CMD_SET_PMKSA: |
| 5193 | rdev_ops = rdev->ops->set_pmksa; |
| 5194 | break; |
| 5195 | case NL80211_CMD_DEL_PMKSA: |
| 5196 | rdev_ops = rdev->ops->del_pmksa; |
| 5197 | break; |
| 5198 | default: |
| 5199 | WARN_ON(1); |
| 5200 | break; |
| 5201 | } |
| 5202 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5203 | if (!rdev_ops) |
| 5204 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5205 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5206 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5207 | } |
| 5208 | |
| 5209 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5210 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5211 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5212 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5213 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5214 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5215 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5216 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5217 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5218 | if (!rdev->ops->flush_pmksa) |
| 5219 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5220 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5221 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5222 | } |
| 5223 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5224 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5225 | { |
| 5226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5227 | struct net_device *dev = info->user_ptr[1]; |
| 5228 | u8 action_code, dialog_token; |
| 5229 | u16 status_code; |
| 5230 | u8 *peer; |
| 5231 | |
| 5232 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5233 | !rdev->ops->tdls_mgmt) |
| 5234 | return -EOPNOTSUPP; |
| 5235 | |
| 5236 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5237 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5238 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5239 | !info->attrs[NL80211_ATTR_IE] || |
| 5240 | !info->attrs[NL80211_ATTR_MAC]) |
| 5241 | return -EINVAL; |
| 5242 | |
| 5243 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5244 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5245 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5246 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5247 | |
| 5248 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5249 | dialog_token, status_code, |
| 5250 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5251 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5252 | } |
| 5253 | |
| 5254 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5255 | { |
| 5256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5257 | struct net_device *dev = info->user_ptr[1]; |
| 5258 | enum nl80211_tdls_operation operation; |
| 5259 | u8 *peer; |
| 5260 | |
| 5261 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5262 | !rdev->ops->tdls_oper) |
| 5263 | return -EOPNOTSUPP; |
| 5264 | |
| 5265 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5266 | !info->attrs[NL80211_ATTR_MAC]) |
| 5267 | return -EINVAL; |
| 5268 | |
| 5269 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5270 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5271 | |
| 5272 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5273 | } |
| 5274 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5275 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5276 | struct genl_info *info) |
| 5277 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5279 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5280 | struct ieee80211_channel *chan; |
| 5281 | struct sk_buff *msg; |
| 5282 | void *hdr; |
| 5283 | u64 cookie; |
| 5284 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5285 | u32 freq, duration; |
| 5286 | int err; |
| 5287 | |
| 5288 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5289 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5290 | return -EINVAL; |
| 5291 | |
| 5292 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5293 | |
| 5294 | /* |
| 5295 | * We should be on that channel for at least one jiffie, |
| 5296 | * and more than 5 seconds seems excessive. |
| 5297 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5298 | if (!duration || !msecs_to_jiffies(duration) || |
| 5299 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5300 | return -EINVAL; |
| 5301 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5302 | if (!rdev->ops->remain_on_channel || |
| 5303 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5304 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5305 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5306 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5307 | channel_type = nla_get_u32( |
| 5308 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5309 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5310 | channel_type != NL80211_CHAN_HT20 && |
| 5311 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5312 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5313 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5314 | } |
| 5315 | |
| 5316 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5317 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5318 | if (chan == NULL) |
| 5319 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5320 | |
| 5321 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5322 | if (!msg) |
| 5323 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5324 | |
| 5325 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5326 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5327 | |
| 5328 | if (IS_ERR(hdr)) { |
| 5329 | err = PTR_ERR(hdr); |
| 5330 | goto free_msg; |
| 5331 | } |
| 5332 | |
| 5333 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5334 | channel_type, duration, &cookie); |
| 5335 | |
| 5336 | if (err) |
| 5337 | goto free_msg; |
| 5338 | |
| 5339 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5340 | |
| 5341 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5342 | |
| 5343 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5344 | |
| 5345 | nla_put_failure: |
| 5346 | err = -ENOBUFS; |
| 5347 | free_msg: |
| 5348 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5349 | return err; |
| 5350 | } |
| 5351 | |
| 5352 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5353 | struct genl_info *info) |
| 5354 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5356 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5357 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5358 | |
| 5359 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5360 | return -EINVAL; |
| 5361 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5362 | if (!rdev->ops->cancel_remain_on_channel) |
| 5363 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5364 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5365 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5366 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5367 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5368 | } |
| 5369 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5370 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5371 | u8 *rates, u8 rates_len) |
| 5372 | { |
| 5373 | u8 i; |
| 5374 | u32 mask = 0; |
| 5375 | |
| 5376 | for (i = 0; i < rates_len; i++) { |
| 5377 | int rate = (rates[i] & 0x7f) * 5; |
| 5378 | int ridx; |
| 5379 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5380 | struct ieee80211_rate *srate = |
| 5381 | &sband->bitrates[ridx]; |
| 5382 | if (rate == srate->bitrate) { |
| 5383 | mask |= 1 << ridx; |
| 5384 | break; |
| 5385 | } |
| 5386 | } |
| 5387 | if (ridx == sband->n_bitrates) |
| 5388 | return 0; /* rate not found */ |
| 5389 | } |
| 5390 | |
| 5391 | return mask; |
| 5392 | } |
| 5393 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5394 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5395 | u8 *rates, u8 rates_len, |
| 5396 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 5397 | { |
| 5398 | u8 i; |
| 5399 | |
| 5400 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 5401 | |
| 5402 | for (i = 0; i < rates_len; i++) { |
| 5403 | int ridx, rbit; |
| 5404 | |
| 5405 | ridx = rates[i] / 8; |
| 5406 | rbit = BIT(rates[i] % 8); |
| 5407 | |
| 5408 | /* check validity */ |
| 5409 | if ((ridx < 0) || (ridx > IEEE80211_HT_MCS_MASK_LEN)) |
| 5410 | return false; |
| 5411 | |
| 5412 | /* check availability */ |
| 5413 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 5414 | mcs[ridx] |= rbit; |
| 5415 | else |
| 5416 | return false; |
| 5417 | } |
| 5418 | |
| 5419 | return true; |
| 5420 | } |
| 5421 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5422 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5423 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5424 | .len = NL80211_MAX_SUPP_RATES }, |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5425 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
| 5426 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5427 | }; |
| 5428 | |
| 5429 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5430 | struct genl_info *info) |
| 5431 | { |
| 5432 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5433 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5434 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5435 | int rem, i; |
| 5436 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5437 | struct nlattr *tx_rates; |
| 5438 | struct ieee80211_supported_band *sband; |
| 5439 | |
| 5440 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5441 | return -EINVAL; |
| 5442 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5443 | if (!rdev->ops->set_bitrate_mask) |
| 5444 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5445 | |
| 5446 | memset(&mask, 0, sizeof(mask)); |
| 5447 | /* Default to all rates enabled */ |
| 5448 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5449 | sband = rdev->wiphy.bands[i]; |
| 5450 | mask.control[i].legacy = |
| 5451 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5452 | if (sband) |
| 5453 | memcpy(mask.control[i].mcs, |
| 5454 | sband->ht_cap.mcs.rx_mask, |
| 5455 | sizeof(mask.control[i].mcs)); |
| 5456 | else |
| 5457 | memset(mask.control[i].mcs, 0, |
| 5458 | sizeof(mask.control[i].mcs)); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5459 | } |
| 5460 | |
| 5461 | /* |
| 5462 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5463 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5464 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5465 | 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] | 5466 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5467 | { |
| 5468 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5469 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5470 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5471 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5472 | if (sband == NULL) |
| 5473 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5474 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5475 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5476 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5477 | mask.control[band].legacy = rateset_to_mask( |
| 5478 | sband, |
| 5479 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5480 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 5481 | } |
| 5482 | if (tb[NL80211_TXRATE_MCS]) { |
| 5483 | if (!ht_rateset_to_mask( |
| 5484 | sband, |
| 5485 | nla_data(tb[NL80211_TXRATE_MCS]), |
| 5486 | nla_len(tb[NL80211_TXRATE_MCS]), |
| 5487 | mask.control[band].mcs)) |
| 5488 | return -EINVAL; |
| 5489 | } |
| 5490 | |
| 5491 | if (mask.control[band].legacy == 0) { |
| 5492 | /* don't allow empty legacy rates if HT |
| 5493 | * is not even supported. */ |
| 5494 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) |
| 5495 | return -EINVAL; |
| 5496 | |
| 5497 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 5498 | if (mask.control[band].mcs[i]) |
| 5499 | break; |
| 5500 | |
| 5501 | /* legacy and mcs rates may not be both empty */ |
| 5502 | if (i == IEEE80211_HT_MCS_MASK_LEN) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5503 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5504 | } |
| 5505 | } |
| 5506 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5507 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5508 | } |
| 5509 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5510 | 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] | 5511 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5513 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5514 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5515 | |
| 5516 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5517 | return -EINVAL; |
| 5518 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5519 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5520 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5521 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5522 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5523 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5524 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5525 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5526 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5527 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5528 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5529 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5530 | |
| 5531 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5532 | if (!rdev->ops->mgmt_tx) |
| 5533 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5534 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5535 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5536 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5537 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5538 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5539 | } |
| 5540 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5541 | 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] | 5542 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5543 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5544 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5545 | struct ieee80211_channel *chan; |
| 5546 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5547 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5548 | u32 freq; |
| 5549 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 5550 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5551 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5552 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5553 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5554 | bool offchan, no_cck, dont_wait_for_ack; |
| 5555 | |
| 5556 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5557 | |
| 5558 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5559 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5560 | return -EINVAL; |
| 5561 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5562 | if (!rdev->ops->mgmt_tx) |
| 5563 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5564 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5565 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5566 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5567 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5568 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5569 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5570 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5571 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5572 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5573 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5574 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5575 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5576 | return -EINVAL; |
| 5577 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5578 | } |
| 5579 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5580 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5581 | channel_type = nla_get_u32( |
| 5582 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5583 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5584 | channel_type != NL80211_CHAN_HT20 && |
| 5585 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5586 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5587 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5588 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5589 | } |
| 5590 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5591 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5592 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5593 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 5594 | return -EINVAL; |
| 5595 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5596 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5597 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5598 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5599 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5600 | if (chan == NULL) |
| 5601 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5602 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5603 | if (!dont_wait_for_ack) { |
| 5604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5605 | if (!msg) |
| 5606 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5607 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5608 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5609 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5610 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5611 | if (IS_ERR(hdr)) { |
| 5612 | err = PTR_ERR(hdr); |
| 5613 | goto free_msg; |
| 5614 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5615 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5616 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5617 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5618 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5619 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5620 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5621 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5622 | if (err) |
| 5623 | goto free_msg; |
| 5624 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5625 | if (msg) { |
| 5626 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5627 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5628 | genlmsg_end(msg, hdr); |
| 5629 | return genlmsg_reply(msg, info); |
| 5630 | } |
| 5631 | |
| 5632 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5633 | |
| 5634 | nla_put_failure: |
| 5635 | err = -ENOBUFS; |
| 5636 | free_msg: |
| 5637 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5638 | return err; |
| 5639 | } |
| 5640 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5641 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5642 | { |
| 5643 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5644 | struct net_device *dev = info->user_ptr[1]; |
| 5645 | u64 cookie; |
| 5646 | |
| 5647 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5648 | return -EINVAL; |
| 5649 | |
| 5650 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5651 | return -EOPNOTSUPP; |
| 5652 | |
| 5653 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5654 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5655 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5656 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5657 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5658 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5659 | return -EOPNOTSUPP; |
| 5660 | |
| 5661 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5662 | |
| 5663 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5664 | } |
| 5665 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5666 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5667 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5669 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5670 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5671 | u8 ps_state; |
| 5672 | bool state; |
| 5673 | int err; |
| 5674 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5675 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5676 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5677 | |
| 5678 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5680 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5681 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5682 | |
| 5683 | wdev = dev->ieee80211_ptr; |
| 5684 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5685 | if (!rdev->ops->set_power_mgmt) |
| 5686 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5687 | |
| 5688 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5689 | |
| 5690 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5691 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5692 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5693 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5694 | wdev->ps_timeout); |
| 5695 | if (!err) |
| 5696 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5697 | return err; |
| 5698 | } |
| 5699 | |
| 5700 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5701 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5703 | enum nl80211_ps_state ps_state; |
| 5704 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5705 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5706 | struct sk_buff *msg; |
| 5707 | void *hdr; |
| 5708 | int err; |
| 5709 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5710 | wdev = dev->ieee80211_ptr; |
| 5711 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5712 | if (!rdev->ops->set_power_mgmt) |
| 5713 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5714 | |
| 5715 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5716 | if (!msg) |
| 5717 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5718 | |
| 5719 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5720 | NL80211_CMD_GET_POWER_SAVE); |
| 5721 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5722 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5723 | goto free_msg; |
| 5724 | } |
| 5725 | |
| 5726 | if (wdev->ps) |
| 5727 | ps_state = NL80211_PS_ENABLED; |
| 5728 | else |
| 5729 | ps_state = NL80211_PS_DISABLED; |
| 5730 | |
| 5731 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5732 | |
| 5733 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5734 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5735 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5736 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5737 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5738 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5739 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5740 | return err; |
| 5741 | } |
| 5742 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5743 | static struct nla_policy |
| 5744 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5745 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5746 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5747 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5748 | }; |
| 5749 | |
| 5750 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5751 | s32 threshold, u32 hysteresis) |
| 5752 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5753 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5754 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5755 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5756 | |
| 5757 | if (threshold > 0) |
| 5758 | return -EINVAL; |
| 5759 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5760 | wdev = dev->ieee80211_ptr; |
| 5761 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5762 | if (!rdev->ops->set_cqm_rssi_config) |
| 5763 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5764 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5765 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5766 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5767 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5768 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5769 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5770 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5771 | } |
| 5772 | |
| 5773 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5774 | { |
| 5775 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5776 | struct nlattr *cqm; |
| 5777 | int err; |
| 5778 | |
| 5779 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5780 | if (!cqm) { |
| 5781 | err = -EINVAL; |
| 5782 | goto out; |
| 5783 | } |
| 5784 | |
| 5785 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5786 | nl80211_attr_cqm_policy); |
| 5787 | if (err) |
| 5788 | goto out; |
| 5789 | |
| 5790 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5791 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5792 | s32 threshold; |
| 5793 | u32 hysteresis; |
| 5794 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5795 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5796 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5797 | } else |
| 5798 | err = -EINVAL; |
| 5799 | |
| 5800 | out: |
| 5801 | return err; |
| 5802 | } |
| 5803 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5804 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5805 | { |
| 5806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5807 | struct net_device *dev = info->user_ptr[1]; |
| 5808 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5809 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5810 | int err; |
| 5811 | |
| 5812 | /* start with default */ |
| 5813 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5814 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5815 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5816 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5817 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5818 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5819 | if (err) |
| 5820 | return err; |
| 5821 | } |
| 5822 | |
| 5823 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5824 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5825 | return -EINVAL; |
| 5826 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5827 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5828 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5829 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 5830 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5831 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 5832 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5833 | return -EINVAL; |
| 5834 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5835 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5836 | /* parse additional setup parameters if given */ |
| 5837 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5838 | if (err) |
| 5839 | return err; |
| 5840 | } |
| 5841 | |
| 5842 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5846 | { |
| 5847 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5848 | struct net_device *dev = info->user_ptr[1]; |
| 5849 | |
| 5850 | return cfg80211_leave_mesh(rdev, dev); |
| 5851 | } |
| 5852 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5853 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5854 | { |
| 5855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5856 | struct sk_buff *msg; |
| 5857 | void *hdr; |
| 5858 | |
| 5859 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5860 | return -EOPNOTSUPP; |
| 5861 | |
| 5862 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5863 | if (!msg) |
| 5864 | return -ENOMEM; |
| 5865 | |
| 5866 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5867 | NL80211_CMD_GET_WOWLAN); |
| 5868 | if (!hdr) |
| 5869 | goto nla_put_failure; |
| 5870 | |
| 5871 | if (rdev->wowlan) { |
| 5872 | struct nlattr *nl_wowlan; |
| 5873 | |
| 5874 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5875 | if (!nl_wowlan) |
| 5876 | goto nla_put_failure; |
| 5877 | |
| 5878 | if (rdev->wowlan->any) |
| 5879 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5880 | if (rdev->wowlan->disconnect) |
| 5881 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5882 | if (rdev->wowlan->magic_pkt) |
| 5883 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5884 | if (rdev->wowlan->gtk_rekey_failure) |
| 5885 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5886 | if (rdev->wowlan->eap_identity_req) |
| 5887 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5888 | if (rdev->wowlan->four_way_handshake) |
| 5889 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5890 | if (rdev->wowlan->rfkill_release) |
| 5891 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5892 | if (rdev->wowlan->n_patterns) { |
| 5893 | struct nlattr *nl_pats, *nl_pat; |
| 5894 | int i, pat_len; |
| 5895 | |
| 5896 | nl_pats = nla_nest_start(msg, |
| 5897 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5898 | if (!nl_pats) |
| 5899 | goto nla_put_failure; |
| 5900 | |
| 5901 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5902 | nl_pat = nla_nest_start(msg, i + 1); |
| 5903 | if (!nl_pat) |
| 5904 | goto nla_put_failure; |
| 5905 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5906 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5907 | DIV_ROUND_UP(pat_len, 8), |
| 5908 | rdev->wowlan->patterns[i].mask); |
| 5909 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5910 | pat_len, |
| 5911 | rdev->wowlan->patterns[i].pattern); |
| 5912 | nla_nest_end(msg, nl_pat); |
| 5913 | } |
| 5914 | nla_nest_end(msg, nl_pats); |
| 5915 | } |
| 5916 | |
| 5917 | nla_nest_end(msg, nl_wowlan); |
| 5918 | } |
| 5919 | |
| 5920 | genlmsg_end(msg, hdr); |
| 5921 | return genlmsg_reply(msg, info); |
| 5922 | |
| 5923 | nla_put_failure: |
| 5924 | nlmsg_free(msg); |
| 5925 | return -ENOBUFS; |
| 5926 | } |
| 5927 | |
| 5928 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5929 | { |
| 5930 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5931 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5932 | struct cfg80211_wowlan no_triggers = {}; |
| 5933 | struct cfg80211_wowlan new_triggers = {}; |
| 5934 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5935 | int err, i; |
| 5936 | |
| 5937 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5938 | return -EOPNOTSUPP; |
| 5939 | |
| 5940 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5941 | goto no_triggers; |
| 5942 | |
| 5943 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5944 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5945 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5946 | nl80211_wowlan_policy); |
| 5947 | if (err) |
| 5948 | return err; |
| 5949 | |
| 5950 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5951 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5952 | return -EINVAL; |
| 5953 | new_triggers.any = true; |
| 5954 | } |
| 5955 | |
| 5956 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5957 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5958 | return -EINVAL; |
| 5959 | new_triggers.disconnect = true; |
| 5960 | } |
| 5961 | |
| 5962 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5963 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5964 | return -EINVAL; |
| 5965 | new_triggers.magic_pkt = true; |
| 5966 | } |
| 5967 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5968 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5969 | return -EINVAL; |
| 5970 | |
| 5971 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5972 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5973 | return -EINVAL; |
| 5974 | new_triggers.gtk_rekey_failure = true; |
| 5975 | } |
| 5976 | |
| 5977 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5978 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5979 | return -EINVAL; |
| 5980 | new_triggers.eap_identity_req = true; |
| 5981 | } |
| 5982 | |
| 5983 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5984 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5985 | return -EINVAL; |
| 5986 | new_triggers.four_way_handshake = true; |
| 5987 | } |
| 5988 | |
| 5989 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5990 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5991 | return -EINVAL; |
| 5992 | new_triggers.rfkill_release = true; |
| 5993 | } |
| 5994 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5995 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5996 | struct nlattr *pat; |
| 5997 | int n_patterns = 0; |
| 5998 | int rem, pat_len, mask_len; |
| 5999 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 6000 | |
| 6001 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6002 | rem) |
| 6003 | n_patterns++; |
| 6004 | if (n_patterns > wowlan->n_patterns) |
| 6005 | return -EINVAL; |
| 6006 | |
| 6007 | new_triggers.patterns = kcalloc(n_patterns, |
| 6008 | sizeof(new_triggers.patterns[0]), |
| 6009 | GFP_KERNEL); |
| 6010 | if (!new_triggers.patterns) |
| 6011 | return -ENOMEM; |
| 6012 | |
| 6013 | new_triggers.n_patterns = n_patterns; |
| 6014 | i = 0; |
| 6015 | |
| 6016 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 6017 | rem) { |
| 6018 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 6019 | nla_data(pat), nla_len(pat), NULL); |
| 6020 | err = -EINVAL; |
| 6021 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 6022 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 6023 | goto error; |
| 6024 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 6025 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 6026 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 6027 | mask_len) |
| 6028 | goto error; |
| 6029 | if (pat_len > wowlan->pattern_max_len || |
| 6030 | pat_len < wowlan->pattern_min_len) |
| 6031 | goto error; |
| 6032 | |
| 6033 | new_triggers.patterns[i].mask = |
| 6034 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 6035 | if (!new_triggers.patterns[i].mask) { |
| 6036 | err = -ENOMEM; |
| 6037 | goto error; |
| 6038 | } |
| 6039 | new_triggers.patterns[i].pattern = |
| 6040 | new_triggers.patterns[i].mask + mask_len; |
| 6041 | memcpy(new_triggers.patterns[i].mask, |
| 6042 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 6043 | mask_len); |
| 6044 | new_triggers.patterns[i].pattern_len = pat_len; |
| 6045 | memcpy(new_triggers.patterns[i].pattern, |
| 6046 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 6047 | pat_len); |
| 6048 | i++; |
| 6049 | } |
| 6050 | } |
| 6051 | |
| 6052 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 6053 | struct cfg80211_wowlan *ntrig; |
| 6054 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 6055 | GFP_KERNEL); |
| 6056 | if (!ntrig) { |
| 6057 | err = -ENOMEM; |
| 6058 | goto error; |
| 6059 | } |
| 6060 | cfg80211_rdev_free_wowlan(rdev); |
| 6061 | rdev->wowlan = ntrig; |
| 6062 | } else { |
| 6063 | no_triggers: |
| 6064 | cfg80211_rdev_free_wowlan(rdev); |
| 6065 | rdev->wowlan = NULL; |
| 6066 | } |
| 6067 | |
| 6068 | return 0; |
| 6069 | error: |
| 6070 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 6071 | kfree(new_triggers.patterns[i].mask); |
| 6072 | kfree(new_triggers.patterns); |
| 6073 | return err; |
| 6074 | } |
| 6075 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6076 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 6077 | { |
| 6078 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6079 | struct net_device *dev = info->user_ptr[1]; |
| 6080 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6081 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 6082 | struct cfg80211_gtk_rekey_data rekey_data; |
| 6083 | int err; |
| 6084 | |
| 6085 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 6086 | return -EINVAL; |
| 6087 | |
| 6088 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 6089 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6090 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 6091 | nl80211_rekey_policy); |
| 6092 | if (err) |
| 6093 | return err; |
| 6094 | |
| 6095 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 6096 | return -ERANGE; |
| 6097 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 6098 | return -ERANGE; |
| 6099 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 6100 | return -ERANGE; |
| 6101 | |
| 6102 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 6103 | NL80211_KEK_LEN); |
| 6104 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 6105 | NL80211_KCK_LEN); |
| 6106 | memcpy(rekey_data.replay_ctr, |
| 6107 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 6108 | NL80211_REPLAY_CTR_LEN); |
| 6109 | |
| 6110 | wdev_lock(wdev); |
| 6111 | if (!wdev->current_bss) { |
| 6112 | err = -ENOTCONN; |
| 6113 | goto out; |
| 6114 | } |
| 6115 | |
| 6116 | if (!rdev->ops->set_rekey_data) { |
| 6117 | err = -EOPNOTSUPP; |
| 6118 | goto out; |
| 6119 | } |
| 6120 | |
| 6121 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 6122 | out: |
| 6123 | wdev_unlock(wdev); |
| 6124 | return err; |
| 6125 | } |
| 6126 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6127 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6128 | struct genl_info *info) |
| 6129 | { |
| 6130 | struct net_device *dev = info->user_ptr[1]; |
| 6131 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6132 | |
| 6133 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6134 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6135 | return -EINVAL; |
| 6136 | |
| 6137 | if (wdev->ap_unexpected_nlpid) |
| 6138 | return -EBUSY; |
| 6139 | |
| 6140 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 6141 | return 0; |
| 6142 | } |
| 6143 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6144 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6145 | struct genl_info *info) |
| 6146 | { |
| 6147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6148 | struct net_device *dev = info->user_ptr[1]; |
| 6149 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6150 | struct sk_buff *msg; |
| 6151 | void *hdr; |
| 6152 | const u8 *addr; |
| 6153 | u64 cookie; |
| 6154 | int err; |
| 6155 | |
| 6156 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6157 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6158 | return -EOPNOTSUPP; |
| 6159 | |
| 6160 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6161 | return -EINVAL; |
| 6162 | |
| 6163 | if (!rdev->ops->probe_client) |
| 6164 | return -EOPNOTSUPP; |
| 6165 | |
| 6166 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6167 | if (!msg) |
| 6168 | return -ENOMEM; |
| 6169 | |
| 6170 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6171 | NL80211_CMD_PROBE_CLIENT); |
| 6172 | |
| 6173 | if (IS_ERR(hdr)) { |
| 6174 | err = PTR_ERR(hdr); |
| 6175 | goto free_msg; |
| 6176 | } |
| 6177 | |
| 6178 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6179 | |
| 6180 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6181 | if (err) |
| 6182 | goto free_msg; |
| 6183 | |
| 6184 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6185 | |
| 6186 | genlmsg_end(msg, hdr); |
| 6187 | |
| 6188 | return genlmsg_reply(msg, info); |
| 6189 | |
| 6190 | nla_put_failure: |
| 6191 | err = -ENOBUFS; |
| 6192 | free_msg: |
| 6193 | nlmsg_free(msg); |
| 6194 | return err; |
| 6195 | } |
| 6196 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6197 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6198 | { |
| 6199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6200 | |
| 6201 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6202 | return -EOPNOTSUPP; |
| 6203 | |
| 6204 | if (rdev->ap_beacons_nlpid) |
| 6205 | return -EBUSY; |
| 6206 | |
| 6207 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 6208 | |
| 6209 | return 0; |
| 6210 | } |
| 6211 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6212 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6213 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6214 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6215 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6216 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6217 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6218 | |
| 6219 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6220 | struct genl_info *info) |
| 6221 | { |
| 6222 | struct cfg80211_registered_device *rdev; |
| 6223 | struct net_device *dev; |
| 6224 | int err; |
| 6225 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6226 | |
| 6227 | if (rtnl) |
| 6228 | rtnl_lock(); |
| 6229 | |
| 6230 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 6231 | rdev = cfg80211_get_dev_from_info(info); |
| 6232 | if (IS_ERR(rdev)) { |
| 6233 | if (rtnl) |
| 6234 | rtnl_unlock(); |
| 6235 | return PTR_ERR(rdev); |
| 6236 | } |
| 6237 | info->user_ptr[0] = rdev; |
| 6238 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 6239 | err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs, |
| 6240 | &rdev, &dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6241 | if (err) { |
| 6242 | if (rtnl) |
| 6243 | rtnl_unlock(); |
| 6244 | return err; |
| 6245 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6246 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 6247 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 6248 | cfg80211_unlock_rdev(rdev); |
| 6249 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6250 | if (rtnl) |
| 6251 | rtnl_unlock(); |
| 6252 | return -ENETDOWN; |
| 6253 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6254 | info->user_ptr[0] = rdev; |
| 6255 | info->user_ptr[1] = dev; |
| 6256 | } |
| 6257 | |
| 6258 | return 0; |
| 6259 | } |
| 6260 | |
| 6261 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6262 | struct genl_info *info) |
| 6263 | { |
| 6264 | if (info->user_ptr[0]) |
| 6265 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 6266 | if (info->user_ptr[1]) |
| 6267 | dev_put(info->user_ptr[1]); |
| 6268 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6269 | rtnl_unlock(); |
| 6270 | } |
| 6271 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6272 | static struct genl_ops nl80211_ops[] = { |
| 6273 | { |
| 6274 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6275 | .doit = nl80211_get_wiphy, |
| 6276 | .dumpit = nl80211_dump_wiphy, |
| 6277 | .policy = nl80211_policy, |
| 6278 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6279 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6280 | }, |
| 6281 | { |
| 6282 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6283 | .doit = nl80211_set_wiphy, |
| 6284 | .policy = nl80211_policy, |
| 6285 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6286 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6287 | }, |
| 6288 | { |
| 6289 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6290 | .doit = nl80211_get_interface, |
| 6291 | .dumpit = nl80211_dump_interface, |
| 6292 | .policy = nl80211_policy, |
| 6293 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6294 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6295 | }, |
| 6296 | { |
| 6297 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6298 | .doit = nl80211_set_interface, |
| 6299 | .policy = nl80211_policy, |
| 6300 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6301 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6302 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6303 | }, |
| 6304 | { |
| 6305 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6306 | .doit = nl80211_new_interface, |
| 6307 | .policy = nl80211_policy, |
| 6308 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6309 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6310 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6311 | }, |
| 6312 | { |
| 6313 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6314 | .doit = nl80211_del_interface, |
| 6315 | .policy = nl80211_policy, |
| 6316 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6317 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6318 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6319 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6320 | { |
| 6321 | .cmd = NL80211_CMD_GET_KEY, |
| 6322 | .doit = nl80211_get_key, |
| 6323 | .policy = nl80211_policy, |
| 6324 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6325 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6326 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6327 | }, |
| 6328 | { |
| 6329 | .cmd = NL80211_CMD_SET_KEY, |
| 6330 | .doit = nl80211_set_key, |
| 6331 | .policy = nl80211_policy, |
| 6332 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6333 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6334 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6335 | }, |
| 6336 | { |
| 6337 | .cmd = NL80211_CMD_NEW_KEY, |
| 6338 | .doit = nl80211_new_key, |
| 6339 | .policy = nl80211_policy, |
| 6340 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6341 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6342 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6343 | }, |
| 6344 | { |
| 6345 | .cmd = NL80211_CMD_DEL_KEY, |
| 6346 | .doit = nl80211_del_key, |
| 6347 | .policy = nl80211_policy, |
| 6348 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6349 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6350 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6351 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6352 | { |
| 6353 | .cmd = NL80211_CMD_SET_BEACON, |
| 6354 | .policy = nl80211_policy, |
| 6355 | .flags = GENL_ADMIN_PERM, |
| 6356 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6357 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6358 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6359 | }, |
| 6360 | { |
| 6361 | .cmd = NL80211_CMD_NEW_BEACON, |
| 6362 | .policy = nl80211_policy, |
| 6363 | .flags = GENL_ADMIN_PERM, |
| 6364 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6365 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6366 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6367 | }, |
| 6368 | { |
| 6369 | .cmd = NL80211_CMD_DEL_BEACON, |
| 6370 | .policy = nl80211_policy, |
| 6371 | .flags = GENL_ADMIN_PERM, |
| 6372 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6373 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6374 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6375 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6376 | { |
| 6377 | .cmd = NL80211_CMD_GET_STATION, |
| 6378 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6379 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6380 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6382 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6383 | }, |
| 6384 | { |
| 6385 | .cmd = NL80211_CMD_SET_STATION, |
| 6386 | .doit = nl80211_set_station, |
| 6387 | .policy = nl80211_policy, |
| 6388 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6389 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6390 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6391 | }, |
| 6392 | { |
| 6393 | .cmd = NL80211_CMD_NEW_STATION, |
| 6394 | .doit = nl80211_new_station, |
| 6395 | .policy = nl80211_policy, |
| 6396 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6397 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6398 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6399 | }, |
| 6400 | { |
| 6401 | .cmd = NL80211_CMD_DEL_STATION, |
| 6402 | .doit = nl80211_del_station, |
| 6403 | .policy = nl80211_policy, |
| 6404 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6405 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6406 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6407 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6408 | { |
| 6409 | .cmd = NL80211_CMD_GET_MPATH, |
| 6410 | .doit = nl80211_get_mpath, |
| 6411 | .dumpit = nl80211_dump_mpath, |
| 6412 | .policy = nl80211_policy, |
| 6413 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6414 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6415 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6416 | }, |
| 6417 | { |
| 6418 | .cmd = NL80211_CMD_SET_MPATH, |
| 6419 | .doit = nl80211_set_mpath, |
| 6420 | .policy = nl80211_policy, |
| 6421 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6422 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6423 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6424 | }, |
| 6425 | { |
| 6426 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6427 | .doit = nl80211_new_mpath, |
| 6428 | .policy = nl80211_policy, |
| 6429 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6430 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6431 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6432 | }, |
| 6433 | { |
| 6434 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6435 | .doit = nl80211_del_mpath, |
| 6436 | .policy = nl80211_policy, |
| 6437 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6438 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6439 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6440 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6441 | { |
| 6442 | .cmd = NL80211_CMD_SET_BSS, |
| 6443 | .doit = nl80211_set_bss, |
| 6444 | .policy = nl80211_policy, |
| 6445 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6446 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6447 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6448 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6449 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6450 | .cmd = NL80211_CMD_GET_REG, |
| 6451 | .doit = nl80211_get_reg, |
| 6452 | .policy = nl80211_policy, |
| 6453 | /* can be retrieved by unprivileged users */ |
| 6454 | }, |
| 6455 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6456 | .cmd = NL80211_CMD_SET_REG, |
| 6457 | .doit = nl80211_set_reg, |
| 6458 | .policy = nl80211_policy, |
| 6459 | .flags = GENL_ADMIN_PERM, |
| 6460 | }, |
| 6461 | { |
| 6462 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6463 | .doit = nl80211_req_set_reg, |
| 6464 | .policy = nl80211_policy, |
| 6465 | .flags = GENL_ADMIN_PERM, |
| 6466 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6467 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6468 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6469 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6470 | .policy = nl80211_policy, |
| 6471 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6472 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6473 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6474 | }, |
| 6475 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6476 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6477 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6478 | .policy = nl80211_policy, |
| 6479 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6480 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6481 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6482 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6483 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6484 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6485 | .doit = nl80211_trigger_scan, |
| 6486 | .policy = nl80211_policy, |
| 6487 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6488 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6489 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6490 | }, |
| 6491 | { |
| 6492 | .cmd = NL80211_CMD_GET_SCAN, |
| 6493 | .policy = nl80211_policy, |
| 6494 | .dumpit = nl80211_dump_scan, |
| 6495 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6496 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6497 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6498 | .doit = nl80211_start_sched_scan, |
| 6499 | .policy = nl80211_policy, |
| 6500 | .flags = GENL_ADMIN_PERM, |
| 6501 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6502 | NL80211_FLAG_NEED_RTNL, |
| 6503 | }, |
| 6504 | { |
| 6505 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6506 | .doit = nl80211_stop_sched_scan, |
| 6507 | .policy = nl80211_policy, |
| 6508 | .flags = GENL_ADMIN_PERM, |
| 6509 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6510 | NL80211_FLAG_NEED_RTNL, |
| 6511 | }, |
| 6512 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6513 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6514 | .doit = nl80211_authenticate, |
| 6515 | .policy = nl80211_policy, |
| 6516 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6517 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6518 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6519 | }, |
| 6520 | { |
| 6521 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6522 | .doit = nl80211_associate, |
| 6523 | .policy = nl80211_policy, |
| 6524 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6525 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6526 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6527 | }, |
| 6528 | { |
| 6529 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6530 | .doit = nl80211_deauthenticate, |
| 6531 | .policy = nl80211_policy, |
| 6532 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6533 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6534 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6535 | }, |
| 6536 | { |
| 6537 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6538 | .doit = nl80211_disassociate, |
| 6539 | .policy = nl80211_policy, |
| 6540 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6541 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6542 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6543 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6544 | { |
| 6545 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6546 | .doit = nl80211_join_ibss, |
| 6547 | .policy = nl80211_policy, |
| 6548 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6549 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6550 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6551 | }, |
| 6552 | { |
| 6553 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6554 | .doit = nl80211_leave_ibss, |
| 6555 | .policy = nl80211_policy, |
| 6556 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6557 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6558 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6559 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6560 | #ifdef CONFIG_NL80211_TESTMODE |
| 6561 | { |
| 6562 | .cmd = NL80211_CMD_TESTMODE, |
| 6563 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6564 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6565 | .policy = nl80211_policy, |
| 6566 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6567 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6568 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6569 | }, |
| 6570 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6571 | { |
| 6572 | .cmd = NL80211_CMD_CONNECT, |
| 6573 | .doit = nl80211_connect, |
| 6574 | .policy = nl80211_policy, |
| 6575 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6576 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6577 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6578 | }, |
| 6579 | { |
| 6580 | .cmd = NL80211_CMD_DISCONNECT, |
| 6581 | .doit = nl80211_disconnect, |
| 6582 | .policy = nl80211_policy, |
| 6583 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6584 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6585 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6586 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6587 | { |
| 6588 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6589 | .doit = nl80211_wiphy_netns, |
| 6590 | .policy = nl80211_policy, |
| 6591 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6592 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6593 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6594 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6595 | { |
| 6596 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6597 | .policy = nl80211_policy, |
| 6598 | .dumpit = nl80211_dump_survey, |
| 6599 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6600 | { |
| 6601 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6602 | .doit = nl80211_setdel_pmksa, |
| 6603 | .policy = nl80211_policy, |
| 6604 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6605 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6606 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6607 | }, |
| 6608 | { |
| 6609 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6610 | .doit = nl80211_setdel_pmksa, |
| 6611 | .policy = nl80211_policy, |
| 6612 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6613 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6614 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6615 | }, |
| 6616 | { |
| 6617 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6618 | .doit = nl80211_flush_pmksa, |
| 6619 | .policy = nl80211_policy, |
| 6620 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6621 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6622 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6623 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6624 | { |
| 6625 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6626 | .doit = nl80211_remain_on_channel, |
| 6627 | .policy = nl80211_policy, |
| 6628 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6629 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6630 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6631 | }, |
| 6632 | { |
| 6633 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6634 | .doit = nl80211_cancel_remain_on_channel, |
| 6635 | .policy = nl80211_policy, |
| 6636 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6637 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6638 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6639 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6640 | { |
| 6641 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6642 | .doit = nl80211_set_tx_bitrate_mask, |
| 6643 | .policy = nl80211_policy, |
| 6644 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6645 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6646 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6647 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6648 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6649 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6650 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6651 | .policy = nl80211_policy, |
| 6652 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6653 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6654 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6655 | }, |
| 6656 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6657 | .cmd = NL80211_CMD_FRAME, |
| 6658 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 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, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6663 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6664 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6665 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6666 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6667 | .policy = nl80211_policy, |
| 6668 | .flags = GENL_ADMIN_PERM, |
| 6669 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6670 | NL80211_FLAG_NEED_RTNL, |
| 6671 | }, |
| 6672 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6673 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6674 | .doit = nl80211_set_power_save, |
| 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_NETDEV | |
| 6678 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6679 | }, |
| 6680 | { |
| 6681 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6682 | .doit = nl80211_get_power_save, |
| 6683 | .policy = nl80211_policy, |
| 6684 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6685 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6686 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6687 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6688 | { |
| 6689 | .cmd = NL80211_CMD_SET_CQM, |
| 6690 | .doit = nl80211_set_cqm, |
| 6691 | .policy = nl80211_policy, |
| 6692 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6693 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6694 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6695 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6696 | { |
| 6697 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6698 | .doit = nl80211_set_channel, |
| 6699 | .policy = nl80211_policy, |
| 6700 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6701 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6702 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6703 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6704 | { |
| 6705 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6706 | .doit = nl80211_set_wds_peer, |
| 6707 | .policy = nl80211_policy, |
| 6708 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6709 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6710 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6711 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6712 | { |
| 6713 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6714 | .doit = nl80211_join_mesh, |
| 6715 | .policy = nl80211_policy, |
| 6716 | .flags = GENL_ADMIN_PERM, |
| 6717 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6718 | NL80211_FLAG_NEED_RTNL, |
| 6719 | }, |
| 6720 | { |
| 6721 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6722 | .doit = nl80211_leave_mesh, |
| 6723 | .policy = nl80211_policy, |
| 6724 | .flags = GENL_ADMIN_PERM, |
| 6725 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6726 | NL80211_FLAG_NEED_RTNL, |
| 6727 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6728 | { |
| 6729 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6730 | .doit = nl80211_get_wowlan, |
| 6731 | .policy = nl80211_policy, |
| 6732 | /* can be retrieved by unprivileged users */ |
| 6733 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6734 | NL80211_FLAG_NEED_RTNL, |
| 6735 | }, |
| 6736 | { |
| 6737 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6738 | .doit = nl80211_set_wowlan, |
| 6739 | .policy = nl80211_policy, |
| 6740 | .flags = GENL_ADMIN_PERM, |
| 6741 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6742 | NL80211_FLAG_NEED_RTNL, |
| 6743 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6744 | { |
| 6745 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6746 | .doit = nl80211_set_rekey_data, |
| 6747 | .policy = nl80211_policy, |
| 6748 | .flags = GENL_ADMIN_PERM, |
| 6749 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6750 | NL80211_FLAG_NEED_RTNL, |
| 6751 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6752 | { |
| 6753 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 6754 | .doit = nl80211_tdls_mgmt, |
| 6755 | .policy = nl80211_policy, |
| 6756 | .flags = GENL_ADMIN_PERM, |
| 6757 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6758 | NL80211_FLAG_NEED_RTNL, |
| 6759 | }, |
| 6760 | { |
| 6761 | .cmd = NL80211_CMD_TDLS_OPER, |
| 6762 | .doit = nl80211_tdls_oper, |
| 6763 | .policy = nl80211_policy, |
| 6764 | .flags = GENL_ADMIN_PERM, |
| 6765 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6766 | NL80211_FLAG_NEED_RTNL, |
| 6767 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6768 | { |
| 6769 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 6770 | .doit = nl80211_register_unexpected_frame, |
| 6771 | .policy = nl80211_policy, |
| 6772 | .flags = GENL_ADMIN_PERM, |
| 6773 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6774 | NL80211_FLAG_NEED_RTNL, |
| 6775 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6776 | { |
| 6777 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 6778 | .doit = nl80211_probe_client, |
| 6779 | .policy = nl80211_policy, |
| 6780 | .flags = GENL_ADMIN_PERM, |
| 6781 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6782 | NL80211_FLAG_NEED_RTNL, |
| 6783 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6784 | { |
| 6785 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 6786 | .doit = nl80211_register_beacons, |
| 6787 | .policy = nl80211_policy, |
| 6788 | .flags = GENL_ADMIN_PERM, |
| 6789 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6790 | NL80211_FLAG_NEED_RTNL, |
| 6791 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 6792 | { |
| 6793 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 6794 | .doit = nl80211_set_noack_map, |
| 6795 | .policy = nl80211_policy, |
| 6796 | .flags = GENL_ADMIN_PERM, |
| 6797 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6798 | NL80211_FLAG_NEED_RTNL, |
| 6799 | }, |
| 6800 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6801 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6802 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6803 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6804 | .name = "mlme", |
| 6805 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6806 | |
| 6807 | /* multicast groups */ |
| 6808 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6809 | .name = "config", |
| 6810 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6811 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6812 | .name = "scan", |
| 6813 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6814 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6815 | .name = "regulatory", |
| 6816 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6817 | |
| 6818 | /* notification functions */ |
| 6819 | |
| 6820 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6821 | { |
| 6822 | struct sk_buff *msg; |
| 6823 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6824 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6825 | if (!msg) |
| 6826 | return; |
| 6827 | |
| 6828 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6829 | nlmsg_free(msg); |
| 6830 | return; |
| 6831 | } |
| 6832 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6833 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6834 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6835 | } |
| 6836 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6837 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6838 | struct cfg80211_registered_device *rdev) |
| 6839 | { |
| 6840 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6841 | struct nlattr *nest; |
| 6842 | int i; |
| 6843 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6844 | ASSERT_RDEV_LOCK(rdev); |
| 6845 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6846 | if (WARN_ON(!req)) |
| 6847 | return 0; |
| 6848 | |
| 6849 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6850 | if (!nest) |
| 6851 | goto nla_put_failure; |
| 6852 | for (i = 0; i < req->n_ssids; i++) |
| 6853 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6854 | nla_nest_end(msg, nest); |
| 6855 | |
| 6856 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6857 | if (!nest) |
| 6858 | goto nla_put_failure; |
| 6859 | for (i = 0; i < req->n_channels; i++) |
| 6860 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6861 | nla_nest_end(msg, nest); |
| 6862 | |
| 6863 | if (req->ie) |
| 6864 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6865 | |
| 6866 | return 0; |
| 6867 | nla_put_failure: |
| 6868 | return -ENOBUFS; |
| 6869 | } |
| 6870 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6871 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6872 | struct cfg80211_registered_device *rdev, |
| 6873 | struct net_device *netdev, |
| 6874 | u32 pid, u32 seq, int flags, |
| 6875 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6876 | { |
| 6877 | void *hdr; |
| 6878 | |
| 6879 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6880 | if (!hdr) |
| 6881 | return -1; |
| 6882 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6883 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6884 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6885 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6886 | /* ignore errors and send incomplete event anyway */ |
| 6887 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6888 | |
| 6889 | return genlmsg_end(msg, hdr); |
| 6890 | |
| 6891 | nla_put_failure: |
| 6892 | genlmsg_cancel(msg, hdr); |
| 6893 | return -EMSGSIZE; |
| 6894 | } |
| 6895 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6896 | static int |
| 6897 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6898 | struct cfg80211_registered_device *rdev, |
| 6899 | struct net_device *netdev, |
| 6900 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6901 | { |
| 6902 | void *hdr; |
| 6903 | |
| 6904 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6905 | if (!hdr) |
| 6906 | return -1; |
| 6907 | |
| 6908 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6909 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6910 | |
| 6911 | return genlmsg_end(msg, hdr); |
| 6912 | |
| 6913 | nla_put_failure: |
| 6914 | genlmsg_cancel(msg, hdr); |
| 6915 | return -EMSGSIZE; |
| 6916 | } |
| 6917 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6918 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6919 | struct net_device *netdev) |
| 6920 | { |
| 6921 | struct sk_buff *msg; |
| 6922 | |
| 6923 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6924 | if (!msg) |
| 6925 | return; |
| 6926 | |
| 6927 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6928 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6929 | nlmsg_free(msg); |
| 6930 | return; |
| 6931 | } |
| 6932 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6933 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6934 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6935 | } |
| 6936 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6937 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6938 | struct net_device *netdev) |
| 6939 | { |
| 6940 | struct sk_buff *msg; |
| 6941 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6942 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6943 | if (!msg) |
| 6944 | return; |
| 6945 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6946 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6947 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6948 | nlmsg_free(msg); |
| 6949 | return; |
| 6950 | } |
| 6951 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6952 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6953 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6954 | } |
| 6955 | |
| 6956 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6957 | struct net_device *netdev) |
| 6958 | { |
| 6959 | struct sk_buff *msg; |
| 6960 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6961 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6962 | if (!msg) |
| 6963 | return; |
| 6964 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6965 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6966 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6967 | nlmsg_free(msg); |
| 6968 | return; |
| 6969 | } |
| 6970 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6971 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6972 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6973 | } |
| 6974 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6975 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6976 | struct net_device *netdev) |
| 6977 | { |
| 6978 | struct sk_buff *msg; |
| 6979 | |
| 6980 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6981 | if (!msg) |
| 6982 | return; |
| 6983 | |
| 6984 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6985 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6986 | nlmsg_free(msg); |
| 6987 | return; |
| 6988 | } |
| 6989 | |
| 6990 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6991 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6992 | } |
| 6993 | |
| 6994 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6995 | struct net_device *netdev, u32 cmd) |
| 6996 | { |
| 6997 | struct sk_buff *msg; |
| 6998 | |
| 6999 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 7000 | if (!msg) |
| 7001 | return; |
| 7002 | |
| 7003 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 7004 | nlmsg_free(msg); |
| 7005 | return; |
| 7006 | } |
| 7007 | |
| 7008 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7009 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 7010 | } |
| 7011 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7012 | /* |
| 7013 | * This can happen on global regulatory changes or device specific settings |
| 7014 | * based on custom world regulatory domains. |
| 7015 | */ |
| 7016 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 7017 | { |
| 7018 | struct sk_buff *msg; |
| 7019 | void *hdr; |
| 7020 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7021 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7022 | if (!msg) |
| 7023 | return; |
| 7024 | |
| 7025 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 7026 | if (!hdr) { |
| 7027 | nlmsg_free(msg); |
| 7028 | return; |
| 7029 | } |
| 7030 | |
| 7031 | /* Userspace can always count this one always being set */ |
| 7032 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 7033 | |
| 7034 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 7035 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7036 | NL80211_REGDOM_TYPE_WORLD); |
| 7037 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 7038 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7039 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 7040 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 7041 | request->intersect) |
| 7042 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7043 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 7044 | else { |
| 7045 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 7046 | NL80211_REGDOM_TYPE_COUNTRY); |
| 7047 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 7048 | } |
| 7049 | |
| 7050 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 7051 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 7052 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7053 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7054 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7055 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7056 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 7057 | GFP_ATOMIC); |
| 7058 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7059 | |
| 7060 | return; |
| 7061 | |
| 7062 | nla_put_failure: |
| 7063 | genlmsg_cancel(msg, hdr); |
| 7064 | nlmsg_free(msg); |
| 7065 | } |
| 7066 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7067 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 7068 | struct net_device *netdev, |
| 7069 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7070 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7071 | { |
| 7072 | struct sk_buff *msg; |
| 7073 | void *hdr; |
| 7074 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7075 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7076 | if (!msg) |
| 7077 | return; |
| 7078 | |
| 7079 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7080 | if (!hdr) { |
| 7081 | nlmsg_free(msg); |
| 7082 | return; |
| 7083 | } |
| 7084 | |
| 7085 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7086 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7087 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7088 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7089 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7090 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7091 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7092 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7093 | return; |
| 7094 | |
| 7095 | nla_put_failure: |
| 7096 | genlmsg_cancel(msg, hdr); |
| 7097 | nlmsg_free(msg); |
| 7098 | } |
| 7099 | |
| 7100 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7101 | struct net_device *netdev, const u8 *buf, |
| 7102 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7103 | { |
| 7104 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7105 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 7109 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7110 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7111 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7112 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7113 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7114 | } |
| 7115 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7116 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7117 | struct net_device *netdev, const u8 *buf, |
| 7118 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7119 | { |
| 7120 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7121 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7122 | } |
| 7123 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 7124 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 7125 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7126 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7127 | { |
| 7128 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7129 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7130 | } |
| 7131 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7132 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7133 | struct net_device *netdev, const u8 *buf, |
| 7134 | size_t len, gfp_t gfp) |
| 7135 | { |
| 7136 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7137 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7138 | } |
| 7139 | |
| 7140 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7141 | struct net_device *netdev, const u8 *buf, |
| 7142 | size_t len, gfp_t gfp) |
| 7143 | { |
| 7144 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7145 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7146 | } |
| 7147 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7148 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7149 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7150 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7151 | { |
| 7152 | struct sk_buff *msg; |
| 7153 | void *hdr; |
| 7154 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7155 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7156 | if (!msg) |
| 7157 | return; |
| 7158 | |
| 7159 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7160 | if (!hdr) { |
| 7161 | nlmsg_free(msg); |
| 7162 | return; |
| 7163 | } |
| 7164 | |
| 7165 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7166 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7167 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 7168 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7169 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7170 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7171 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7172 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7173 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7174 | return; |
| 7175 | |
| 7176 | nla_put_failure: |
| 7177 | genlmsg_cancel(msg, hdr); |
| 7178 | nlmsg_free(msg); |
| 7179 | } |
| 7180 | |
| 7181 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7182 | struct net_device *netdev, const u8 *addr, |
| 7183 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7184 | { |
| 7185 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7186 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7187 | } |
| 7188 | |
| 7189 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7190 | struct net_device *netdev, const u8 *addr, |
| 7191 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7192 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7193 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 7194 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7195 | } |
| 7196 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7197 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 7198 | struct net_device *netdev, const u8 *bssid, |
| 7199 | const u8 *req_ie, size_t req_ie_len, |
| 7200 | const u8 *resp_ie, size_t resp_ie_len, |
| 7201 | u16 status, gfp_t gfp) |
| 7202 | { |
| 7203 | struct sk_buff *msg; |
| 7204 | void *hdr; |
| 7205 | |
| 7206 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7207 | if (!msg) |
| 7208 | return; |
| 7209 | |
| 7210 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 7211 | if (!hdr) { |
| 7212 | nlmsg_free(msg); |
| 7213 | return; |
| 7214 | } |
| 7215 | |
| 7216 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7217 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7218 | if (bssid) |
| 7219 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7220 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 7221 | if (req_ie) |
| 7222 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 7223 | if (resp_ie) |
| 7224 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 7225 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7226 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7227 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7228 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7229 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7230 | return; |
| 7231 | |
| 7232 | nla_put_failure: |
| 7233 | genlmsg_cancel(msg, hdr); |
| 7234 | nlmsg_free(msg); |
| 7235 | |
| 7236 | } |
| 7237 | |
| 7238 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 7239 | struct net_device *netdev, const u8 *bssid, |
| 7240 | const u8 *req_ie, size_t req_ie_len, |
| 7241 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 7242 | { |
| 7243 | struct sk_buff *msg; |
| 7244 | void *hdr; |
| 7245 | |
| 7246 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7247 | if (!msg) |
| 7248 | return; |
| 7249 | |
| 7250 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 7251 | if (!hdr) { |
| 7252 | nlmsg_free(msg); |
| 7253 | return; |
| 7254 | } |
| 7255 | |
| 7256 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7257 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7258 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7259 | if (req_ie) |
| 7260 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 7261 | if (resp_ie) |
| 7262 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 7263 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7264 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7265 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7266 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7267 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7268 | return; |
| 7269 | |
| 7270 | nla_put_failure: |
| 7271 | genlmsg_cancel(msg, hdr); |
| 7272 | nlmsg_free(msg); |
| 7273 | |
| 7274 | } |
| 7275 | |
| 7276 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 7277 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7278 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7279 | { |
| 7280 | struct sk_buff *msg; |
| 7281 | void *hdr; |
| 7282 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7283 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7284 | if (!msg) |
| 7285 | return; |
| 7286 | |
| 7287 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7288 | if (!hdr) { |
| 7289 | nlmsg_free(msg); |
| 7290 | return; |
| 7291 | } |
| 7292 | |
| 7293 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7294 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7295 | if (from_ap && reason) |
| 7296 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 7297 | if (from_ap) |
| 7298 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 7299 | if (ie) |
| 7300 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 7301 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7302 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7303 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7304 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7305 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7306 | return; |
| 7307 | |
| 7308 | nla_put_failure: |
| 7309 | genlmsg_cancel(msg, hdr); |
| 7310 | nlmsg_free(msg); |
| 7311 | |
| 7312 | } |
| 7313 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7314 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7315 | struct net_device *netdev, const u8 *bssid, |
| 7316 | gfp_t gfp) |
| 7317 | { |
| 7318 | struct sk_buff *msg; |
| 7319 | void *hdr; |
| 7320 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7321 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7322 | if (!msg) |
| 7323 | return; |
| 7324 | |
| 7325 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7326 | if (!hdr) { |
| 7327 | nlmsg_free(msg); |
| 7328 | return; |
| 7329 | } |
| 7330 | |
| 7331 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7332 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7333 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7334 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7335 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7336 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7337 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7338 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7339 | return; |
| 7340 | |
| 7341 | nla_put_failure: |
| 7342 | genlmsg_cancel(msg, hdr); |
| 7343 | nlmsg_free(msg); |
| 7344 | } |
| 7345 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7346 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7347 | struct net_device *netdev, |
| 7348 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7349 | gfp_t gfp) |
| 7350 | { |
| 7351 | struct sk_buff *msg; |
| 7352 | void *hdr; |
| 7353 | |
| 7354 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7355 | if (!msg) |
| 7356 | return; |
| 7357 | |
| 7358 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7359 | if (!hdr) { |
| 7360 | nlmsg_free(msg); |
| 7361 | return; |
| 7362 | } |
| 7363 | |
| 7364 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7365 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7366 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 7367 | if (ie_len && ie) |
| 7368 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 7369 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7370 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7371 | |
| 7372 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7373 | nl80211_mlme_mcgrp.id, gfp); |
| 7374 | return; |
| 7375 | |
| 7376 | nla_put_failure: |
| 7377 | genlmsg_cancel(msg, hdr); |
| 7378 | nlmsg_free(msg); |
| 7379 | } |
| 7380 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7381 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7382 | struct net_device *netdev, const u8 *addr, |
| 7383 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7384 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7385 | { |
| 7386 | struct sk_buff *msg; |
| 7387 | void *hdr; |
| 7388 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7389 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7390 | if (!msg) |
| 7391 | return; |
| 7392 | |
| 7393 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7394 | if (!hdr) { |
| 7395 | nlmsg_free(msg); |
| 7396 | return; |
| 7397 | } |
| 7398 | |
| 7399 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7400 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7401 | if (addr) |
| 7402 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7403 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 7404 | if (key_id != -1) |
| 7405 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7406 | if (tsc) |
| 7407 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 7408 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7409 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7410 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7411 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7412 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7413 | return; |
| 7414 | |
| 7415 | nla_put_failure: |
| 7416 | genlmsg_cancel(msg, hdr); |
| 7417 | nlmsg_free(msg); |
| 7418 | } |
| 7419 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7420 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7421 | struct ieee80211_channel *channel_before, |
| 7422 | struct ieee80211_channel *channel_after) |
| 7423 | { |
| 7424 | struct sk_buff *msg; |
| 7425 | void *hdr; |
| 7426 | struct nlattr *nl_freq; |
| 7427 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7428 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7429 | if (!msg) |
| 7430 | return; |
| 7431 | |
| 7432 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7433 | if (!hdr) { |
| 7434 | nlmsg_free(msg); |
| 7435 | return; |
| 7436 | } |
| 7437 | |
| 7438 | /* |
| 7439 | * Since we are applying the beacon hint to a wiphy we know its |
| 7440 | * wiphy_idx is valid |
| 7441 | */ |
| 7442 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 7443 | |
| 7444 | /* Before */ |
| 7445 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7446 | if (!nl_freq) |
| 7447 | goto nla_put_failure; |
| 7448 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7449 | goto nla_put_failure; |
| 7450 | nla_nest_end(msg, nl_freq); |
| 7451 | |
| 7452 | /* After */ |
| 7453 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7454 | if (!nl_freq) |
| 7455 | goto nla_put_failure; |
| 7456 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7457 | goto nla_put_failure; |
| 7458 | nla_nest_end(msg, nl_freq); |
| 7459 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7460 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7461 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7462 | rcu_read_lock(); |
| 7463 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7464 | GFP_ATOMIC); |
| 7465 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7466 | |
| 7467 | return; |
| 7468 | |
| 7469 | nla_put_failure: |
| 7470 | genlmsg_cancel(msg, hdr); |
| 7471 | nlmsg_free(msg); |
| 7472 | } |
| 7473 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7474 | static void nl80211_send_remain_on_chan_event( |
| 7475 | int cmd, struct cfg80211_registered_device *rdev, |
| 7476 | struct net_device *netdev, u64 cookie, |
| 7477 | struct ieee80211_channel *chan, |
| 7478 | enum nl80211_channel_type channel_type, |
| 7479 | unsigned int duration, gfp_t gfp) |
| 7480 | { |
| 7481 | struct sk_buff *msg; |
| 7482 | void *hdr; |
| 7483 | |
| 7484 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7485 | if (!msg) |
| 7486 | return; |
| 7487 | |
| 7488 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7489 | if (!hdr) { |
| 7490 | nlmsg_free(msg); |
| 7491 | return; |
| 7492 | } |
| 7493 | |
| 7494 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7495 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7496 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7497 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7498 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7499 | |
| 7500 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7501 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7502 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7503 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7504 | |
| 7505 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7506 | nl80211_mlme_mcgrp.id, gfp); |
| 7507 | return; |
| 7508 | |
| 7509 | nla_put_failure: |
| 7510 | genlmsg_cancel(msg, hdr); |
| 7511 | nlmsg_free(msg); |
| 7512 | } |
| 7513 | |
| 7514 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7515 | struct net_device *netdev, u64 cookie, |
| 7516 | struct ieee80211_channel *chan, |
| 7517 | enum nl80211_channel_type channel_type, |
| 7518 | unsigned int duration, gfp_t gfp) |
| 7519 | { |
| 7520 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7521 | rdev, netdev, cookie, chan, |
| 7522 | channel_type, duration, gfp); |
| 7523 | } |
| 7524 | |
| 7525 | void nl80211_send_remain_on_channel_cancel( |
| 7526 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7527 | u64 cookie, struct ieee80211_channel *chan, |
| 7528 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7529 | { |
| 7530 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7531 | rdev, netdev, cookie, chan, |
| 7532 | channel_type, 0, gfp); |
| 7533 | } |
| 7534 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7535 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7536 | struct net_device *dev, const u8 *mac_addr, |
| 7537 | struct station_info *sinfo, gfp_t gfp) |
| 7538 | { |
| 7539 | struct sk_buff *msg; |
| 7540 | |
| 7541 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7542 | if (!msg) |
| 7543 | return; |
| 7544 | |
| 7545 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 7546 | nlmsg_free(msg); |
| 7547 | return; |
| 7548 | } |
| 7549 | |
| 7550 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7551 | nl80211_mlme_mcgrp.id, gfp); |
| 7552 | } |
| 7553 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7554 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7555 | struct net_device *dev, const u8 *mac_addr, |
| 7556 | gfp_t gfp) |
| 7557 | { |
| 7558 | struct sk_buff *msg; |
| 7559 | void *hdr; |
| 7560 | |
| 7561 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7562 | if (!msg) |
| 7563 | return; |
| 7564 | |
| 7565 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7566 | if (!hdr) { |
| 7567 | nlmsg_free(msg); |
| 7568 | return; |
| 7569 | } |
| 7570 | |
| 7571 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7572 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7573 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7574 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7575 | |
| 7576 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7577 | nl80211_mlme_mcgrp.id, gfp); |
| 7578 | return; |
| 7579 | |
| 7580 | nla_put_failure: |
| 7581 | genlmsg_cancel(msg, hdr); |
| 7582 | nlmsg_free(msg); |
| 7583 | } |
| 7584 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7585 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 7586 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7587 | { |
| 7588 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7589 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7590 | struct sk_buff *msg; |
| 7591 | void *hdr; |
| 7592 | int err; |
| 7593 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 7594 | |
| 7595 | if (!nlpid) |
| 7596 | return false; |
| 7597 | |
| 7598 | msg = nlmsg_new(100, gfp); |
| 7599 | if (!msg) |
| 7600 | return true; |
| 7601 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7602 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7603 | if (!hdr) { |
| 7604 | nlmsg_free(msg); |
| 7605 | return true; |
| 7606 | } |
| 7607 | |
| 7608 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7609 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7610 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7611 | |
| 7612 | err = genlmsg_end(msg, hdr); |
| 7613 | if (err < 0) { |
| 7614 | nlmsg_free(msg); |
| 7615 | return true; |
| 7616 | } |
| 7617 | |
| 7618 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7619 | return true; |
| 7620 | |
| 7621 | nla_put_failure: |
| 7622 | genlmsg_cancel(msg, hdr); |
| 7623 | nlmsg_free(msg); |
| 7624 | return true; |
| 7625 | } |
| 7626 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7627 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 7628 | { |
| 7629 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 7630 | addr, gfp); |
| 7631 | } |
| 7632 | |
| 7633 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 7634 | const u8 *addr, gfp_t gfp) |
| 7635 | { |
| 7636 | return __nl80211_unexpected_frame(dev, |
| 7637 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 7638 | addr, gfp); |
| 7639 | } |
| 7640 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7641 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7642 | struct net_device *netdev, u32 nlpid, |
| 7643 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7644 | { |
| 7645 | struct sk_buff *msg; |
| 7646 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7647 | |
| 7648 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7649 | if (!msg) |
| 7650 | return -ENOMEM; |
| 7651 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7652 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7653 | if (!hdr) { |
| 7654 | nlmsg_free(msg); |
| 7655 | return -ENOMEM; |
| 7656 | } |
| 7657 | |
| 7658 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7659 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7660 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7661 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7662 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7663 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7664 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7665 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7666 | |
| 7667 | nla_put_failure: |
| 7668 | genlmsg_cancel(msg, hdr); |
| 7669 | nlmsg_free(msg); |
| 7670 | return -ENOBUFS; |
| 7671 | } |
| 7672 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7673 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7674 | struct net_device *netdev, u64 cookie, |
| 7675 | const u8 *buf, size_t len, bool ack, |
| 7676 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7677 | { |
| 7678 | struct sk_buff *msg; |
| 7679 | void *hdr; |
| 7680 | |
| 7681 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7682 | if (!msg) |
| 7683 | return; |
| 7684 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7685 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7686 | if (!hdr) { |
| 7687 | nlmsg_free(msg); |
| 7688 | return; |
| 7689 | } |
| 7690 | |
| 7691 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7692 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7693 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7694 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7695 | if (ack) |
| 7696 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7697 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7698 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7699 | |
| 7700 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7701 | return; |
| 7702 | |
| 7703 | nla_put_failure: |
| 7704 | genlmsg_cancel(msg, hdr); |
| 7705 | nlmsg_free(msg); |
| 7706 | } |
| 7707 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7708 | void |
| 7709 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7710 | struct net_device *netdev, |
| 7711 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7712 | gfp_t gfp) |
| 7713 | { |
| 7714 | struct sk_buff *msg; |
| 7715 | struct nlattr *pinfoattr; |
| 7716 | void *hdr; |
| 7717 | |
| 7718 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7719 | if (!msg) |
| 7720 | return; |
| 7721 | |
| 7722 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7723 | if (!hdr) { |
| 7724 | nlmsg_free(msg); |
| 7725 | return; |
| 7726 | } |
| 7727 | |
| 7728 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7729 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7730 | |
| 7731 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7732 | if (!pinfoattr) |
| 7733 | goto nla_put_failure; |
| 7734 | |
| 7735 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7736 | rssi_event); |
| 7737 | |
| 7738 | nla_nest_end(msg, pinfoattr); |
| 7739 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7740 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7741 | |
| 7742 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7743 | nl80211_mlme_mcgrp.id, gfp); |
| 7744 | return; |
| 7745 | |
| 7746 | nla_put_failure: |
| 7747 | genlmsg_cancel(msg, hdr); |
| 7748 | nlmsg_free(msg); |
| 7749 | } |
| 7750 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7751 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7752 | struct net_device *netdev, const u8 *bssid, |
| 7753 | const u8 *replay_ctr, gfp_t gfp) |
| 7754 | { |
| 7755 | struct sk_buff *msg; |
| 7756 | struct nlattr *rekey_attr; |
| 7757 | void *hdr; |
| 7758 | |
| 7759 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7760 | if (!msg) |
| 7761 | return; |
| 7762 | |
| 7763 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7764 | if (!hdr) { |
| 7765 | nlmsg_free(msg); |
| 7766 | return; |
| 7767 | } |
| 7768 | |
| 7769 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7770 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7771 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7772 | |
| 7773 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7774 | if (!rekey_attr) |
| 7775 | goto nla_put_failure; |
| 7776 | |
| 7777 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7778 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7779 | |
| 7780 | nla_nest_end(msg, rekey_attr); |
| 7781 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7782 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7783 | |
| 7784 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7785 | nl80211_mlme_mcgrp.id, gfp); |
| 7786 | return; |
| 7787 | |
| 7788 | nla_put_failure: |
| 7789 | genlmsg_cancel(msg, hdr); |
| 7790 | nlmsg_free(msg); |
| 7791 | } |
| 7792 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7793 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7794 | struct net_device *netdev, int index, |
| 7795 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7796 | { |
| 7797 | struct sk_buff *msg; |
| 7798 | struct nlattr *attr; |
| 7799 | void *hdr; |
| 7800 | |
| 7801 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7802 | if (!msg) |
| 7803 | return; |
| 7804 | |
| 7805 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7806 | if (!hdr) { |
| 7807 | nlmsg_free(msg); |
| 7808 | return; |
| 7809 | } |
| 7810 | |
| 7811 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7812 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7813 | |
| 7814 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7815 | if (!attr) |
| 7816 | goto nla_put_failure; |
| 7817 | |
| 7818 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7819 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7820 | if (preauth) |
| 7821 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7822 | |
| 7823 | nla_nest_end(msg, attr); |
| 7824 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7825 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7826 | |
| 7827 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7828 | nl80211_mlme_mcgrp.id, gfp); |
| 7829 | return; |
| 7830 | |
| 7831 | nla_put_failure: |
| 7832 | genlmsg_cancel(msg, hdr); |
| 7833 | nlmsg_free(msg); |
| 7834 | } |
| 7835 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7836 | void |
| 7837 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7838 | struct net_device *netdev, const u8 *peer, |
| 7839 | u32 num_packets, gfp_t gfp) |
| 7840 | { |
| 7841 | struct sk_buff *msg; |
| 7842 | struct nlattr *pinfoattr; |
| 7843 | void *hdr; |
| 7844 | |
| 7845 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7846 | if (!msg) |
| 7847 | return; |
| 7848 | |
| 7849 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7850 | if (!hdr) { |
| 7851 | nlmsg_free(msg); |
| 7852 | return; |
| 7853 | } |
| 7854 | |
| 7855 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7856 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7857 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7858 | |
| 7859 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7860 | if (!pinfoattr) |
| 7861 | goto nla_put_failure; |
| 7862 | |
| 7863 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7864 | |
| 7865 | nla_nest_end(msg, pinfoattr); |
| 7866 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7867 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7868 | |
| 7869 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7870 | nl80211_mlme_mcgrp.id, gfp); |
| 7871 | return; |
| 7872 | |
| 7873 | nla_put_failure: |
| 7874 | genlmsg_cancel(msg, hdr); |
| 7875 | nlmsg_free(msg); |
| 7876 | } |
| 7877 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7878 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 7879 | u64 cookie, bool acked, gfp_t gfp) |
| 7880 | { |
| 7881 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7882 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7883 | struct sk_buff *msg; |
| 7884 | void *hdr; |
| 7885 | int err; |
| 7886 | |
| 7887 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7888 | if (!msg) |
| 7889 | return; |
| 7890 | |
| 7891 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 7892 | if (!hdr) { |
| 7893 | nlmsg_free(msg); |
| 7894 | return; |
| 7895 | } |
| 7896 | |
| 7897 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7898 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7899 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7900 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7901 | if (acked) |
| 7902 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7903 | |
| 7904 | err = genlmsg_end(msg, hdr); |
| 7905 | if (err < 0) { |
| 7906 | nlmsg_free(msg); |
| 7907 | return; |
| 7908 | } |
| 7909 | |
| 7910 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7911 | nl80211_mlme_mcgrp.id, gfp); |
| 7912 | return; |
| 7913 | |
| 7914 | nla_put_failure: |
| 7915 | genlmsg_cancel(msg, hdr); |
| 7916 | nlmsg_free(msg); |
| 7917 | } |
| 7918 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 7919 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7920 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 7921 | const u8 *frame, size_t len, |
| 7922 | int freq, gfp_t gfp) |
| 7923 | { |
| 7924 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 7925 | struct sk_buff *msg; |
| 7926 | void *hdr; |
| 7927 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 7928 | |
| 7929 | if (!nlpid) |
| 7930 | return; |
| 7931 | |
| 7932 | msg = nlmsg_new(len + 100, gfp); |
| 7933 | if (!msg) |
| 7934 | return; |
| 7935 | |
| 7936 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 7937 | if (!hdr) { |
| 7938 | nlmsg_free(msg); |
| 7939 | return; |
| 7940 | } |
| 7941 | |
| 7942 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7943 | if (freq) |
| 7944 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7945 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame); |
| 7946 | |
| 7947 | genlmsg_end(msg, hdr); |
| 7948 | |
| 7949 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7950 | return; |
| 7951 | |
| 7952 | nla_put_failure: |
| 7953 | genlmsg_cancel(msg, hdr); |
| 7954 | nlmsg_free(msg); |
| 7955 | } |
| 7956 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 7957 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7958 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7959 | unsigned long state, |
| 7960 | void *_notify) |
| 7961 | { |
| 7962 | struct netlink_notify *notify = _notify; |
| 7963 | struct cfg80211_registered_device *rdev; |
| 7964 | struct wireless_dev *wdev; |
| 7965 | |
| 7966 | if (state != NETLINK_URELEASE) |
| 7967 | return NOTIFY_DONE; |
| 7968 | |
| 7969 | rcu_read_lock(); |
| 7970 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7971 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7972 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7973 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7974 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 7975 | rdev->ap_beacons_nlpid = 0; |
| 7976 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7977 | |
| 7978 | rcu_read_unlock(); |
| 7979 | |
| 7980 | return NOTIFY_DONE; |
| 7981 | } |
| 7982 | |
| 7983 | static struct notifier_block nl80211_netlink_notifier = { |
| 7984 | .notifier_call = nl80211_netlink_notify, |
| 7985 | }; |
| 7986 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7987 | /* initialisation/exit functions */ |
| 7988 | |
| 7989 | int nl80211_init(void) |
| 7990 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7991 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7992 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7993 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7994 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7995 | if (err) |
| 7996 | return err; |
| 7997 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7998 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7999 | if (err) |
| 8000 | goto err_out; |
| 8001 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8002 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 8003 | if (err) |
| 8004 | goto err_out; |
| 8005 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 8006 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 8007 | if (err) |
| 8008 | goto err_out; |
| 8009 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 8010 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 8011 | if (err) |
| 8012 | goto err_out; |
| 8013 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8014 | #ifdef CONFIG_NL80211_TESTMODE |
| 8015 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 8016 | if (err) |
| 8017 | goto err_out; |
| 8018 | #endif |
| 8019 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8020 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 8021 | if (err) |
| 8022 | goto err_out; |
| 8023 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8024 | return 0; |
| 8025 | err_out: |
| 8026 | genl_unregister_family(&nl80211_fam); |
| 8027 | return err; |
| 8028 | } |
| 8029 | |
| 8030 | void nl80211_exit(void) |
| 8031 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8032 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 8033 | genl_unregister_family(&nl80211_fam); |
| 8034 | } |