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 | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 50 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 51 | struct cfg80211_registered_device **rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | struct net_device **dev) |
| 53 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 54 | struct nlattr **attrs = info->attrs; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 55 | int ifindex; |
| 56 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 57 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 58 | return -EINVAL; |
| 59 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 60 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 61 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | if (!*dev) |
| 63 | return -ENODEV; |
| 64 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 65 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 66 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 67 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 68 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 75 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 77 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 78 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 79 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 80 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 81 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 82 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 83 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 84 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 85 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 86 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
| 88 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 89 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 90 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 91 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 92 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 93 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 94 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 95 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 96 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 97 | .len = WLAN_MAX_KEY_LEN }, |
| 98 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 99 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 100 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 101 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 102 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 103 | |
| 104 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 105 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 106 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 107 | .len = IEEE80211_MAX_DATA_LEN }, |
| 108 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 109 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 110 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 111 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 112 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 113 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 114 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 115 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 116 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 117 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 118 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 119 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 120 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 121 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 122 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 123 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 124 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 125 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 126 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 127 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 128 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 129 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 130 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 131 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 132 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 133 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 134 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 135 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 136 | |
| 137 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 138 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 139 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 140 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 141 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 142 | |
| 143 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 144 | .len = IEEE80211_MAX_SSID_LEN }, |
| 145 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 146 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 147 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 150 | [NL80211_ATTR_STA_FLAGS2] = { |
| 151 | .len = sizeof(struct nl80211_sta_flag_update), |
| 152 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 153 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 154 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 155 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 156 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 157 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 158 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 159 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 160 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 161 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 162 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 163 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 164 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 166 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 167 | .len = IEEE80211_MAX_DATA_LEN }, |
| 168 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 169 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 171 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 172 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 173 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 174 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 175 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 176 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 177 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 178 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 179 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 180 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 181 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 182 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 183 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 184 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 185 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 186 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 187 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 188 | .len = IEEE80211_MAX_DATA_LEN }, |
| 189 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 190 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 191 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 192 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 193 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 194 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 195 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 196 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 197 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 198 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 199 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 200 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 201 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 202 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 203 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 204 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 205 | .len = NL80211_HT_CAPABILITY_LEN |
| 206 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 207 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 208 | }; |
| 209 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 210 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 211 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 212 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 213 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 214 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 215 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 216 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 217 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 218 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 219 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 220 | }; |
| 221 | |
| 222 | /* policy for the key default flags */ |
| 223 | static const struct nla_policy |
| 224 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 225 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 226 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 227 | }; |
| 228 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 229 | /* policy for WoWLAN attributes */ |
| 230 | static const struct nla_policy |
| 231 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 232 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 233 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 234 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 235 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 236 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 237 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 238 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 239 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 240 | }; |
| 241 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 242 | /* policy for GTK rekey offload attributes */ |
| 243 | static const struct nla_policy |
| 244 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 245 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 246 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 247 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 248 | }; |
| 249 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 250 | static const struct nla_policy |
| 251 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 252 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 253 | .len = IEEE80211_MAX_SSID_LEN }, |
| 254 | }; |
| 255 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 256 | /* ifidx get helper */ |
| 257 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 258 | { |
| 259 | int res; |
| 260 | |
| 261 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 262 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 263 | nl80211_policy); |
| 264 | if (res) |
| 265 | return res; |
| 266 | |
| 267 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 268 | return -EINVAL; |
| 269 | |
| 270 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 271 | if (!res) |
| 272 | return -EINVAL; |
| 273 | return res; |
| 274 | } |
| 275 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 276 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 277 | struct netlink_callback *cb, |
| 278 | struct cfg80211_registered_device **rdev, |
| 279 | struct net_device **dev) |
| 280 | { |
| 281 | int ifidx = cb->args[0]; |
| 282 | int err; |
| 283 | |
| 284 | if (!ifidx) |
| 285 | ifidx = nl80211_get_ifidx(cb); |
| 286 | if (ifidx < 0) |
| 287 | return ifidx; |
| 288 | |
| 289 | cb->args[0] = ifidx; |
| 290 | |
| 291 | rtnl_lock(); |
| 292 | |
| 293 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 294 | if (!*dev) { |
| 295 | err = -ENODEV; |
| 296 | goto out_rtnl; |
| 297 | } |
| 298 | |
| 299 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 300 | if (IS_ERR(*rdev)) { |
| 301 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 302 | goto out_rtnl; |
| 303 | } |
| 304 | |
| 305 | return 0; |
| 306 | out_rtnl: |
| 307 | rtnl_unlock(); |
| 308 | return err; |
| 309 | } |
| 310 | |
| 311 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 312 | { |
| 313 | cfg80211_unlock_rdev(rdev); |
| 314 | rtnl_unlock(); |
| 315 | } |
| 316 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 317 | /* IE validation */ |
| 318 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 319 | { |
| 320 | const u8 *pos; |
| 321 | int len; |
| 322 | |
| 323 | if (!attr) |
| 324 | return true; |
| 325 | |
| 326 | pos = nla_data(attr); |
| 327 | len = nla_len(attr); |
| 328 | |
| 329 | while (len) { |
| 330 | u8 elemlen; |
| 331 | |
| 332 | if (len < 2) |
| 333 | return false; |
| 334 | len -= 2; |
| 335 | |
| 336 | elemlen = pos[1]; |
| 337 | if (elemlen > len) |
| 338 | return false; |
| 339 | |
| 340 | len -= elemlen; |
| 341 | pos += 2 + elemlen; |
| 342 | } |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 347 | /* message building helper */ |
| 348 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 349 | int flags, u8 cmd) |
| 350 | { |
| 351 | /* since there is no private header just add the generic one */ |
| 352 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 353 | } |
| 354 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 355 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 356 | struct ieee80211_channel *chan) |
| 357 | { |
| 358 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 359 | chan->center_freq); |
| 360 | |
| 361 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 362 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 363 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 364 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 365 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 366 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 367 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 368 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 369 | |
| 370 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 371 | DBM_TO_MBM(chan->max_power)); |
| 372 | |
| 373 | return 0; |
| 374 | |
| 375 | nla_put_failure: |
| 376 | return -ENOBUFS; |
| 377 | } |
| 378 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 379 | /* netlink command implementations */ |
| 380 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 381 | struct key_parse { |
| 382 | struct key_params p; |
| 383 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 384 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 385 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 386 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 390 | { |
| 391 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 392 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 393 | nl80211_key_policy); |
| 394 | if (err) |
| 395 | return err; |
| 396 | |
| 397 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 398 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 399 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 400 | if (k->def) { |
| 401 | k->def_uni = true; |
| 402 | k->def_multi = true; |
| 403 | } |
| 404 | if (k->defmgmt) |
| 405 | k->def_multi = true; |
| 406 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 407 | if (tb[NL80211_KEY_IDX]) |
| 408 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 409 | |
| 410 | if (tb[NL80211_KEY_DATA]) { |
| 411 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 412 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 413 | } |
| 414 | |
| 415 | if (tb[NL80211_KEY_SEQ]) { |
| 416 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 417 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 418 | } |
| 419 | |
| 420 | if (tb[NL80211_KEY_CIPHER]) |
| 421 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 422 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 423 | if (tb[NL80211_KEY_TYPE]) { |
| 424 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 425 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 426 | return -EINVAL; |
| 427 | } |
| 428 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 429 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 430 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 431 | int err = nla_parse_nested(kdt, |
| 432 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 433 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 434 | nl80211_key_default_policy); |
| 435 | if (err) |
| 436 | return err; |
| 437 | |
| 438 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 439 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 440 | } |
| 441 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 446 | { |
| 447 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 448 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 449 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 450 | } |
| 451 | |
| 452 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 453 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 454 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 455 | } |
| 456 | |
| 457 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 458 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 459 | |
| 460 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 461 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 462 | |
| 463 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 464 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 465 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 466 | if (k->def) { |
| 467 | k->def_uni = true; |
| 468 | k->def_multi = true; |
| 469 | } |
| 470 | if (k->defmgmt) |
| 471 | k->def_multi = true; |
| 472 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 473 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 474 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 475 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 476 | return -EINVAL; |
| 477 | } |
| 478 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 479 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 480 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 481 | int err = nla_parse_nested( |
| 482 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 483 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 484 | nl80211_key_default_policy); |
| 485 | if (err) |
| 486 | return err; |
| 487 | |
| 488 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 489 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 490 | } |
| 491 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 496 | { |
| 497 | int err; |
| 498 | |
| 499 | memset(k, 0, sizeof(*k)); |
| 500 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 501 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 502 | |
| 503 | if (info->attrs[NL80211_ATTR_KEY]) |
| 504 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 505 | else |
| 506 | err = nl80211_parse_key_old(info, k); |
| 507 | |
| 508 | if (err) |
| 509 | return err; |
| 510 | |
| 511 | if (k->def && k->defmgmt) |
| 512 | return -EINVAL; |
| 513 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 514 | if (k->defmgmt) { |
| 515 | if (k->def_uni || !k->def_multi) |
| 516 | return -EINVAL; |
| 517 | } |
| 518 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 519 | if (k->idx != -1) { |
| 520 | if (k->defmgmt) { |
| 521 | if (k->idx < 4 || k->idx > 5) |
| 522 | return -EINVAL; |
| 523 | } else if (k->def) { |
| 524 | if (k->idx < 0 || k->idx > 3) |
| 525 | return -EINVAL; |
| 526 | } else { |
| 527 | if (k->idx < 0 || k->idx > 5) |
| 528 | return -EINVAL; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 535 | static struct cfg80211_cached_keys * |
| 536 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 537 | struct nlattr *keys) |
| 538 | { |
| 539 | struct key_parse parse; |
| 540 | struct nlattr *key; |
| 541 | struct cfg80211_cached_keys *result; |
| 542 | int rem, err, def = 0; |
| 543 | |
| 544 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 545 | if (!result) |
| 546 | return ERR_PTR(-ENOMEM); |
| 547 | |
| 548 | result->def = -1; |
| 549 | result->defmgmt = -1; |
| 550 | |
| 551 | nla_for_each_nested(key, keys, rem) { |
| 552 | memset(&parse, 0, sizeof(parse)); |
| 553 | parse.idx = -1; |
| 554 | |
| 555 | err = nl80211_parse_key_new(key, &parse); |
| 556 | if (err) |
| 557 | goto error; |
| 558 | err = -EINVAL; |
| 559 | if (!parse.p.key) |
| 560 | goto error; |
| 561 | if (parse.idx < 0 || parse.idx > 4) |
| 562 | goto error; |
| 563 | if (parse.def) { |
| 564 | if (def) |
| 565 | goto error; |
| 566 | def = 1; |
| 567 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 568 | if (!parse.def_uni || !parse.def_multi) |
| 569 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 570 | } else if (parse.defmgmt) |
| 571 | goto error; |
| 572 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 573 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 574 | if (err) |
| 575 | goto error; |
| 576 | result->params[parse.idx].cipher = parse.p.cipher; |
| 577 | result->params[parse.idx].key_len = parse.p.key_len; |
| 578 | result->params[parse.idx].key = result->data[parse.idx]; |
| 579 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 580 | } |
| 581 | |
| 582 | return result; |
| 583 | error: |
| 584 | kfree(result); |
| 585 | return ERR_PTR(err); |
| 586 | } |
| 587 | |
| 588 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 589 | { |
| 590 | ASSERT_WDEV_LOCK(wdev); |
| 591 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 592 | switch (wdev->iftype) { |
| 593 | case NL80211_IFTYPE_AP: |
| 594 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 595 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 596 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 597 | break; |
| 598 | case NL80211_IFTYPE_ADHOC: |
| 599 | if (!wdev->current_bss) |
| 600 | return -ENOLINK; |
| 601 | break; |
| 602 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 603 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 604 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 605 | return -ENOLINK; |
| 606 | break; |
| 607 | default: |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | |
| 611 | return 0; |
| 612 | } |
| 613 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 614 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 615 | { |
| 616 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 617 | int i; |
| 618 | |
| 619 | if (!nl_modes) |
| 620 | goto nla_put_failure; |
| 621 | |
| 622 | i = 0; |
| 623 | while (ifmodes) { |
| 624 | if (ifmodes & 1) |
| 625 | NLA_PUT_FLAG(msg, i); |
| 626 | ifmodes >>= 1; |
| 627 | i++; |
| 628 | } |
| 629 | |
| 630 | nla_nest_end(msg, nl_modes); |
| 631 | return 0; |
| 632 | |
| 633 | nla_put_failure: |
| 634 | return -ENOBUFS; |
| 635 | } |
| 636 | |
| 637 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 638 | struct sk_buff *msg) |
| 639 | { |
| 640 | struct nlattr *nl_combis; |
| 641 | int i, j; |
| 642 | |
| 643 | nl_combis = nla_nest_start(msg, |
| 644 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 645 | if (!nl_combis) |
| 646 | goto nla_put_failure; |
| 647 | |
| 648 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 649 | const struct ieee80211_iface_combination *c; |
| 650 | struct nlattr *nl_combi, *nl_limits; |
| 651 | |
| 652 | c = &wiphy->iface_combinations[i]; |
| 653 | |
| 654 | nl_combi = nla_nest_start(msg, i + 1); |
| 655 | if (!nl_combi) |
| 656 | goto nla_put_failure; |
| 657 | |
| 658 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 659 | if (!nl_limits) |
| 660 | goto nla_put_failure; |
| 661 | |
| 662 | for (j = 0; j < c->n_limits; j++) { |
| 663 | struct nlattr *nl_limit; |
| 664 | |
| 665 | nl_limit = nla_nest_start(msg, j + 1); |
| 666 | if (!nl_limit) |
| 667 | goto nla_put_failure; |
| 668 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 669 | c->limits[j].max); |
| 670 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 671 | c->limits[j].types)) |
| 672 | goto nla_put_failure; |
| 673 | nla_nest_end(msg, nl_limit); |
| 674 | } |
| 675 | |
| 676 | nla_nest_end(msg, nl_limits); |
| 677 | |
| 678 | if (c->beacon_int_infra_match) |
| 679 | NLA_PUT_FLAG(msg, |
| 680 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 681 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 682 | c->num_different_channels); |
| 683 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 684 | c->max_interfaces); |
| 685 | |
| 686 | nla_nest_end(msg, nl_combi); |
| 687 | } |
| 688 | |
| 689 | nla_nest_end(msg, nl_combis); |
| 690 | |
| 691 | return 0; |
| 692 | nla_put_failure: |
| 693 | return -ENOBUFS; |
| 694 | } |
| 695 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 696 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 697 | struct cfg80211_registered_device *dev) |
| 698 | { |
| 699 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 700 | struct nlattr *nl_bands, *nl_band; |
| 701 | struct nlattr *nl_freqs, *nl_freq; |
| 702 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 703 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 704 | enum ieee80211_band band; |
| 705 | struct ieee80211_channel *chan; |
| 706 | struct ieee80211_rate *rate; |
| 707 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 708 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 709 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 710 | |
| 711 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 712 | if (!hdr) |
| 713 | return -1; |
| 714 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 715 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 716 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 717 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 718 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 719 | cfg80211_rdev_list_generation); |
| 720 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 721 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 722 | dev->wiphy.retry_short); |
| 723 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 724 | dev->wiphy.retry_long); |
| 725 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 726 | dev->wiphy.frag_threshold); |
| 727 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 728 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 729 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 730 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 731 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 732 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 733 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 734 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 735 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 736 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 737 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 738 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 739 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 740 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 741 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 742 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 743 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 744 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 745 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 746 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 747 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 748 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 749 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 750 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) |
| 751 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT); |
| 752 | if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) |
| 753 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 754 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 755 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 756 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 757 | dev->wiphy.cipher_suites); |
| 758 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 759 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 760 | dev->wiphy.max_num_pmkids); |
| 761 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 762 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 763 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 764 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 765 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 766 | dev->wiphy.available_antennas_tx); |
| 767 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 768 | dev->wiphy.available_antennas_rx); |
| 769 | |
Arik Nemtsov | 87bbbe2 | 2011-11-10 11:28:55 +0200 | [diff] [blame] | 770 | if (dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) |
| 771 | NLA_PUT_U32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
| 772 | dev->wiphy.probe_resp_offload); |
| 773 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 774 | if ((dev->wiphy.available_antennas_tx || |
| 775 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 776 | u32 tx_ant = 0, rx_ant = 0; |
| 777 | int res; |
| 778 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 779 | if (!res) { |
| 780 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 781 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 782 | } |
| 783 | } |
| 784 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 785 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 786 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 787 | goto nla_put_failure; |
| 788 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 789 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 790 | if (!nl_bands) |
| 791 | goto nla_put_failure; |
| 792 | |
| 793 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 794 | if (!dev->wiphy.bands[band]) |
| 795 | continue; |
| 796 | |
| 797 | nl_band = nla_nest_start(msg, band); |
| 798 | if (!nl_band) |
| 799 | goto nla_put_failure; |
| 800 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 801 | /* add HT info */ |
| 802 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 803 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 804 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 805 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 806 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 807 | dev->wiphy.bands[band]->ht_cap.cap); |
| 808 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 809 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 810 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 811 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 812 | } |
| 813 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 814 | /* add frequencies */ |
| 815 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 816 | if (!nl_freqs) |
| 817 | goto nla_put_failure; |
| 818 | |
| 819 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 820 | nl_freq = nla_nest_start(msg, i); |
| 821 | if (!nl_freq) |
| 822 | goto nla_put_failure; |
| 823 | |
| 824 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 825 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 826 | if (nl80211_msg_put_channel(msg, chan)) |
| 827 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 828 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 829 | nla_nest_end(msg, nl_freq); |
| 830 | } |
| 831 | |
| 832 | nla_nest_end(msg, nl_freqs); |
| 833 | |
| 834 | /* add bitrates */ |
| 835 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 836 | if (!nl_rates) |
| 837 | goto nla_put_failure; |
| 838 | |
| 839 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 840 | nl_rate = nla_nest_start(msg, i); |
| 841 | if (!nl_rate) |
| 842 | goto nla_put_failure; |
| 843 | |
| 844 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 845 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 846 | rate->bitrate); |
| 847 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 848 | NLA_PUT_FLAG(msg, |
| 849 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 850 | |
| 851 | nla_nest_end(msg, nl_rate); |
| 852 | } |
| 853 | |
| 854 | nla_nest_end(msg, nl_rates); |
| 855 | |
| 856 | nla_nest_end(msg, nl_band); |
| 857 | } |
| 858 | nla_nest_end(msg, nl_bands); |
| 859 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 860 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 861 | if (!nl_cmds) |
| 862 | goto nla_put_failure; |
| 863 | |
| 864 | i = 0; |
| 865 | #define CMD(op, n) \ |
| 866 | do { \ |
| 867 | if (dev->ops->op) { \ |
| 868 | i++; \ |
| 869 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 870 | } \ |
| 871 | } while (0) |
| 872 | |
| 873 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 874 | CMD(change_virtual_intf, SET_INTERFACE); |
| 875 | CMD(add_key, NEW_KEY); |
| 876 | CMD(add_beacon, NEW_BEACON); |
| 877 | CMD(add_station, NEW_STATION); |
| 878 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 879 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 880 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 881 | CMD(auth, AUTHENTICATE); |
| 882 | CMD(assoc, ASSOCIATE); |
| 883 | CMD(deauth, DEAUTHENTICATE); |
| 884 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 885 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 886 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 887 | CMD(set_pmksa, SET_PMKSA); |
| 888 | CMD(del_pmksa, DEL_PMKSA); |
| 889 | CMD(flush_pmksa, FLUSH_PMKSA); |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 890 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 891 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 892 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 893 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 894 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 895 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 896 | i++; |
| 897 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 898 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 899 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 900 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 901 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 902 | CMD(tdls_mgmt, TDLS_MGMT); |
| 903 | CMD(tdls_oper, TDLS_OPER); |
| 904 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 905 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 906 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 907 | CMD(probe_client, PROBE_CLIENT); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 908 | CMD(set_noack_map, SET_NOACK_MAP); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 909 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 910 | i++; |
| 911 | NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS); |
| 912 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 913 | |
Kalle Valo | 4745fc0 | 2011-11-17 19:06:10 +0200 | [diff] [blame] | 914 | #ifdef CONFIG_NL80211_TESTMODE |
| 915 | CMD(testmode_cmd, TESTMODE); |
| 916 | #endif |
| 917 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 918 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 919 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 920 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 921 | i++; |
| 922 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 923 | } |
| 924 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 925 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 926 | i++; |
| 927 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 928 | } |
| 929 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 930 | nla_nest_end(msg, nl_cmds); |
| 931 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 932 | if (dev->ops->remain_on_channel && |
| 933 | dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 934 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 935 | dev->wiphy.max_remain_on_channel_duration); |
| 936 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 937 | if (dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 938 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 939 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 940 | if (mgmt_stypes) { |
| 941 | u16 stypes; |
| 942 | struct nlattr *nl_ftypes, *nl_ifs; |
| 943 | enum nl80211_iftype ift; |
| 944 | |
| 945 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 946 | if (!nl_ifs) |
| 947 | goto nla_put_failure; |
| 948 | |
| 949 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 950 | nl_ftypes = nla_nest_start(msg, ift); |
| 951 | if (!nl_ftypes) |
| 952 | goto nla_put_failure; |
| 953 | i = 0; |
| 954 | stypes = mgmt_stypes[ift].tx; |
| 955 | while (stypes) { |
| 956 | if (stypes & 1) |
| 957 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 958 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 959 | stypes >>= 1; |
| 960 | i++; |
| 961 | } |
| 962 | nla_nest_end(msg, nl_ftypes); |
| 963 | } |
| 964 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 965 | nla_nest_end(msg, nl_ifs); |
| 966 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 967 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 968 | if (!nl_ifs) |
| 969 | goto nla_put_failure; |
| 970 | |
| 971 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 972 | nl_ftypes = nla_nest_start(msg, ift); |
| 973 | if (!nl_ftypes) |
| 974 | goto nla_put_failure; |
| 975 | i = 0; |
| 976 | stypes = mgmt_stypes[ift].rx; |
| 977 | while (stypes) { |
| 978 | if (stypes & 1) |
| 979 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 980 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 981 | stypes >>= 1; |
| 982 | i++; |
| 983 | } |
| 984 | nla_nest_end(msg, nl_ftypes); |
| 985 | } |
| 986 | nla_nest_end(msg, nl_ifs); |
| 987 | } |
| 988 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 989 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 990 | struct nlattr *nl_wowlan; |
| 991 | |
| 992 | nl_wowlan = nla_nest_start(msg, |
| 993 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 994 | if (!nl_wowlan) |
| 995 | goto nla_put_failure; |
| 996 | |
| 997 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 998 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 999 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 1000 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 1001 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 1002 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 1003 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 1004 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 1005 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 1006 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 1007 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 1008 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 1009 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 1010 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 1011 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 1012 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1013 | if (dev->wiphy.wowlan.n_patterns) { |
| 1014 | struct nl80211_wowlan_pattern_support pat = { |
| 1015 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 1016 | .min_pattern_len = |
| 1017 | dev->wiphy.wowlan.pattern_min_len, |
| 1018 | .max_pattern_len = |
| 1019 | dev->wiphy.wowlan.pattern_max_len, |
| 1020 | }; |
| 1021 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1022 | sizeof(pat), &pat); |
| 1023 | } |
| 1024 | |
| 1025 | nla_nest_end(msg, nl_wowlan); |
| 1026 | } |
| 1027 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1028 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1029 | dev->wiphy.software_iftypes)) |
| 1030 | goto nla_put_failure; |
| 1031 | |
| 1032 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1033 | goto nla_put_failure; |
| 1034 | |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1035 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) |
| 1036 | NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1037 | dev->wiphy.ap_sme_capa); |
| 1038 | |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1039 | NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features); |
| 1040 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 1041 | if (dev->wiphy.ht_capa_mod_mask) |
| 1042 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
| 1043 | sizeof(*dev->wiphy.ht_capa_mod_mask), |
| 1044 | dev->wiphy.ht_capa_mod_mask); |
| 1045 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1046 | return genlmsg_end(msg, hdr); |
| 1047 | |
| 1048 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1049 | genlmsg_cancel(msg, hdr); |
| 1050 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1054 | { |
| 1055 | int idx = 0; |
| 1056 | int start = cb->args[0]; |
| 1057 | struct cfg80211_registered_device *dev; |
| 1058 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1059 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1060 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1061 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1062 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1063 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1064 | continue; |
| 1065 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1066 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1067 | dev) < 0) { |
| 1068 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1069 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1070 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1071 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1072 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1073 | |
| 1074 | cb->args[0] = idx; |
| 1075 | |
| 1076 | return skb->len; |
| 1077 | } |
| 1078 | |
| 1079 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1080 | { |
| 1081 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1082 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1083 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1084 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1085 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1086 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1088 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1089 | nlmsg_free(msg); |
| 1090 | return -ENOBUFS; |
| 1091 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1092 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1093 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1094 | } |
| 1095 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1096 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1097 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1098 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1099 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1100 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1101 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1102 | }; |
| 1103 | |
| 1104 | static int parse_txq_params(struct nlattr *tb[], |
| 1105 | struct ieee80211_txq_params *txq_params) |
| 1106 | { |
| 1107 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1108 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1109 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1110 | return -EINVAL; |
| 1111 | |
| 1112 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1113 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1114 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1115 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1116 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1117 | |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1121 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1122 | { |
| 1123 | /* |
| 1124 | * You can only set the channel explicitly for AP, mesh |
| 1125 | * and WDS type interfaces; all others have their channel |
| 1126 | * managed via their respective "establish a connection" |
| 1127 | * command (connect, join, ...) |
| 1128 | * |
| 1129 | * Monitors are special as they are normally slaved to |
| 1130 | * whatever else is going on, so they behave as though |
| 1131 | * you tried setting the wiphy channel itself. |
| 1132 | */ |
| 1133 | return !wdev || |
| 1134 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1135 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1136 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1137 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1138 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1142 | struct wireless_dev *wdev, |
| 1143 | struct genl_info *info) |
| 1144 | { |
| 1145 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1146 | u32 freq; |
| 1147 | int result; |
| 1148 | |
| 1149 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1150 | return -EINVAL; |
| 1151 | |
| 1152 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1153 | return -EOPNOTSUPP; |
| 1154 | |
| 1155 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1156 | channel_type = nla_get_u32(info->attrs[ |
| 1157 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1158 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1159 | channel_type != NL80211_CHAN_HT20 && |
| 1160 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1161 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1162 | return -EINVAL; |
| 1163 | } |
| 1164 | |
| 1165 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1166 | |
| 1167 | mutex_lock(&rdev->devlist_mtx); |
| 1168 | if (wdev) { |
| 1169 | wdev_lock(wdev); |
| 1170 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1171 | wdev_unlock(wdev); |
| 1172 | } else { |
| 1173 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1174 | } |
| 1175 | mutex_unlock(&rdev->devlist_mtx); |
| 1176 | |
| 1177 | return result; |
| 1178 | } |
| 1179 | |
| 1180 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1181 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1183 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1184 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1185 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1186 | } |
| 1187 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1188 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1189 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1190 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1191 | struct net_device *dev = info->user_ptr[1]; |
| 1192 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1193 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1194 | |
| 1195 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1196 | return -EINVAL; |
| 1197 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1198 | if (netif_running(dev)) |
| 1199 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1200 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1201 | if (!rdev->ops->set_wds_peer) |
| 1202 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1203 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1204 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1205 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1206 | |
| 1207 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1208 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1212 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1213 | { |
| 1214 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1215 | struct net_device *netdev = NULL; |
| 1216 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1217 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1218 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1219 | u32 changed; |
| 1220 | u8 retry_short = 0, retry_long = 0; |
| 1221 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1222 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1223 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1224 | /* |
| 1225 | * Try to find the wiphy and netdev. Normally this |
| 1226 | * function shouldn't need the netdev, but this is |
| 1227 | * done for backward compatibility -- previously |
| 1228 | * setting the channel was done per wiphy, but now |
| 1229 | * it is per netdev. Previous userland like hostapd |
| 1230 | * also passed a netdev to set_wiphy, so that it is |
| 1231 | * possible to let that go to the right netdev! |
| 1232 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1233 | mutex_lock(&cfg80211_mutex); |
| 1234 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1235 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1236 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1237 | |
| 1238 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1239 | if (netdev && netdev->ieee80211_ptr) { |
| 1240 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1241 | mutex_lock(&rdev->mtx); |
| 1242 | } else |
| 1243 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1244 | } |
| 1245 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1246 | if (!netdev) { |
| 1247 | rdev = __cfg80211_rdev_from_info(info); |
| 1248 | if (IS_ERR(rdev)) { |
| 1249 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1250 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1251 | } |
| 1252 | wdev = NULL; |
| 1253 | netdev = NULL; |
| 1254 | result = 0; |
| 1255 | |
| 1256 | mutex_lock(&rdev->mtx); |
| 1257 | } else if (netif_running(netdev) && |
| 1258 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1259 | wdev = netdev->ieee80211_ptr; |
| 1260 | else |
| 1261 | wdev = NULL; |
| 1262 | |
| 1263 | /* |
| 1264 | * end workaround code, by now the rdev is available |
| 1265 | * and locked, and wdev may or may not be NULL. |
| 1266 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1267 | |
| 1268 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1269 | result = cfg80211_dev_rename( |
| 1270 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1271 | |
| 1272 | mutex_unlock(&cfg80211_mutex); |
| 1273 | |
| 1274 | if (result) |
| 1275 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1276 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1277 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1278 | struct ieee80211_txq_params txq_params; |
| 1279 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1280 | |
| 1281 | if (!rdev->ops->set_txq_params) { |
| 1282 | result = -EOPNOTSUPP; |
| 1283 | goto bad_res; |
| 1284 | } |
| 1285 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1286 | if (!netdev) { |
| 1287 | result = -EINVAL; |
| 1288 | goto bad_res; |
| 1289 | } |
| 1290 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1291 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1292 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1293 | result = -EINVAL; |
| 1294 | goto bad_res; |
| 1295 | } |
| 1296 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1297 | nla_for_each_nested(nl_txq_params, |
| 1298 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1299 | rem_txq_params) { |
| 1300 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1301 | nla_data(nl_txq_params), |
| 1302 | nla_len(nl_txq_params), |
| 1303 | txq_params_policy); |
| 1304 | result = parse_txq_params(tb, &txq_params); |
| 1305 | if (result) |
| 1306 | goto bad_res; |
| 1307 | |
| 1308 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1309 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1310 | &txq_params); |
| 1311 | if (result) |
| 1312 | goto bad_res; |
| 1313 | } |
| 1314 | } |
| 1315 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1316 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1317 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1318 | if (result) |
| 1319 | goto bad_res; |
| 1320 | } |
| 1321 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1322 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1323 | enum nl80211_tx_power_setting type; |
| 1324 | int idx, mbm = 0; |
| 1325 | |
| 1326 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1327 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1328 | goto bad_res; |
| 1329 | } |
| 1330 | |
| 1331 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1332 | type = nla_get_u32(info->attrs[idx]); |
| 1333 | |
| 1334 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1335 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1336 | result = -EINVAL; |
| 1337 | goto bad_res; |
| 1338 | } |
| 1339 | |
| 1340 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1341 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1342 | mbm = nla_get_u32(info->attrs[idx]); |
| 1343 | } |
| 1344 | |
| 1345 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1346 | if (result) |
| 1347 | goto bad_res; |
| 1348 | } |
| 1349 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1350 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1351 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1352 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1353 | if ((!rdev->wiphy.available_antennas_tx && |
| 1354 | !rdev->wiphy.available_antennas_rx) || |
| 1355 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1356 | result = -EOPNOTSUPP; |
| 1357 | goto bad_res; |
| 1358 | } |
| 1359 | |
| 1360 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1361 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1362 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1363 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1364 | * available antenna masks, except for the "all" mask */ |
| 1365 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1366 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1367 | result = -EINVAL; |
| 1368 | goto bad_res; |
| 1369 | } |
| 1370 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1371 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1372 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1373 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1374 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1375 | if (result) |
| 1376 | goto bad_res; |
| 1377 | } |
| 1378 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1379 | changed = 0; |
| 1380 | |
| 1381 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1382 | retry_short = nla_get_u8( |
| 1383 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1384 | if (retry_short == 0) { |
| 1385 | result = -EINVAL; |
| 1386 | goto bad_res; |
| 1387 | } |
| 1388 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1389 | } |
| 1390 | |
| 1391 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1392 | retry_long = nla_get_u8( |
| 1393 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1394 | if (retry_long == 0) { |
| 1395 | result = -EINVAL; |
| 1396 | goto bad_res; |
| 1397 | } |
| 1398 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1399 | } |
| 1400 | |
| 1401 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1402 | frag_threshold = nla_get_u32( |
| 1403 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1404 | if (frag_threshold < 256) { |
| 1405 | result = -EINVAL; |
| 1406 | goto bad_res; |
| 1407 | } |
| 1408 | if (frag_threshold != (u32) -1) { |
| 1409 | /* |
| 1410 | * Fragments (apart from the last one) are required to |
| 1411 | * have even length. Make the fragmentation code |
| 1412 | * simpler by stripping LSB should someone try to use |
| 1413 | * odd threshold value. |
| 1414 | */ |
| 1415 | frag_threshold &= ~0x1; |
| 1416 | } |
| 1417 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1418 | } |
| 1419 | |
| 1420 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1421 | rts_threshold = nla_get_u32( |
| 1422 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1423 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1424 | } |
| 1425 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1426 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1427 | coverage_class = nla_get_u8( |
| 1428 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1429 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1430 | } |
| 1431 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1432 | if (changed) { |
| 1433 | u8 old_retry_short, old_retry_long; |
| 1434 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1435 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1436 | |
| 1437 | if (!rdev->ops->set_wiphy_params) { |
| 1438 | result = -EOPNOTSUPP; |
| 1439 | goto bad_res; |
| 1440 | } |
| 1441 | |
| 1442 | old_retry_short = rdev->wiphy.retry_short; |
| 1443 | old_retry_long = rdev->wiphy.retry_long; |
| 1444 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1445 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1446 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1447 | |
| 1448 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1449 | rdev->wiphy.retry_short = retry_short; |
| 1450 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1451 | rdev->wiphy.retry_long = retry_long; |
| 1452 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1453 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1454 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1455 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1456 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1457 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1458 | |
| 1459 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1460 | if (result) { |
| 1461 | rdev->wiphy.retry_short = old_retry_short; |
| 1462 | rdev->wiphy.retry_long = old_retry_long; |
| 1463 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1464 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1465 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1466 | } |
| 1467 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1468 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1469 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1470 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1471 | if (netdev) |
| 1472 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1473 | return result; |
| 1474 | } |
| 1475 | |
| 1476 | |
| 1477 | 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] | 1478 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1479 | struct net_device *dev) |
| 1480 | { |
| 1481 | void *hdr; |
| 1482 | |
| 1483 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1484 | if (!hdr) |
| 1485 | return -1; |
| 1486 | |
| 1487 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1488 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1489 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1490 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1491 | |
| 1492 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1493 | rdev->devlist_generation ^ |
| 1494 | (cfg80211_rdev_list_generation << 2)); |
| 1495 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1496 | return genlmsg_end(msg, hdr); |
| 1497 | |
| 1498 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1499 | genlmsg_cancel(msg, hdr); |
| 1500 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1504 | { |
| 1505 | int wp_idx = 0; |
| 1506 | int if_idx = 0; |
| 1507 | int wp_start = cb->args[0]; |
| 1508 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1509 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1510 | struct wireless_dev *wdev; |
| 1511 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1512 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1513 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1514 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1515 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1516 | if (wp_idx < wp_start) { |
| 1517 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1518 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1519 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1520 | if_idx = 0; |
| 1521 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1522 | mutex_lock(&rdev->devlist_mtx); |
| 1523 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1524 | if (if_idx < if_start) { |
| 1525 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1526 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1527 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1528 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1529 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1530 | rdev, wdev->netdev) < 0) { |
| 1531 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1532 | goto out; |
| 1533 | } |
| 1534 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1535 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1536 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1537 | |
| 1538 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1539 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1540 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1541 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1542 | |
| 1543 | cb->args[0] = wp_idx; |
| 1544 | cb->args[1] = if_idx; |
| 1545 | |
| 1546 | return skb->len; |
| 1547 | } |
| 1548 | |
| 1549 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1550 | { |
| 1551 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1552 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1553 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1554 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1555 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1556 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1557 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1558 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1559 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1560 | dev, netdev) < 0) { |
| 1561 | nlmsg_free(msg); |
| 1562 | return -ENOBUFS; |
| 1563 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1564 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1565 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1566 | } |
| 1567 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1568 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1569 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1570 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1571 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1572 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1573 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1574 | }; |
| 1575 | |
| 1576 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1577 | { |
| 1578 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1579 | int flag; |
| 1580 | |
| 1581 | *mntrflags = 0; |
| 1582 | |
| 1583 | if (!nla) |
| 1584 | return -EINVAL; |
| 1585 | |
| 1586 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1587 | nla, mntr_flags_policy)) |
| 1588 | return -EINVAL; |
| 1589 | |
| 1590 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1591 | if (flags[flag]) |
| 1592 | *mntrflags |= (1<<flag); |
| 1593 | |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1597 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1598 | struct net_device *netdev, u8 use_4addr, |
| 1599 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1600 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1601 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1602 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1603 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1604 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1605 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1606 | |
| 1607 | switch (iftype) { |
| 1608 | case NL80211_IFTYPE_AP_VLAN: |
| 1609 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1610 | return 0; |
| 1611 | break; |
| 1612 | case NL80211_IFTYPE_STATION: |
| 1613 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1614 | return 0; |
| 1615 | break; |
| 1616 | default: |
| 1617 | break; |
| 1618 | } |
| 1619 | |
| 1620 | return -EOPNOTSUPP; |
| 1621 | } |
| 1622 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1623 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1624 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1626 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1627 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1628 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1629 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1630 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1631 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1632 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1633 | memset(¶ms, 0, sizeof(params)); |
| 1634 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1635 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1636 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1637 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1638 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1639 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1640 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1641 | if (ntype > NL80211_IFTYPE_MAX) |
| 1642 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1643 | } |
| 1644 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1645 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1646 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1647 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1648 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1649 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1650 | if (netif_running(dev)) |
| 1651 | return -EBUSY; |
| 1652 | |
| 1653 | wdev_lock(wdev); |
| 1654 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1655 | IEEE80211_MAX_MESH_ID_LEN); |
| 1656 | wdev->mesh_id_up_len = |
| 1657 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1658 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1659 | wdev->mesh_id_up_len); |
| 1660 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1661 | } |
| 1662 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1663 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1664 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1665 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1666 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1667 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1668 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1669 | } else { |
| 1670 | params.use_4addr = -1; |
| 1671 | } |
| 1672 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1673 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1674 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1675 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1676 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1677 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1678 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1679 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1680 | |
| 1681 | flags = &_flags; |
| 1682 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1683 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1684 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1685 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1686 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1687 | else |
| 1688 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1689 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1690 | if (!err && params.use_4addr != -1) |
| 1691 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1692 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1693 | return err; |
| 1694 | } |
| 1695 | |
| 1696 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1697 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1699 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1700 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1701 | int err; |
| 1702 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1703 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1704 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1705 | memset(¶ms, 0, sizeof(params)); |
| 1706 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1707 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1708 | return -EINVAL; |
| 1709 | |
| 1710 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1711 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1712 | if (type > NL80211_IFTYPE_MAX) |
| 1713 | return -EINVAL; |
| 1714 | } |
| 1715 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1716 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1717 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1718 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1719 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1720 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1721 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1722 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1723 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1724 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1725 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1726 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1727 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1728 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1729 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1730 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1731 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1732 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1733 | if (IS_ERR(dev)) |
| 1734 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1735 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1736 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1737 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1738 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1739 | |
| 1740 | wdev_lock(wdev); |
| 1741 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1742 | IEEE80211_MAX_MESH_ID_LEN); |
| 1743 | wdev->mesh_id_up_len = |
| 1744 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1745 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1746 | wdev->mesh_id_up_len); |
| 1747 | wdev_unlock(wdev); |
| 1748 | } |
| 1749 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1750 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1754 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1755 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1756 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1757 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1758 | if (!rdev->ops->del_virtual_intf) |
| 1759 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1761 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1762 | } |
| 1763 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 1764 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 1765 | { |
| 1766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1767 | struct net_device *dev = info->user_ptr[1]; |
| 1768 | u16 noack_map; |
| 1769 | |
| 1770 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 1771 | return -EINVAL; |
| 1772 | |
| 1773 | if (!rdev->ops->set_noack_map) |
| 1774 | return -EOPNOTSUPP; |
| 1775 | |
| 1776 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 1777 | |
| 1778 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); |
| 1779 | } |
| 1780 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1781 | struct get_key_cookie { |
| 1782 | struct sk_buff *msg; |
| 1783 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1784 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1785 | }; |
| 1786 | |
| 1787 | static void get_key_callback(void *c, struct key_params *params) |
| 1788 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1789 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1790 | struct get_key_cookie *cookie = c; |
| 1791 | |
| 1792 | if (params->key) |
| 1793 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1794 | params->key_len, params->key); |
| 1795 | |
| 1796 | if (params->seq) |
| 1797 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1798 | params->seq_len, params->seq); |
| 1799 | |
| 1800 | if (params->cipher) |
| 1801 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1802 | params->cipher); |
| 1803 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1804 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1805 | if (!key) |
| 1806 | goto nla_put_failure; |
| 1807 | |
| 1808 | if (params->key) |
| 1809 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1810 | params->key_len, params->key); |
| 1811 | |
| 1812 | if (params->seq) |
| 1813 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1814 | params->seq_len, params->seq); |
| 1815 | |
| 1816 | if (params->cipher) |
| 1817 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1818 | params->cipher); |
| 1819 | |
| 1820 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1821 | |
| 1822 | nla_nest_end(cookie->msg, key); |
| 1823 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1824 | return; |
| 1825 | nla_put_failure: |
| 1826 | cookie->error = 1; |
| 1827 | } |
| 1828 | |
| 1829 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1830 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1832 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1833 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1834 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1835 | const u8 *mac_addr = NULL; |
| 1836 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1837 | struct get_key_cookie cookie = { |
| 1838 | .error = 0, |
| 1839 | }; |
| 1840 | void *hdr; |
| 1841 | struct sk_buff *msg; |
| 1842 | |
| 1843 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1844 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1845 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1846 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1847 | return -EINVAL; |
| 1848 | |
| 1849 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1850 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1851 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1852 | pairwise = !!mac_addr; |
| 1853 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1854 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1855 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1856 | return -EINVAL; |
| 1857 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1858 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1859 | return -EINVAL; |
| 1860 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1861 | } |
| 1862 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1863 | if (!rdev->ops->get_key) |
| 1864 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1865 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1866 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1867 | if (!msg) |
| 1868 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1869 | |
| 1870 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1871 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1872 | if (IS_ERR(hdr)) |
| 1873 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1874 | |
| 1875 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1876 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1877 | |
| 1878 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1879 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1880 | if (mac_addr) |
| 1881 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1882 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1883 | if (pairwise && mac_addr && |
| 1884 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1885 | return -ENOENT; |
| 1886 | |
| 1887 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1888 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1889 | |
| 1890 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1891 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1892 | |
| 1893 | if (cookie.error) |
| 1894 | goto nla_put_failure; |
| 1895 | |
| 1896 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1897 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1898 | |
| 1899 | nla_put_failure: |
| 1900 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1901 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1902 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1903 | return err; |
| 1904 | } |
| 1905 | |
| 1906 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1907 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1909 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1910 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1911 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1912 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1913 | err = nl80211_parse_key(info, &key); |
| 1914 | if (err) |
| 1915 | return err; |
| 1916 | |
| 1917 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1918 | return -EINVAL; |
| 1919 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1920 | /* only support setting default key */ |
| 1921 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1922 | return -EINVAL; |
| 1923 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1924 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1925 | |
| 1926 | if (key.def) { |
| 1927 | if (!rdev->ops->set_default_key) { |
| 1928 | err = -EOPNOTSUPP; |
| 1929 | goto out; |
| 1930 | } |
| 1931 | |
| 1932 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1933 | if (err) |
| 1934 | goto out; |
| 1935 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1936 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1937 | key.def_uni, key.def_multi); |
| 1938 | |
| 1939 | if (err) |
| 1940 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1941 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1942 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1943 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1944 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1945 | } else { |
| 1946 | if (key.def_uni || !key.def_multi) { |
| 1947 | err = -EINVAL; |
| 1948 | goto out; |
| 1949 | } |
| 1950 | |
| 1951 | if (!rdev->ops->set_default_mgmt_key) { |
| 1952 | err = -EOPNOTSUPP; |
| 1953 | goto out; |
| 1954 | } |
| 1955 | |
| 1956 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1957 | if (err) |
| 1958 | goto out; |
| 1959 | |
| 1960 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1961 | dev, key.idx); |
| 1962 | if (err) |
| 1963 | goto out; |
| 1964 | |
| 1965 | #ifdef CONFIG_CFG80211_WEXT |
| 1966 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1967 | #endif |
| 1968 | } |
| 1969 | |
| 1970 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1971 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1972 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1973 | return err; |
| 1974 | } |
| 1975 | |
| 1976 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1977 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1978 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1979 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1980 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1981 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1982 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1983 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1984 | err = nl80211_parse_key(info, &key); |
| 1985 | if (err) |
| 1986 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1987 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1988 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1989 | return -EINVAL; |
| 1990 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1991 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1992 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1993 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1994 | if (key.type == -1) { |
| 1995 | if (mac_addr) |
| 1996 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1997 | else |
| 1998 | key.type = NL80211_KEYTYPE_GROUP; |
| 1999 | } |
| 2000 | |
| 2001 | /* for now */ |
| 2002 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2003 | key.type != NL80211_KEYTYPE_GROUP) |
| 2004 | return -EINVAL; |
| 2005 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2006 | if (!rdev->ops->add_key) |
| 2007 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2008 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2009 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2010 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2011 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2012 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2013 | |
| 2014 | wdev_lock(dev->ieee80211_ptr); |
| 2015 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2016 | if (!err) |
| 2017 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2018 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2019 | mac_addr, &key.p); |
| 2020 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2021 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2022 | return err; |
| 2023 | } |
| 2024 | |
| 2025 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2028 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2029 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2030 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2031 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2032 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2033 | err = nl80211_parse_key(info, &key); |
| 2034 | if (err) |
| 2035 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2036 | |
| 2037 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2038 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2039 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2040 | if (key.type == -1) { |
| 2041 | if (mac_addr) |
| 2042 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2043 | else |
| 2044 | key.type = NL80211_KEYTYPE_GROUP; |
| 2045 | } |
| 2046 | |
| 2047 | /* for now */ |
| 2048 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2049 | key.type != NL80211_KEYTYPE_GROUP) |
| 2050 | return -EINVAL; |
| 2051 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2052 | if (!rdev->ops->del_key) |
| 2053 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2054 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2055 | wdev_lock(dev->ieee80211_ptr); |
| 2056 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2057 | |
| 2058 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2059 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2060 | err = -ENOENT; |
| 2061 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2062 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2063 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2064 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2065 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2066 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2067 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2068 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2069 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2070 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2071 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2072 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2073 | } |
| 2074 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2075 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2076 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2077 | return err; |
| 2078 | } |
| 2079 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2080 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2081 | { |
| 2082 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 2083 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2085 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2086 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2087 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2088 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2089 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2090 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2091 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2092 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2093 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2094 | return -EINVAL; |
| 2095 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2096 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2097 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2098 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2099 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2100 | memset(¶ms, 0, sizeof(params)); |
| 2101 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2102 | switch (info->genlhdr->cmd) { |
| 2103 | case NL80211_CMD_NEW_BEACON: |
| 2104 | /* these are required for NEW_BEACON */ |
| 2105 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2106 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2107 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2108 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2109 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2110 | params.interval = |
| 2111 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2112 | params.dtim_period = |
| 2113 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2114 | |
| 2115 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2116 | if (err) |
| 2117 | return err; |
| 2118 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2119 | /* |
| 2120 | * In theory, some of these attributes could be required for |
| 2121 | * NEW_BEACON, but since they were not used when the command was |
| 2122 | * originally added, keep them optional for old user space |
| 2123 | * programs to work with drivers that do not need the additional |
| 2124 | * information. |
| 2125 | */ |
| 2126 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2127 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2128 | params.ssid_len = |
| 2129 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2130 | if (params.ssid_len == 0 || |
| 2131 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2132 | return -EINVAL; |
| 2133 | } |
| 2134 | |
| 2135 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2136 | params.hidden_ssid = nla_get_u32( |
| 2137 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2138 | if (params.hidden_ssid != |
| 2139 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2140 | params.hidden_ssid != |
| 2141 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2142 | params.hidden_ssid != |
| 2143 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2144 | return -EINVAL; |
| 2145 | } |
| 2146 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2147 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2148 | |
| 2149 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2150 | params.auth_type = nla_get_u32( |
| 2151 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2152 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2153 | return -EINVAL; |
| 2154 | } else |
| 2155 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2156 | |
| 2157 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2158 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2159 | if (err) |
| 2160 | return err; |
| 2161 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2162 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2163 | break; |
| 2164 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2165 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2166 | break; |
| 2167 | default: |
| 2168 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2169 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2170 | } |
| 2171 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2172 | if (!call) |
| 2173 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2174 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2175 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2176 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2177 | params.head_len = |
| 2178 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2179 | haveinfo = 1; |
| 2180 | } |
| 2181 | |
| 2182 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2183 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2184 | params.tail_len = |
| 2185 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2186 | haveinfo = 1; |
| 2187 | } |
| 2188 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2189 | if (!haveinfo) |
| 2190 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2191 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2192 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2193 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2194 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2195 | } |
| 2196 | |
| 2197 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2198 | params.proberesp_ies = |
| 2199 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2200 | params.proberesp_ies_len = |
| 2201 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2202 | } |
| 2203 | |
| 2204 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2205 | params.assocresp_ies = |
| 2206 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2207 | params.assocresp_ies_len = |
| 2208 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2209 | } |
| 2210 | |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 2211 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
| 2212 | params.probe_resp = |
| 2213 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2214 | params.probe_resp_len = |
| 2215 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
| 2216 | } |
| 2217 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2218 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2219 | if (!err && params.interval) |
| 2220 | wdev->beacon_interval = params.interval; |
| 2221 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2225 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2227 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2228 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2229 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2230 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2231 | if (!rdev->ops->del_beacon) |
| 2232 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2233 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2234 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2235 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2236 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2237 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2238 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2239 | if (!err) |
| 2240 | wdev->beacon_interval = 0; |
| 2241 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2242 | } |
| 2243 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2244 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2245 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2246 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2247 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2248 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2249 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2250 | }; |
| 2251 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2252 | static int parse_station_flags(struct genl_info *info, |
| 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 | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2286 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2287 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2288 | |
| 2289 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2290 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2291 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2292 | |
| 2293 | return 0; |
| 2294 | } |
| 2295 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2296 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2297 | int attr) |
| 2298 | { |
| 2299 | struct nlattr *rate; |
| 2300 | u16 bitrate; |
| 2301 | |
| 2302 | rate = nla_nest_start(msg, attr); |
| 2303 | if (!rate) |
| 2304 | goto nla_put_failure; |
| 2305 | |
| 2306 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2307 | bitrate = cfg80211_calculate_bitrate(info); |
| 2308 | if (bitrate > 0) |
| 2309 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2310 | |
| 2311 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2312 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2313 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2314 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2315 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2316 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2317 | |
| 2318 | nla_nest_end(msg, rate); |
| 2319 | return true; |
| 2320 | |
| 2321 | nla_put_failure: |
| 2322 | return false; |
| 2323 | } |
| 2324 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2325 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2326 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2327 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2328 | { |
| 2329 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2330 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2331 | |
| 2332 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2333 | if (!hdr) |
| 2334 | return -1; |
| 2335 | |
| 2336 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2337 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2338 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2339 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2340 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2341 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2342 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2343 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2344 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2345 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2346 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2347 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2348 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2349 | sinfo->inactive_time); |
| 2350 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2351 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2352 | sinfo->rx_bytes); |
| 2353 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2354 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2355 | sinfo->tx_bytes); |
| 2356 | if (sinfo->filled & STATION_INFO_LLID) |
| 2357 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2358 | sinfo->llid); |
| 2359 | if (sinfo->filled & STATION_INFO_PLID) |
| 2360 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2361 | sinfo->plid); |
| 2362 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2363 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2364 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2365 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2366 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2367 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2368 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2369 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2370 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2371 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2372 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2373 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2374 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2375 | } |
| 2376 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2377 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2378 | NL80211_STA_INFO_RX_BITRATE)) |
| 2379 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2380 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2381 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2382 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2383 | sinfo->rx_packets); |
| 2384 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2385 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2386 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2387 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2388 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2389 | sinfo->tx_retries); |
| 2390 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2391 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2392 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2393 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2394 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2395 | if (!bss_param) |
| 2396 | goto nla_put_failure; |
| 2397 | |
| 2398 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2399 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2400 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2401 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2402 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2403 | NLA_PUT_FLAG(msg, |
| 2404 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2405 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2406 | sinfo->bss_param.dtim_period); |
| 2407 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2408 | sinfo->bss_param.beacon_interval); |
| 2409 | |
| 2410 | nla_nest_end(msg, bss_param); |
| 2411 | } |
Helmut Schaa | bb6e753 | 2011-10-13 16:30:39 +0200 | [diff] [blame] | 2412 | if (sinfo->filled & STATION_INFO_STA_FLAGS) |
| 2413 | NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2414 | sizeof(struct nl80211_sta_flag_update), |
| 2415 | &sinfo->sta_flags); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2416 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2417 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2418 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2419 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2420 | sinfo->assoc_req_ies); |
| 2421 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2422 | return genlmsg_end(msg, hdr); |
| 2423 | |
| 2424 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2425 | genlmsg_cancel(msg, hdr); |
| 2426 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2427 | } |
| 2428 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2429 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2430 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2431 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2432 | struct station_info sinfo; |
| 2433 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2434 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2435 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2436 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2437 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2438 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2439 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2440 | if (err) |
| 2441 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2442 | |
| 2443 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2444 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2445 | goto out_err; |
| 2446 | } |
| 2447 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2448 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2449 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2450 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2451 | mac_addr, &sinfo); |
| 2452 | if (err == -ENOENT) |
| 2453 | break; |
| 2454 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2455 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2456 | |
| 2457 | if (nl80211_send_station(skb, |
| 2458 | NETLINK_CB(cb->skb).pid, |
| 2459 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2460 | netdev, mac_addr, |
| 2461 | &sinfo) < 0) |
| 2462 | goto out; |
| 2463 | |
| 2464 | sta_idx++; |
| 2465 | } |
| 2466 | |
| 2467 | |
| 2468 | out: |
| 2469 | cb->args[1] = sta_idx; |
| 2470 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2471 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2472 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2473 | |
| 2474 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2475 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2476 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2477 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2478 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2479 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2480 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2481 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2482 | struct sk_buff *msg; |
| 2483 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2484 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2485 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2486 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2487 | |
| 2488 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2489 | return -EINVAL; |
| 2490 | |
| 2491 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2492 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2493 | if (!rdev->ops->get_station) |
| 2494 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2495 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2496 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2497 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2498 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2499 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2500 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2501 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2502 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2503 | |
| 2504 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2505 | dev, mac_addr, &sinfo) < 0) { |
| 2506 | nlmsg_free(msg); |
| 2507 | return -ENOBUFS; |
| 2508 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2509 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2510 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2514 | * 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] | 2515 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2516 | static struct net_device *get_vlan(struct genl_info *info, |
| 2517 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2518 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2519 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2520 | struct net_device *v; |
| 2521 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2522 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2523 | if (!vlanattr) |
| 2524 | return NULL; |
| 2525 | |
| 2526 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 2527 | if (!v) |
| 2528 | return ERR_PTR(-ENODEV); |
| 2529 | |
| 2530 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 2531 | ret = -EINVAL; |
| 2532 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2533 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2534 | |
| 2535 | if (!netif_running(v)) { |
| 2536 | ret = -ENETDOWN; |
| 2537 | goto error; |
| 2538 | } |
| 2539 | |
| 2540 | return v; |
| 2541 | error: |
| 2542 | dev_put(v); |
| 2543 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2547 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2548 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2549 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2550 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2551 | struct station_parameters params; |
| 2552 | u8 *mac_addr = NULL; |
| 2553 | |
| 2554 | memset(¶ms, 0, sizeof(params)); |
| 2555 | |
| 2556 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2557 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2558 | |
| 2559 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2560 | return -EINVAL; |
| 2561 | |
| 2562 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2563 | return -EINVAL; |
| 2564 | |
| 2565 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2566 | |
| 2567 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2568 | params.supported_rates = |
| 2569 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2570 | params.supported_rates_len = |
| 2571 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2572 | } |
| 2573 | |
| 2574 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2575 | params.listen_interval = |
| 2576 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2577 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2578 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2579 | params.ht_capa = |
| 2580 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2581 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2582 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2583 | return -EINVAL; |
| 2584 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2585 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2586 | params.plink_action = |
| 2587 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2588 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2589 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2590 | params.plink_state = |
| 2591 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2592 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2593 | params.vlan = get_vlan(info, rdev); |
| 2594 | if (IS_ERR(params.vlan)) |
| 2595 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2596 | |
| 2597 | /* validate settings */ |
| 2598 | err = 0; |
| 2599 | |
| 2600 | switch (dev->ieee80211_ptr->iftype) { |
| 2601 | case NL80211_IFTYPE_AP: |
| 2602 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2603 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2604 | /* disallow mesh-specific things */ |
| 2605 | if (params.plink_action) |
| 2606 | err = -EINVAL; |
| 2607 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2608 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2609 | case NL80211_IFTYPE_STATION: |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2610 | /* disallow things sta doesn't support */ |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2611 | if (params.plink_action) |
| 2612 | err = -EINVAL; |
| 2613 | if (params.vlan) |
| 2614 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2615 | if (params.supported_rates && |
| 2616 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2617 | err = -EINVAL; |
| 2618 | if (params.ht_capa) |
| 2619 | err = -EINVAL; |
| 2620 | if (params.listen_interval >= 0) |
| 2621 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2622 | if (params.sta_flags_mask & |
| 2623 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2624 | BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 2625 | err = -EINVAL; |
| 2626 | /* can't change the TDLS bit */ |
| 2627 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2628 | (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2629 | err = -EINVAL; |
| 2630 | break; |
| 2631 | case NL80211_IFTYPE_MESH_POINT: |
| 2632 | /* disallow things mesh doesn't support */ |
| 2633 | if (params.vlan) |
| 2634 | err = -EINVAL; |
| 2635 | if (params.ht_capa) |
| 2636 | err = -EINVAL; |
| 2637 | if (params.listen_interval >= 0) |
| 2638 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2639 | if (params.sta_flags_mask & |
| 2640 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2641 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2642 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2643 | err = -EINVAL; |
| 2644 | break; |
| 2645 | default: |
| 2646 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2647 | } |
| 2648 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2649 | if (err) |
| 2650 | goto out; |
| 2651 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2652 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2653 | err = -EOPNOTSUPP; |
| 2654 | goto out; |
| 2655 | } |
| 2656 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2657 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2658 | |
| 2659 | out: |
| 2660 | if (params.vlan) |
| 2661 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2662 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2663 | return err; |
| 2664 | } |
| 2665 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2666 | static struct nla_policy |
| 2667 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2668 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2669 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2670 | }; |
| 2671 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2672 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2673 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2675 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2676 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2677 | struct station_parameters params; |
| 2678 | u8 *mac_addr = NULL; |
| 2679 | |
| 2680 | memset(¶ms, 0, sizeof(params)); |
| 2681 | |
| 2682 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2683 | return -EINVAL; |
| 2684 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2685 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2686 | return -EINVAL; |
| 2687 | |
| 2688 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2689 | return -EINVAL; |
| 2690 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2691 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2692 | return -EINVAL; |
| 2693 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2694 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2695 | params.supported_rates = |
| 2696 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2697 | params.supported_rates_len = |
| 2698 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2699 | params.listen_interval = |
| 2700 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2701 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2702 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2703 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2704 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2705 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2706 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2707 | params.ht_capa = |
| 2708 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2709 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2710 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2711 | params.plink_action = |
| 2712 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2713 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2714 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2715 | return -EINVAL; |
| 2716 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2717 | /* parse WME attributes if sta is WME capable */ |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 2718 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Arik Nemtsov | cd32984 | 2011-09-26 09:36:42 +0300 | [diff] [blame] | 2719 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2720 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2721 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2722 | struct nlattr *nla; |
| 2723 | |
| 2724 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2725 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2726 | nl80211_sta_wme_policy); |
| 2727 | if (err) |
| 2728 | return err; |
| 2729 | |
| 2730 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2731 | params.uapsd_queues = |
| 2732 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2733 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2734 | return -EINVAL; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2735 | |
| 2736 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2737 | params.max_sp = |
| 2738 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2739 | |
| 2740 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2741 | return -EINVAL; |
Johannes Berg | 3b9ce80 | 2011-09-27 20:56:12 +0200 | [diff] [blame] | 2742 | |
| 2743 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2744 | } |
| 2745 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2746 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2747 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2748 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2749 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO && |
| 2750 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) |
| 2751 | return -EINVAL; |
| 2752 | |
| 2753 | /* |
| 2754 | * Only managed stations can add TDLS peers, and only when the |
| 2755 | * wiphy supports external TDLS setup. |
| 2756 | */ |
| 2757 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION && |
| 2758 | !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2759 | (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 2760 | (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2761 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2762 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 2763 | params.vlan = get_vlan(info, rdev); |
| 2764 | if (IS_ERR(params.vlan)) |
| 2765 | return PTR_ERR(params.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2766 | |
| 2767 | /* validate settings */ |
| 2768 | err = 0; |
| 2769 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2770 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2771 | err = -EOPNOTSUPP; |
| 2772 | goto out; |
| 2773 | } |
| 2774 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2775 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2776 | |
| 2777 | out: |
| 2778 | if (params.vlan) |
| 2779 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2780 | return err; |
| 2781 | } |
| 2782 | |
| 2783 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2784 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2785 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2786 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2787 | u8 *mac_addr = NULL; |
| 2788 | |
| 2789 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2790 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2791 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2792 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2793 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2794 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2795 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2796 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2797 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2798 | if (!rdev->ops->del_station) |
| 2799 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2800 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2801 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2802 | } |
| 2803 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2804 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2805 | int flags, struct net_device *dev, |
| 2806 | u8 *dst, u8 *next_hop, |
| 2807 | struct mpath_info *pinfo) |
| 2808 | { |
| 2809 | void *hdr; |
| 2810 | struct nlattr *pinfoattr; |
| 2811 | |
| 2812 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2813 | if (!hdr) |
| 2814 | return -1; |
| 2815 | |
| 2816 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2817 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2818 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2819 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2820 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2821 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2822 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2823 | if (!pinfoattr) |
| 2824 | goto nla_put_failure; |
| 2825 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2826 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2827 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2828 | if (pinfo->filled & MPATH_INFO_SN) |
| 2829 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2830 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2831 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2832 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2833 | pinfo->metric); |
| 2834 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2835 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2836 | pinfo->exptime); |
| 2837 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2838 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2839 | pinfo->flags); |
| 2840 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2841 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2842 | pinfo->discovery_timeout); |
| 2843 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2844 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2845 | pinfo->discovery_retries); |
| 2846 | |
| 2847 | nla_nest_end(msg, pinfoattr); |
| 2848 | |
| 2849 | return genlmsg_end(msg, hdr); |
| 2850 | |
| 2851 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2852 | genlmsg_cancel(msg, hdr); |
| 2853 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2857 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2858 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2859 | struct mpath_info pinfo; |
| 2860 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2861 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2862 | u8 dst[ETH_ALEN]; |
| 2863 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2864 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2865 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2866 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2867 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2868 | if (err) |
| 2869 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2870 | |
| 2871 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2872 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2873 | goto out_err; |
| 2874 | } |
| 2875 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2876 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2877 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2878 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2879 | } |
| 2880 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2881 | while (1) { |
| 2882 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2883 | dst, next_hop, &pinfo); |
| 2884 | if (err == -ENOENT) |
| 2885 | break; |
| 2886 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2887 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2888 | |
| 2889 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2890 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2891 | netdev, dst, next_hop, |
| 2892 | &pinfo) < 0) |
| 2893 | goto out; |
| 2894 | |
| 2895 | path_idx++; |
| 2896 | } |
| 2897 | |
| 2898 | |
| 2899 | out: |
| 2900 | cb->args[1] = path_idx; |
| 2901 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2902 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2903 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2904 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2908 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2910 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2911 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2912 | struct mpath_info pinfo; |
| 2913 | struct sk_buff *msg; |
| 2914 | u8 *dst = NULL; |
| 2915 | u8 next_hop[ETH_ALEN]; |
| 2916 | |
| 2917 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2918 | |
| 2919 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2920 | return -EINVAL; |
| 2921 | |
| 2922 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2923 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2924 | if (!rdev->ops->get_mpath) |
| 2925 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2926 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2927 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2928 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2929 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2930 | 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] | 2931 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2932 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2933 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2934 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2935 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2936 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2937 | |
| 2938 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2939 | dev, dst, next_hop, &pinfo) < 0) { |
| 2940 | nlmsg_free(msg); |
| 2941 | return -ENOBUFS; |
| 2942 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2943 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2944 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2948 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2949 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2950 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2951 | u8 *dst = NULL; |
| 2952 | u8 *next_hop = NULL; |
| 2953 | |
| 2954 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2955 | return -EINVAL; |
| 2956 | |
| 2957 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2958 | return -EINVAL; |
| 2959 | |
| 2960 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2961 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2962 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2963 | if (!rdev->ops->change_mpath) |
| 2964 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2965 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2966 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2967 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2968 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2969 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2970 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2971 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2972 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2973 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2975 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2976 | u8 *dst = NULL; |
| 2977 | u8 *next_hop = NULL; |
| 2978 | |
| 2979 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2980 | return -EINVAL; |
| 2981 | |
| 2982 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2983 | return -EINVAL; |
| 2984 | |
| 2985 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2986 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2987 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2988 | if (!rdev->ops->add_mpath) |
| 2989 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2990 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2991 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2992 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2993 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2994 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2998 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2999 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3000 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3001 | u8 *dst = NULL; |
| 3002 | |
| 3003 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3004 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3005 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3006 | if (!rdev->ops->del_mpath) |
| 3007 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3008 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3009 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3010 | } |
| 3011 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3012 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 3013 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3015 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3016 | struct bss_parameters params; |
| 3017 | |
| 3018 | memset(¶ms, 0, sizeof(params)); |
| 3019 | /* default to not changing parameters */ |
| 3020 | params.use_cts_prot = -1; |
| 3021 | params.use_short_preamble = -1; |
| 3022 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3023 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3024 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3025 | |
| 3026 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 3027 | params.use_cts_prot = |
| 3028 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 3029 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 3030 | params.use_short_preamble = |
| 3031 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 3032 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 3033 | params.use_short_slot_time = |
| 3034 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 3035 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 3036 | params.basic_rates = |
| 3037 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3038 | params.basic_rates_len = |
| 3039 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 3040 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 3041 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 3042 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 3043 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 3044 | params.ht_opmode = |
| 3045 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3046 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3047 | if (!rdev->ops->change_bss) |
| 3048 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3049 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3050 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3051 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3052 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3053 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3054 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3055 | } |
| 3056 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3057 | 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] | 3058 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3059 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3060 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3061 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3062 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3063 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3064 | }; |
| 3065 | |
| 3066 | static int parse_reg_rule(struct nlattr *tb[], |
| 3067 | struct ieee80211_reg_rule *reg_rule) |
| 3068 | { |
| 3069 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3070 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3071 | |
| 3072 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3073 | return -EINVAL; |
| 3074 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3075 | return -EINVAL; |
| 3076 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3077 | return -EINVAL; |
| 3078 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3079 | return -EINVAL; |
| 3080 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3081 | return -EINVAL; |
| 3082 | |
| 3083 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3084 | |
| 3085 | freq_range->start_freq_khz = |
| 3086 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3087 | freq_range->end_freq_khz = |
| 3088 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3089 | freq_range->max_bandwidth_khz = |
| 3090 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3091 | |
| 3092 | power_rule->max_eirp = |
| 3093 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3094 | |
| 3095 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3096 | power_rule->max_antenna_gain = |
| 3097 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3098 | |
| 3099 | return 0; |
| 3100 | } |
| 3101 | |
| 3102 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3103 | { |
| 3104 | int r; |
| 3105 | char *data = NULL; |
| 3106 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3107 | /* |
| 3108 | * You should only get this when cfg80211 hasn't yet initialized |
| 3109 | * completely when built-in to the kernel right between the time |
| 3110 | * window between nl80211_init() and regulatory_init(), if that is |
| 3111 | * even possible. |
| 3112 | */ |
| 3113 | mutex_lock(&cfg80211_mutex); |
| 3114 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3115 | mutex_unlock(&cfg80211_mutex); |
| 3116 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3117 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3118 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3119 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3120 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3121 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3122 | |
| 3123 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3124 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3125 | r = regulatory_hint_user(data); |
| 3126 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3127 | return r; |
| 3128 | } |
| 3129 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3130 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3131 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3132 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3133 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3134 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3135 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3136 | struct mesh_config cur_params; |
| 3137 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3138 | void *hdr; |
| 3139 | struct nlattr *pinfoattr; |
| 3140 | struct sk_buff *msg; |
| 3141 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3142 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3143 | return -EOPNOTSUPP; |
| 3144 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3145 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3146 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3147 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3148 | wdev_lock(wdev); |
| 3149 | /* If not connected, get default parameters */ |
| 3150 | if (!wdev->mesh_id_len) |
| 3151 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3152 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3153 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3154 | &cur_params); |
| 3155 | wdev_unlock(wdev); |
| 3156 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3157 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3158 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3159 | |
| 3160 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3161 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3162 | if (!msg) |
| 3163 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3164 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3165 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3166 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3167 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3168 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3169 | if (!pinfoattr) |
| 3170 | goto nla_put_failure; |
| 3171 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3172 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3173 | cur_params.dot11MeshRetryTimeout); |
| 3174 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3175 | cur_params.dot11MeshConfirmTimeout); |
| 3176 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3177 | cur_params.dot11MeshHoldingTimeout); |
| 3178 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3179 | cur_params.dot11MeshMaxPeerLinks); |
| 3180 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3181 | cur_params.dot11MeshMaxRetries); |
| 3182 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3183 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3184 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3185 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3186 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3187 | cur_params.auto_open_plinks); |
| 3188 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3189 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3190 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3191 | cur_params.path_refresh_time); |
| 3192 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3193 | cur_params.min_discovery_timeout); |
| 3194 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3195 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3196 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3197 | cur_params.dot11MeshHWMPpreqMinInterval); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3198 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3199 | cur_params.dot11MeshHWMPperrMinInterval); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3200 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3201 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3202 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3203 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3204 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3205 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3206 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3207 | cur_params.dot11MeshGateAnnouncementProtocol); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3208 | nla_nest_end(msg, pinfoattr); |
| 3209 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3210 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3211 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3212 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3213 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3214 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3215 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3216 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3219 | 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] | 3220 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3221 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3222 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3223 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3224 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3225 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3226 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3227 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3228 | |
| 3229 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3230 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3231 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3232 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3233 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3234 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3235 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3236 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3237 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3238 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3239 | }; |
| 3240 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3241 | static const struct nla_policy |
| 3242 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3243 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3244 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3245 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3246 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3247 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3248 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3249 | }; |
| 3250 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3251 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3252 | struct mesh_config *cfg, |
| 3253 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3254 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3255 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3256 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3257 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3258 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3259 | do {\ |
| 3260 | if (table[attr_num]) {\ |
| 3261 | cfg->param = nla_fn(table[attr_num]); \ |
| 3262 | mask |= (1 << (attr_num - 1)); \ |
| 3263 | } \ |
| 3264 | } while (0);\ |
| 3265 | |
| 3266 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3267 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3268 | return -EINVAL; |
| 3269 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3270 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3271 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3272 | return -EINVAL; |
| 3273 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3274 | /* This makes sure that there aren't more than 32 mesh config |
| 3275 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3276 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3277 | |
| 3278 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3279 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3280 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3281 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3282 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3283 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3284 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3285 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3286 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3287 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3288 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3289 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3290 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3291 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3292 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3293 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3294 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3295 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3296 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3297 | nla_get_u8); |
| 3298 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3299 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3300 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3301 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3302 | nla_get_u16); |
| 3303 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3304 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3305 | nla_get_u32); |
| 3306 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3307 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3308 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 3309 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
| 3310 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 3311 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3312 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3313 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3314 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3315 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3316 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3317 | dot11MeshHWMPRootMode, mask, |
| 3318 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3319 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3320 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3321 | dot11MeshHWMPRannInterval, mask, |
| 3322 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3323 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3324 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3325 | dot11MeshGateAnnouncementProtocol, mask, |
| 3326 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3327 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3328 | if (mask_out) |
| 3329 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3330 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3331 | return 0; |
| 3332 | |
| 3333 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3334 | } |
| 3335 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3336 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3337 | struct mesh_setup *setup) |
| 3338 | { |
| 3339 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3340 | |
| 3341 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3342 | return -EINVAL; |
| 3343 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3344 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3345 | nl80211_mesh_setup_params_policy)) |
| 3346 | return -EINVAL; |
| 3347 | |
| 3348 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3349 | setup->path_sel_proto = |
| 3350 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3351 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3352 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3353 | |
| 3354 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3355 | setup->path_metric = |
| 3356 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3357 | IEEE80211_PATH_METRIC_VENDOR : |
| 3358 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3359 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3360 | |
| 3361 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3362 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3363 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3364 | if (!is_valid_ie_attr(ieattr)) |
| 3365 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3366 | setup->ie = nla_data(ieattr); |
| 3367 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3368 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3369 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3370 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3371 | |
| 3372 | return 0; |
| 3373 | } |
| 3374 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3375 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3376 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3377 | { |
| 3378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3379 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3380 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3381 | struct mesh_config cfg; |
| 3382 | u32 mask; |
| 3383 | int err; |
| 3384 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3385 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3386 | return -EOPNOTSUPP; |
| 3387 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3388 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3389 | return -EOPNOTSUPP; |
| 3390 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3391 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3392 | if (err) |
| 3393 | return err; |
| 3394 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3395 | wdev_lock(wdev); |
| 3396 | if (!wdev->mesh_id_len) |
| 3397 | err = -ENOLINK; |
| 3398 | |
| 3399 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3400 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3401 | mask, &cfg); |
| 3402 | |
| 3403 | wdev_unlock(wdev); |
| 3404 | |
| 3405 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3406 | } |
| 3407 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3408 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3409 | { |
| 3410 | struct sk_buff *msg; |
| 3411 | void *hdr = NULL; |
| 3412 | struct nlattr *nl_reg_rules; |
| 3413 | unsigned int i; |
| 3414 | int err = -EINVAL; |
| 3415 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3416 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3417 | |
| 3418 | if (!cfg80211_regdomain) |
| 3419 | goto out; |
| 3420 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3421 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3422 | if (!msg) { |
| 3423 | err = -ENOBUFS; |
| 3424 | goto out; |
| 3425 | } |
| 3426 | |
| 3427 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3428 | NL80211_CMD_GET_REG); |
| 3429 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3430 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3431 | |
| 3432 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3433 | cfg80211_regdomain->alpha2); |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3434 | if (cfg80211_regdomain->dfs_region) |
| 3435 | NLA_PUT_U8(msg, NL80211_ATTR_DFS_REGION, |
| 3436 | cfg80211_regdomain->dfs_region); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3437 | |
| 3438 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3439 | if (!nl_reg_rules) |
| 3440 | goto nla_put_failure; |
| 3441 | |
| 3442 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3443 | struct nlattr *nl_reg_rule; |
| 3444 | const struct ieee80211_reg_rule *reg_rule; |
| 3445 | const struct ieee80211_freq_range *freq_range; |
| 3446 | const struct ieee80211_power_rule *power_rule; |
| 3447 | |
| 3448 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3449 | freq_range = ®_rule->freq_range; |
| 3450 | power_rule = ®_rule->power_rule; |
| 3451 | |
| 3452 | nl_reg_rule = nla_nest_start(msg, i); |
| 3453 | if (!nl_reg_rule) |
| 3454 | goto nla_put_failure; |
| 3455 | |
| 3456 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3457 | reg_rule->flags); |
| 3458 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3459 | freq_range->start_freq_khz); |
| 3460 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3461 | freq_range->end_freq_khz); |
| 3462 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3463 | freq_range->max_bandwidth_khz); |
| 3464 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3465 | power_rule->max_antenna_gain); |
| 3466 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3467 | power_rule->max_eirp); |
| 3468 | |
| 3469 | nla_nest_end(msg, nl_reg_rule); |
| 3470 | } |
| 3471 | |
| 3472 | nla_nest_end(msg, nl_reg_rules); |
| 3473 | |
| 3474 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3475 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3476 | goto out; |
| 3477 | |
| 3478 | nla_put_failure: |
| 3479 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3480 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3481 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3482 | err = -EMSGSIZE; |
| 3483 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3484 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3485 | return err; |
| 3486 | } |
| 3487 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3488 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3489 | { |
| 3490 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3491 | struct nlattr *nl_reg_rule; |
| 3492 | char *alpha2 = NULL; |
| 3493 | int rem_reg_rules = 0, r = 0; |
| 3494 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3495 | u8 dfs_region = 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3496 | struct ieee80211_regdomain *rd = NULL; |
| 3497 | |
| 3498 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3499 | return -EINVAL; |
| 3500 | |
| 3501 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3502 | return -EINVAL; |
| 3503 | |
| 3504 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3505 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3506 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 3507 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 3508 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3509 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3510 | rem_reg_rules) { |
| 3511 | num_rules++; |
| 3512 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3513 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3516 | mutex_lock(&cfg80211_mutex); |
| 3517 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3518 | if (!reg_is_valid_request(alpha2)) { |
| 3519 | r = -EINVAL; |
| 3520 | goto bad_reg; |
| 3521 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3522 | |
| 3523 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3524 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3525 | |
| 3526 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3527 | if (!rd) { |
| 3528 | r = -ENOMEM; |
| 3529 | goto bad_reg; |
| 3530 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3531 | |
| 3532 | rd->n_reg_rules = num_rules; |
| 3533 | rd->alpha2[0] = alpha2[0]; |
| 3534 | rd->alpha2[1] = alpha2[1]; |
| 3535 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 3536 | /* |
| 3537 | * Disable DFS master mode if the DFS region was |
| 3538 | * not supported or known on this kernel. |
| 3539 | */ |
| 3540 | if (reg_supported_dfs_region(dfs_region)) |
| 3541 | rd->dfs_region = dfs_region; |
| 3542 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3543 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3544 | rem_reg_rules) { |
| 3545 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3546 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3547 | reg_rule_policy); |
| 3548 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3549 | if (r) |
| 3550 | goto bad_reg; |
| 3551 | |
| 3552 | rule_idx++; |
| 3553 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3554 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3555 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3556 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3557 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | BUG_ON(rule_idx != num_rules); |
| 3561 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3562 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3563 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3564 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3565 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3566 | return r; |
| 3567 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3568 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3569 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3570 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3571 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3572 | } |
| 3573 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3574 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3575 | { |
| 3576 | struct nlattr *attr1, *attr2; |
| 3577 | int n_channels = 0, tmp1, tmp2; |
| 3578 | |
| 3579 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3580 | n_channels++; |
| 3581 | /* |
| 3582 | * Some hardware has a limited channel list for |
| 3583 | * scanning, and it is pretty much nonsensical |
| 3584 | * to scan for a channel twice, so disallow that |
| 3585 | * and don't require drivers to check that the |
| 3586 | * channel list they get isn't longer than what |
| 3587 | * they can scan, as long as they can scan all |
| 3588 | * the channels they registered at once. |
| 3589 | */ |
| 3590 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3591 | if (attr1 != attr2 && |
| 3592 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3593 | return 0; |
| 3594 | } |
| 3595 | |
| 3596 | return n_channels; |
| 3597 | } |
| 3598 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3599 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3600 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3602 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3603 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3604 | struct nlattr *attr; |
| 3605 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3606 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3607 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3608 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3609 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3610 | return -EINVAL; |
| 3611 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3612 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3613 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3614 | if (!rdev->ops->scan) |
| 3615 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3616 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3617 | if (rdev->scan_req) |
| 3618 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3619 | |
| 3620 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3621 | n_channels = validate_scan_freqs( |
| 3622 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3623 | if (!n_channels) |
| 3624 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3625 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3626 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3627 | n_channels = 0; |
| 3628 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3629 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3630 | if (wiphy->bands[band]) |
| 3631 | n_channels += wiphy->bands[band]->n_channels; |
| 3632 | } |
| 3633 | |
| 3634 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3635 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3636 | n_ssids++; |
| 3637 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3638 | if (n_ssids > wiphy->max_scan_ssids) |
| 3639 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3640 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3641 | if (info->attrs[NL80211_ATTR_IE]) |
| 3642 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3643 | else |
| 3644 | ie_len = 0; |
| 3645 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3646 | if (ie_len > wiphy->max_scan_ie_len) |
| 3647 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3648 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3649 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3650 | + sizeof(*request->ssids) * n_ssids |
| 3651 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3652 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3653 | if (!request) |
| 3654 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3655 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3656 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3657 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3658 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3659 | if (ie_len) { |
| 3660 | if (request->ssids) |
| 3661 | request->ie = (void *)(request->ssids + n_ssids); |
| 3662 | else |
| 3663 | request->ie = (void *)(request->channels + n_channels); |
| 3664 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3665 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3666 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3667 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3668 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3669 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3670 | struct ieee80211_channel *chan; |
| 3671 | |
| 3672 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3673 | |
| 3674 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3675 | err = -EINVAL; |
| 3676 | goto out_free; |
| 3677 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3678 | |
| 3679 | /* ignore disabled channels */ |
| 3680 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3681 | continue; |
| 3682 | |
| 3683 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3684 | i++; |
| 3685 | } |
| 3686 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3687 | enum ieee80211_band band; |
| 3688 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3689 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3690 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3691 | int j; |
| 3692 | if (!wiphy->bands[band]) |
| 3693 | continue; |
| 3694 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3695 | struct ieee80211_channel *chan; |
| 3696 | |
| 3697 | chan = &wiphy->bands[band]->channels[j]; |
| 3698 | |
| 3699 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3700 | continue; |
| 3701 | |
| 3702 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3703 | i++; |
| 3704 | } |
| 3705 | } |
| 3706 | } |
| 3707 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3708 | if (!i) { |
| 3709 | err = -EINVAL; |
| 3710 | goto out_free; |
| 3711 | } |
| 3712 | |
| 3713 | request->n_channels = i; |
| 3714 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3715 | i = 0; |
| 3716 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3717 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3718 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3719 | err = -EINVAL; |
| 3720 | goto out_free; |
| 3721 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3722 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3723 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3724 | i++; |
| 3725 | } |
| 3726 | } |
| 3727 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3728 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3729 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3730 | memcpy((void *)request->ie, |
| 3731 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3732 | request->ie_len); |
| 3733 | } |
| 3734 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3735 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3736 | if (wiphy->bands[i]) |
| 3737 | request->rates[i] = |
| 3738 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3739 | |
| 3740 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3741 | nla_for_each_nested(attr, |
| 3742 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3743 | tmp) { |
| 3744 | enum ieee80211_band band = nla_type(attr); |
| 3745 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3746 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3747 | err = -EINVAL; |
| 3748 | goto out_free; |
| 3749 | } |
| 3750 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3751 | nla_data(attr), |
| 3752 | nla_len(attr), |
| 3753 | &request->rates[band]); |
| 3754 | if (err) |
| 3755 | goto out_free; |
| 3756 | } |
| 3757 | } |
| 3758 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3759 | request->no_cck = |
| 3760 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3761 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3762 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3763 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3764 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3765 | rdev->scan_req = request; |
| 3766 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3767 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3768 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3769 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3770 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3771 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3772 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3773 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3774 | kfree(request); |
| 3775 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3776 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3777 | return err; |
| 3778 | } |
| 3779 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3780 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3781 | struct genl_info *info) |
| 3782 | { |
| 3783 | struct cfg80211_sched_scan_request *request; |
| 3784 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3785 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3786 | struct nlattr *attr; |
| 3787 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3788 | 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] | 3789 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3790 | enum ieee80211_band band; |
| 3791 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3792 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3793 | |
| 3794 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3795 | !rdev->ops->sched_scan_start) |
| 3796 | return -EOPNOTSUPP; |
| 3797 | |
| 3798 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3799 | return -EINVAL; |
| 3800 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3801 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3802 | return -EINVAL; |
| 3803 | |
| 3804 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3805 | if (interval == 0) |
| 3806 | return -EINVAL; |
| 3807 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3808 | wiphy = &rdev->wiphy; |
| 3809 | |
| 3810 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3811 | n_channels = validate_scan_freqs( |
| 3812 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3813 | if (!n_channels) |
| 3814 | return -EINVAL; |
| 3815 | } else { |
| 3816 | n_channels = 0; |
| 3817 | |
| 3818 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3819 | if (wiphy->bands[band]) |
| 3820 | n_channels += wiphy->bands[band]->n_channels; |
| 3821 | } |
| 3822 | |
| 3823 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3824 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3825 | tmp) |
| 3826 | n_ssids++; |
| 3827 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3828 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3829 | return -EINVAL; |
| 3830 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3831 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3832 | nla_for_each_nested(attr, |
| 3833 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3834 | tmp) |
| 3835 | n_match_sets++; |
| 3836 | |
| 3837 | if (n_match_sets > wiphy->max_match_sets) |
| 3838 | return -EINVAL; |
| 3839 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3840 | if (info->attrs[NL80211_ATTR_IE]) |
| 3841 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3842 | else |
| 3843 | ie_len = 0; |
| 3844 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3845 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3846 | return -EINVAL; |
| 3847 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3848 | mutex_lock(&rdev->sched_scan_mtx); |
| 3849 | |
| 3850 | if (rdev->sched_scan_req) { |
| 3851 | err = -EINPROGRESS; |
| 3852 | goto out; |
| 3853 | } |
| 3854 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3855 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3856 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3857 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3858 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3859 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3860 | if (!request) { |
| 3861 | err = -ENOMEM; |
| 3862 | goto out; |
| 3863 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3864 | |
| 3865 | if (n_ssids) |
| 3866 | request->ssids = (void *)&request->channels[n_channels]; |
| 3867 | request->n_ssids = n_ssids; |
| 3868 | if (ie_len) { |
| 3869 | if (request->ssids) |
| 3870 | request->ie = (void *)(request->ssids + n_ssids); |
| 3871 | else |
| 3872 | request->ie = (void *)(request->channels + n_channels); |
| 3873 | } |
| 3874 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3875 | if (n_match_sets) { |
| 3876 | if (request->ie) |
| 3877 | request->match_sets = (void *)(request->ie + ie_len); |
| 3878 | else if (request->ssids) |
| 3879 | request->match_sets = |
| 3880 | (void *)(request->ssids + n_ssids); |
| 3881 | else |
| 3882 | request->match_sets = |
| 3883 | (void *)(request->channels + n_channels); |
| 3884 | } |
| 3885 | request->n_match_sets = n_match_sets; |
| 3886 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3887 | i = 0; |
| 3888 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3889 | /* user specified, bail out if channel not found */ |
| 3890 | nla_for_each_nested(attr, |
| 3891 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3892 | tmp) { |
| 3893 | struct ieee80211_channel *chan; |
| 3894 | |
| 3895 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3896 | |
| 3897 | if (!chan) { |
| 3898 | err = -EINVAL; |
| 3899 | goto out_free; |
| 3900 | } |
| 3901 | |
| 3902 | /* ignore disabled channels */ |
| 3903 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3904 | continue; |
| 3905 | |
| 3906 | request->channels[i] = chan; |
| 3907 | i++; |
| 3908 | } |
| 3909 | } else { |
| 3910 | /* all channels */ |
| 3911 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3912 | int j; |
| 3913 | if (!wiphy->bands[band]) |
| 3914 | continue; |
| 3915 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3916 | struct ieee80211_channel *chan; |
| 3917 | |
| 3918 | chan = &wiphy->bands[band]->channels[j]; |
| 3919 | |
| 3920 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3921 | continue; |
| 3922 | |
| 3923 | request->channels[i] = chan; |
| 3924 | i++; |
| 3925 | } |
| 3926 | } |
| 3927 | } |
| 3928 | |
| 3929 | if (!i) { |
| 3930 | err = -EINVAL; |
| 3931 | goto out_free; |
| 3932 | } |
| 3933 | |
| 3934 | request->n_channels = i; |
| 3935 | |
| 3936 | i = 0; |
| 3937 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3938 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3939 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3940 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3941 | err = -EINVAL; |
| 3942 | goto out_free; |
| 3943 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3944 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3945 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3946 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3947 | i++; |
| 3948 | } |
| 3949 | } |
| 3950 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3951 | i = 0; |
| 3952 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 3953 | nla_for_each_nested(attr, |
| 3954 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3955 | tmp) { |
| 3956 | struct nlattr *ssid; |
| 3957 | |
| 3958 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 3959 | nla_data(attr), nla_len(attr), |
| 3960 | nl80211_match_policy); |
| 3961 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 3962 | if (ssid) { |
| 3963 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 3964 | err = -EINVAL; |
| 3965 | goto out_free; |
| 3966 | } |
| 3967 | memcpy(request->match_sets[i].ssid.ssid, |
| 3968 | nla_data(ssid), nla_len(ssid)); |
| 3969 | request->match_sets[i].ssid.ssid_len = |
| 3970 | nla_len(ssid); |
| 3971 | } |
| 3972 | i++; |
| 3973 | } |
| 3974 | } |
| 3975 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3976 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3977 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3978 | memcpy((void *)request->ie, |
| 3979 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3980 | request->ie_len); |
| 3981 | } |
| 3982 | |
| 3983 | request->dev = dev; |
| 3984 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3985 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3986 | |
| 3987 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3988 | if (!err) { |
| 3989 | rdev->sched_scan_req = request; |
| 3990 | nl80211_send_sched_scan(rdev, dev, |
| 3991 | NL80211_CMD_START_SCHED_SCAN); |
| 3992 | goto out; |
| 3993 | } |
| 3994 | |
| 3995 | out_free: |
| 3996 | kfree(request); |
| 3997 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3998 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3999 | return err; |
| 4000 | } |
| 4001 | |
| 4002 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 4003 | struct genl_info *info) |
| 4004 | { |
| 4005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4006 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4007 | |
| 4008 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 4009 | !rdev->ops->sched_scan_stop) |
| 4010 | return -EOPNOTSUPP; |
| 4011 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 4012 | mutex_lock(&rdev->sched_scan_mtx); |
| 4013 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 4014 | mutex_unlock(&rdev->sched_scan_mtx); |
| 4015 | |
| 4016 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 4017 | } |
| 4018 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4019 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 4020 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4021 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4022 | struct wireless_dev *wdev, |
| 4023 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4024 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4025 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4026 | void *hdr; |
| 4027 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4028 | int i; |
| 4029 | |
| 4030 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4031 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4032 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4033 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 4034 | if (!hdr) |
| 4035 | return -1; |
| 4036 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4037 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 4038 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4039 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4040 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4041 | |
| 4042 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 4043 | if (!bss) |
| 4044 | goto nla_put_failure; |
| 4045 | if (!is_zero_ether_addr(res->bssid)) |
| 4046 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 4047 | if (res->information_elements && res->len_information_elements) |
| 4048 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 4049 | res->len_information_elements, |
| 4050 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 4051 | if (res->beacon_ies && res->len_beacon_ies && |
| 4052 | res->beacon_ies != res->information_elements) |
| 4053 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 4054 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4055 | if (res->tsf) |
| 4056 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 4057 | if (res->beacon_interval) |
| 4058 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 4059 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 4060 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 4061 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 4062 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4063 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 4064 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4065 | case CFG80211_SIGNAL_TYPE_MBM: |
| 4066 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 4067 | break; |
| 4068 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 4069 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 4070 | break; |
| 4071 | default: |
| 4072 | break; |
| 4073 | } |
| 4074 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4075 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4076 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4077 | case NL80211_IFTYPE_STATION: |
| 4078 | if (intbss == wdev->current_bss) |
| 4079 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4080 | NL80211_BSS_STATUS_ASSOCIATED); |
| 4081 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 4082 | if (intbss != wdev->auth_bsses[i]) |
| 4083 | continue; |
| 4084 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4085 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 4086 | break; |
| 4087 | } |
| 4088 | break; |
| 4089 | case NL80211_IFTYPE_ADHOC: |
| 4090 | if (intbss == wdev->current_bss) |
| 4091 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4092 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 4093 | break; |
| 4094 | default: |
| 4095 | break; |
| 4096 | } |
| 4097 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4098 | nla_nest_end(msg, bss); |
| 4099 | |
| 4100 | return genlmsg_end(msg, hdr); |
| 4101 | |
| 4102 | nla_put_failure: |
| 4103 | genlmsg_cancel(msg, hdr); |
| 4104 | return -EMSGSIZE; |
| 4105 | } |
| 4106 | |
| 4107 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4108 | struct netlink_callback *cb) |
| 4109 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4110 | struct cfg80211_registered_device *rdev; |
| 4111 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4112 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4113 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4114 | int start = cb->args[1], idx = 0; |
| 4115 | int err; |
| 4116 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4117 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4118 | if (err) |
| 4119 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4120 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4121 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4122 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4123 | wdev_lock(wdev); |
| 4124 | spin_lock_bh(&rdev->bss_lock); |
| 4125 | cfg80211_bss_expire(rdev); |
| 4126 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4127 | cb->seq = rdev->bss_generation; |
| 4128 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4129 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4130 | if (++idx <= start) |
| 4131 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4132 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4133 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4134 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4135 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4136 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4137 | } |
| 4138 | } |
| 4139 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4140 | spin_unlock_bh(&rdev->bss_lock); |
| 4141 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4142 | |
| 4143 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4144 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4145 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4146 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4147 | } |
| 4148 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4149 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4150 | int flags, struct net_device *dev, |
| 4151 | struct survey_info *survey) |
| 4152 | { |
| 4153 | void *hdr; |
| 4154 | struct nlattr *infoattr; |
| 4155 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4156 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4157 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4158 | if (!hdr) |
| 4159 | return -ENOMEM; |
| 4160 | |
| 4161 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4162 | |
| 4163 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4164 | if (!infoattr) |
| 4165 | goto nla_put_failure; |
| 4166 | |
| 4167 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4168 | survey->channel->center_freq); |
| 4169 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4170 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4171 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4172 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4173 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4174 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4175 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4176 | survey->channel_time); |
| 4177 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4178 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4179 | survey->channel_time_busy); |
| 4180 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4181 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4182 | survey->channel_time_ext_busy); |
| 4183 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4184 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4185 | survey->channel_time_rx); |
| 4186 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4187 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4188 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4189 | |
| 4190 | nla_nest_end(msg, infoattr); |
| 4191 | |
| 4192 | return genlmsg_end(msg, hdr); |
| 4193 | |
| 4194 | nla_put_failure: |
| 4195 | genlmsg_cancel(msg, hdr); |
| 4196 | return -EMSGSIZE; |
| 4197 | } |
| 4198 | |
| 4199 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4200 | struct netlink_callback *cb) |
| 4201 | { |
| 4202 | struct survey_info survey; |
| 4203 | struct cfg80211_registered_device *dev; |
| 4204 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4205 | int survey_idx = cb->args[1]; |
| 4206 | int res; |
| 4207 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4208 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4209 | if (res) |
| 4210 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4211 | |
| 4212 | if (!dev->ops->dump_survey) { |
| 4213 | res = -EOPNOTSUPP; |
| 4214 | goto out_err; |
| 4215 | } |
| 4216 | |
| 4217 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4218 | struct ieee80211_channel *chan; |
| 4219 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4220 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4221 | &survey); |
| 4222 | if (res == -ENOENT) |
| 4223 | break; |
| 4224 | if (res) |
| 4225 | goto out_err; |
| 4226 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4227 | /* Survey without a channel doesn't make sense */ |
| 4228 | if (!survey.channel) { |
| 4229 | res = -EINVAL; |
| 4230 | goto out; |
| 4231 | } |
| 4232 | |
| 4233 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4234 | survey.channel->center_freq); |
| 4235 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4236 | survey_idx++; |
| 4237 | continue; |
| 4238 | } |
| 4239 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4240 | if (nl80211_send_survey(skb, |
| 4241 | NETLINK_CB(cb->skb).pid, |
| 4242 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4243 | netdev, |
| 4244 | &survey) < 0) |
| 4245 | goto out; |
| 4246 | survey_idx++; |
| 4247 | } |
| 4248 | |
| 4249 | out: |
| 4250 | cb->args[1] = survey_idx; |
| 4251 | res = skb->len; |
| 4252 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4253 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4254 | return res; |
| 4255 | } |
| 4256 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4257 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4258 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4259 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4260 | } |
| 4261 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4262 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4263 | { |
| 4264 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4265 | NL80211_WPA_VERSION_2)); |
| 4266 | } |
| 4267 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4268 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4269 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4271 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4272 | struct ieee80211_channel *chan; |
| 4273 | const u8 *bssid, *ssid, *ie = NULL; |
| 4274 | int err, ssid_len, ie_len = 0; |
| 4275 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4276 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4277 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4278 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4279 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4280 | return -EINVAL; |
| 4281 | |
| 4282 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4283 | return -EINVAL; |
| 4284 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4285 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4286 | return -EINVAL; |
| 4287 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4288 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4289 | return -EINVAL; |
| 4290 | |
| 4291 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4292 | return -EINVAL; |
| 4293 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4294 | err = nl80211_parse_key(info, &key); |
| 4295 | if (err) |
| 4296 | return err; |
| 4297 | |
| 4298 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4299 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4300 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4301 | if (!key.p.key || !key.p.key_len) |
| 4302 | return -EINVAL; |
| 4303 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4304 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4305 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4306 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4307 | return -EINVAL; |
| 4308 | if (key.idx > 4) |
| 4309 | return -EINVAL; |
| 4310 | } else { |
| 4311 | key.p.key_len = 0; |
| 4312 | key.p.key = NULL; |
| 4313 | } |
| 4314 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4315 | if (key.idx >= 0) { |
| 4316 | int i; |
| 4317 | bool ok = false; |
| 4318 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4319 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4320 | ok = true; |
| 4321 | break; |
| 4322 | } |
| 4323 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4324 | if (!ok) |
| 4325 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4326 | } |
| 4327 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4328 | if (!rdev->ops->auth) |
| 4329 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4330 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4331 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4332 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4333 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4334 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4335 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4336 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4337 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4338 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4339 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4340 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4341 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4342 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4343 | |
| 4344 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4345 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4346 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4347 | } |
| 4348 | |
| 4349 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4350 | if (!nl80211_valid_auth_type(auth_type)) |
| 4351 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4352 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4353 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4354 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4355 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4356 | ssid, ssid_len, ie, ie_len, |
| 4357 | key.p.key, key.p.key_len, key.idx, |
| 4358 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4359 | } |
| 4360 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4361 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4362 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4363 | struct cfg80211_crypto_settings *settings, |
| 4364 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4365 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4366 | memset(settings, 0, sizeof(*settings)); |
| 4367 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4368 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4369 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4370 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4371 | u16 proto; |
| 4372 | proto = nla_get_u16( |
| 4373 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4374 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4375 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4376 | proto != ETH_P_PAE) |
| 4377 | return -EINVAL; |
| 4378 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4379 | settings->control_port_no_encrypt = true; |
| 4380 | } else |
| 4381 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4382 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4383 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4384 | void *data; |
| 4385 | int len, i; |
| 4386 | |
| 4387 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4388 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4389 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4390 | |
| 4391 | if (len % sizeof(u32)) |
| 4392 | return -EINVAL; |
| 4393 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4394 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4395 | return -EINVAL; |
| 4396 | |
| 4397 | memcpy(settings->ciphers_pairwise, data, len); |
| 4398 | |
| 4399 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4400 | if (!cfg80211_supported_cipher_suite( |
| 4401 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4402 | settings->ciphers_pairwise[i])) |
| 4403 | return -EINVAL; |
| 4404 | } |
| 4405 | |
| 4406 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4407 | settings->cipher_group = |
| 4408 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4409 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4410 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4411 | return -EINVAL; |
| 4412 | } |
| 4413 | |
| 4414 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4415 | settings->wpa_versions = |
| 4416 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4417 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4418 | return -EINVAL; |
| 4419 | } |
| 4420 | |
| 4421 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4422 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4423 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4424 | |
| 4425 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4426 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4427 | settings->n_akm_suites = len / sizeof(u32); |
| 4428 | |
| 4429 | if (len % sizeof(u32)) |
| 4430 | return -EINVAL; |
| 4431 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4432 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4433 | return -EINVAL; |
| 4434 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4435 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4436 | } |
| 4437 | |
| 4438 | return 0; |
| 4439 | } |
| 4440 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4441 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4442 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4443 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4444 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4445 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4446 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4447 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4448 | int err, ssid_len, ie_len = 0; |
| 4449 | bool use_mfp = false; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4450 | u32 flags = 0; |
| 4451 | struct ieee80211_ht_cap *ht_capa = NULL; |
| 4452 | struct ieee80211_ht_cap *ht_capa_mask = NULL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4453 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4454 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4455 | return -EINVAL; |
| 4456 | |
| 4457 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4458 | !info->attrs[NL80211_ATTR_SSID] || |
| 4459 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4460 | return -EINVAL; |
| 4461 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4462 | if (!rdev->ops->assoc) |
| 4463 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4464 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4465 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4466 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4467 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4468 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4469 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4470 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4471 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4472 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4473 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4474 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4475 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4476 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4477 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4478 | |
| 4479 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4480 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4481 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4482 | } |
| 4483 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4484 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4485 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4486 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4487 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4488 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4489 | else if (mfp != NL80211_MFP_NO) |
| 4490 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4491 | } |
| 4492 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4493 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4494 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4495 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4496 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 4497 | flags |= ASSOC_REQ_DISABLE_HT; |
| 4498 | |
| 4499 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 4500 | ht_capa_mask = |
| 4501 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); |
| 4502 | |
| 4503 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 4504 | if (!ht_capa_mask) |
| 4505 | return -EINVAL; |
| 4506 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4507 | } |
| 4508 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4509 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4510 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4511 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4512 | ssid, ssid_len, ie, ie_len, use_mfp, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 4513 | &crypto, flags, ht_capa, |
| 4514 | ht_capa_mask); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4515 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4516 | return err; |
| 4517 | } |
| 4518 | |
| 4519 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4520 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4522 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4523 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4524 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4525 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4526 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4527 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4528 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4529 | return -EINVAL; |
| 4530 | |
| 4531 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4532 | return -EINVAL; |
| 4533 | |
| 4534 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4535 | return -EINVAL; |
| 4536 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4537 | if (!rdev->ops->deauth) |
| 4538 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4539 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4540 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4541 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4542 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4543 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4544 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4545 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4546 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4547 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4548 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4549 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4550 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4551 | |
| 4552 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4553 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4554 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4555 | } |
| 4556 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4557 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4558 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4559 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4560 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4561 | } |
| 4562 | |
| 4563 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4564 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4565 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4566 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4567 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4568 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4569 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4570 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4571 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4572 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4573 | return -EINVAL; |
| 4574 | |
| 4575 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4576 | return -EINVAL; |
| 4577 | |
| 4578 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4579 | return -EINVAL; |
| 4580 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4581 | if (!rdev->ops->disassoc) |
| 4582 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4583 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4584 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4585 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4586 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4587 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4588 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4589 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4590 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4591 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4592 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4593 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4594 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4595 | |
| 4596 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4597 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4598 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4599 | } |
| 4600 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4601 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4602 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4603 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4604 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4605 | } |
| 4606 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4607 | static bool |
| 4608 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4609 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4610 | int rateval) |
| 4611 | { |
| 4612 | struct wiphy *wiphy = &rdev->wiphy; |
| 4613 | bool found = false; |
| 4614 | int band, i; |
| 4615 | |
| 4616 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4617 | struct ieee80211_supported_band *sband; |
| 4618 | |
| 4619 | sband = wiphy->bands[band]; |
| 4620 | if (!sband) |
| 4621 | continue; |
| 4622 | |
| 4623 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4624 | if (sband->bitrates[i].bitrate == rateval) { |
| 4625 | mcast_rate[band] = i + 1; |
| 4626 | found = true; |
| 4627 | break; |
| 4628 | } |
| 4629 | } |
| 4630 | } |
| 4631 | |
| 4632 | return found; |
| 4633 | } |
| 4634 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4635 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4636 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4638 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4639 | struct cfg80211_ibss_params ibss; |
| 4640 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4641 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4642 | int err; |
| 4643 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4644 | memset(&ibss, 0, sizeof(ibss)); |
| 4645 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4646 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4647 | return -EINVAL; |
| 4648 | |
| 4649 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4650 | !info->attrs[NL80211_ATTR_SSID] || |
| 4651 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4652 | return -EINVAL; |
| 4653 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4654 | ibss.beacon_interval = 100; |
| 4655 | |
| 4656 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4657 | ibss.beacon_interval = |
| 4658 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4659 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4660 | return -EINVAL; |
| 4661 | } |
| 4662 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4663 | if (!rdev->ops->join_ibss) |
| 4664 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4665 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4666 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4667 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4668 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4669 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4670 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4671 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4672 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4673 | |
| 4674 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4675 | return -EINVAL; |
| 4676 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4677 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4678 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4679 | |
| 4680 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4681 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4682 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4683 | } |
| 4684 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame^] | 4685 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 4686 | enum nl80211_channel_type channel_type; |
| 4687 | |
| 4688 | channel_type = nla_get_u32( |
| 4689 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 4690 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4691 | channel_type != NL80211_CHAN_HT20 && |
| 4692 | channel_type != NL80211_CHAN_HT40MINUS && |
| 4693 | channel_type != NL80211_CHAN_HT40PLUS) |
| 4694 | return -EINVAL; |
| 4695 | |
| 4696 | if (channel_type != NL80211_CHAN_NO_HT && |
| 4697 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) |
| 4698 | return -EINVAL; |
| 4699 | |
| 4700 | ibss.channel_type = channel_type; |
| 4701 | } else { |
| 4702 | ibss.channel_type = NL80211_CHAN_NO_HT; |
| 4703 | } |
| 4704 | |
| 4705 | ibss.channel = rdev_freq_to_chan(rdev, |
| 4706 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), |
| 4707 | ibss.channel_type); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4708 | if (!ibss.channel || |
| 4709 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4710 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4711 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4712 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame^] | 4713 | /* Both channels should be able to initiate communication */ |
| 4714 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || |
| 4715 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && |
| 4716 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, |
| 4717 | ibss.channel_type)) |
| 4718 | return -EINVAL; |
| 4719 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4720 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4721 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4722 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4723 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4724 | u8 *rates = |
| 4725 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4726 | int n_rates = |
| 4727 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4728 | struct ieee80211_supported_band *sband = |
| 4729 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4730 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4731 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4732 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4733 | &ibss.basic_rates); |
| 4734 | if (err) |
| 4735 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4736 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4737 | |
| 4738 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4739 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4740 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4741 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4742 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4743 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4744 | connkeys = nl80211_parse_connkeys(rdev, |
| 4745 | info->attrs[NL80211_ATTR_KEYS]); |
| 4746 | if (IS_ERR(connkeys)) |
| 4747 | return PTR_ERR(connkeys); |
| 4748 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4749 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4750 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4751 | if (err) |
| 4752 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4753 | return err; |
| 4754 | } |
| 4755 | |
| 4756 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4757 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4759 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4761 | if (!rdev->ops->leave_ibss) |
| 4762 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4763 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4764 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4765 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4766 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4767 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4768 | } |
| 4769 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4770 | #ifdef CONFIG_NL80211_TESTMODE |
| 4771 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4772 | .name = "testmode", |
| 4773 | }; |
| 4774 | |
| 4775 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4776 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4777 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4778 | int err; |
| 4779 | |
| 4780 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4781 | return -EINVAL; |
| 4782 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4783 | err = -EOPNOTSUPP; |
| 4784 | if (rdev->ops->testmode_cmd) { |
| 4785 | rdev->testmode_info = info; |
| 4786 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4787 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4788 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4789 | rdev->testmode_info = NULL; |
| 4790 | } |
| 4791 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4792 | return err; |
| 4793 | } |
| 4794 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4795 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4796 | struct netlink_callback *cb) |
| 4797 | { |
| 4798 | struct cfg80211_registered_device *dev; |
| 4799 | int err; |
| 4800 | long phy_idx; |
| 4801 | void *data = NULL; |
| 4802 | int data_len = 0; |
| 4803 | |
| 4804 | if (cb->args[0]) { |
| 4805 | /* |
| 4806 | * 0 is a valid index, but not valid for args[0], |
| 4807 | * so we need to offset by 1. |
| 4808 | */ |
| 4809 | phy_idx = cb->args[0] - 1; |
| 4810 | } else { |
| 4811 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4812 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4813 | nl80211_policy); |
| 4814 | if (err) |
| 4815 | return err; |
| 4816 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4817 | return -EINVAL; |
| 4818 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4819 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4820 | cb->args[1] = |
| 4821 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4822 | } |
| 4823 | |
| 4824 | if (cb->args[1]) { |
| 4825 | data = nla_data((void *)cb->args[1]); |
| 4826 | data_len = nla_len((void *)cb->args[1]); |
| 4827 | } |
| 4828 | |
| 4829 | mutex_lock(&cfg80211_mutex); |
| 4830 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4831 | if (!dev) { |
| 4832 | mutex_unlock(&cfg80211_mutex); |
| 4833 | return -ENOENT; |
| 4834 | } |
| 4835 | cfg80211_lock_rdev(dev); |
| 4836 | mutex_unlock(&cfg80211_mutex); |
| 4837 | |
| 4838 | if (!dev->ops->testmode_dump) { |
| 4839 | err = -EOPNOTSUPP; |
| 4840 | goto out_err; |
| 4841 | } |
| 4842 | |
| 4843 | while (1) { |
| 4844 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4845 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4846 | NL80211_CMD_TESTMODE); |
| 4847 | struct nlattr *tmdata; |
| 4848 | |
| 4849 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4850 | genlmsg_cancel(skb, hdr); |
| 4851 | break; |
| 4852 | } |
| 4853 | |
| 4854 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4855 | if (!tmdata) { |
| 4856 | genlmsg_cancel(skb, hdr); |
| 4857 | break; |
| 4858 | } |
| 4859 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4860 | data, data_len); |
| 4861 | nla_nest_end(skb, tmdata); |
| 4862 | |
| 4863 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4864 | genlmsg_cancel(skb, hdr); |
| 4865 | break; |
| 4866 | } else if (err) { |
| 4867 | genlmsg_cancel(skb, hdr); |
| 4868 | goto out_err; |
| 4869 | } |
| 4870 | |
| 4871 | genlmsg_end(skb, hdr); |
| 4872 | } |
| 4873 | |
| 4874 | err = skb->len; |
| 4875 | /* see above */ |
| 4876 | cb->args[0] = phy_idx + 1; |
| 4877 | out_err: |
| 4878 | cfg80211_unlock_rdev(dev); |
| 4879 | return err; |
| 4880 | } |
| 4881 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4882 | static struct sk_buff * |
| 4883 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4884 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4885 | { |
| 4886 | struct sk_buff *skb; |
| 4887 | void *hdr; |
| 4888 | struct nlattr *data; |
| 4889 | |
| 4890 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4891 | if (!skb) |
| 4892 | return NULL; |
| 4893 | |
| 4894 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4895 | if (!hdr) { |
| 4896 | kfree_skb(skb); |
| 4897 | return NULL; |
| 4898 | } |
| 4899 | |
| 4900 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4901 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4902 | |
| 4903 | ((void **)skb->cb)[0] = rdev; |
| 4904 | ((void **)skb->cb)[1] = hdr; |
| 4905 | ((void **)skb->cb)[2] = data; |
| 4906 | |
| 4907 | return skb; |
| 4908 | |
| 4909 | nla_put_failure: |
| 4910 | kfree_skb(skb); |
| 4911 | return NULL; |
| 4912 | } |
| 4913 | |
| 4914 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4915 | int approxlen) |
| 4916 | { |
| 4917 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4918 | |
| 4919 | if (WARN_ON(!rdev->testmode_info)) |
| 4920 | return NULL; |
| 4921 | |
| 4922 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4923 | rdev->testmode_info->snd_pid, |
| 4924 | rdev->testmode_info->snd_seq, |
| 4925 | GFP_KERNEL); |
| 4926 | } |
| 4927 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4928 | |
| 4929 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4930 | { |
| 4931 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4932 | void *hdr = ((void **)skb->cb)[1]; |
| 4933 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4934 | |
| 4935 | if (WARN_ON(!rdev->testmode_info)) { |
| 4936 | kfree_skb(skb); |
| 4937 | return -EINVAL; |
| 4938 | } |
| 4939 | |
| 4940 | nla_nest_end(skb, data); |
| 4941 | genlmsg_end(skb, hdr); |
| 4942 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4943 | } |
| 4944 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4945 | |
| 4946 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4947 | int approxlen, gfp_t gfp) |
| 4948 | { |
| 4949 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4950 | |
| 4951 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4952 | } |
| 4953 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4954 | |
| 4955 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4956 | { |
| 4957 | void *hdr = ((void **)skb->cb)[1]; |
| 4958 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4959 | |
| 4960 | nla_nest_end(skb, data); |
| 4961 | genlmsg_end(skb, hdr); |
| 4962 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4963 | } |
| 4964 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4965 | #endif |
| 4966 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4967 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4968 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4969 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4970 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4971 | struct cfg80211_connect_params connect; |
| 4972 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4973 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4974 | int err; |
| 4975 | |
| 4976 | memset(&connect, 0, sizeof(connect)); |
| 4977 | |
| 4978 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4979 | return -EINVAL; |
| 4980 | |
| 4981 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4982 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4983 | return -EINVAL; |
| 4984 | |
| 4985 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4986 | connect.auth_type = |
| 4987 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4988 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4989 | return -EINVAL; |
| 4990 | } else |
| 4991 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4992 | |
| 4993 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4994 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4995 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4996 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4997 | if (err) |
| 4998 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4999 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5000 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5001 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5002 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5003 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5004 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5005 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5006 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5007 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5008 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5009 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 5010 | |
| 5011 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5012 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 5013 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5014 | } |
| 5015 | |
| 5016 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 5017 | connect.channel = |
| 5018 | ieee80211_get_channel(wiphy, |
| 5019 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 5020 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5021 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 5022 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5023 | } |
| 5024 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5025 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 5026 | connkeys = nl80211_parse_connkeys(rdev, |
| 5027 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5028 | if (IS_ERR(connkeys)) |
| 5029 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5030 | } |
| 5031 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 5032 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 5033 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 5034 | |
| 5035 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5036 | memcpy(&connect.ht_capa_mask, |
| 5037 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 5038 | sizeof(connect.ht_capa_mask)); |
| 5039 | |
| 5040 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 5041 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 5042 | return -EINVAL; |
| 5043 | memcpy(&connect.ht_capa, |
| 5044 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 5045 | sizeof(connect.ht_capa)); |
| 5046 | } |
| 5047 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5048 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 5049 | if (err) |
| 5050 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5051 | return err; |
| 5052 | } |
| 5053 | |
| 5054 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 5055 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5057 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5058 | u16 reason; |
| 5059 | |
| 5060 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 5061 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 5062 | else |
| 5063 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5064 | |
| 5065 | if (reason == 0) |
| 5066 | return -EINVAL; |
| 5067 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5068 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5069 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5070 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5071 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5072 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 5073 | } |
| 5074 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5075 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 5076 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5077 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5078 | struct net *net; |
| 5079 | int err; |
| 5080 | u32 pid; |
| 5081 | |
| 5082 | if (!info->attrs[NL80211_ATTR_PID]) |
| 5083 | return -EINVAL; |
| 5084 | |
| 5085 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 5086 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5087 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5088 | if (IS_ERR(net)) |
| 5089 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5090 | |
| 5091 | err = 0; |
| 5092 | |
| 5093 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5094 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 5095 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5096 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5097 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5098 | return err; |
| 5099 | } |
| 5100 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5101 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5102 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5103 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5104 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 5105 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5106 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5107 | struct cfg80211_pmksa pmksa; |
| 5108 | |
| 5109 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 5110 | |
| 5111 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5112 | return -EINVAL; |
| 5113 | |
| 5114 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 5115 | return -EINVAL; |
| 5116 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5117 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 5118 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5119 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5120 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5121 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5122 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5123 | |
| 5124 | switch (info->genlhdr->cmd) { |
| 5125 | case NL80211_CMD_SET_PMKSA: |
| 5126 | rdev_ops = rdev->ops->set_pmksa; |
| 5127 | break; |
| 5128 | case NL80211_CMD_DEL_PMKSA: |
| 5129 | rdev_ops = rdev->ops->del_pmksa; |
| 5130 | break; |
| 5131 | default: |
| 5132 | WARN_ON(1); |
| 5133 | break; |
| 5134 | } |
| 5135 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5136 | if (!rdev_ops) |
| 5137 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5138 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5139 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5140 | } |
| 5141 | |
| 5142 | static int nl80211_flush_pmksa(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]; |
| 5145 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5146 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5147 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5148 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5149 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5150 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5151 | if (!rdev->ops->flush_pmksa) |
| 5152 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5153 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5154 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5155 | } |
| 5156 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5157 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5158 | { |
| 5159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5160 | struct net_device *dev = info->user_ptr[1]; |
| 5161 | u8 action_code, dialog_token; |
| 5162 | u16 status_code; |
| 5163 | u8 *peer; |
| 5164 | |
| 5165 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5166 | !rdev->ops->tdls_mgmt) |
| 5167 | return -EOPNOTSUPP; |
| 5168 | |
| 5169 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5170 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5171 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5172 | !info->attrs[NL80211_ATTR_IE] || |
| 5173 | !info->attrs[NL80211_ATTR_MAC]) |
| 5174 | return -EINVAL; |
| 5175 | |
| 5176 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5177 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5178 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5179 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5180 | |
| 5181 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5182 | dialog_token, status_code, |
| 5183 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5184 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5185 | } |
| 5186 | |
| 5187 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5188 | { |
| 5189 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5190 | struct net_device *dev = info->user_ptr[1]; |
| 5191 | enum nl80211_tdls_operation operation; |
| 5192 | u8 *peer; |
| 5193 | |
| 5194 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5195 | !rdev->ops->tdls_oper) |
| 5196 | return -EOPNOTSUPP; |
| 5197 | |
| 5198 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5199 | !info->attrs[NL80211_ATTR_MAC]) |
| 5200 | return -EINVAL; |
| 5201 | |
| 5202 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5203 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5204 | |
| 5205 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5206 | } |
| 5207 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5208 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5209 | 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]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5213 | struct ieee80211_channel *chan; |
| 5214 | struct sk_buff *msg; |
| 5215 | void *hdr; |
| 5216 | u64 cookie; |
| 5217 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5218 | u32 freq, duration; |
| 5219 | int err; |
| 5220 | |
| 5221 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5222 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5223 | return -EINVAL; |
| 5224 | |
| 5225 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5226 | |
| 5227 | /* |
| 5228 | * We should be on that channel for at least one jiffie, |
| 5229 | * and more than 5 seconds seems excessive. |
| 5230 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5231 | if (!duration || !msecs_to_jiffies(duration) || |
| 5232 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5233 | return -EINVAL; |
| 5234 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5235 | if (!rdev->ops->remain_on_channel || |
| 5236 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5237 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5238 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5239 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5240 | channel_type = nla_get_u32( |
| 5241 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5242 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5243 | channel_type != NL80211_CHAN_HT20 && |
| 5244 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5245 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5246 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5247 | } |
| 5248 | |
| 5249 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5250 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5251 | if (chan == NULL) |
| 5252 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5253 | |
| 5254 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5255 | if (!msg) |
| 5256 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5257 | |
| 5258 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5259 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5260 | |
| 5261 | if (IS_ERR(hdr)) { |
| 5262 | err = PTR_ERR(hdr); |
| 5263 | goto free_msg; |
| 5264 | } |
| 5265 | |
| 5266 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5267 | channel_type, duration, &cookie); |
| 5268 | |
| 5269 | if (err) |
| 5270 | goto free_msg; |
| 5271 | |
| 5272 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5273 | |
| 5274 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5275 | |
| 5276 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5277 | |
| 5278 | nla_put_failure: |
| 5279 | err = -ENOBUFS; |
| 5280 | free_msg: |
| 5281 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5282 | return err; |
| 5283 | } |
| 5284 | |
| 5285 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5286 | struct genl_info *info) |
| 5287 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5288 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5289 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5290 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5291 | |
| 5292 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5293 | return -EINVAL; |
| 5294 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5295 | if (!rdev->ops->cancel_remain_on_channel) |
| 5296 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5297 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5298 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5299 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5300 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5301 | } |
| 5302 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5303 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5304 | u8 *rates, u8 rates_len) |
| 5305 | { |
| 5306 | u8 i; |
| 5307 | u32 mask = 0; |
| 5308 | |
| 5309 | for (i = 0; i < rates_len; i++) { |
| 5310 | int rate = (rates[i] & 0x7f) * 5; |
| 5311 | int ridx; |
| 5312 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5313 | struct ieee80211_rate *srate = |
| 5314 | &sband->bitrates[ridx]; |
| 5315 | if (rate == srate->bitrate) { |
| 5316 | mask |= 1 << ridx; |
| 5317 | break; |
| 5318 | } |
| 5319 | } |
| 5320 | if (ridx == sband->n_bitrates) |
| 5321 | return 0; /* rate not found */ |
| 5322 | } |
| 5323 | |
| 5324 | return mask; |
| 5325 | } |
| 5326 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5327 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5328 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5329 | .len = NL80211_MAX_SUPP_RATES }, |
| 5330 | }; |
| 5331 | |
| 5332 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5333 | struct genl_info *info) |
| 5334 | { |
| 5335 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5337 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5338 | int rem, i; |
| 5339 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5340 | struct nlattr *tx_rates; |
| 5341 | struct ieee80211_supported_band *sband; |
| 5342 | |
| 5343 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5344 | return -EINVAL; |
| 5345 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5346 | if (!rdev->ops->set_bitrate_mask) |
| 5347 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5348 | |
| 5349 | memset(&mask, 0, sizeof(mask)); |
| 5350 | /* Default to all rates enabled */ |
| 5351 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5352 | sband = rdev->wiphy.bands[i]; |
| 5353 | mask.control[i].legacy = |
| 5354 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5355 | } |
| 5356 | |
| 5357 | /* |
| 5358 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5359 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5360 | */ |
| 5361 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5362 | { |
| 5363 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5364 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5365 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5366 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5367 | if (sband == NULL) |
| 5368 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5369 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5370 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5371 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5372 | mask.control[band].legacy = rateset_to_mask( |
| 5373 | sband, |
| 5374 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5375 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5376 | if (mask.control[band].legacy == 0) |
| 5377 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5378 | } |
| 5379 | } |
| 5380 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5381 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5382 | } |
| 5383 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5384 | 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] | 5385 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5387 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5388 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5389 | |
| 5390 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5391 | return -EINVAL; |
| 5392 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5393 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5394 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5395 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5396 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5397 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5398 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5399 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5400 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5401 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5402 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5403 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5404 | |
| 5405 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5406 | if (!rdev->ops->mgmt_tx) |
| 5407 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5408 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5409 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5410 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5411 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5412 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5413 | } |
| 5414 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5415 | 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] | 5416 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5418 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5419 | struct ieee80211_channel *chan; |
| 5420 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5421 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5422 | u32 freq; |
| 5423 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 5424 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5425 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5426 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5427 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5428 | bool offchan, no_cck, dont_wait_for_ack; |
| 5429 | |
| 5430 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5431 | |
| 5432 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5433 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5434 | return -EINVAL; |
| 5435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5436 | if (!rdev->ops->mgmt_tx) |
| 5437 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5438 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5439 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5440 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5441 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5442 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5443 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5444 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5445 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5446 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5447 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5448 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5449 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5450 | return -EINVAL; |
| 5451 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5452 | } |
| 5453 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5454 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5455 | channel_type = nla_get_u32( |
| 5456 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5457 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5458 | channel_type != NL80211_CHAN_HT20 && |
| 5459 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5460 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5461 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5462 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5463 | } |
| 5464 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5465 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5466 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 5467 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
| 5468 | return -EINVAL; |
| 5469 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5470 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5471 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5472 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5473 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5474 | if (chan == NULL) |
| 5475 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5476 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5477 | if (!dont_wait_for_ack) { |
| 5478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5479 | if (!msg) |
| 5480 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5481 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5482 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5483 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5484 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5485 | if (IS_ERR(hdr)) { |
| 5486 | err = PTR_ERR(hdr); |
| 5487 | goto free_msg; |
| 5488 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5489 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5490 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5491 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5492 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5493 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5494 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5495 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5496 | if (err) |
| 5497 | goto free_msg; |
| 5498 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5499 | if (msg) { |
| 5500 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5501 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5502 | genlmsg_end(msg, hdr); |
| 5503 | return genlmsg_reply(msg, info); |
| 5504 | } |
| 5505 | |
| 5506 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5507 | |
| 5508 | nla_put_failure: |
| 5509 | err = -ENOBUFS; |
| 5510 | free_msg: |
| 5511 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5512 | return err; |
| 5513 | } |
| 5514 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5515 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5516 | { |
| 5517 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5518 | struct net_device *dev = info->user_ptr[1]; |
| 5519 | u64 cookie; |
| 5520 | |
| 5521 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5522 | return -EINVAL; |
| 5523 | |
| 5524 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5525 | return -EOPNOTSUPP; |
| 5526 | |
| 5527 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5528 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5529 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5530 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5531 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5532 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5533 | return -EOPNOTSUPP; |
| 5534 | |
| 5535 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5536 | |
| 5537 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5538 | } |
| 5539 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5540 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5541 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5542 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5543 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5544 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5545 | u8 ps_state; |
| 5546 | bool state; |
| 5547 | int err; |
| 5548 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5549 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5550 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5551 | |
| 5552 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5553 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5554 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5555 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5556 | |
| 5557 | wdev = dev->ieee80211_ptr; |
| 5558 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5559 | if (!rdev->ops->set_power_mgmt) |
| 5560 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5561 | |
| 5562 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5563 | |
| 5564 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5565 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5566 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5567 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5568 | wdev->ps_timeout); |
| 5569 | if (!err) |
| 5570 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5571 | return err; |
| 5572 | } |
| 5573 | |
| 5574 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5575 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5576 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5577 | enum nl80211_ps_state ps_state; |
| 5578 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5579 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5580 | struct sk_buff *msg; |
| 5581 | void *hdr; |
| 5582 | int err; |
| 5583 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5584 | wdev = dev->ieee80211_ptr; |
| 5585 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5586 | if (!rdev->ops->set_power_mgmt) |
| 5587 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5588 | |
| 5589 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5590 | if (!msg) |
| 5591 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5592 | |
| 5593 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5594 | NL80211_CMD_GET_POWER_SAVE); |
| 5595 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5596 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5597 | goto free_msg; |
| 5598 | } |
| 5599 | |
| 5600 | if (wdev->ps) |
| 5601 | ps_state = NL80211_PS_ENABLED; |
| 5602 | else |
| 5603 | ps_state = NL80211_PS_DISABLED; |
| 5604 | |
| 5605 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5606 | |
| 5607 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5608 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5609 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5610 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5611 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5612 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5613 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5614 | return err; |
| 5615 | } |
| 5616 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5617 | static struct nla_policy |
| 5618 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5619 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5620 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5621 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5622 | }; |
| 5623 | |
| 5624 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5625 | s32 threshold, u32 hysteresis) |
| 5626 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5627 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5628 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5629 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5630 | |
| 5631 | if (threshold > 0) |
| 5632 | return -EINVAL; |
| 5633 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5634 | wdev = dev->ieee80211_ptr; |
| 5635 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5636 | if (!rdev->ops->set_cqm_rssi_config) |
| 5637 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5638 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5639 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5640 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5641 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5642 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5643 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5644 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5648 | { |
| 5649 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5650 | struct nlattr *cqm; |
| 5651 | int err; |
| 5652 | |
| 5653 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5654 | if (!cqm) { |
| 5655 | err = -EINVAL; |
| 5656 | goto out; |
| 5657 | } |
| 5658 | |
| 5659 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5660 | nl80211_attr_cqm_policy); |
| 5661 | if (err) |
| 5662 | goto out; |
| 5663 | |
| 5664 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5665 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5666 | s32 threshold; |
| 5667 | u32 hysteresis; |
| 5668 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5669 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5670 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5671 | } else |
| 5672 | err = -EINVAL; |
| 5673 | |
| 5674 | out: |
| 5675 | return err; |
| 5676 | } |
| 5677 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5678 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5679 | { |
| 5680 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5681 | struct net_device *dev = info->user_ptr[1]; |
| 5682 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5683 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5684 | int err; |
| 5685 | |
| 5686 | /* start with default */ |
| 5687 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5688 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5689 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5690 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5691 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5692 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5693 | if (err) |
| 5694 | return err; |
| 5695 | } |
| 5696 | |
| 5697 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5698 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5699 | return -EINVAL; |
| 5700 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5701 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5702 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5703 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 5704 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 5705 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 5706 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 5707 | return -EINVAL; |
| 5708 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5709 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5710 | /* parse additional setup parameters if given */ |
| 5711 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5712 | if (err) |
| 5713 | return err; |
| 5714 | } |
| 5715 | |
| 5716 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5717 | } |
| 5718 | |
| 5719 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5720 | { |
| 5721 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5722 | struct net_device *dev = info->user_ptr[1]; |
| 5723 | |
| 5724 | return cfg80211_leave_mesh(rdev, dev); |
| 5725 | } |
| 5726 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5727 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5728 | { |
| 5729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5730 | struct sk_buff *msg; |
| 5731 | void *hdr; |
| 5732 | |
| 5733 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5734 | return -EOPNOTSUPP; |
| 5735 | |
| 5736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5737 | if (!msg) |
| 5738 | return -ENOMEM; |
| 5739 | |
| 5740 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5741 | NL80211_CMD_GET_WOWLAN); |
| 5742 | if (!hdr) |
| 5743 | goto nla_put_failure; |
| 5744 | |
| 5745 | if (rdev->wowlan) { |
| 5746 | struct nlattr *nl_wowlan; |
| 5747 | |
| 5748 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5749 | if (!nl_wowlan) |
| 5750 | goto nla_put_failure; |
| 5751 | |
| 5752 | if (rdev->wowlan->any) |
| 5753 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5754 | if (rdev->wowlan->disconnect) |
| 5755 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5756 | if (rdev->wowlan->magic_pkt) |
| 5757 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5758 | if (rdev->wowlan->gtk_rekey_failure) |
| 5759 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5760 | if (rdev->wowlan->eap_identity_req) |
| 5761 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5762 | if (rdev->wowlan->four_way_handshake) |
| 5763 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5764 | if (rdev->wowlan->rfkill_release) |
| 5765 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5766 | if (rdev->wowlan->n_patterns) { |
| 5767 | struct nlattr *nl_pats, *nl_pat; |
| 5768 | int i, pat_len; |
| 5769 | |
| 5770 | nl_pats = nla_nest_start(msg, |
| 5771 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5772 | if (!nl_pats) |
| 5773 | goto nla_put_failure; |
| 5774 | |
| 5775 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5776 | nl_pat = nla_nest_start(msg, i + 1); |
| 5777 | if (!nl_pat) |
| 5778 | goto nla_put_failure; |
| 5779 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5780 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5781 | DIV_ROUND_UP(pat_len, 8), |
| 5782 | rdev->wowlan->patterns[i].mask); |
| 5783 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5784 | pat_len, |
| 5785 | rdev->wowlan->patterns[i].pattern); |
| 5786 | nla_nest_end(msg, nl_pat); |
| 5787 | } |
| 5788 | nla_nest_end(msg, nl_pats); |
| 5789 | } |
| 5790 | |
| 5791 | nla_nest_end(msg, nl_wowlan); |
| 5792 | } |
| 5793 | |
| 5794 | genlmsg_end(msg, hdr); |
| 5795 | return genlmsg_reply(msg, info); |
| 5796 | |
| 5797 | nla_put_failure: |
| 5798 | nlmsg_free(msg); |
| 5799 | return -ENOBUFS; |
| 5800 | } |
| 5801 | |
| 5802 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5803 | { |
| 5804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5805 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5806 | struct cfg80211_wowlan no_triggers = {}; |
| 5807 | struct cfg80211_wowlan new_triggers = {}; |
| 5808 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5809 | int err, i; |
| 5810 | |
| 5811 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5812 | return -EOPNOTSUPP; |
| 5813 | |
| 5814 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5815 | goto no_triggers; |
| 5816 | |
| 5817 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5818 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5819 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5820 | nl80211_wowlan_policy); |
| 5821 | if (err) |
| 5822 | return err; |
| 5823 | |
| 5824 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5825 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5826 | return -EINVAL; |
| 5827 | new_triggers.any = true; |
| 5828 | } |
| 5829 | |
| 5830 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5831 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5832 | return -EINVAL; |
| 5833 | new_triggers.disconnect = true; |
| 5834 | } |
| 5835 | |
| 5836 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5837 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5838 | return -EINVAL; |
| 5839 | new_triggers.magic_pkt = true; |
| 5840 | } |
| 5841 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5842 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5843 | return -EINVAL; |
| 5844 | |
| 5845 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5846 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5847 | return -EINVAL; |
| 5848 | new_triggers.gtk_rekey_failure = true; |
| 5849 | } |
| 5850 | |
| 5851 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5852 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5853 | return -EINVAL; |
| 5854 | new_triggers.eap_identity_req = true; |
| 5855 | } |
| 5856 | |
| 5857 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5858 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5859 | return -EINVAL; |
| 5860 | new_triggers.four_way_handshake = true; |
| 5861 | } |
| 5862 | |
| 5863 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5864 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5865 | return -EINVAL; |
| 5866 | new_triggers.rfkill_release = true; |
| 5867 | } |
| 5868 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5869 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5870 | struct nlattr *pat; |
| 5871 | int n_patterns = 0; |
| 5872 | int rem, pat_len, mask_len; |
| 5873 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5874 | |
| 5875 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5876 | rem) |
| 5877 | n_patterns++; |
| 5878 | if (n_patterns > wowlan->n_patterns) |
| 5879 | return -EINVAL; |
| 5880 | |
| 5881 | new_triggers.patterns = kcalloc(n_patterns, |
| 5882 | sizeof(new_triggers.patterns[0]), |
| 5883 | GFP_KERNEL); |
| 5884 | if (!new_triggers.patterns) |
| 5885 | return -ENOMEM; |
| 5886 | |
| 5887 | new_triggers.n_patterns = n_patterns; |
| 5888 | i = 0; |
| 5889 | |
| 5890 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5891 | rem) { |
| 5892 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5893 | nla_data(pat), nla_len(pat), NULL); |
| 5894 | err = -EINVAL; |
| 5895 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5896 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5897 | goto error; |
| 5898 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5899 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5900 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5901 | mask_len) |
| 5902 | goto error; |
| 5903 | if (pat_len > wowlan->pattern_max_len || |
| 5904 | pat_len < wowlan->pattern_min_len) |
| 5905 | goto error; |
| 5906 | |
| 5907 | new_triggers.patterns[i].mask = |
| 5908 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5909 | if (!new_triggers.patterns[i].mask) { |
| 5910 | err = -ENOMEM; |
| 5911 | goto error; |
| 5912 | } |
| 5913 | new_triggers.patterns[i].pattern = |
| 5914 | new_triggers.patterns[i].mask + mask_len; |
| 5915 | memcpy(new_triggers.patterns[i].mask, |
| 5916 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5917 | mask_len); |
| 5918 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5919 | memcpy(new_triggers.patterns[i].pattern, |
| 5920 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5921 | pat_len); |
| 5922 | i++; |
| 5923 | } |
| 5924 | } |
| 5925 | |
| 5926 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5927 | struct cfg80211_wowlan *ntrig; |
| 5928 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5929 | GFP_KERNEL); |
| 5930 | if (!ntrig) { |
| 5931 | err = -ENOMEM; |
| 5932 | goto error; |
| 5933 | } |
| 5934 | cfg80211_rdev_free_wowlan(rdev); |
| 5935 | rdev->wowlan = ntrig; |
| 5936 | } else { |
| 5937 | no_triggers: |
| 5938 | cfg80211_rdev_free_wowlan(rdev); |
| 5939 | rdev->wowlan = NULL; |
| 5940 | } |
| 5941 | |
| 5942 | return 0; |
| 5943 | error: |
| 5944 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5945 | kfree(new_triggers.patterns[i].mask); |
| 5946 | kfree(new_triggers.patterns); |
| 5947 | return err; |
| 5948 | } |
| 5949 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5950 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5951 | { |
| 5952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5953 | struct net_device *dev = info->user_ptr[1]; |
| 5954 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5955 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5956 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5957 | int err; |
| 5958 | |
| 5959 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5960 | return -EINVAL; |
| 5961 | |
| 5962 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5963 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5964 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5965 | nl80211_rekey_policy); |
| 5966 | if (err) |
| 5967 | return err; |
| 5968 | |
| 5969 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5970 | return -ERANGE; |
| 5971 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5972 | return -ERANGE; |
| 5973 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5974 | return -ERANGE; |
| 5975 | |
| 5976 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5977 | NL80211_KEK_LEN); |
| 5978 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5979 | NL80211_KCK_LEN); |
| 5980 | memcpy(rekey_data.replay_ctr, |
| 5981 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5982 | NL80211_REPLAY_CTR_LEN); |
| 5983 | |
| 5984 | wdev_lock(wdev); |
| 5985 | if (!wdev->current_bss) { |
| 5986 | err = -ENOTCONN; |
| 5987 | goto out; |
| 5988 | } |
| 5989 | |
| 5990 | if (!rdev->ops->set_rekey_data) { |
| 5991 | err = -EOPNOTSUPP; |
| 5992 | goto out; |
| 5993 | } |
| 5994 | |
| 5995 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5996 | out: |
| 5997 | wdev_unlock(wdev); |
| 5998 | return err; |
| 5999 | } |
| 6000 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6001 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 6002 | struct genl_info *info) |
| 6003 | { |
| 6004 | struct net_device *dev = info->user_ptr[1]; |
| 6005 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6006 | |
| 6007 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6008 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6009 | return -EINVAL; |
| 6010 | |
| 6011 | if (wdev->ap_unexpected_nlpid) |
| 6012 | return -EBUSY; |
| 6013 | |
| 6014 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 6015 | return 0; |
| 6016 | } |
| 6017 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6018 | static int nl80211_probe_client(struct sk_buff *skb, |
| 6019 | struct genl_info *info) |
| 6020 | { |
| 6021 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6022 | struct net_device *dev = info->user_ptr[1]; |
| 6023 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6024 | struct sk_buff *msg; |
| 6025 | void *hdr; |
| 6026 | const u8 *addr; |
| 6027 | u64 cookie; |
| 6028 | int err; |
| 6029 | |
| 6030 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 6031 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 6032 | return -EOPNOTSUPP; |
| 6033 | |
| 6034 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6035 | return -EINVAL; |
| 6036 | |
| 6037 | if (!rdev->ops->probe_client) |
| 6038 | return -EOPNOTSUPP; |
| 6039 | |
| 6040 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6041 | if (!msg) |
| 6042 | return -ENOMEM; |
| 6043 | |
| 6044 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 6045 | NL80211_CMD_PROBE_CLIENT); |
| 6046 | |
| 6047 | if (IS_ERR(hdr)) { |
| 6048 | err = PTR_ERR(hdr); |
| 6049 | goto free_msg; |
| 6050 | } |
| 6051 | |
| 6052 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6053 | |
| 6054 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 6055 | if (err) |
| 6056 | goto free_msg; |
| 6057 | |
| 6058 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 6059 | |
| 6060 | genlmsg_end(msg, hdr); |
| 6061 | |
| 6062 | return genlmsg_reply(msg, info); |
| 6063 | |
| 6064 | nla_put_failure: |
| 6065 | err = -ENOBUFS; |
| 6066 | free_msg: |
| 6067 | nlmsg_free(msg); |
| 6068 | return err; |
| 6069 | } |
| 6070 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6071 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 6072 | { |
| 6073 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6074 | |
| 6075 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 6076 | return -EOPNOTSUPP; |
| 6077 | |
| 6078 | if (rdev->ap_beacons_nlpid) |
| 6079 | return -EBUSY; |
| 6080 | |
| 6081 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 6082 | |
| 6083 | return 0; |
| 6084 | } |
| 6085 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6086 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 6087 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 6088 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6089 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 6090 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 6091 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6092 | |
| 6093 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6094 | struct genl_info *info) |
| 6095 | { |
| 6096 | struct cfg80211_registered_device *rdev; |
| 6097 | struct net_device *dev; |
| 6098 | int err; |
| 6099 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 6100 | |
| 6101 | if (rtnl) |
| 6102 | rtnl_lock(); |
| 6103 | |
| 6104 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 6105 | rdev = cfg80211_get_dev_from_info(info); |
| 6106 | if (IS_ERR(rdev)) { |
| 6107 | if (rtnl) |
| 6108 | rtnl_unlock(); |
| 6109 | return PTR_ERR(rdev); |
| 6110 | } |
| 6111 | info->user_ptr[0] = rdev; |
| 6112 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 6113 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 6114 | if (err) { |
| 6115 | if (rtnl) |
| 6116 | rtnl_unlock(); |
| 6117 | return err; |
| 6118 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6119 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 6120 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 6121 | cfg80211_unlock_rdev(rdev); |
| 6122 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6123 | if (rtnl) |
| 6124 | rtnl_unlock(); |
| 6125 | return -ENETDOWN; |
| 6126 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6127 | info->user_ptr[0] = rdev; |
| 6128 | info->user_ptr[1] = dev; |
| 6129 | } |
| 6130 | |
| 6131 | return 0; |
| 6132 | } |
| 6133 | |
| 6134 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 6135 | struct genl_info *info) |
| 6136 | { |
| 6137 | if (info->user_ptr[0]) |
| 6138 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 6139 | if (info->user_ptr[1]) |
| 6140 | dev_put(info->user_ptr[1]); |
| 6141 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 6142 | rtnl_unlock(); |
| 6143 | } |
| 6144 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6145 | static struct genl_ops nl80211_ops[] = { |
| 6146 | { |
| 6147 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6148 | .doit = nl80211_get_wiphy, |
| 6149 | .dumpit = nl80211_dump_wiphy, |
| 6150 | .policy = nl80211_policy, |
| 6151 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6152 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6153 | }, |
| 6154 | { |
| 6155 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6156 | .doit = nl80211_set_wiphy, |
| 6157 | .policy = nl80211_policy, |
| 6158 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6159 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6160 | }, |
| 6161 | { |
| 6162 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6163 | .doit = nl80211_get_interface, |
| 6164 | .dumpit = nl80211_dump_interface, |
| 6165 | .policy = nl80211_policy, |
| 6166 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6167 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6168 | }, |
| 6169 | { |
| 6170 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6171 | .doit = nl80211_set_interface, |
| 6172 | .policy = nl80211_policy, |
| 6173 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6174 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6175 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6176 | }, |
| 6177 | { |
| 6178 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6179 | .doit = nl80211_new_interface, |
| 6180 | .policy = nl80211_policy, |
| 6181 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6182 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6183 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6184 | }, |
| 6185 | { |
| 6186 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6187 | .doit = nl80211_del_interface, |
| 6188 | .policy = nl80211_policy, |
| 6189 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6190 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6191 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6192 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6193 | { |
| 6194 | .cmd = NL80211_CMD_GET_KEY, |
| 6195 | .doit = nl80211_get_key, |
| 6196 | .policy = nl80211_policy, |
| 6197 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6198 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6199 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6200 | }, |
| 6201 | { |
| 6202 | .cmd = NL80211_CMD_SET_KEY, |
| 6203 | .doit = nl80211_set_key, |
| 6204 | .policy = nl80211_policy, |
| 6205 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6206 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6207 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6208 | }, |
| 6209 | { |
| 6210 | .cmd = NL80211_CMD_NEW_KEY, |
| 6211 | .doit = nl80211_new_key, |
| 6212 | .policy = nl80211_policy, |
| 6213 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6214 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6215 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6216 | }, |
| 6217 | { |
| 6218 | .cmd = NL80211_CMD_DEL_KEY, |
| 6219 | .doit = nl80211_del_key, |
| 6220 | .policy = nl80211_policy, |
| 6221 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6222 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6223 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6224 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6225 | { |
| 6226 | .cmd = NL80211_CMD_SET_BEACON, |
| 6227 | .policy = nl80211_policy, |
| 6228 | .flags = GENL_ADMIN_PERM, |
| 6229 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6230 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6231 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6232 | }, |
| 6233 | { |
| 6234 | .cmd = NL80211_CMD_NEW_BEACON, |
| 6235 | .policy = nl80211_policy, |
| 6236 | .flags = GENL_ADMIN_PERM, |
| 6237 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6238 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6239 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6240 | }, |
| 6241 | { |
| 6242 | .cmd = NL80211_CMD_DEL_BEACON, |
| 6243 | .policy = nl80211_policy, |
| 6244 | .flags = GENL_ADMIN_PERM, |
| 6245 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6246 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6247 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6248 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6249 | { |
| 6250 | .cmd = NL80211_CMD_GET_STATION, |
| 6251 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6252 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6253 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6254 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6255 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6256 | }, |
| 6257 | { |
| 6258 | .cmd = NL80211_CMD_SET_STATION, |
| 6259 | .doit = nl80211_set_station, |
| 6260 | .policy = nl80211_policy, |
| 6261 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6262 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6263 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6264 | }, |
| 6265 | { |
| 6266 | .cmd = NL80211_CMD_NEW_STATION, |
| 6267 | .doit = nl80211_new_station, |
| 6268 | .policy = nl80211_policy, |
| 6269 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6270 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6271 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6272 | }, |
| 6273 | { |
| 6274 | .cmd = NL80211_CMD_DEL_STATION, |
| 6275 | .doit = nl80211_del_station, |
| 6276 | .policy = nl80211_policy, |
| 6277 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6278 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6279 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6280 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6281 | { |
| 6282 | .cmd = NL80211_CMD_GET_MPATH, |
| 6283 | .doit = nl80211_get_mpath, |
| 6284 | .dumpit = nl80211_dump_mpath, |
| 6285 | .policy = nl80211_policy, |
| 6286 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6287 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6288 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6289 | }, |
| 6290 | { |
| 6291 | .cmd = NL80211_CMD_SET_MPATH, |
| 6292 | .doit = nl80211_set_mpath, |
| 6293 | .policy = nl80211_policy, |
| 6294 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6295 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6296 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6297 | }, |
| 6298 | { |
| 6299 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6300 | .doit = nl80211_new_mpath, |
| 6301 | .policy = nl80211_policy, |
| 6302 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6303 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6304 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6305 | }, |
| 6306 | { |
| 6307 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6308 | .doit = nl80211_del_mpath, |
| 6309 | .policy = nl80211_policy, |
| 6310 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6311 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6312 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6313 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6314 | { |
| 6315 | .cmd = NL80211_CMD_SET_BSS, |
| 6316 | .doit = nl80211_set_bss, |
| 6317 | .policy = nl80211_policy, |
| 6318 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6319 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6320 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6321 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6322 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6323 | .cmd = NL80211_CMD_GET_REG, |
| 6324 | .doit = nl80211_get_reg, |
| 6325 | .policy = nl80211_policy, |
| 6326 | /* can be retrieved by unprivileged users */ |
| 6327 | }, |
| 6328 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6329 | .cmd = NL80211_CMD_SET_REG, |
| 6330 | .doit = nl80211_set_reg, |
| 6331 | .policy = nl80211_policy, |
| 6332 | .flags = GENL_ADMIN_PERM, |
| 6333 | }, |
| 6334 | { |
| 6335 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6336 | .doit = nl80211_req_set_reg, |
| 6337 | .policy = nl80211_policy, |
| 6338 | .flags = GENL_ADMIN_PERM, |
| 6339 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6340 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6341 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6342 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6343 | .policy = nl80211_policy, |
| 6344 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6345 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6346 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6347 | }, |
| 6348 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6349 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6350 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6351 | .policy = nl80211_policy, |
| 6352 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6353 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6354 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6355 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6356 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6357 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6358 | .doit = nl80211_trigger_scan, |
| 6359 | .policy = nl80211_policy, |
| 6360 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6361 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6362 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6363 | }, |
| 6364 | { |
| 6365 | .cmd = NL80211_CMD_GET_SCAN, |
| 6366 | .policy = nl80211_policy, |
| 6367 | .dumpit = nl80211_dump_scan, |
| 6368 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6369 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6370 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6371 | .doit = nl80211_start_sched_scan, |
| 6372 | .policy = nl80211_policy, |
| 6373 | .flags = GENL_ADMIN_PERM, |
| 6374 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6375 | NL80211_FLAG_NEED_RTNL, |
| 6376 | }, |
| 6377 | { |
| 6378 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6379 | .doit = nl80211_stop_sched_scan, |
| 6380 | .policy = nl80211_policy, |
| 6381 | .flags = GENL_ADMIN_PERM, |
| 6382 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6383 | NL80211_FLAG_NEED_RTNL, |
| 6384 | }, |
| 6385 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6386 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6387 | .doit = nl80211_authenticate, |
| 6388 | .policy = nl80211_policy, |
| 6389 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6390 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6391 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6392 | }, |
| 6393 | { |
| 6394 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6395 | .doit = nl80211_associate, |
| 6396 | .policy = nl80211_policy, |
| 6397 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6398 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6399 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6400 | }, |
| 6401 | { |
| 6402 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6403 | .doit = nl80211_deauthenticate, |
| 6404 | .policy = nl80211_policy, |
| 6405 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6406 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6407 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6408 | }, |
| 6409 | { |
| 6410 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6411 | .doit = nl80211_disassociate, |
| 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, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6416 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6417 | { |
| 6418 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6419 | .doit = nl80211_join_ibss, |
| 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, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6424 | }, |
| 6425 | { |
| 6426 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6427 | .doit = nl80211_leave_ibss, |
| 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, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6432 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6433 | #ifdef CONFIG_NL80211_TESTMODE |
| 6434 | { |
| 6435 | .cmd = NL80211_CMD_TESTMODE, |
| 6436 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6437 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6438 | .policy = nl80211_policy, |
| 6439 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6440 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6441 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6442 | }, |
| 6443 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6444 | { |
| 6445 | .cmd = NL80211_CMD_CONNECT, |
| 6446 | .doit = nl80211_connect, |
| 6447 | .policy = nl80211_policy, |
| 6448 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6449 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6450 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6451 | }, |
| 6452 | { |
| 6453 | .cmd = NL80211_CMD_DISCONNECT, |
| 6454 | .doit = nl80211_disconnect, |
| 6455 | .policy = nl80211_policy, |
| 6456 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6457 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6458 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6459 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6460 | { |
| 6461 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6462 | .doit = nl80211_wiphy_netns, |
| 6463 | .policy = nl80211_policy, |
| 6464 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6465 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6466 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6467 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6468 | { |
| 6469 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6470 | .policy = nl80211_policy, |
| 6471 | .dumpit = nl80211_dump_survey, |
| 6472 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6473 | { |
| 6474 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6475 | .doit = nl80211_setdel_pmksa, |
| 6476 | .policy = nl80211_policy, |
| 6477 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6478 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6479 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6480 | }, |
| 6481 | { |
| 6482 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6483 | .doit = nl80211_setdel_pmksa, |
| 6484 | .policy = nl80211_policy, |
| 6485 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6486 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6487 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6488 | }, |
| 6489 | { |
| 6490 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6491 | .doit = nl80211_flush_pmksa, |
| 6492 | .policy = nl80211_policy, |
| 6493 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6494 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6495 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6496 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6497 | { |
| 6498 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6499 | .doit = nl80211_remain_on_channel, |
| 6500 | .policy = nl80211_policy, |
| 6501 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6502 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6503 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6504 | }, |
| 6505 | { |
| 6506 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6507 | .doit = nl80211_cancel_remain_on_channel, |
| 6508 | .policy = nl80211_policy, |
| 6509 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6510 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6511 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6512 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6513 | { |
| 6514 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6515 | .doit = nl80211_set_tx_bitrate_mask, |
| 6516 | .policy = nl80211_policy, |
| 6517 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6518 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6519 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6520 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6521 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6522 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6523 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6524 | .policy = nl80211_policy, |
| 6525 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6526 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6527 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6528 | }, |
| 6529 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6530 | .cmd = NL80211_CMD_FRAME, |
| 6531 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6532 | .policy = nl80211_policy, |
| 6533 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6534 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6535 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6536 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6537 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6538 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6539 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6540 | .policy = nl80211_policy, |
| 6541 | .flags = GENL_ADMIN_PERM, |
| 6542 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6543 | NL80211_FLAG_NEED_RTNL, |
| 6544 | }, |
| 6545 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6546 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6547 | .doit = nl80211_set_power_save, |
| 6548 | .policy = nl80211_policy, |
| 6549 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6550 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6551 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6552 | }, |
| 6553 | { |
| 6554 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6555 | .doit = nl80211_get_power_save, |
| 6556 | .policy = nl80211_policy, |
| 6557 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6558 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6559 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6560 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6561 | { |
| 6562 | .cmd = NL80211_CMD_SET_CQM, |
| 6563 | .doit = nl80211_set_cqm, |
| 6564 | .policy = nl80211_policy, |
| 6565 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6566 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6567 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6568 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6569 | { |
| 6570 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6571 | .doit = nl80211_set_channel, |
| 6572 | .policy = nl80211_policy, |
| 6573 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6574 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6575 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6576 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6577 | { |
| 6578 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6579 | .doit = nl80211_set_wds_peer, |
| 6580 | .policy = nl80211_policy, |
| 6581 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6582 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6583 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6584 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6585 | { |
| 6586 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6587 | .doit = nl80211_join_mesh, |
| 6588 | .policy = nl80211_policy, |
| 6589 | .flags = GENL_ADMIN_PERM, |
| 6590 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6591 | NL80211_FLAG_NEED_RTNL, |
| 6592 | }, |
| 6593 | { |
| 6594 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6595 | .doit = nl80211_leave_mesh, |
| 6596 | .policy = nl80211_policy, |
| 6597 | .flags = GENL_ADMIN_PERM, |
| 6598 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6599 | NL80211_FLAG_NEED_RTNL, |
| 6600 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6601 | { |
| 6602 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6603 | .doit = nl80211_get_wowlan, |
| 6604 | .policy = nl80211_policy, |
| 6605 | /* can be retrieved by unprivileged users */ |
| 6606 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6607 | NL80211_FLAG_NEED_RTNL, |
| 6608 | }, |
| 6609 | { |
| 6610 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6611 | .doit = nl80211_set_wowlan, |
| 6612 | .policy = nl80211_policy, |
| 6613 | .flags = GENL_ADMIN_PERM, |
| 6614 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6615 | NL80211_FLAG_NEED_RTNL, |
| 6616 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6617 | { |
| 6618 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6619 | .doit = nl80211_set_rekey_data, |
| 6620 | .policy = nl80211_policy, |
| 6621 | .flags = GENL_ADMIN_PERM, |
| 6622 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6623 | NL80211_FLAG_NEED_RTNL, |
| 6624 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6625 | { |
| 6626 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 6627 | .doit = nl80211_tdls_mgmt, |
| 6628 | .policy = nl80211_policy, |
| 6629 | .flags = GENL_ADMIN_PERM, |
| 6630 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6631 | NL80211_FLAG_NEED_RTNL, |
| 6632 | }, |
| 6633 | { |
| 6634 | .cmd = NL80211_CMD_TDLS_OPER, |
| 6635 | .doit = nl80211_tdls_oper, |
| 6636 | .policy = nl80211_policy, |
| 6637 | .flags = GENL_ADMIN_PERM, |
| 6638 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6639 | NL80211_FLAG_NEED_RTNL, |
| 6640 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6641 | { |
| 6642 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 6643 | .doit = nl80211_register_unexpected_frame, |
| 6644 | .policy = nl80211_policy, |
| 6645 | .flags = GENL_ADMIN_PERM, |
| 6646 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6647 | NL80211_FLAG_NEED_RTNL, |
| 6648 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6649 | { |
| 6650 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 6651 | .doit = nl80211_probe_client, |
| 6652 | .policy = nl80211_policy, |
| 6653 | .flags = GENL_ADMIN_PERM, |
| 6654 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6655 | NL80211_FLAG_NEED_RTNL, |
| 6656 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6657 | { |
| 6658 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 6659 | .doit = nl80211_register_beacons, |
| 6660 | .policy = nl80211_policy, |
| 6661 | .flags = GENL_ADMIN_PERM, |
| 6662 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6663 | NL80211_FLAG_NEED_RTNL, |
| 6664 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 6665 | { |
| 6666 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 6667 | .doit = nl80211_set_noack_map, |
| 6668 | .policy = nl80211_policy, |
| 6669 | .flags = GENL_ADMIN_PERM, |
| 6670 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6671 | NL80211_FLAG_NEED_RTNL, |
| 6672 | }, |
| 6673 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6674 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6675 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6676 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6677 | .name = "mlme", |
| 6678 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6679 | |
| 6680 | /* multicast groups */ |
| 6681 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6682 | .name = "config", |
| 6683 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6684 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6685 | .name = "scan", |
| 6686 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6687 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6688 | .name = "regulatory", |
| 6689 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6690 | |
| 6691 | /* notification functions */ |
| 6692 | |
| 6693 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6694 | { |
| 6695 | struct sk_buff *msg; |
| 6696 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6697 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6698 | if (!msg) |
| 6699 | return; |
| 6700 | |
| 6701 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6702 | nlmsg_free(msg); |
| 6703 | return; |
| 6704 | } |
| 6705 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6706 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6707 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6708 | } |
| 6709 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6710 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6711 | struct cfg80211_registered_device *rdev) |
| 6712 | { |
| 6713 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6714 | struct nlattr *nest; |
| 6715 | int i; |
| 6716 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6717 | ASSERT_RDEV_LOCK(rdev); |
| 6718 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6719 | if (WARN_ON(!req)) |
| 6720 | return 0; |
| 6721 | |
| 6722 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6723 | if (!nest) |
| 6724 | goto nla_put_failure; |
| 6725 | for (i = 0; i < req->n_ssids; i++) |
| 6726 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6727 | nla_nest_end(msg, nest); |
| 6728 | |
| 6729 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6730 | if (!nest) |
| 6731 | goto nla_put_failure; |
| 6732 | for (i = 0; i < req->n_channels; i++) |
| 6733 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6734 | nla_nest_end(msg, nest); |
| 6735 | |
| 6736 | if (req->ie) |
| 6737 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6738 | |
| 6739 | return 0; |
| 6740 | nla_put_failure: |
| 6741 | return -ENOBUFS; |
| 6742 | } |
| 6743 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6744 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6745 | struct cfg80211_registered_device *rdev, |
| 6746 | struct net_device *netdev, |
| 6747 | u32 pid, u32 seq, int flags, |
| 6748 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6749 | { |
| 6750 | void *hdr; |
| 6751 | |
| 6752 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6753 | if (!hdr) |
| 6754 | return -1; |
| 6755 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6756 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6757 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6758 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6759 | /* ignore errors and send incomplete event anyway */ |
| 6760 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6761 | |
| 6762 | return genlmsg_end(msg, hdr); |
| 6763 | |
| 6764 | nla_put_failure: |
| 6765 | genlmsg_cancel(msg, hdr); |
| 6766 | return -EMSGSIZE; |
| 6767 | } |
| 6768 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6769 | static int |
| 6770 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6771 | struct cfg80211_registered_device *rdev, |
| 6772 | struct net_device *netdev, |
| 6773 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6774 | { |
| 6775 | void *hdr; |
| 6776 | |
| 6777 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6778 | if (!hdr) |
| 6779 | return -1; |
| 6780 | |
| 6781 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6782 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6783 | |
| 6784 | return genlmsg_end(msg, hdr); |
| 6785 | |
| 6786 | nla_put_failure: |
| 6787 | genlmsg_cancel(msg, hdr); |
| 6788 | return -EMSGSIZE; |
| 6789 | } |
| 6790 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6791 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6792 | struct net_device *netdev) |
| 6793 | { |
| 6794 | struct sk_buff *msg; |
| 6795 | |
| 6796 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6797 | if (!msg) |
| 6798 | return; |
| 6799 | |
| 6800 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6801 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6802 | nlmsg_free(msg); |
| 6803 | return; |
| 6804 | } |
| 6805 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6806 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6807 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6808 | } |
| 6809 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6810 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6811 | struct net_device *netdev) |
| 6812 | { |
| 6813 | struct sk_buff *msg; |
| 6814 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6815 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6816 | if (!msg) |
| 6817 | return; |
| 6818 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6819 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6820 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6821 | nlmsg_free(msg); |
| 6822 | return; |
| 6823 | } |
| 6824 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6825 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6826 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6827 | } |
| 6828 | |
| 6829 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6830 | struct net_device *netdev) |
| 6831 | { |
| 6832 | struct sk_buff *msg; |
| 6833 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6834 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6835 | if (!msg) |
| 6836 | return; |
| 6837 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6838 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6839 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6840 | nlmsg_free(msg); |
| 6841 | return; |
| 6842 | } |
| 6843 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6844 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6845 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6846 | } |
| 6847 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6848 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6849 | struct net_device *netdev) |
| 6850 | { |
| 6851 | struct sk_buff *msg; |
| 6852 | |
| 6853 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6854 | if (!msg) |
| 6855 | return; |
| 6856 | |
| 6857 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6858 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6859 | nlmsg_free(msg); |
| 6860 | return; |
| 6861 | } |
| 6862 | |
| 6863 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6864 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6865 | } |
| 6866 | |
| 6867 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6868 | struct net_device *netdev, u32 cmd) |
| 6869 | { |
| 6870 | struct sk_buff *msg; |
| 6871 | |
| 6872 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6873 | if (!msg) |
| 6874 | return; |
| 6875 | |
| 6876 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6877 | nlmsg_free(msg); |
| 6878 | return; |
| 6879 | } |
| 6880 | |
| 6881 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6882 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6883 | } |
| 6884 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6885 | /* |
| 6886 | * This can happen on global regulatory changes or device specific settings |
| 6887 | * based on custom world regulatory domains. |
| 6888 | */ |
| 6889 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6890 | { |
| 6891 | struct sk_buff *msg; |
| 6892 | void *hdr; |
| 6893 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6894 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6895 | if (!msg) |
| 6896 | return; |
| 6897 | |
| 6898 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6899 | if (!hdr) { |
| 6900 | nlmsg_free(msg); |
| 6901 | return; |
| 6902 | } |
| 6903 | |
| 6904 | /* Userspace can always count this one always being set */ |
| 6905 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6906 | |
| 6907 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6908 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6909 | NL80211_REGDOM_TYPE_WORLD); |
| 6910 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6911 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6912 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6913 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6914 | request->intersect) |
| 6915 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6916 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6917 | else { |
| 6918 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6919 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6920 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6921 | } |
| 6922 | |
| 6923 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6924 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6925 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6926 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6927 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6928 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6929 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6930 | GFP_ATOMIC); |
| 6931 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6932 | |
| 6933 | return; |
| 6934 | |
| 6935 | nla_put_failure: |
| 6936 | genlmsg_cancel(msg, hdr); |
| 6937 | nlmsg_free(msg); |
| 6938 | } |
| 6939 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6940 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6941 | struct net_device *netdev, |
| 6942 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6943 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6944 | { |
| 6945 | struct sk_buff *msg; |
| 6946 | void *hdr; |
| 6947 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6948 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6949 | if (!msg) |
| 6950 | return; |
| 6951 | |
| 6952 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6953 | if (!hdr) { |
| 6954 | nlmsg_free(msg); |
| 6955 | return; |
| 6956 | } |
| 6957 | |
| 6958 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6959 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6960 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6961 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6962 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6963 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6964 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6965 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6966 | return; |
| 6967 | |
| 6968 | nla_put_failure: |
| 6969 | genlmsg_cancel(msg, hdr); |
| 6970 | nlmsg_free(msg); |
| 6971 | } |
| 6972 | |
| 6973 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6974 | struct net_device *netdev, const u8 *buf, |
| 6975 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6976 | { |
| 6977 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6978 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6982 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6983 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6984 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6985 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6986 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6987 | } |
| 6988 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6989 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6990 | struct net_device *netdev, const u8 *buf, |
| 6991 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6992 | { |
| 6993 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6994 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6995 | } |
| 6996 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6997 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6998 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6999 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7000 | { |
| 7001 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7002 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7003 | } |
| 7004 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 7005 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 7006 | struct net_device *netdev, const u8 *buf, |
| 7007 | size_t len, gfp_t gfp) |
| 7008 | { |
| 7009 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7010 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 7011 | } |
| 7012 | |
| 7013 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 7014 | struct net_device *netdev, const u8 *buf, |
| 7015 | size_t len, gfp_t gfp) |
| 7016 | { |
| 7017 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 7018 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 7019 | } |
| 7020 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 7021 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 7022 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7023 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7024 | { |
| 7025 | struct sk_buff *msg; |
| 7026 | void *hdr; |
| 7027 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7028 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7029 | if (!msg) |
| 7030 | return; |
| 7031 | |
| 7032 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7033 | if (!hdr) { |
| 7034 | nlmsg_free(msg); |
| 7035 | return; |
| 7036 | } |
| 7037 | |
| 7038 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7039 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7040 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 7041 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7042 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7043 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7044 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7045 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7046 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7047 | return; |
| 7048 | |
| 7049 | nla_put_failure: |
| 7050 | genlmsg_cancel(msg, hdr); |
| 7051 | nlmsg_free(msg); |
| 7052 | } |
| 7053 | |
| 7054 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7055 | struct net_device *netdev, const u8 *addr, |
| 7056 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7057 | { |
| 7058 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7059 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7060 | } |
| 7061 | |
| 7062 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7063 | struct net_device *netdev, const u8 *addr, |
| 7064 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7065 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7066 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 7067 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 7068 | } |
| 7069 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7070 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 7071 | struct net_device *netdev, const u8 *bssid, |
| 7072 | const u8 *req_ie, size_t req_ie_len, |
| 7073 | const u8 *resp_ie, size_t resp_ie_len, |
| 7074 | u16 status, gfp_t gfp) |
| 7075 | { |
| 7076 | struct sk_buff *msg; |
| 7077 | void *hdr; |
| 7078 | |
| 7079 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7080 | if (!msg) |
| 7081 | return; |
| 7082 | |
| 7083 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 7084 | if (!hdr) { |
| 7085 | nlmsg_free(msg); |
| 7086 | return; |
| 7087 | } |
| 7088 | |
| 7089 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7090 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7091 | if (bssid) |
| 7092 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7093 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 7094 | if (req_ie) |
| 7095 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 7096 | if (resp_ie) |
| 7097 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 7098 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7099 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7100 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7101 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7102 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7103 | return; |
| 7104 | |
| 7105 | nla_put_failure: |
| 7106 | genlmsg_cancel(msg, hdr); |
| 7107 | nlmsg_free(msg); |
| 7108 | |
| 7109 | } |
| 7110 | |
| 7111 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 7112 | struct net_device *netdev, const u8 *bssid, |
| 7113 | const u8 *req_ie, size_t req_ie_len, |
| 7114 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 7115 | { |
| 7116 | struct sk_buff *msg; |
| 7117 | void *hdr; |
| 7118 | |
| 7119 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7120 | if (!msg) |
| 7121 | return; |
| 7122 | |
| 7123 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 7124 | if (!hdr) { |
| 7125 | nlmsg_free(msg); |
| 7126 | return; |
| 7127 | } |
| 7128 | |
| 7129 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7130 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7131 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7132 | if (req_ie) |
| 7133 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 7134 | if (resp_ie) |
| 7135 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 7136 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7137 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7138 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7139 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7140 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7141 | return; |
| 7142 | |
| 7143 | nla_put_failure: |
| 7144 | genlmsg_cancel(msg, hdr); |
| 7145 | nlmsg_free(msg); |
| 7146 | |
| 7147 | } |
| 7148 | |
| 7149 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 7150 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7151 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7152 | { |
| 7153 | struct sk_buff *msg; |
| 7154 | void *hdr; |
| 7155 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7156 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7157 | if (!msg) |
| 7158 | return; |
| 7159 | |
| 7160 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7161 | if (!hdr) { |
| 7162 | nlmsg_free(msg); |
| 7163 | return; |
| 7164 | } |
| 7165 | |
| 7166 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7167 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7168 | if (from_ap && reason) |
| 7169 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 7170 | if (from_ap) |
| 7171 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 7172 | if (ie) |
| 7173 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 7174 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7175 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7176 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7177 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7178 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7179 | return; |
| 7180 | |
| 7181 | nla_put_failure: |
| 7182 | genlmsg_cancel(msg, hdr); |
| 7183 | nlmsg_free(msg); |
| 7184 | |
| 7185 | } |
| 7186 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7187 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7188 | struct net_device *netdev, const u8 *bssid, |
| 7189 | gfp_t gfp) |
| 7190 | { |
| 7191 | struct sk_buff *msg; |
| 7192 | void *hdr; |
| 7193 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7194 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7195 | if (!msg) |
| 7196 | return; |
| 7197 | |
| 7198 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7199 | if (!hdr) { |
| 7200 | nlmsg_free(msg); |
| 7201 | return; |
| 7202 | } |
| 7203 | |
| 7204 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7205 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7206 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7207 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7208 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7209 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7210 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7211 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7212 | return; |
| 7213 | |
| 7214 | nla_put_failure: |
| 7215 | genlmsg_cancel(msg, hdr); |
| 7216 | nlmsg_free(msg); |
| 7217 | } |
| 7218 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7219 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7220 | struct net_device *netdev, |
| 7221 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7222 | gfp_t gfp) |
| 7223 | { |
| 7224 | struct sk_buff *msg; |
| 7225 | void *hdr; |
| 7226 | |
| 7227 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7228 | if (!msg) |
| 7229 | return; |
| 7230 | |
| 7231 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7232 | if (!hdr) { |
| 7233 | nlmsg_free(msg); |
| 7234 | return; |
| 7235 | } |
| 7236 | |
| 7237 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7238 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7239 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 7240 | if (ie_len && ie) |
| 7241 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 7242 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7243 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7244 | |
| 7245 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7246 | nl80211_mlme_mcgrp.id, gfp); |
| 7247 | return; |
| 7248 | |
| 7249 | nla_put_failure: |
| 7250 | genlmsg_cancel(msg, hdr); |
| 7251 | nlmsg_free(msg); |
| 7252 | } |
| 7253 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7254 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7255 | struct net_device *netdev, const u8 *addr, |
| 7256 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7257 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7258 | { |
| 7259 | struct sk_buff *msg; |
| 7260 | void *hdr; |
| 7261 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7262 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7263 | if (!msg) |
| 7264 | return; |
| 7265 | |
| 7266 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7267 | if (!hdr) { |
| 7268 | nlmsg_free(msg); |
| 7269 | return; |
| 7270 | } |
| 7271 | |
| 7272 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7273 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7274 | if (addr) |
| 7275 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7276 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 7277 | if (key_id != -1) |
| 7278 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7279 | if (tsc) |
| 7280 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 7281 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7282 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7283 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7284 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7285 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7286 | return; |
| 7287 | |
| 7288 | nla_put_failure: |
| 7289 | genlmsg_cancel(msg, hdr); |
| 7290 | nlmsg_free(msg); |
| 7291 | } |
| 7292 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7293 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7294 | struct ieee80211_channel *channel_before, |
| 7295 | struct ieee80211_channel *channel_after) |
| 7296 | { |
| 7297 | struct sk_buff *msg; |
| 7298 | void *hdr; |
| 7299 | struct nlattr *nl_freq; |
| 7300 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7301 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7302 | if (!msg) |
| 7303 | return; |
| 7304 | |
| 7305 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7306 | if (!hdr) { |
| 7307 | nlmsg_free(msg); |
| 7308 | return; |
| 7309 | } |
| 7310 | |
| 7311 | /* |
| 7312 | * Since we are applying the beacon hint to a wiphy we know its |
| 7313 | * wiphy_idx is valid |
| 7314 | */ |
| 7315 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 7316 | |
| 7317 | /* Before */ |
| 7318 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7319 | if (!nl_freq) |
| 7320 | goto nla_put_failure; |
| 7321 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7322 | goto nla_put_failure; |
| 7323 | nla_nest_end(msg, nl_freq); |
| 7324 | |
| 7325 | /* After */ |
| 7326 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7327 | if (!nl_freq) |
| 7328 | goto nla_put_failure; |
| 7329 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7330 | goto nla_put_failure; |
| 7331 | nla_nest_end(msg, nl_freq); |
| 7332 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7333 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7334 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7335 | rcu_read_lock(); |
| 7336 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7337 | GFP_ATOMIC); |
| 7338 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7339 | |
| 7340 | return; |
| 7341 | |
| 7342 | nla_put_failure: |
| 7343 | genlmsg_cancel(msg, hdr); |
| 7344 | nlmsg_free(msg); |
| 7345 | } |
| 7346 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7347 | static void nl80211_send_remain_on_chan_event( |
| 7348 | int cmd, struct cfg80211_registered_device *rdev, |
| 7349 | struct net_device *netdev, u64 cookie, |
| 7350 | struct ieee80211_channel *chan, |
| 7351 | enum nl80211_channel_type channel_type, |
| 7352 | unsigned int duration, gfp_t gfp) |
| 7353 | { |
| 7354 | struct sk_buff *msg; |
| 7355 | void *hdr; |
| 7356 | |
| 7357 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7358 | if (!msg) |
| 7359 | return; |
| 7360 | |
| 7361 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7362 | if (!hdr) { |
| 7363 | nlmsg_free(msg); |
| 7364 | return; |
| 7365 | } |
| 7366 | |
| 7367 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7368 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7369 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7370 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7371 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7372 | |
| 7373 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7374 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7375 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7376 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7377 | |
| 7378 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7379 | nl80211_mlme_mcgrp.id, gfp); |
| 7380 | return; |
| 7381 | |
| 7382 | nla_put_failure: |
| 7383 | genlmsg_cancel(msg, hdr); |
| 7384 | nlmsg_free(msg); |
| 7385 | } |
| 7386 | |
| 7387 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7388 | struct net_device *netdev, u64 cookie, |
| 7389 | struct ieee80211_channel *chan, |
| 7390 | enum nl80211_channel_type channel_type, |
| 7391 | unsigned int duration, gfp_t gfp) |
| 7392 | { |
| 7393 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7394 | rdev, netdev, cookie, chan, |
| 7395 | channel_type, duration, gfp); |
| 7396 | } |
| 7397 | |
| 7398 | void nl80211_send_remain_on_channel_cancel( |
| 7399 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7400 | u64 cookie, struct ieee80211_channel *chan, |
| 7401 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7402 | { |
| 7403 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7404 | rdev, netdev, cookie, chan, |
| 7405 | channel_type, 0, gfp); |
| 7406 | } |
| 7407 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7408 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7409 | struct net_device *dev, const u8 *mac_addr, |
| 7410 | struct station_info *sinfo, gfp_t gfp) |
| 7411 | { |
| 7412 | struct sk_buff *msg; |
| 7413 | |
| 7414 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7415 | if (!msg) |
| 7416 | return; |
| 7417 | |
| 7418 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 7419 | nlmsg_free(msg); |
| 7420 | return; |
| 7421 | } |
| 7422 | |
| 7423 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7424 | nl80211_mlme_mcgrp.id, gfp); |
| 7425 | } |
| 7426 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7427 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7428 | struct net_device *dev, const u8 *mac_addr, |
| 7429 | gfp_t gfp) |
| 7430 | { |
| 7431 | struct sk_buff *msg; |
| 7432 | void *hdr; |
| 7433 | |
| 7434 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7435 | if (!msg) |
| 7436 | return; |
| 7437 | |
| 7438 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7439 | if (!hdr) { |
| 7440 | nlmsg_free(msg); |
| 7441 | return; |
| 7442 | } |
| 7443 | |
| 7444 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7445 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7446 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7447 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7448 | |
| 7449 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7450 | nl80211_mlme_mcgrp.id, gfp); |
| 7451 | return; |
| 7452 | |
| 7453 | nla_put_failure: |
| 7454 | genlmsg_cancel(msg, hdr); |
| 7455 | nlmsg_free(msg); |
| 7456 | } |
| 7457 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7458 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 7459 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7460 | { |
| 7461 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7462 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7463 | struct sk_buff *msg; |
| 7464 | void *hdr; |
| 7465 | int err; |
| 7466 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 7467 | |
| 7468 | if (!nlpid) |
| 7469 | return false; |
| 7470 | |
| 7471 | msg = nlmsg_new(100, gfp); |
| 7472 | if (!msg) |
| 7473 | return true; |
| 7474 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7475 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7476 | if (!hdr) { |
| 7477 | nlmsg_free(msg); |
| 7478 | return true; |
| 7479 | } |
| 7480 | |
| 7481 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7482 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7483 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7484 | |
| 7485 | err = genlmsg_end(msg, hdr); |
| 7486 | if (err < 0) { |
| 7487 | nlmsg_free(msg); |
| 7488 | return true; |
| 7489 | } |
| 7490 | |
| 7491 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7492 | return true; |
| 7493 | |
| 7494 | nla_put_failure: |
| 7495 | genlmsg_cancel(msg, hdr); |
| 7496 | nlmsg_free(msg); |
| 7497 | return true; |
| 7498 | } |
| 7499 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7500 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 7501 | { |
| 7502 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 7503 | addr, gfp); |
| 7504 | } |
| 7505 | |
| 7506 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 7507 | const u8 *addr, gfp_t gfp) |
| 7508 | { |
| 7509 | return __nl80211_unexpected_frame(dev, |
| 7510 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 7511 | addr, gfp); |
| 7512 | } |
| 7513 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7514 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7515 | struct net_device *netdev, u32 nlpid, |
| 7516 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7517 | { |
| 7518 | struct sk_buff *msg; |
| 7519 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7520 | |
| 7521 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7522 | if (!msg) |
| 7523 | return -ENOMEM; |
| 7524 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7525 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7526 | if (!hdr) { |
| 7527 | nlmsg_free(msg); |
| 7528 | return -ENOMEM; |
| 7529 | } |
| 7530 | |
| 7531 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7532 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7533 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7534 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7535 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7536 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7537 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7538 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7539 | |
| 7540 | nla_put_failure: |
| 7541 | genlmsg_cancel(msg, hdr); |
| 7542 | nlmsg_free(msg); |
| 7543 | return -ENOBUFS; |
| 7544 | } |
| 7545 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7546 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7547 | struct net_device *netdev, u64 cookie, |
| 7548 | const u8 *buf, size_t len, bool ack, |
| 7549 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7550 | { |
| 7551 | struct sk_buff *msg; |
| 7552 | void *hdr; |
| 7553 | |
| 7554 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7555 | if (!msg) |
| 7556 | return; |
| 7557 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7558 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7559 | if (!hdr) { |
| 7560 | nlmsg_free(msg); |
| 7561 | return; |
| 7562 | } |
| 7563 | |
| 7564 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7565 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7566 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7567 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7568 | if (ack) |
| 7569 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7570 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7571 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7572 | |
| 7573 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7574 | return; |
| 7575 | |
| 7576 | nla_put_failure: |
| 7577 | genlmsg_cancel(msg, hdr); |
| 7578 | nlmsg_free(msg); |
| 7579 | } |
| 7580 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7581 | void |
| 7582 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7583 | struct net_device *netdev, |
| 7584 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7585 | gfp_t gfp) |
| 7586 | { |
| 7587 | struct sk_buff *msg; |
| 7588 | struct nlattr *pinfoattr; |
| 7589 | void *hdr; |
| 7590 | |
| 7591 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7592 | if (!msg) |
| 7593 | return; |
| 7594 | |
| 7595 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7596 | if (!hdr) { |
| 7597 | nlmsg_free(msg); |
| 7598 | return; |
| 7599 | } |
| 7600 | |
| 7601 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7602 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7603 | |
| 7604 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7605 | if (!pinfoattr) |
| 7606 | goto nla_put_failure; |
| 7607 | |
| 7608 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7609 | rssi_event); |
| 7610 | |
| 7611 | nla_nest_end(msg, pinfoattr); |
| 7612 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7613 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7614 | |
| 7615 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7616 | nl80211_mlme_mcgrp.id, gfp); |
| 7617 | return; |
| 7618 | |
| 7619 | nla_put_failure: |
| 7620 | genlmsg_cancel(msg, hdr); |
| 7621 | nlmsg_free(msg); |
| 7622 | } |
| 7623 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7624 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7625 | struct net_device *netdev, const u8 *bssid, |
| 7626 | const u8 *replay_ctr, gfp_t gfp) |
| 7627 | { |
| 7628 | struct sk_buff *msg; |
| 7629 | struct nlattr *rekey_attr; |
| 7630 | void *hdr; |
| 7631 | |
| 7632 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7633 | if (!msg) |
| 7634 | return; |
| 7635 | |
| 7636 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7637 | if (!hdr) { |
| 7638 | nlmsg_free(msg); |
| 7639 | return; |
| 7640 | } |
| 7641 | |
| 7642 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7643 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7644 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7645 | |
| 7646 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7647 | if (!rekey_attr) |
| 7648 | goto nla_put_failure; |
| 7649 | |
| 7650 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7651 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7652 | |
| 7653 | nla_nest_end(msg, rekey_attr); |
| 7654 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7655 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7656 | |
| 7657 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7658 | nl80211_mlme_mcgrp.id, gfp); |
| 7659 | return; |
| 7660 | |
| 7661 | nla_put_failure: |
| 7662 | genlmsg_cancel(msg, hdr); |
| 7663 | nlmsg_free(msg); |
| 7664 | } |
| 7665 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7666 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7667 | struct net_device *netdev, int index, |
| 7668 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7669 | { |
| 7670 | struct sk_buff *msg; |
| 7671 | struct nlattr *attr; |
| 7672 | void *hdr; |
| 7673 | |
| 7674 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7675 | if (!msg) |
| 7676 | return; |
| 7677 | |
| 7678 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7679 | if (!hdr) { |
| 7680 | nlmsg_free(msg); |
| 7681 | return; |
| 7682 | } |
| 7683 | |
| 7684 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7685 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7686 | |
| 7687 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7688 | if (!attr) |
| 7689 | goto nla_put_failure; |
| 7690 | |
| 7691 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7692 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7693 | if (preauth) |
| 7694 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7695 | |
| 7696 | nla_nest_end(msg, attr); |
| 7697 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7698 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7699 | |
| 7700 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7701 | nl80211_mlme_mcgrp.id, gfp); |
| 7702 | return; |
| 7703 | |
| 7704 | nla_put_failure: |
| 7705 | genlmsg_cancel(msg, hdr); |
| 7706 | nlmsg_free(msg); |
| 7707 | } |
| 7708 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7709 | void |
| 7710 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7711 | struct net_device *netdev, const u8 *peer, |
| 7712 | u32 num_packets, 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 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7731 | |
| 7732 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7733 | if (!pinfoattr) |
| 7734 | goto nla_put_failure; |
| 7735 | |
| 7736 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 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); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [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 | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7751 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 7752 | u64 cookie, bool acked, gfp_t gfp) |
| 7753 | { |
| 7754 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7755 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7756 | struct sk_buff *msg; |
| 7757 | void *hdr; |
| 7758 | int err; |
| 7759 | |
| 7760 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7761 | if (!msg) |
| 7762 | return; |
| 7763 | |
| 7764 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 7765 | if (!hdr) { |
| 7766 | nlmsg_free(msg); |
| 7767 | return; |
| 7768 | } |
| 7769 | |
| 7770 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7771 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7772 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7773 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7774 | if (acked) |
| 7775 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7776 | |
| 7777 | err = genlmsg_end(msg, hdr); |
| 7778 | if (err < 0) { |
| 7779 | nlmsg_free(msg); |
| 7780 | return; |
| 7781 | } |
| 7782 | |
| 7783 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7784 | nl80211_mlme_mcgrp.id, gfp); |
| 7785 | return; |
| 7786 | |
| 7787 | nla_put_failure: |
| 7788 | genlmsg_cancel(msg, hdr); |
| 7789 | nlmsg_free(msg); |
| 7790 | } |
| 7791 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 7792 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7793 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 7794 | const u8 *frame, size_t len, |
| 7795 | int freq, gfp_t gfp) |
| 7796 | { |
| 7797 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 7798 | struct sk_buff *msg; |
| 7799 | void *hdr; |
| 7800 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 7801 | |
| 7802 | if (!nlpid) |
| 7803 | return; |
| 7804 | |
| 7805 | msg = nlmsg_new(len + 100, gfp); |
| 7806 | if (!msg) |
| 7807 | return; |
| 7808 | |
| 7809 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 7810 | if (!hdr) { |
| 7811 | nlmsg_free(msg); |
| 7812 | return; |
| 7813 | } |
| 7814 | |
| 7815 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7816 | if (freq) |
| 7817 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7818 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame); |
| 7819 | |
| 7820 | genlmsg_end(msg, hdr); |
| 7821 | |
| 7822 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7823 | return; |
| 7824 | |
| 7825 | nla_put_failure: |
| 7826 | genlmsg_cancel(msg, hdr); |
| 7827 | nlmsg_free(msg); |
| 7828 | } |
| 7829 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 7830 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7831 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7832 | unsigned long state, |
| 7833 | void *_notify) |
| 7834 | { |
| 7835 | struct netlink_notify *notify = _notify; |
| 7836 | struct cfg80211_registered_device *rdev; |
| 7837 | struct wireless_dev *wdev; |
| 7838 | |
| 7839 | if (state != NETLINK_URELEASE) |
| 7840 | return NOTIFY_DONE; |
| 7841 | |
| 7842 | rcu_read_lock(); |
| 7843 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7844 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7845 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7846 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7847 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 7848 | rdev->ap_beacons_nlpid = 0; |
| 7849 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7850 | |
| 7851 | rcu_read_unlock(); |
| 7852 | |
| 7853 | return NOTIFY_DONE; |
| 7854 | } |
| 7855 | |
| 7856 | static struct notifier_block nl80211_netlink_notifier = { |
| 7857 | .notifier_call = nl80211_netlink_notify, |
| 7858 | }; |
| 7859 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7860 | /* initialisation/exit functions */ |
| 7861 | |
| 7862 | int nl80211_init(void) |
| 7863 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7864 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7865 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7866 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7867 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7868 | if (err) |
| 7869 | return err; |
| 7870 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7871 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7872 | if (err) |
| 7873 | goto err_out; |
| 7874 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7875 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7876 | if (err) |
| 7877 | goto err_out; |
| 7878 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7879 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7880 | if (err) |
| 7881 | goto err_out; |
| 7882 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7883 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7884 | if (err) |
| 7885 | goto err_out; |
| 7886 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7887 | #ifdef CONFIG_NL80211_TESTMODE |
| 7888 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7889 | if (err) |
| 7890 | goto err_out; |
| 7891 | #endif |
| 7892 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7893 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7894 | if (err) |
| 7895 | goto err_out; |
| 7896 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7897 | return 0; |
| 7898 | err_out: |
| 7899 | genl_unregister_family(&nl80211_fam); |
| 7900 | return err; |
| 7901 | } |
| 7902 | |
| 7903 | void nl80211_exit(void) |
| 7904 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7905 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7906 | genl_unregister_family(&nl80211_fam); |
| 7907 | } |