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 | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 101 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 199 | }; |
| 200 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 201 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 202 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 203 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 204 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 205 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 206 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 207 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 208 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 209 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 210 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 211 | }; |
| 212 | |
| 213 | /* policy for the key default flags */ |
| 214 | static const struct nla_policy |
| 215 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 216 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 217 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 218 | }; |
| 219 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 220 | /* policy for WoWLAN attributes */ |
| 221 | static const struct nla_policy |
| 222 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 223 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 224 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 225 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 226 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 227 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 228 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 229 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 230 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 231 | }; |
| 232 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 233 | /* policy for GTK rekey offload attributes */ |
| 234 | static const struct nla_policy |
| 235 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 236 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 237 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 238 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 239 | }; |
| 240 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 241 | static const struct nla_policy |
| 242 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 243 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 244 | .len = IEEE80211_MAX_SSID_LEN }, |
| 245 | }; |
| 246 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 247 | /* ifidx get helper */ |
| 248 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 249 | { |
| 250 | int res; |
| 251 | |
| 252 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 253 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 254 | nl80211_policy); |
| 255 | if (res) |
| 256 | return res; |
| 257 | |
| 258 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 259 | return -EINVAL; |
| 260 | |
| 261 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 262 | if (!res) |
| 263 | return -EINVAL; |
| 264 | return res; |
| 265 | } |
| 266 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 267 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 268 | struct netlink_callback *cb, |
| 269 | struct cfg80211_registered_device **rdev, |
| 270 | struct net_device **dev) |
| 271 | { |
| 272 | int ifidx = cb->args[0]; |
| 273 | int err; |
| 274 | |
| 275 | if (!ifidx) |
| 276 | ifidx = nl80211_get_ifidx(cb); |
| 277 | if (ifidx < 0) |
| 278 | return ifidx; |
| 279 | |
| 280 | cb->args[0] = ifidx; |
| 281 | |
| 282 | rtnl_lock(); |
| 283 | |
| 284 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 285 | if (!*dev) { |
| 286 | err = -ENODEV; |
| 287 | goto out_rtnl; |
| 288 | } |
| 289 | |
| 290 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 291 | if (IS_ERR(*rdev)) { |
| 292 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 293 | goto out_rtnl; |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | out_rtnl: |
| 298 | rtnl_unlock(); |
| 299 | return err; |
| 300 | } |
| 301 | |
| 302 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 303 | { |
| 304 | cfg80211_unlock_rdev(rdev); |
| 305 | rtnl_unlock(); |
| 306 | } |
| 307 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 308 | /* IE validation */ |
| 309 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 310 | { |
| 311 | const u8 *pos; |
| 312 | int len; |
| 313 | |
| 314 | if (!attr) |
| 315 | return true; |
| 316 | |
| 317 | pos = nla_data(attr); |
| 318 | len = nla_len(attr); |
| 319 | |
| 320 | while (len) { |
| 321 | u8 elemlen; |
| 322 | |
| 323 | if (len < 2) |
| 324 | return false; |
| 325 | len -= 2; |
| 326 | |
| 327 | elemlen = pos[1]; |
| 328 | if (elemlen > len) |
| 329 | return false; |
| 330 | |
| 331 | len -= elemlen; |
| 332 | pos += 2 + elemlen; |
| 333 | } |
| 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 338 | /* message building helper */ |
| 339 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 340 | int flags, u8 cmd) |
| 341 | { |
| 342 | /* since there is no private header just add the generic one */ |
| 343 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 344 | } |
| 345 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 346 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 347 | struct ieee80211_channel *chan) |
| 348 | { |
| 349 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 350 | chan->center_freq); |
| 351 | |
| 352 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 353 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 354 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 355 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 356 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 357 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 358 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 359 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 360 | |
| 361 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 362 | DBM_TO_MBM(chan->max_power)); |
| 363 | |
| 364 | return 0; |
| 365 | |
| 366 | nla_put_failure: |
| 367 | return -ENOBUFS; |
| 368 | } |
| 369 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 370 | /* netlink command implementations */ |
| 371 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 372 | struct key_parse { |
| 373 | struct key_params p; |
| 374 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 375 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 376 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 377 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 381 | { |
| 382 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 383 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 384 | nl80211_key_policy); |
| 385 | if (err) |
| 386 | return err; |
| 387 | |
| 388 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 389 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 390 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 391 | if (k->def) { |
| 392 | k->def_uni = true; |
| 393 | k->def_multi = true; |
| 394 | } |
| 395 | if (k->defmgmt) |
| 396 | k->def_multi = true; |
| 397 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 398 | if (tb[NL80211_KEY_IDX]) |
| 399 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 400 | |
| 401 | if (tb[NL80211_KEY_DATA]) { |
| 402 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 403 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 404 | } |
| 405 | |
| 406 | if (tb[NL80211_KEY_SEQ]) { |
| 407 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 408 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 409 | } |
| 410 | |
| 411 | if (tb[NL80211_KEY_CIPHER]) |
| 412 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 413 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 414 | if (tb[NL80211_KEY_TYPE]) { |
| 415 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 416 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 420 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 421 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 422 | int err = nla_parse_nested(kdt, |
| 423 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 424 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 425 | nl80211_key_default_policy); |
| 426 | if (err) |
| 427 | return err; |
| 428 | |
| 429 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 430 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 431 | } |
| 432 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 437 | { |
| 438 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 439 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 440 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 441 | } |
| 442 | |
| 443 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 444 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 445 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 446 | } |
| 447 | |
| 448 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 449 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 450 | |
| 451 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 452 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 453 | |
| 454 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 455 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 456 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 457 | if (k->def) { |
| 458 | k->def_uni = true; |
| 459 | k->def_multi = true; |
| 460 | } |
| 461 | if (k->defmgmt) |
| 462 | k->def_multi = true; |
| 463 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 464 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 465 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 466 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 467 | return -EINVAL; |
| 468 | } |
| 469 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 470 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 471 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 472 | int err = nla_parse_nested( |
| 473 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 474 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 475 | nl80211_key_default_policy); |
| 476 | if (err) |
| 477 | return err; |
| 478 | |
| 479 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 480 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 481 | } |
| 482 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 487 | { |
| 488 | int err; |
| 489 | |
| 490 | memset(k, 0, sizeof(*k)); |
| 491 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 492 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 493 | |
| 494 | if (info->attrs[NL80211_ATTR_KEY]) |
| 495 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 496 | else |
| 497 | err = nl80211_parse_key_old(info, k); |
| 498 | |
| 499 | if (err) |
| 500 | return err; |
| 501 | |
| 502 | if (k->def && k->defmgmt) |
| 503 | return -EINVAL; |
| 504 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 505 | if (k->defmgmt) { |
| 506 | if (k->def_uni || !k->def_multi) |
| 507 | return -EINVAL; |
| 508 | } |
| 509 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 510 | if (k->idx != -1) { |
| 511 | if (k->defmgmt) { |
| 512 | if (k->idx < 4 || k->idx > 5) |
| 513 | return -EINVAL; |
| 514 | } else if (k->def) { |
| 515 | if (k->idx < 0 || k->idx > 3) |
| 516 | return -EINVAL; |
| 517 | } else { |
| 518 | if (k->idx < 0 || k->idx > 5) |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 526 | static struct cfg80211_cached_keys * |
| 527 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 528 | struct nlattr *keys) |
| 529 | { |
| 530 | struct key_parse parse; |
| 531 | struct nlattr *key; |
| 532 | struct cfg80211_cached_keys *result; |
| 533 | int rem, err, def = 0; |
| 534 | |
| 535 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 536 | if (!result) |
| 537 | return ERR_PTR(-ENOMEM); |
| 538 | |
| 539 | result->def = -1; |
| 540 | result->defmgmt = -1; |
| 541 | |
| 542 | nla_for_each_nested(key, keys, rem) { |
| 543 | memset(&parse, 0, sizeof(parse)); |
| 544 | parse.idx = -1; |
| 545 | |
| 546 | err = nl80211_parse_key_new(key, &parse); |
| 547 | if (err) |
| 548 | goto error; |
| 549 | err = -EINVAL; |
| 550 | if (!parse.p.key) |
| 551 | goto error; |
| 552 | if (parse.idx < 0 || parse.idx > 4) |
| 553 | goto error; |
| 554 | if (parse.def) { |
| 555 | if (def) |
| 556 | goto error; |
| 557 | def = 1; |
| 558 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 559 | if (!parse.def_uni || !parse.def_multi) |
| 560 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 561 | } else if (parse.defmgmt) |
| 562 | goto error; |
| 563 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 564 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 565 | if (err) |
| 566 | goto error; |
| 567 | result->params[parse.idx].cipher = parse.p.cipher; |
| 568 | result->params[parse.idx].key_len = parse.p.key_len; |
| 569 | result->params[parse.idx].key = result->data[parse.idx]; |
| 570 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 571 | } |
| 572 | |
| 573 | return result; |
| 574 | error: |
| 575 | kfree(result); |
| 576 | return ERR_PTR(err); |
| 577 | } |
| 578 | |
| 579 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 580 | { |
| 581 | ASSERT_WDEV_LOCK(wdev); |
| 582 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 583 | switch (wdev->iftype) { |
| 584 | case NL80211_IFTYPE_AP: |
| 585 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 586 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 587 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 588 | break; |
| 589 | case NL80211_IFTYPE_ADHOC: |
| 590 | if (!wdev->current_bss) |
| 591 | return -ENOLINK; |
| 592 | break; |
| 593 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 594 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 595 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 596 | return -ENOLINK; |
| 597 | break; |
| 598 | default: |
| 599 | return -EINVAL; |
| 600 | } |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 605 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 606 | { |
| 607 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 608 | int i; |
| 609 | |
| 610 | if (!nl_modes) |
| 611 | goto nla_put_failure; |
| 612 | |
| 613 | i = 0; |
| 614 | while (ifmodes) { |
| 615 | if (ifmodes & 1) |
| 616 | NLA_PUT_FLAG(msg, i); |
| 617 | ifmodes >>= 1; |
| 618 | i++; |
| 619 | } |
| 620 | |
| 621 | nla_nest_end(msg, nl_modes); |
| 622 | return 0; |
| 623 | |
| 624 | nla_put_failure: |
| 625 | return -ENOBUFS; |
| 626 | } |
| 627 | |
| 628 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 629 | struct sk_buff *msg) |
| 630 | { |
| 631 | struct nlattr *nl_combis; |
| 632 | int i, j; |
| 633 | |
| 634 | nl_combis = nla_nest_start(msg, |
| 635 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 636 | if (!nl_combis) |
| 637 | goto nla_put_failure; |
| 638 | |
| 639 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 640 | const struct ieee80211_iface_combination *c; |
| 641 | struct nlattr *nl_combi, *nl_limits; |
| 642 | |
| 643 | c = &wiphy->iface_combinations[i]; |
| 644 | |
| 645 | nl_combi = nla_nest_start(msg, i + 1); |
| 646 | if (!nl_combi) |
| 647 | goto nla_put_failure; |
| 648 | |
| 649 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 650 | if (!nl_limits) |
| 651 | goto nla_put_failure; |
| 652 | |
| 653 | for (j = 0; j < c->n_limits; j++) { |
| 654 | struct nlattr *nl_limit; |
| 655 | |
| 656 | nl_limit = nla_nest_start(msg, j + 1); |
| 657 | if (!nl_limit) |
| 658 | goto nla_put_failure; |
| 659 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 660 | c->limits[j].max); |
| 661 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 662 | c->limits[j].types)) |
| 663 | goto nla_put_failure; |
| 664 | nla_nest_end(msg, nl_limit); |
| 665 | } |
| 666 | |
| 667 | nla_nest_end(msg, nl_limits); |
| 668 | |
| 669 | if (c->beacon_int_infra_match) |
| 670 | NLA_PUT_FLAG(msg, |
| 671 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 672 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 673 | c->num_different_channels); |
| 674 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 675 | c->max_interfaces); |
| 676 | |
| 677 | nla_nest_end(msg, nl_combi); |
| 678 | } |
| 679 | |
| 680 | nla_nest_end(msg, nl_combis); |
| 681 | |
| 682 | return 0; |
| 683 | nla_put_failure: |
| 684 | return -ENOBUFS; |
| 685 | } |
| 686 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 687 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 688 | struct cfg80211_registered_device *dev) |
| 689 | { |
| 690 | void *hdr; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 691 | struct nlattr *nl_bands, *nl_band; |
| 692 | struct nlattr *nl_freqs, *nl_freq; |
| 693 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 694 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 695 | enum ieee80211_band band; |
| 696 | struct ieee80211_channel *chan; |
| 697 | struct ieee80211_rate *rate; |
| 698 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 699 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 700 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 701 | |
| 702 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 703 | if (!hdr) |
| 704 | return -1; |
| 705 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 706 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 707 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 708 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 709 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 710 | cfg80211_rdev_list_generation); |
| 711 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 712 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 713 | dev->wiphy.retry_short); |
| 714 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 715 | dev->wiphy.retry_long); |
| 716 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 717 | dev->wiphy.frag_threshold); |
| 718 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 719 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 720 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 721 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 722 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 723 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 724 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 725 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 726 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 727 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 728 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 729 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 730 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 731 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 732 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 733 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 734 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 735 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 736 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 737 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 738 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 739 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 740 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 741 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) |
| 742 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT); |
| 743 | if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) |
| 744 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 745 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 746 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 747 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 748 | dev->wiphy.cipher_suites); |
| 749 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 750 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 751 | dev->wiphy.max_num_pmkids); |
| 752 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 753 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 754 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 755 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 756 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 757 | dev->wiphy.available_antennas_tx); |
| 758 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 759 | dev->wiphy.available_antennas_rx); |
| 760 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 761 | if ((dev->wiphy.available_antennas_tx || |
| 762 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 763 | u32 tx_ant = 0, rx_ant = 0; |
| 764 | int res; |
| 765 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 766 | if (!res) { |
| 767 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 768 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 769 | } |
| 770 | } |
| 771 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 772 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 773 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 774 | goto nla_put_failure; |
| 775 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 776 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 777 | if (!nl_bands) |
| 778 | goto nla_put_failure; |
| 779 | |
| 780 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 781 | if (!dev->wiphy.bands[band]) |
| 782 | continue; |
| 783 | |
| 784 | nl_band = nla_nest_start(msg, band); |
| 785 | if (!nl_band) |
| 786 | goto nla_put_failure; |
| 787 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 788 | /* add HT info */ |
| 789 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 790 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 791 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 792 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 793 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 794 | dev->wiphy.bands[band]->ht_cap.cap); |
| 795 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 796 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 797 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 798 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 799 | } |
| 800 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 801 | /* add frequencies */ |
| 802 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 803 | if (!nl_freqs) |
| 804 | goto nla_put_failure; |
| 805 | |
| 806 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 807 | nl_freq = nla_nest_start(msg, i); |
| 808 | if (!nl_freq) |
| 809 | goto nla_put_failure; |
| 810 | |
| 811 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 812 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 813 | if (nl80211_msg_put_channel(msg, chan)) |
| 814 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 815 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 816 | nla_nest_end(msg, nl_freq); |
| 817 | } |
| 818 | |
| 819 | nla_nest_end(msg, nl_freqs); |
| 820 | |
| 821 | /* add bitrates */ |
| 822 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 823 | if (!nl_rates) |
| 824 | goto nla_put_failure; |
| 825 | |
| 826 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 827 | nl_rate = nla_nest_start(msg, i); |
| 828 | if (!nl_rate) |
| 829 | goto nla_put_failure; |
| 830 | |
| 831 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 832 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 833 | rate->bitrate); |
| 834 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 835 | NLA_PUT_FLAG(msg, |
| 836 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 837 | |
| 838 | nla_nest_end(msg, nl_rate); |
| 839 | } |
| 840 | |
| 841 | nla_nest_end(msg, nl_rates); |
| 842 | |
| 843 | nla_nest_end(msg, nl_band); |
| 844 | } |
| 845 | nla_nest_end(msg, nl_bands); |
| 846 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 847 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 848 | if (!nl_cmds) |
| 849 | goto nla_put_failure; |
| 850 | |
| 851 | i = 0; |
| 852 | #define CMD(op, n) \ |
| 853 | do { \ |
| 854 | if (dev->ops->op) { \ |
| 855 | i++; \ |
| 856 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 857 | } \ |
| 858 | } while (0) |
| 859 | |
| 860 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 861 | CMD(change_virtual_intf, SET_INTERFACE); |
| 862 | CMD(add_key, NEW_KEY); |
| 863 | CMD(add_beacon, NEW_BEACON); |
| 864 | CMD(add_station, NEW_STATION); |
| 865 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 866 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 867 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 868 | CMD(auth, AUTHENTICATE); |
| 869 | CMD(assoc, ASSOCIATE); |
| 870 | CMD(deauth, DEAUTHENTICATE); |
| 871 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 872 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 873 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 874 | CMD(set_pmksa, SET_PMKSA); |
| 875 | CMD(del_pmksa, DEL_PMKSA); |
| 876 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 877 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 878 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 879 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 880 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 881 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 882 | i++; |
| 883 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 884 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 885 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 886 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 887 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 888 | CMD(tdls_mgmt, TDLS_MGMT); |
| 889 | CMD(tdls_oper, TDLS_OPER); |
| 890 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 891 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 892 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 893 | |
| 894 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 895 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 896 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 897 | i++; |
| 898 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 899 | } |
| 900 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 901 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 902 | i++; |
| 903 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 904 | } |
| 905 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 906 | nla_nest_end(msg, nl_cmds); |
| 907 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 908 | if (dev->ops->remain_on_channel) |
| 909 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 910 | dev->wiphy.max_remain_on_channel_duration); |
| 911 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 912 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 913 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 914 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 915 | if (mgmt_stypes) { |
| 916 | u16 stypes; |
| 917 | struct nlattr *nl_ftypes, *nl_ifs; |
| 918 | enum nl80211_iftype ift; |
| 919 | |
| 920 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 921 | if (!nl_ifs) |
| 922 | goto nla_put_failure; |
| 923 | |
| 924 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 925 | nl_ftypes = nla_nest_start(msg, ift); |
| 926 | if (!nl_ftypes) |
| 927 | goto nla_put_failure; |
| 928 | i = 0; |
| 929 | stypes = mgmt_stypes[ift].tx; |
| 930 | while (stypes) { |
| 931 | if (stypes & 1) |
| 932 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 933 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 934 | stypes >>= 1; |
| 935 | i++; |
| 936 | } |
| 937 | nla_nest_end(msg, nl_ftypes); |
| 938 | } |
| 939 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 940 | nla_nest_end(msg, nl_ifs); |
| 941 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 942 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 943 | if (!nl_ifs) |
| 944 | goto nla_put_failure; |
| 945 | |
| 946 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 947 | nl_ftypes = nla_nest_start(msg, ift); |
| 948 | if (!nl_ftypes) |
| 949 | goto nla_put_failure; |
| 950 | i = 0; |
| 951 | stypes = mgmt_stypes[ift].rx; |
| 952 | while (stypes) { |
| 953 | if (stypes & 1) |
| 954 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 955 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 956 | stypes >>= 1; |
| 957 | i++; |
| 958 | } |
| 959 | nla_nest_end(msg, nl_ftypes); |
| 960 | } |
| 961 | nla_nest_end(msg, nl_ifs); |
| 962 | } |
| 963 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 964 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 965 | struct nlattr *nl_wowlan; |
| 966 | |
| 967 | nl_wowlan = nla_nest_start(msg, |
| 968 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 969 | if (!nl_wowlan) |
| 970 | goto nla_put_failure; |
| 971 | |
| 972 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 973 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 974 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 975 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 976 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 977 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 978 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 979 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 980 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 981 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 982 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 983 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 984 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 985 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 986 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 987 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 988 | if (dev->wiphy.wowlan.n_patterns) { |
| 989 | struct nl80211_wowlan_pattern_support pat = { |
| 990 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 991 | .min_pattern_len = |
| 992 | dev->wiphy.wowlan.pattern_min_len, |
| 993 | .max_pattern_len = |
| 994 | dev->wiphy.wowlan.pattern_max_len, |
| 995 | }; |
| 996 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 997 | sizeof(pat), &pat); |
| 998 | } |
| 999 | |
| 1000 | nla_nest_end(msg, nl_wowlan); |
| 1001 | } |
| 1002 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1003 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1004 | dev->wiphy.software_iftypes)) |
| 1005 | goto nla_put_failure; |
| 1006 | |
| 1007 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1008 | goto nla_put_failure; |
| 1009 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1010 | return genlmsg_end(msg, hdr); |
| 1011 | |
| 1012 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1013 | genlmsg_cancel(msg, hdr); |
| 1014 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1018 | { |
| 1019 | int idx = 0; |
| 1020 | int start = cb->args[0]; |
| 1021 | struct cfg80211_registered_device *dev; |
| 1022 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1023 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1024 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1025 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1026 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1027 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1028 | continue; |
| 1029 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1030 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1031 | dev) < 0) { |
| 1032 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1033 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1034 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1035 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1036 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1037 | |
| 1038 | cb->args[0] = idx; |
| 1039 | |
| 1040 | return skb->len; |
| 1041 | } |
| 1042 | |
| 1043 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1044 | { |
| 1045 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1046 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1047 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1048 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1049 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1050 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1051 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1052 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1053 | nlmsg_free(msg); |
| 1054 | return -ENOBUFS; |
| 1055 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1056 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1057 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1060 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1061 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1062 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1063 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1064 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1065 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1066 | }; |
| 1067 | |
| 1068 | static int parse_txq_params(struct nlattr *tb[], |
| 1069 | struct ieee80211_txq_params *txq_params) |
| 1070 | { |
| 1071 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1072 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1073 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1074 | return -EINVAL; |
| 1075 | |
| 1076 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1077 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1078 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1079 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1080 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1081 | |
| 1082 | return 0; |
| 1083 | } |
| 1084 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1085 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1086 | { |
| 1087 | /* |
| 1088 | * You can only set the channel explicitly for AP, mesh |
| 1089 | * and WDS type interfaces; all others have their channel |
| 1090 | * managed via their respective "establish a connection" |
| 1091 | * command (connect, join, ...) |
| 1092 | * |
| 1093 | * Monitors are special as they are normally slaved to |
| 1094 | * whatever else is going on, so they behave as though |
| 1095 | * you tried setting the wiphy channel itself. |
| 1096 | */ |
| 1097 | return !wdev || |
| 1098 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1099 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1100 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1101 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1102 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1106 | struct wireless_dev *wdev, |
| 1107 | struct genl_info *info) |
| 1108 | { |
| 1109 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1110 | u32 freq; |
| 1111 | int result; |
| 1112 | |
| 1113 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1114 | return -EINVAL; |
| 1115 | |
| 1116 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1117 | return -EOPNOTSUPP; |
| 1118 | |
| 1119 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1120 | channel_type = nla_get_u32(info->attrs[ |
| 1121 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1122 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1123 | channel_type != NL80211_CHAN_HT20 && |
| 1124 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1125 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1126 | return -EINVAL; |
| 1127 | } |
| 1128 | |
| 1129 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1130 | |
| 1131 | mutex_lock(&rdev->devlist_mtx); |
| 1132 | if (wdev) { |
| 1133 | wdev_lock(wdev); |
| 1134 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1135 | wdev_unlock(wdev); |
| 1136 | } else { |
| 1137 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1138 | } |
| 1139 | mutex_unlock(&rdev->devlist_mtx); |
| 1140 | |
| 1141 | return result; |
| 1142 | } |
| 1143 | |
| 1144 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1145 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1147 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1148 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1149 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1152 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1153 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1155 | struct net_device *dev = info->user_ptr[1]; |
| 1156 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1157 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1158 | |
| 1159 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1160 | return -EINVAL; |
| 1161 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1162 | if (netif_running(dev)) |
| 1163 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1164 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1165 | if (!rdev->ops->set_wds_peer) |
| 1166 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1167 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1168 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1169 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1170 | |
| 1171 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1172 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1176 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1177 | { |
| 1178 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1179 | struct net_device *netdev = NULL; |
| 1180 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1181 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1182 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1183 | u32 changed; |
| 1184 | u8 retry_short = 0, retry_long = 0; |
| 1185 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1186 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1187 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1188 | /* |
| 1189 | * Try to find the wiphy and netdev. Normally this |
| 1190 | * function shouldn't need the netdev, but this is |
| 1191 | * done for backward compatibility -- previously |
| 1192 | * setting the channel was done per wiphy, but now |
| 1193 | * it is per netdev. Previous userland like hostapd |
| 1194 | * also passed a netdev to set_wiphy, so that it is |
| 1195 | * possible to let that go to the right netdev! |
| 1196 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1197 | mutex_lock(&cfg80211_mutex); |
| 1198 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1199 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1200 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1201 | |
| 1202 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1203 | if (netdev && netdev->ieee80211_ptr) { |
| 1204 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1205 | mutex_lock(&rdev->mtx); |
| 1206 | } else |
| 1207 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1210 | if (!netdev) { |
| 1211 | rdev = __cfg80211_rdev_from_info(info); |
| 1212 | if (IS_ERR(rdev)) { |
| 1213 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1214 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1215 | } |
| 1216 | wdev = NULL; |
| 1217 | netdev = NULL; |
| 1218 | result = 0; |
| 1219 | |
| 1220 | mutex_lock(&rdev->mtx); |
| 1221 | } else if (netif_running(netdev) && |
| 1222 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1223 | wdev = netdev->ieee80211_ptr; |
| 1224 | else |
| 1225 | wdev = NULL; |
| 1226 | |
| 1227 | /* |
| 1228 | * end workaround code, by now the rdev is available |
| 1229 | * and locked, and wdev may or may not be NULL. |
| 1230 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1231 | |
| 1232 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1233 | result = cfg80211_dev_rename( |
| 1234 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1235 | |
| 1236 | mutex_unlock(&cfg80211_mutex); |
| 1237 | |
| 1238 | if (result) |
| 1239 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1240 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1241 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1242 | struct ieee80211_txq_params txq_params; |
| 1243 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1244 | |
| 1245 | if (!rdev->ops->set_txq_params) { |
| 1246 | result = -EOPNOTSUPP; |
| 1247 | goto bad_res; |
| 1248 | } |
| 1249 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1250 | if (!netdev) { |
| 1251 | result = -EINVAL; |
| 1252 | goto bad_res; |
| 1253 | } |
| 1254 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1255 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1256 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1257 | result = -EINVAL; |
| 1258 | goto bad_res; |
| 1259 | } |
| 1260 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1261 | nla_for_each_nested(nl_txq_params, |
| 1262 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1263 | rem_txq_params) { |
| 1264 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1265 | nla_data(nl_txq_params), |
| 1266 | nla_len(nl_txq_params), |
| 1267 | txq_params_policy); |
| 1268 | result = parse_txq_params(tb, &txq_params); |
| 1269 | if (result) |
| 1270 | goto bad_res; |
| 1271 | |
| 1272 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1273 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1274 | &txq_params); |
| 1275 | if (result) |
| 1276 | goto bad_res; |
| 1277 | } |
| 1278 | } |
| 1279 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1280 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1281 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1282 | if (result) |
| 1283 | goto bad_res; |
| 1284 | } |
| 1285 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1286 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1287 | enum nl80211_tx_power_setting type; |
| 1288 | int idx, mbm = 0; |
| 1289 | |
| 1290 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1291 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1292 | goto bad_res; |
| 1293 | } |
| 1294 | |
| 1295 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1296 | type = nla_get_u32(info->attrs[idx]); |
| 1297 | |
| 1298 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1299 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1300 | result = -EINVAL; |
| 1301 | goto bad_res; |
| 1302 | } |
| 1303 | |
| 1304 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1305 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1306 | mbm = nla_get_u32(info->attrs[idx]); |
| 1307 | } |
| 1308 | |
| 1309 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1310 | if (result) |
| 1311 | goto bad_res; |
| 1312 | } |
| 1313 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1314 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1315 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1316 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1317 | if ((!rdev->wiphy.available_antennas_tx && |
| 1318 | !rdev->wiphy.available_antennas_rx) || |
| 1319 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1320 | result = -EOPNOTSUPP; |
| 1321 | goto bad_res; |
| 1322 | } |
| 1323 | |
| 1324 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1325 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1326 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1327 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1328 | * available antenna masks, except for the "all" mask */ |
| 1329 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1330 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1331 | result = -EINVAL; |
| 1332 | goto bad_res; |
| 1333 | } |
| 1334 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1335 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1336 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1337 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1338 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1339 | if (result) |
| 1340 | goto bad_res; |
| 1341 | } |
| 1342 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1343 | changed = 0; |
| 1344 | |
| 1345 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1346 | retry_short = nla_get_u8( |
| 1347 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1348 | if (retry_short == 0) { |
| 1349 | result = -EINVAL; |
| 1350 | goto bad_res; |
| 1351 | } |
| 1352 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1353 | } |
| 1354 | |
| 1355 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1356 | retry_long = nla_get_u8( |
| 1357 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1358 | if (retry_long == 0) { |
| 1359 | result = -EINVAL; |
| 1360 | goto bad_res; |
| 1361 | } |
| 1362 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1363 | } |
| 1364 | |
| 1365 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1366 | frag_threshold = nla_get_u32( |
| 1367 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1368 | if (frag_threshold < 256) { |
| 1369 | result = -EINVAL; |
| 1370 | goto bad_res; |
| 1371 | } |
| 1372 | if (frag_threshold != (u32) -1) { |
| 1373 | /* |
| 1374 | * Fragments (apart from the last one) are required to |
| 1375 | * have even length. Make the fragmentation code |
| 1376 | * simpler by stripping LSB should someone try to use |
| 1377 | * odd threshold value. |
| 1378 | */ |
| 1379 | frag_threshold &= ~0x1; |
| 1380 | } |
| 1381 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1382 | } |
| 1383 | |
| 1384 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1385 | rts_threshold = nla_get_u32( |
| 1386 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1387 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1388 | } |
| 1389 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1390 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1391 | coverage_class = nla_get_u8( |
| 1392 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1393 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1394 | } |
| 1395 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1396 | if (changed) { |
| 1397 | u8 old_retry_short, old_retry_long; |
| 1398 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1399 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1400 | |
| 1401 | if (!rdev->ops->set_wiphy_params) { |
| 1402 | result = -EOPNOTSUPP; |
| 1403 | goto bad_res; |
| 1404 | } |
| 1405 | |
| 1406 | old_retry_short = rdev->wiphy.retry_short; |
| 1407 | old_retry_long = rdev->wiphy.retry_long; |
| 1408 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1409 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1410 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1411 | |
| 1412 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1413 | rdev->wiphy.retry_short = retry_short; |
| 1414 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1415 | rdev->wiphy.retry_long = retry_long; |
| 1416 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1417 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1418 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1419 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1420 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1421 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1422 | |
| 1423 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1424 | if (result) { |
| 1425 | rdev->wiphy.retry_short = old_retry_short; |
| 1426 | rdev->wiphy.retry_long = old_retry_long; |
| 1427 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1428 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1429 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1430 | } |
| 1431 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1432 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1433 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1434 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1435 | if (netdev) |
| 1436 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1437 | return result; |
| 1438 | } |
| 1439 | |
| 1440 | |
| 1441 | 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] | 1442 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1443 | struct net_device *dev) |
| 1444 | { |
| 1445 | void *hdr; |
| 1446 | |
| 1447 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1448 | if (!hdr) |
| 1449 | return -1; |
| 1450 | |
| 1451 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1452 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1453 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1454 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1455 | |
| 1456 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1457 | rdev->devlist_generation ^ |
| 1458 | (cfg80211_rdev_list_generation << 2)); |
| 1459 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1460 | return genlmsg_end(msg, hdr); |
| 1461 | |
| 1462 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1463 | genlmsg_cancel(msg, hdr); |
| 1464 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1468 | { |
| 1469 | int wp_idx = 0; |
| 1470 | int if_idx = 0; |
| 1471 | int wp_start = cb->args[0]; |
| 1472 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1473 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1474 | struct wireless_dev *wdev; |
| 1475 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1476 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1477 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1478 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1479 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1480 | if (wp_idx < wp_start) { |
| 1481 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1482 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1483 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1484 | if_idx = 0; |
| 1485 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1486 | mutex_lock(&rdev->devlist_mtx); |
| 1487 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1488 | if (if_idx < if_start) { |
| 1489 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1490 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1491 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1492 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1493 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1494 | rdev, wdev->netdev) < 0) { |
| 1495 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1496 | goto out; |
| 1497 | } |
| 1498 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1499 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1500 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1501 | |
| 1502 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1503 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1504 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1505 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1506 | |
| 1507 | cb->args[0] = wp_idx; |
| 1508 | cb->args[1] = if_idx; |
| 1509 | |
| 1510 | return skb->len; |
| 1511 | } |
| 1512 | |
| 1513 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1514 | { |
| 1515 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1516 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1517 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1518 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1519 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1520 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1521 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1522 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1523 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1524 | dev, netdev) < 0) { |
| 1525 | nlmsg_free(msg); |
| 1526 | return -ENOBUFS; |
| 1527 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1528 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1529 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1530 | } |
| 1531 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1532 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1533 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1534 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1535 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1536 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1537 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1538 | }; |
| 1539 | |
| 1540 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1541 | { |
| 1542 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1543 | int flag; |
| 1544 | |
| 1545 | *mntrflags = 0; |
| 1546 | |
| 1547 | if (!nla) |
| 1548 | return -EINVAL; |
| 1549 | |
| 1550 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1551 | nla, mntr_flags_policy)) |
| 1552 | return -EINVAL; |
| 1553 | |
| 1554 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1555 | if (flags[flag]) |
| 1556 | *mntrflags |= (1<<flag); |
| 1557 | |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1561 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1562 | struct net_device *netdev, u8 use_4addr, |
| 1563 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1564 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1565 | if (!use_4addr) { |
Jiri Pirko | f350a0a | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1566 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1567 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1568 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1569 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1570 | |
| 1571 | switch (iftype) { |
| 1572 | case NL80211_IFTYPE_AP_VLAN: |
| 1573 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1574 | return 0; |
| 1575 | break; |
| 1576 | case NL80211_IFTYPE_STATION: |
| 1577 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1578 | return 0; |
| 1579 | break; |
| 1580 | default: |
| 1581 | break; |
| 1582 | } |
| 1583 | |
| 1584 | return -EOPNOTSUPP; |
| 1585 | } |
| 1586 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1587 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1588 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1590 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1591 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1592 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1593 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1594 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1595 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1596 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1597 | memset(¶ms, 0, sizeof(params)); |
| 1598 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1599 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1600 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1601 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1602 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1603 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1604 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1605 | if (ntype > NL80211_IFTYPE_MAX) |
| 1606 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1607 | } |
| 1608 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1609 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1610 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1611 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1612 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1613 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1614 | if (netif_running(dev)) |
| 1615 | return -EBUSY; |
| 1616 | |
| 1617 | wdev_lock(wdev); |
| 1618 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1619 | IEEE80211_MAX_MESH_ID_LEN); |
| 1620 | wdev->mesh_id_up_len = |
| 1621 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1622 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1623 | wdev->mesh_id_up_len); |
| 1624 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1625 | } |
| 1626 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1627 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1628 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1629 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1630 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1631 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1632 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1633 | } else { |
| 1634 | params.use_4addr = -1; |
| 1635 | } |
| 1636 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1637 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1638 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1639 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1640 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1641 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1642 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1643 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1644 | |
| 1645 | flags = &_flags; |
| 1646 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1647 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1648 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1649 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1650 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1651 | else |
| 1652 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1653 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1654 | if (!err && params.use_4addr != -1) |
| 1655 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1656 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1657 | return err; |
| 1658 | } |
| 1659 | |
| 1660 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1661 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1663 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1664 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1665 | int err; |
| 1666 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1667 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1668 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1669 | memset(¶ms, 0, sizeof(params)); |
| 1670 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1671 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1672 | return -EINVAL; |
| 1673 | |
| 1674 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1675 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1676 | if (type > NL80211_IFTYPE_MAX) |
| 1677 | return -EINVAL; |
| 1678 | } |
| 1679 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1680 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1681 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1682 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1683 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1684 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1685 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1686 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1687 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1688 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1689 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1690 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1691 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1692 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1693 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1694 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1695 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1696 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1697 | if (IS_ERR(dev)) |
| 1698 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1699 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1700 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1701 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1702 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1703 | |
| 1704 | wdev_lock(wdev); |
| 1705 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1706 | IEEE80211_MAX_MESH_ID_LEN); |
| 1707 | wdev->mesh_id_up_len = |
| 1708 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1709 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1710 | wdev->mesh_id_up_len); |
| 1711 | wdev_unlock(wdev); |
| 1712 | } |
| 1713 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1714 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1718 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1720 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1721 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1722 | if (!rdev->ops->del_virtual_intf) |
| 1723 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1724 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1725 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1726 | } |
| 1727 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1728 | struct get_key_cookie { |
| 1729 | struct sk_buff *msg; |
| 1730 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1731 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1732 | }; |
| 1733 | |
| 1734 | static void get_key_callback(void *c, struct key_params *params) |
| 1735 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1736 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1737 | struct get_key_cookie *cookie = c; |
| 1738 | |
| 1739 | if (params->key) |
| 1740 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1741 | params->key_len, params->key); |
| 1742 | |
| 1743 | if (params->seq) |
| 1744 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1745 | params->seq_len, params->seq); |
| 1746 | |
| 1747 | if (params->cipher) |
| 1748 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1749 | params->cipher); |
| 1750 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1751 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1752 | if (!key) |
| 1753 | goto nla_put_failure; |
| 1754 | |
| 1755 | if (params->key) |
| 1756 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1757 | params->key_len, params->key); |
| 1758 | |
| 1759 | if (params->seq) |
| 1760 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1761 | params->seq_len, params->seq); |
| 1762 | |
| 1763 | if (params->cipher) |
| 1764 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1765 | params->cipher); |
| 1766 | |
| 1767 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1768 | |
| 1769 | nla_nest_end(cookie->msg, key); |
| 1770 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1771 | return; |
| 1772 | nla_put_failure: |
| 1773 | cookie->error = 1; |
| 1774 | } |
| 1775 | |
| 1776 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1777 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1779 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1780 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1781 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1782 | const u8 *mac_addr = NULL; |
| 1783 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1784 | struct get_key_cookie cookie = { |
| 1785 | .error = 0, |
| 1786 | }; |
| 1787 | void *hdr; |
| 1788 | struct sk_buff *msg; |
| 1789 | |
| 1790 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1791 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1792 | |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1793 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1794 | return -EINVAL; |
| 1795 | |
| 1796 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1797 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1798 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1799 | pairwise = !!mac_addr; |
| 1800 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1801 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1802 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1803 | return -EINVAL; |
| 1804 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1805 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1806 | return -EINVAL; |
| 1807 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1808 | } |
| 1809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1810 | if (!rdev->ops->get_key) |
| 1811 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1812 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1813 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1814 | if (!msg) |
| 1815 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1816 | |
| 1817 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1818 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1819 | if (IS_ERR(hdr)) |
| 1820 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1821 | |
| 1822 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1823 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1824 | |
| 1825 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1826 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1827 | if (mac_addr) |
| 1828 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1829 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1830 | if (pairwise && mac_addr && |
| 1831 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1832 | return -ENOENT; |
| 1833 | |
| 1834 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1835 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1836 | |
| 1837 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1838 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1839 | |
| 1840 | if (cookie.error) |
| 1841 | goto nla_put_failure; |
| 1842 | |
| 1843 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1844 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1845 | |
| 1846 | nla_put_failure: |
| 1847 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1848 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1849 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1850 | return err; |
| 1851 | } |
| 1852 | |
| 1853 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1854 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1856 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1857 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1858 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1859 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1860 | err = nl80211_parse_key(info, &key); |
| 1861 | if (err) |
| 1862 | return err; |
| 1863 | |
| 1864 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1865 | return -EINVAL; |
| 1866 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1867 | /* only support setting default key */ |
| 1868 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1869 | return -EINVAL; |
| 1870 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1871 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1872 | |
| 1873 | if (key.def) { |
| 1874 | if (!rdev->ops->set_default_key) { |
| 1875 | err = -EOPNOTSUPP; |
| 1876 | goto out; |
| 1877 | } |
| 1878 | |
| 1879 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1880 | if (err) |
| 1881 | goto out; |
| 1882 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1883 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1884 | key.def_uni, key.def_multi); |
| 1885 | |
| 1886 | if (err) |
| 1887 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1888 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1889 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1890 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1891 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1892 | } else { |
| 1893 | if (key.def_uni || !key.def_multi) { |
| 1894 | err = -EINVAL; |
| 1895 | goto out; |
| 1896 | } |
| 1897 | |
| 1898 | if (!rdev->ops->set_default_mgmt_key) { |
| 1899 | err = -EOPNOTSUPP; |
| 1900 | goto out; |
| 1901 | } |
| 1902 | |
| 1903 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1904 | if (err) |
| 1905 | goto out; |
| 1906 | |
| 1907 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1908 | dev, key.idx); |
| 1909 | if (err) |
| 1910 | goto out; |
| 1911 | |
| 1912 | #ifdef CONFIG_CFG80211_WEXT |
| 1913 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1914 | #endif |
| 1915 | } |
| 1916 | |
| 1917 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1918 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1919 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1920 | return err; |
| 1921 | } |
| 1922 | |
| 1923 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1924 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1926 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1927 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1928 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1929 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1930 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1931 | err = nl80211_parse_key(info, &key); |
| 1932 | if (err) |
| 1933 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1934 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1935 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1936 | return -EINVAL; |
| 1937 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1938 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1939 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1940 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1941 | if (key.type == -1) { |
| 1942 | if (mac_addr) |
| 1943 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1944 | else |
| 1945 | key.type = NL80211_KEYTYPE_GROUP; |
| 1946 | } |
| 1947 | |
| 1948 | /* for now */ |
| 1949 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1950 | key.type != NL80211_KEYTYPE_GROUP) |
| 1951 | return -EINVAL; |
| 1952 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1953 | if (!rdev->ops->add_key) |
| 1954 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1955 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1956 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1957 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1958 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1959 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1960 | |
| 1961 | wdev_lock(dev->ieee80211_ptr); |
| 1962 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1963 | if (!err) |
| 1964 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1965 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1966 | mac_addr, &key.p); |
| 1967 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1968 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1969 | return err; |
| 1970 | } |
| 1971 | |
| 1972 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1973 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1975 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1976 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1977 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1978 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1979 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1980 | err = nl80211_parse_key(info, &key); |
| 1981 | if (err) |
| 1982 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1983 | |
| 1984 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1985 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1986 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1987 | if (key.type == -1) { |
| 1988 | if (mac_addr) |
| 1989 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1990 | else |
| 1991 | key.type = NL80211_KEYTYPE_GROUP; |
| 1992 | } |
| 1993 | |
| 1994 | /* for now */ |
| 1995 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1996 | key.type != NL80211_KEYTYPE_GROUP) |
| 1997 | return -EINVAL; |
| 1998 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1999 | if (!rdev->ops->del_key) |
| 2000 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2001 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2002 | wdev_lock(dev->ieee80211_ptr); |
| 2003 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2004 | |
| 2005 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2006 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2007 | err = -ENOENT; |
| 2008 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2009 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2010 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2011 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2012 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2013 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2014 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2015 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2016 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2017 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2018 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2019 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2020 | } |
| 2021 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2022 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2023 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2024 | return err; |
| 2025 | } |
| 2026 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2027 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2028 | { |
| 2029 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 2030 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2031 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2032 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2033 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2034 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2035 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2036 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2037 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2038 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2039 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2040 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2041 | return -EINVAL; |
| 2042 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2043 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2044 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2045 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2046 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2047 | memset(¶ms, 0, sizeof(params)); |
| 2048 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2049 | switch (info->genlhdr->cmd) { |
| 2050 | case NL80211_CMD_NEW_BEACON: |
| 2051 | /* these are required for NEW_BEACON */ |
| 2052 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2053 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2054 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2055 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2056 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2057 | params.interval = |
| 2058 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2059 | params.dtim_period = |
| 2060 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2061 | |
| 2062 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2063 | if (err) |
| 2064 | return err; |
| 2065 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2066 | /* |
| 2067 | * In theory, some of these attributes could be required for |
| 2068 | * NEW_BEACON, but since they were not used when the command was |
| 2069 | * originally added, keep them optional for old user space |
| 2070 | * programs to work with drivers that do not need the additional |
| 2071 | * information. |
| 2072 | */ |
| 2073 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2074 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2075 | params.ssid_len = |
| 2076 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2077 | if (params.ssid_len == 0 || |
| 2078 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2079 | return -EINVAL; |
| 2080 | } |
| 2081 | |
| 2082 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2083 | params.hidden_ssid = nla_get_u32( |
| 2084 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2085 | if (params.hidden_ssid != |
| 2086 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2087 | params.hidden_ssid != |
| 2088 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2089 | params.hidden_ssid != |
| 2090 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2091 | return -EINVAL; |
| 2092 | } |
| 2093 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2094 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2095 | |
| 2096 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2097 | params.auth_type = nla_get_u32( |
| 2098 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2099 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2100 | return -EINVAL; |
| 2101 | } else |
| 2102 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2103 | |
| 2104 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2105 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2106 | if (err) |
| 2107 | return err; |
| 2108 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2109 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2110 | break; |
| 2111 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2112 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2113 | break; |
| 2114 | default: |
| 2115 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2116 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2117 | } |
| 2118 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2119 | if (!call) |
| 2120 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2121 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2122 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2123 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2124 | params.head_len = |
| 2125 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2126 | haveinfo = 1; |
| 2127 | } |
| 2128 | |
| 2129 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2130 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2131 | params.tail_len = |
| 2132 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2133 | haveinfo = 1; |
| 2134 | } |
| 2135 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2136 | if (!haveinfo) |
| 2137 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2138 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2139 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2140 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2141 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2142 | } |
| 2143 | |
| 2144 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2145 | params.proberesp_ies = |
| 2146 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2147 | params.proberesp_ies_len = |
| 2148 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2149 | } |
| 2150 | |
| 2151 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2152 | params.assocresp_ies = |
| 2153 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2154 | params.assocresp_ies_len = |
| 2155 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2156 | } |
| 2157 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2158 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2159 | if (!err && params.interval) |
| 2160 | wdev->beacon_interval = params.interval; |
| 2161 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2165 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2167 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2168 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2169 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2170 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2171 | if (!rdev->ops->del_beacon) |
| 2172 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2173 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2174 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2175 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2176 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2177 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2178 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2179 | if (!err) |
| 2180 | wdev->beacon_interval = 0; |
| 2181 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2182 | } |
| 2183 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2184 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2185 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2186 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2187 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2188 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2189 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2190 | }; |
| 2191 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2192 | static int parse_station_flags(struct genl_info *info, |
| 2193 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2194 | { |
| 2195 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2196 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2197 | int flag; |
| 2198 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2199 | /* |
| 2200 | * Try parsing the new attribute first so userspace |
| 2201 | * can specify both for older kernels. |
| 2202 | */ |
| 2203 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2204 | if (nla) { |
| 2205 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2206 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2207 | sta_flags = nla_data(nla); |
| 2208 | params->sta_flags_mask = sta_flags->mask; |
| 2209 | params->sta_flags_set = sta_flags->set; |
| 2210 | if ((params->sta_flags_mask | |
| 2211 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2212 | return -EINVAL; |
| 2213 | return 0; |
| 2214 | } |
| 2215 | |
| 2216 | /* if present, parse the old attribute */ |
| 2217 | |
| 2218 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2219 | if (!nla) |
| 2220 | return 0; |
| 2221 | |
| 2222 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2223 | nla, sta_flags_policy)) |
| 2224 | return -EINVAL; |
| 2225 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2226 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2227 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2228 | |
| 2229 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2230 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2231 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2232 | |
| 2233 | return 0; |
| 2234 | } |
| 2235 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2236 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2237 | int attr) |
| 2238 | { |
| 2239 | struct nlattr *rate; |
| 2240 | u16 bitrate; |
| 2241 | |
| 2242 | rate = nla_nest_start(msg, attr); |
| 2243 | if (!rate) |
| 2244 | goto nla_put_failure; |
| 2245 | |
| 2246 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2247 | bitrate = cfg80211_calculate_bitrate(info); |
| 2248 | if (bitrate > 0) |
| 2249 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2250 | |
| 2251 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2252 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2253 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2254 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2255 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2256 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2257 | |
| 2258 | nla_nest_end(msg, rate); |
| 2259 | return true; |
| 2260 | |
| 2261 | nla_put_failure: |
| 2262 | return false; |
| 2263 | } |
| 2264 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2265 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2266 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2267 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2268 | { |
| 2269 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2270 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2271 | |
| 2272 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2273 | if (!hdr) |
| 2274 | return -1; |
| 2275 | |
| 2276 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2277 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2278 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2279 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2280 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2281 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2282 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2283 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2284 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2285 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2286 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2287 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2288 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2289 | sinfo->inactive_time); |
| 2290 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2291 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2292 | sinfo->rx_bytes); |
| 2293 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2294 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2295 | sinfo->tx_bytes); |
| 2296 | if (sinfo->filled & STATION_INFO_LLID) |
| 2297 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2298 | sinfo->llid); |
| 2299 | if (sinfo->filled & STATION_INFO_PLID) |
| 2300 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2301 | sinfo->plid); |
| 2302 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2303 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2304 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2305 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2306 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2307 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2308 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2309 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2310 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2311 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2312 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2313 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2314 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2315 | } |
| 2316 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2317 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2318 | NL80211_STA_INFO_RX_BITRATE)) |
| 2319 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2320 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2321 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2322 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2323 | sinfo->rx_packets); |
| 2324 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2325 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2326 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2327 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2328 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2329 | sinfo->tx_retries); |
| 2330 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2331 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2332 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2333 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2334 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2335 | if (!bss_param) |
| 2336 | goto nla_put_failure; |
| 2337 | |
| 2338 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2339 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2340 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2341 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2342 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2343 | NLA_PUT_FLAG(msg, |
| 2344 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2345 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2346 | sinfo->bss_param.dtim_period); |
| 2347 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2348 | sinfo->bss_param.beacon_interval); |
| 2349 | |
| 2350 | nla_nest_end(msg, bss_param); |
| 2351 | } |
Helmut Schaa | bb6e753 | 2011-10-13 16:30:39 +0200 | [diff] [blame] | 2352 | if (sinfo->filled & STATION_INFO_STA_FLAGS) |
| 2353 | NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2354 | sizeof(struct nl80211_sta_flag_update), |
| 2355 | &sinfo->sta_flags); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2356 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2357 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2358 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2359 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2360 | sinfo->assoc_req_ies); |
| 2361 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2362 | return genlmsg_end(msg, hdr); |
| 2363 | |
| 2364 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2365 | genlmsg_cancel(msg, hdr); |
| 2366 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2367 | } |
| 2368 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2369 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2370 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2371 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2372 | struct station_info sinfo; |
| 2373 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2374 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2375 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2376 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2377 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2378 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2379 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2380 | if (err) |
| 2381 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2382 | |
| 2383 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2384 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2385 | goto out_err; |
| 2386 | } |
| 2387 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2388 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2389 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2390 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2391 | mac_addr, &sinfo); |
| 2392 | if (err == -ENOENT) |
| 2393 | break; |
| 2394 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2395 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2396 | |
| 2397 | if (nl80211_send_station(skb, |
| 2398 | NETLINK_CB(cb->skb).pid, |
| 2399 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2400 | netdev, mac_addr, |
| 2401 | &sinfo) < 0) |
| 2402 | goto out; |
| 2403 | |
| 2404 | sta_idx++; |
| 2405 | } |
| 2406 | |
| 2407 | |
| 2408 | out: |
| 2409 | cb->args[1] = sta_idx; |
| 2410 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2411 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2412 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2413 | |
| 2414 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2415 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2416 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2417 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2418 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2420 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2421 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2422 | struct sk_buff *msg; |
| 2423 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2424 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2425 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2426 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2427 | |
| 2428 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2429 | return -EINVAL; |
| 2430 | |
| 2431 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2432 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2433 | if (!rdev->ops->get_station) |
| 2434 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2435 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2436 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2437 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2438 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2439 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2440 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2441 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2442 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2443 | |
| 2444 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2445 | dev, mac_addr, &sinfo) < 0) { |
| 2446 | nlmsg_free(msg); |
| 2447 | return -ENOBUFS; |
| 2448 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2449 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2450 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2454 | * 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] | 2455 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2456 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2457 | struct cfg80211_registered_device *rdev, |
| 2458 | struct net_device **vlan) |
| 2459 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2460 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2461 | *vlan = NULL; |
| 2462 | |
| 2463 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2464 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2465 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2466 | if (!*vlan) |
| 2467 | return -ENODEV; |
| 2468 | if (!(*vlan)->ieee80211_ptr) |
| 2469 | return -EINVAL; |
| 2470 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2471 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2472 | if (!netif_running(*vlan)) |
| 2473 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2474 | } |
| 2475 | return 0; |
| 2476 | } |
| 2477 | |
| 2478 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2479 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2480 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2481 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2482 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2483 | struct station_parameters params; |
| 2484 | u8 *mac_addr = NULL; |
| 2485 | |
| 2486 | memset(¶ms, 0, sizeof(params)); |
| 2487 | |
| 2488 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2489 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2490 | |
| 2491 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2492 | return -EINVAL; |
| 2493 | |
| 2494 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2495 | return -EINVAL; |
| 2496 | |
| 2497 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2498 | |
| 2499 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2500 | params.supported_rates = |
| 2501 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2502 | params.supported_rates_len = |
| 2503 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2504 | } |
| 2505 | |
| 2506 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2507 | params.listen_interval = |
| 2508 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2509 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2510 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2511 | params.ht_capa = |
| 2512 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2513 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2514 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2515 | return -EINVAL; |
| 2516 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2517 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2518 | params.plink_action = |
| 2519 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2520 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2521 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2522 | params.plink_state = |
| 2523 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2524 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2525 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2526 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2527 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2528 | |
| 2529 | /* validate settings */ |
| 2530 | err = 0; |
| 2531 | |
| 2532 | switch (dev->ieee80211_ptr->iftype) { |
| 2533 | case NL80211_IFTYPE_AP: |
| 2534 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2535 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2536 | /* disallow mesh-specific things */ |
| 2537 | if (params.plink_action) |
| 2538 | err = -EINVAL; |
| 2539 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2540 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2541 | case NL80211_IFTYPE_STATION: |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2542 | /* disallow things sta doesn't support */ |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2543 | if (params.plink_action) |
| 2544 | err = -EINVAL; |
| 2545 | if (params.vlan) |
| 2546 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2547 | if (params.supported_rates && |
| 2548 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2549 | err = -EINVAL; |
| 2550 | if (params.ht_capa) |
| 2551 | err = -EINVAL; |
| 2552 | if (params.listen_interval >= 0) |
| 2553 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2554 | if (params.sta_flags_mask & |
| 2555 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2556 | BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 2557 | err = -EINVAL; |
| 2558 | /* can't change the TDLS bit */ |
| 2559 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2560 | (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2561 | err = -EINVAL; |
| 2562 | break; |
| 2563 | case NL80211_IFTYPE_MESH_POINT: |
| 2564 | /* disallow things mesh doesn't support */ |
| 2565 | if (params.vlan) |
| 2566 | err = -EINVAL; |
| 2567 | if (params.ht_capa) |
| 2568 | err = -EINVAL; |
| 2569 | if (params.listen_interval >= 0) |
| 2570 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2571 | if (params.sta_flags_mask & |
| 2572 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2573 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2574 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2575 | err = -EINVAL; |
| 2576 | break; |
| 2577 | default: |
| 2578 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2579 | } |
| 2580 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2581 | if (err) |
| 2582 | goto out; |
| 2583 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2584 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2585 | err = -EOPNOTSUPP; |
| 2586 | goto out; |
| 2587 | } |
| 2588 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2589 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2590 | |
| 2591 | out: |
| 2592 | if (params.vlan) |
| 2593 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2594 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2595 | return err; |
| 2596 | } |
| 2597 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2598 | static struct nla_policy |
| 2599 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2600 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2601 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2602 | }; |
| 2603 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2604 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2605 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2607 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2608 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2609 | struct station_parameters params; |
| 2610 | u8 *mac_addr = NULL; |
| 2611 | |
| 2612 | memset(¶ms, 0, sizeof(params)); |
| 2613 | |
| 2614 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2615 | return -EINVAL; |
| 2616 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2617 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2618 | return -EINVAL; |
| 2619 | |
| 2620 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2621 | return -EINVAL; |
| 2622 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2623 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2624 | return -EINVAL; |
| 2625 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2626 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2627 | params.supported_rates = |
| 2628 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2629 | params.supported_rates_len = |
| 2630 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2631 | params.listen_interval = |
| 2632 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2633 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2634 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2635 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2636 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2637 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2638 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2639 | params.ht_capa = |
| 2640 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2641 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2642 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2643 | params.plink_action = |
| 2644 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2645 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2646 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2647 | return -EINVAL; |
| 2648 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2649 | /* parse WME attributes if sta is WME capable */ |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 2650 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Arik Nemtsov | cd32984 | 2011-09-26 09:36:42 +0300 | [diff] [blame] | 2651 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2652 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2653 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2654 | struct nlattr *nla; |
| 2655 | |
| 2656 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2657 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2658 | nl80211_sta_wme_policy); |
| 2659 | if (err) |
| 2660 | return err; |
| 2661 | |
| 2662 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2663 | params.uapsd_queues = |
| 2664 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2665 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2666 | return -EINVAL; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2667 | |
| 2668 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2669 | params.max_sp = |
| 2670 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2671 | |
| 2672 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2673 | return -EINVAL; |
Johannes Berg | 3b9ce80 | 2011-09-27 20:56:12 +0200 | [diff] [blame] | 2674 | |
| 2675 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2676 | } |
| 2677 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2678 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2679 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2680 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2681 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO && |
| 2682 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) |
| 2683 | return -EINVAL; |
| 2684 | |
| 2685 | /* |
| 2686 | * Only managed stations can add TDLS peers, and only when the |
| 2687 | * wiphy supports external TDLS setup. |
| 2688 | */ |
| 2689 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION && |
| 2690 | !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2691 | (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 2692 | (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2693 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2694 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2695 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2696 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2697 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2698 | |
| 2699 | /* validate settings */ |
| 2700 | err = 0; |
| 2701 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2702 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2703 | err = -EOPNOTSUPP; |
| 2704 | goto out; |
| 2705 | } |
| 2706 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2707 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2708 | |
| 2709 | out: |
| 2710 | if (params.vlan) |
| 2711 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2712 | return err; |
| 2713 | } |
| 2714 | |
| 2715 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2716 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2717 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2718 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2719 | u8 *mac_addr = NULL; |
| 2720 | |
| 2721 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2722 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2723 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2724 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2725 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2726 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2727 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2728 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2729 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2730 | if (!rdev->ops->del_station) |
| 2731 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2732 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2733 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2734 | } |
| 2735 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2736 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2737 | int flags, struct net_device *dev, |
| 2738 | u8 *dst, u8 *next_hop, |
| 2739 | struct mpath_info *pinfo) |
| 2740 | { |
| 2741 | void *hdr; |
| 2742 | struct nlattr *pinfoattr; |
| 2743 | |
| 2744 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2745 | if (!hdr) |
| 2746 | return -1; |
| 2747 | |
| 2748 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2749 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2750 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2751 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2752 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2753 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2754 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2755 | if (!pinfoattr) |
| 2756 | goto nla_put_failure; |
| 2757 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2758 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2759 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2760 | if (pinfo->filled & MPATH_INFO_SN) |
| 2761 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2762 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2763 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2764 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2765 | pinfo->metric); |
| 2766 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2767 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2768 | pinfo->exptime); |
| 2769 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2770 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2771 | pinfo->flags); |
| 2772 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2773 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2774 | pinfo->discovery_timeout); |
| 2775 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2776 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2777 | pinfo->discovery_retries); |
| 2778 | |
| 2779 | nla_nest_end(msg, pinfoattr); |
| 2780 | |
| 2781 | return genlmsg_end(msg, hdr); |
| 2782 | |
| 2783 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2784 | genlmsg_cancel(msg, hdr); |
| 2785 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2789 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2790 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2791 | struct mpath_info pinfo; |
| 2792 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2793 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2794 | u8 dst[ETH_ALEN]; |
| 2795 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2796 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2797 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2798 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2799 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2800 | if (err) |
| 2801 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2802 | |
| 2803 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2804 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2805 | goto out_err; |
| 2806 | } |
| 2807 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2808 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2809 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2810 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2811 | } |
| 2812 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2813 | while (1) { |
| 2814 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2815 | dst, next_hop, &pinfo); |
| 2816 | if (err == -ENOENT) |
| 2817 | break; |
| 2818 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2819 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2820 | |
| 2821 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2822 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2823 | netdev, dst, next_hop, |
| 2824 | &pinfo) < 0) |
| 2825 | goto out; |
| 2826 | |
| 2827 | path_idx++; |
| 2828 | } |
| 2829 | |
| 2830 | |
| 2831 | out: |
| 2832 | cb->args[1] = path_idx; |
| 2833 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2834 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2835 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2836 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2840 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2842 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2843 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2844 | struct mpath_info pinfo; |
| 2845 | struct sk_buff *msg; |
| 2846 | u8 *dst = NULL; |
| 2847 | u8 next_hop[ETH_ALEN]; |
| 2848 | |
| 2849 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2850 | |
| 2851 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2852 | return -EINVAL; |
| 2853 | |
| 2854 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2855 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2856 | if (!rdev->ops->get_mpath) |
| 2857 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2859 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2860 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2861 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2862 | 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] | 2863 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2864 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2865 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2866 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2867 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2868 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2869 | |
| 2870 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2871 | dev, dst, next_hop, &pinfo) < 0) { |
| 2872 | nlmsg_free(msg); |
| 2873 | return -ENOBUFS; |
| 2874 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2875 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2876 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2880 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2882 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2883 | u8 *dst = NULL; |
| 2884 | u8 *next_hop = NULL; |
| 2885 | |
| 2886 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2887 | return -EINVAL; |
| 2888 | |
| 2889 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2890 | return -EINVAL; |
| 2891 | |
| 2892 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2893 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2894 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2895 | if (!rdev->ops->change_mpath) |
| 2896 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2897 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2898 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2899 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2900 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2901 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2902 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2903 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2904 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2905 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2907 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2908 | u8 *dst = NULL; |
| 2909 | u8 *next_hop = NULL; |
| 2910 | |
| 2911 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2912 | return -EINVAL; |
| 2913 | |
| 2914 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2915 | return -EINVAL; |
| 2916 | |
| 2917 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2918 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2920 | if (!rdev->ops->add_mpath) |
| 2921 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2922 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2923 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2924 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2925 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2926 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2930 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2932 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2933 | u8 *dst = NULL; |
| 2934 | |
| 2935 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2936 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2938 | if (!rdev->ops->del_mpath) |
| 2939 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2940 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2941 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2942 | } |
| 2943 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2944 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2945 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2947 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2948 | struct bss_parameters params; |
| 2949 | |
| 2950 | memset(¶ms, 0, sizeof(params)); |
| 2951 | /* default to not changing parameters */ |
| 2952 | params.use_cts_prot = -1; |
| 2953 | params.use_short_preamble = -1; |
| 2954 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2955 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2956 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2957 | |
| 2958 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2959 | params.use_cts_prot = |
| 2960 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2961 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2962 | params.use_short_preamble = |
| 2963 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2964 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2965 | params.use_short_slot_time = |
| 2966 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2967 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2968 | params.basic_rates = |
| 2969 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2970 | params.basic_rates_len = |
| 2971 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2972 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2973 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2974 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2975 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2976 | params.ht_opmode = |
| 2977 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2978 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2979 | if (!rdev->ops->change_bss) |
| 2980 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2981 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2982 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2983 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2984 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2985 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2986 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2987 | } |
| 2988 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2989 | 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] | 2990 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2991 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2992 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2993 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2994 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2995 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2996 | }; |
| 2997 | |
| 2998 | static int parse_reg_rule(struct nlattr *tb[], |
| 2999 | struct ieee80211_reg_rule *reg_rule) |
| 3000 | { |
| 3001 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3002 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3003 | |
| 3004 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3005 | return -EINVAL; |
| 3006 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3007 | return -EINVAL; |
| 3008 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3009 | return -EINVAL; |
| 3010 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3011 | return -EINVAL; |
| 3012 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3013 | return -EINVAL; |
| 3014 | |
| 3015 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3016 | |
| 3017 | freq_range->start_freq_khz = |
| 3018 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3019 | freq_range->end_freq_khz = |
| 3020 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3021 | freq_range->max_bandwidth_khz = |
| 3022 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3023 | |
| 3024 | power_rule->max_eirp = |
| 3025 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3026 | |
| 3027 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3028 | power_rule->max_antenna_gain = |
| 3029 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3030 | |
| 3031 | return 0; |
| 3032 | } |
| 3033 | |
| 3034 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3035 | { |
| 3036 | int r; |
| 3037 | char *data = NULL; |
| 3038 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3039 | /* |
| 3040 | * You should only get this when cfg80211 hasn't yet initialized |
| 3041 | * completely when built-in to the kernel right between the time |
| 3042 | * window between nl80211_init() and regulatory_init(), if that is |
| 3043 | * even possible. |
| 3044 | */ |
| 3045 | mutex_lock(&cfg80211_mutex); |
| 3046 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3047 | mutex_unlock(&cfg80211_mutex); |
| 3048 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3049 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3050 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3051 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3052 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3053 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3054 | |
| 3055 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3056 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3057 | r = regulatory_hint_user(data); |
| 3058 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3059 | return r; |
| 3060 | } |
| 3061 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3062 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3063 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3064 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3065 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3066 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3067 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3068 | struct mesh_config cur_params; |
| 3069 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3070 | void *hdr; |
| 3071 | struct nlattr *pinfoattr; |
| 3072 | struct sk_buff *msg; |
| 3073 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3074 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3075 | return -EOPNOTSUPP; |
| 3076 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3077 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3078 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3079 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3080 | wdev_lock(wdev); |
| 3081 | /* If not connected, get default parameters */ |
| 3082 | if (!wdev->mesh_id_len) |
| 3083 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3084 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3085 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3086 | &cur_params); |
| 3087 | wdev_unlock(wdev); |
| 3088 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3089 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3090 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3091 | |
| 3092 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3093 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3094 | if (!msg) |
| 3095 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3096 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3097 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3098 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3099 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3100 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3101 | if (!pinfoattr) |
| 3102 | goto nla_put_failure; |
| 3103 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3104 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3105 | cur_params.dot11MeshRetryTimeout); |
| 3106 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3107 | cur_params.dot11MeshConfirmTimeout); |
| 3108 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3109 | cur_params.dot11MeshHoldingTimeout); |
| 3110 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3111 | cur_params.dot11MeshMaxPeerLinks); |
| 3112 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3113 | cur_params.dot11MeshMaxRetries); |
| 3114 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3115 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3116 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3117 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3118 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3119 | cur_params.auto_open_plinks); |
| 3120 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3121 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3122 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3123 | cur_params.path_refresh_time); |
| 3124 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3125 | cur_params.min_discovery_timeout); |
| 3126 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3127 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3128 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3129 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 3130 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3131 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3132 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3133 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3134 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3135 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3136 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3137 | cur_params.dot11MeshGateAnnouncementProtocol); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3138 | nla_nest_end(msg, pinfoattr); |
| 3139 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3140 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3141 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3142 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3143 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3144 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3145 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3146 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3147 | } |
| 3148 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3149 | 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] | 3150 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3151 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3152 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3153 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3154 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3155 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3156 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3157 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3158 | |
| 3159 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3160 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3161 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3162 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3163 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 3164 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3165 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3166 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3167 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3168 | }; |
| 3169 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3170 | static const struct nla_policy |
| 3171 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3172 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3173 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3174 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3175 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3176 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3177 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3178 | }; |
| 3179 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3180 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3181 | struct mesh_config *cfg, |
| 3182 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3183 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3184 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3185 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3186 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3187 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3188 | do {\ |
| 3189 | if (table[attr_num]) {\ |
| 3190 | cfg->param = nla_fn(table[attr_num]); \ |
| 3191 | mask |= (1 << (attr_num - 1)); \ |
| 3192 | } \ |
| 3193 | } while (0);\ |
| 3194 | |
| 3195 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3196 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3197 | return -EINVAL; |
| 3198 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3199 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3200 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3201 | return -EINVAL; |
| 3202 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3203 | /* This makes sure that there aren't more than 32 mesh config |
| 3204 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3205 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3206 | |
| 3207 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3208 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3209 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3210 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3211 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3212 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3213 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3214 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3215 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3216 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3217 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3218 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3219 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3220 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3221 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3222 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3223 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3224 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3225 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3226 | nla_get_u8); |
| 3227 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3228 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3229 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3230 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3231 | nla_get_u16); |
| 3232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3233 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3234 | nla_get_u32); |
| 3235 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3236 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3237 | nla_get_u16); |
| 3238 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3239 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3240 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3241 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3242 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3243 | dot11MeshHWMPRootMode, mask, |
| 3244 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3245 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3246 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3247 | dot11MeshHWMPRannInterval, mask, |
| 3248 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3249 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3250 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3251 | dot11MeshGateAnnouncementProtocol, mask, |
| 3252 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3253 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3254 | if (mask_out) |
| 3255 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3256 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3257 | return 0; |
| 3258 | |
| 3259 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3260 | } |
| 3261 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3262 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3263 | struct mesh_setup *setup) |
| 3264 | { |
| 3265 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3266 | |
| 3267 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3268 | return -EINVAL; |
| 3269 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3270 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3271 | nl80211_mesh_setup_params_policy)) |
| 3272 | return -EINVAL; |
| 3273 | |
| 3274 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3275 | setup->path_sel_proto = |
| 3276 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3277 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3278 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3279 | |
| 3280 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3281 | setup->path_metric = |
| 3282 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3283 | IEEE80211_PATH_METRIC_VENDOR : |
| 3284 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3285 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3286 | |
| 3287 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3288 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3289 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3290 | if (!is_valid_ie_attr(ieattr)) |
| 3291 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3292 | setup->ie = nla_data(ieattr); |
| 3293 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3294 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3295 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3296 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3297 | |
| 3298 | return 0; |
| 3299 | } |
| 3300 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3301 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3302 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3303 | { |
| 3304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3305 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3306 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3307 | struct mesh_config cfg; |
| 3308 | u32 mask; |
| 3309 | int err; |
| 3310 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3311 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3312 | return -EOPNOTSUPP; |
| 3313 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3314 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3315 | return -EOPNOTSUPP; |
| 3316 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3317 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3318 | if (err) |
| 3319 | return err; |
| 3320 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3321 | wdev_lock(wdev); |
| 3322 | if (!wdev->mesh_id_len) |
| 3323 | err = -ENOLINK; |
| 3324 | |
| 3325 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3326 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3327 | mask, &cfg); |
| 3328 | |
| 3329 | wdev_unlock(wdev); |
| 3330 | |
| 3331 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3334 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3335 | { |
| 3336 | struct sk_buff *msg; |
| 3337 | void *hdr = NULL; |
| 3338 | struct nlattr *nl_reg_rules; |
| 3339 | unsigned int i; |
| 3340 | int err = -EINVAL; |
| 3341 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3342 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3343 | |
| 3344 | if (!cfg80211_regdomain) |
| 3345 | goto out; |
| 3346 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3347 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3348 | if (!msg) { |
| 3349 | err = -ENOBUFS; |
| 3350 | goto out; |
| 3351 | } |
| 3352 | |
| 3353 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3354 | NL80211_CMD_GET_REG); |
| 3355 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3356 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3357 | |
| 3358 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3359 | cfg80211_regdomain->alpha2); |
| 3360 | |
| 3361 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3362 | if (!nl_reg_rules) |
| 3363 | goto nla_put_failure; |
| 3364 | |
| 3365 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3366 | struct nlattr *nl_reg_rule; |
| 3367 | const struct ieee80211_reg_rule *reg_rule; |
| 3368 | const struct ieee80211_freq_range *freq_range; |
| 3369 | const struct ieee80211_power_rule *power_rule; |
| 3370 | |
| 3371 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3372 | freq_range = ®_rule->freq_range; |
| 3373 | power_rule = ®_rule->power_rule; |
| 3374 | |
| 3375 | nl_reg_rule = nla_nest_start(msg, i); |
| 3376 | if (!nl_reg_rule) |
| 3377 | goto nla_put_failure; |
| 3378 | |
| 3379 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3380 | reg_rule->flags); |
| 3381 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3382 | freq_range->start_freq_khz); |
| 3383 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3384 | freq_range->end_freq_khz); |
| 3385 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3386 | freq_range->max_bandwidth_khz); |
| 3387 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3388 | power_rule->max_antenna_gain); |
| 3389 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3390 | power_rule->max_eirp); |
| 3391 | |
| 3392 | nla_nest_end(msg, nl_reg_rule); |
| 3393 | } |
| 3394 | |
| 3395 | nla_nest_end(msg, nl_reg_rules); |
| 3396 | |
| 3397 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3398 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3399 | goto out; |
| 3400 | |
| 3401 | nla_put_failure: |
| 3402 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3403 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3404 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3405 | err = -EMSGSIZE; |
| 3406 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3407 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3408 | return err; |
| 3409 | } |
| 3410 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3411 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3412 | { |
| 3413 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3414 | struct nlattr *nl_reg_rule; |
| 3415 | char *alpha2 = NULL; |
| 3416 | int rem_reg_rules = 0, r = 0; |
| 3417 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3418 | struct ieee80211_regdomain *rd = NULL; |
| 3419 | |
| 3420 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3421 | return -EINVAL; |
| 3422 | |
| 3423 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3424 | return -EINVAL; |
| 3425 | |
| 3426 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3427 | |
| 3428 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3429 | rem_reg_rules) { |
| 3430 | num_rules++; |
| 3431 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3432 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3435 | mutex_lock(&cfg80211_mutex); |
| 3436 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3437 | if (!reg_is_valid_request(alpha2)) { |
| 3438 | r = -EINVAL; |
| 3439 | goto bad_reg; |
| 3440 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3441 | |
| 3442 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3443 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3444 | |
| 3445 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3446 | if (!rd) { |
| 3447 | r = -ENOMEM; |
| 3448 | goto bad_reg; |
| 3449 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3450 | |
| 3451 | rd->n_reg_rules = num_rules; |
| 3452 | rd->alpha2[0] = alpha2[0]; |
| 3453 | rd->alpha2[1] = alpha2[1]; |
| 3454 | |
| 3455 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3456 | rem_reg_rules) { |
| 3457 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3458 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3459 | reg_rule_policy); |
| 3460 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3461 | if (r) |
| 3462 | goto bad_reg; |
| 3463 | |
| 3464 | rule_idx++; |
| 3465 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3466 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3467 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3468 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3469 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
| 3472 | BUG_ON(rule_idx != num_rules); |
| 3473 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3474 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3475 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3476 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3477 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3478 | return r; |
| 3479 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3480 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3481 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3482 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3483 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3484 | } |
| 3485 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3486 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3487 | { |
| 3488 | struct nlattr *attr1, *attr2; |
| 3489 | int n_channels = 0, tmp1, tmp2; |
| 3490 | |
| 3491 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3492 | n_channels++; |
| 3493 | /* |
| 3494 | * Some hardware has a limited channel list for |
| 3495 | * scanning, and it is pretty much nonsensical |
| 3496 | * to scan for a channel twice, so disallow that |
| 3497 | * and don't require drivers to check that the |
| 3498 | * channel list they get isn't longer than what |
| 3499 | * they can scan, as long as they can scan all |
| 3500 | * the channels they registered at once. |
| 3501 | */ |
| 3502 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3503 | if (attr1 != attr2 && |
| 3504 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3505 | return 0; |
| 3506 | } |
| 3507 | |
| 3508 | return n_channels; |
| 3509 | } |
| 3510 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3511 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3512 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3514 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3515 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3516 | struct nlattr *attr; |
| 3517 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3518 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3519 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3520 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3521 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3522 | return -EINVAL; |
| 3523 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3524 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3525 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3526 | if (!rdev->ops->scan) |
| 3527 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3528 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3529 | if (rdev->scan_req) |
| 3530 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3531 | |
| 3532 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3533 | n_channels = validate_scan_freqs( |
| 3534 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3535 | if (!n_channels) |
| 3536 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3537 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3538 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3539 | n_channels = 0; |
| 3540 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3541 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3542 | if (wiphy->bands[band]) |
| 3543 | n_channels += wiphy->bands[band]->n_channels; |
| 3544 | } |
| 3545 | |
| 3546 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3547 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3548 | n_ssids++; |
| 3549 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3550 | if (n_ssids > wiphy->max_scan_ssids) |
| 3551 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3552 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3553 | if (info->attrs[NL80211_ATTR_IE]) |
| 3554 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3555 | else |
| 3556 | ie_len = 0; |
| 3557 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3558 | if (ie_len > wiphy->max_scan_ie_len) |
| 3559 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3560 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3561 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3562 | + sizeof(*request->ssids) * n_ssids |
| 3563 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3564 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3565 | if (!request) |
| 3566 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3567 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3568 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3569 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3570 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3571 | if (ie_len) { |
| 3572 | if (request->ssids) |
| 3573 | request->ie = (void *)(request->ssids + n_ssids); |
| 3574 | else |
| 3575 | request->ie = (void *)(request->channels + n_channels); |
| 3576 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3577 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3578 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3579 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3580 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3581 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3582 | struct ieee80211_channel *chan; |
| 3583 | |
| 3584 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3585 | |
| 3586 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3587 | err = -EINVAL; |
| 3588 | goto out_free; |
| 3589 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3590 | |
| 3591 | /* ignore disabled channels */ |
| 3592 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3593 | continue; |
| 3594 | |
| 3595 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3596 | i++; |
| 3597 | } |
| 3598 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3599 | enum ieee80211_band band; |
| 3600 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3601 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3602 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3603 | int j; |
| 3604 | if (!wiphy->bands[band]) |
| 3605 | continue; |
| 3606 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3607 | struct ieee80211_channel *chan; |
| 3608 | |
| 3609 | chan = &wiphy->bands[band]->channels[j]; |
| 3610 | |
| 3611 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3612 | continue; |
| 3613 | |
| 3614 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3615 | i++; |
| 3616 | } |
| 3617 | } |
| 3618 | } |
| 3619 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3620 | if (!i) { |
| 3621 | err = -EINVAL; |
| 3622 | goto out_free; |
| 3623 | } |
| 3624 | |
| 3625 | request->n_channels = i; |
| 3626 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3627 | i = 0; |
| 3628 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3629 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3630 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3631 | err = -EINVAL; |
| 3632 | goto out_free; |
| 3633 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3634 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3635 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3636 | i++; |
| 3637 | } |
| 3638 | } |
| 3639 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3640 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3641 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3642 | memcpy((void *)request->ie, |
| 3643 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3644 | request->ie_len); |
| 3645 | } |
| 3646 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3647 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3648 | if (wiphy->bands[i]) |
| 3649 | request->rates[i] = |
| 3650 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3651 | |
| 3652 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3653 | nla_for_each_nested(attr, |
| 3654 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3655 | tmp) { |
| 3656 | enum ieee80211_band band = nla_type(attr); |
| 3657 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3658 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3659 | err = -EINVAL; |
| 3660 | goto out_free; |
| 3661 | } |
| 3662 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3663 | nla_data(attr), |
| 3664 | nla_len(attr), |
| 3665 | &request->rates[band]); |
| 3666 | if (err) |
| 3667 | goto out_free; |
| 3668 | } |
| 3669 | } |
| 3670 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3671 | request->no_cck = |
| 3672 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3673 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3674 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3675 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3676 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3677 | rdev->scan_req = request; |
| 3678 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3679 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3680 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3681 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3682 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3683 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3684 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3685 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3686 | kfree(request); |
| 3687 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3688 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3689 | return err; |
| 3690 | } |
| 3691 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3692 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3693 | struct genl_info *info) |
| 3694 | { |
| 3695 | struct cfg80211_sched_scan_request *request; |
| 3696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3697 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3698 | struct nlattr *attr; |
| 3699 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3700 | 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] | 3701 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3702 | enum ieee80211_band band; |
| 3703 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3704 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3705 | |
| 3706 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3707 | !rdev->ops->sched_scan_start) |
| 3708 | return -EOPNOTSUPP; |
| 3709 | |
| 3710 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3711 | return -EINVAL; |
| 3712 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3713 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3714 | return -EINVAL; |
| 3715 | |
| 3716 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3717 | if (interval == 0) |
| 3718 | return -EINVAL; |
| 3719 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3720 | wiphy = &rdev->wiphy; |
| 3721 | |
| 3722 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3723 | n_channels = validate_scan_freqs( |
| 3724 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3725 | if (!n_channels) |
| 3726 | return -EINVAL; |
| 3727 | } else { |
| 3728 | n_channels = 0; |
| 3729 | |
| 3730 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3731 | if (wiphy->bands[band]) |
| 3732 | n_channels += wiphy->bands[band]->n_channels; |
| 3733 | } |
| 3734 | |
| 3735 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3736 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3737 | tmp) |
| 3738 | n_ssids++; |
| 3739 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3740 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3741 | return -EINVAL; |
| 3742 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3743 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3744 | nla_for_each_nested(attr, |
| 3745 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3746 | tmp) |
| 3747 | n_match_sets++; |
| 3748 | |
| 3749 | if (n_match_sets > wiphy->max_match_sets) |
| 3750 | return -EINVAL; |
| 3751 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3752 | if (info->attrs[NL80211_ATTR_IE]) |
| 3753 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3754 | else |
| 3755 | ie_len = 0; |
| 3756 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3757 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3758 | return -EINVAL; |
| 3759 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3760 | mutex_lock(&rdev->sched_scan_mtx); |
| 3761 | |
| 3762 | if (rdev->sched_scan_req) { |
| 3763 | err = -EINPROGRESS; |
| 3764 | goto out; |
| 3765 | } |
| 3766 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3767 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3768 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3769 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3770 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3771 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3772 | if (!request) { |
| 3773 | err = -ENOMEM; |
| 3774 | goto out; |
| 3775 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3776 | |
| 3777 | if (n_ssids) |
| 3778 | request->ssids = (void *)&request->channels[n_channels]; |
| 3779 | request->n_ssids = n_ssids; |
| 3780 | if (ie_len) { |
| 3781 | if (request->ssids) |
| 3782 | request->ie = (void *)(request->ssids + n_ssids); |
| 3783 | else |
| 3784 | request->ie = (void *)(request->channels + n_channels); |
| 3785 | } |
| 3786 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3787 | if (n_match_sets) { |
| 3788 | if (request->ie) |
| 3789 | request->match_sets = (void *)(request->ie + ie_len); |
| 3790 | else if (request->ssids) |
| 3791 | request->match_sets = |
| 3792 | (void *)(request->ssids + n_ssids); |
| 3793 | else |
| 3794 | request->match_sets = |
| 3795 | (void *)(request->channels + n_channels); |
| 3796 | } |
| 3797 | request->n_match_sets = n_match_sets; |
| 3798 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3799 | i = 0; |
| 3800 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3801 | /* user specified, bail out if channel not found */ |
| 3802 | nla_for_each_nested(attr, |
| 3803 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3804 | tmp) { |
| 3805 | struct ieee80211_channel *chan; |
| 3806 | |
| 3807 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3808 | |
| 3809 | if (!chan) { |
| 3810 | err = -EINVAL; |
| 3811 | goto out_free; |
| 3812 | } |
| 3813 | |
| 3814 | /* ignore disabled channels */ |
| 3815 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3816 | continue; |
| 3817 | |
| 3818 | request->channels[i] = chan; |
| 3819 | i++; |
| 3820 | } |
| 3821 | } else { |
| 3822 | /* all channels */ |
| 3823 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3824 | int j; |
| 3825 | if (!wiphy->bands[band]) |
| 3826 | continue; |
| 3827 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3828 | struct ieee80211_channel *chan; |
| 3829 | |
| 3830 | chan = &wiphy->bands[band]->channels[j]; |
| 3831 | |
| 3832 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3833 | continue; |
| 3834 | |
| 3835 | request->channels[i] = chan; |
| 3836 | i++; |
| 3837 | } |
| 3838 | } |
| 3839 | } |
| 3840 | |
| 3841 | if (!i) { |
| 3842 | err = -EINVAL; |
| 3843 | goto out_free; |
| 3844 | } |
| 3845 | |
| 3846 | request->n_channels = i; |
| 3847 | |
| 3848 | i = 0; |
| 3849 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3850 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3851 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3852 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3853 | err = -EINVAL; |
| 3854 | goto out_free; |
| 3855 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3856 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3857 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3858 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3859 | i++; |
| 3860 | } |
| 3861 | } |
| 3862 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3863 | i = 0; |
| 3864 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 3865 | nla_for_each_nested(attr, |
| 3866 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3867 | tmp) { |
| 3868 | struct nlattr *ssid; |
| 3869 | |
| 3870 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 3871 | nla_data(attr), nla_len(attr), |
| 3872 | nl80211_match_policy); |
| 3873 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 3874 | if (ssid) { |
| 3875 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 3876 | err = -EINVAL; |
| 3877 | goto out_free; |
| 3878 | } |
| 3879 | memcpy(request->match_sets[i].ssid.ssid, |
| 3880 | nla_data(ssid), nla_len(ssid)); |
| 3881 | request->match_sets[i].ssid.ssid_len = |
| 3882 | nla_len(ssid); |
| 3883 | } |
| 3884 | i++; |
| 3885 | } |
| 3886 | } |
| 3887 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3888 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3889 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3890 | memcpy((void *)request->ie, |
| 3891 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3892 | request->ie_len); |
| 3893 | } |
| 3894 | |
| 3895 | request->dev = dev; |
| 3896 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3897 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3898 | |
| 3899 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3900 | if (!err) { |
| 3901 | rdev->sched_scan_req = request; |
| 3902 | nl80211_send_sched_scan(rdev, dev, |
| 3903 | NL80211_CMD_START_SCHED_SCAN); |
| 3904 | goto out; |
| 3905 | } |
| 3906 | |
| 3907 | out_free: |
| 3908 | kfree(request); |
| 3909 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3910 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3911 | return err; |
| 3912 | } |
| 3913 | |
| 3914 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3915 | struct genl_info *info) |
| 3916 | { |
| 3917 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3918 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3919 | |
| 3920 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3921 | !rdev->ops->sched_scan_stop) |
| 3922 | return -EOPNOTSUPP; |
| 3923 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3924 | mutex_lock(&rdev->sched_scan_mtx); |
| 3925 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3926 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3927 | |
| 3928 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3929 | } |
| 3930 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3931 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3932 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3933 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3934 | struct wireless_dev *wdev, |
| 3935 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3936 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3937 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3938 | void *hdr; |
| 3939 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3940 | int i; |
| 3941 | |
| 3942 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3943 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3944 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3945 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3946 | if (!hdr) |
| 3947 | return -1; |
| 3948 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3949 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3950 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3951 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3952 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3953 | |
| 3954 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3955 | if (!bss) |
| 3956 | goto nla_put_failure; |
| 3957 | if (!is_zero_ether_addr(res->bssid)) |
| 3958 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3959 | if (res->information_elements && res->len_information_elements) |
| 3960 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3961 | res->len_information_elements, |
| 3962 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3963 | if (res->beacon_ies && res->len_beacon_ies && |
| 3964 | res->beacon_ies != res->information_elements) |
| 3965 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3966 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3967 | if (res->tsf) |
| 3968 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3969 | if (res->beacon_interval) |
| 3970 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3971 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3972 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3973 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3974 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3975 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3976 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3977 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3978 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3979 | break; |
| 3980 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3981 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3982 | break; |
| 3983 | default: |
| 3984 | break; |
| 3985 | } |
| 3986 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3987 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3988 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3989 | case NL80211_IFTYPE_STATION: |
| 3990 | if (intbss == wdev->current_bss) |
| 3991 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3992 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3993 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3994 | if (intbss != wdev->auth_bsses[i]) |
| 3995 | continue; |
| 3996 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3997 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3998 | break; |
| 3999 | } |
| 4000 | break; |
| 4001 | case NL80211_IFTYPE_ADHOC: |
| 4002 | if (intbss == wdev->current_bss) |
| 4003 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4004 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 4005 | break; |
| 4006 | default: |
| 4007 | break; |
| 4008 | } |
| 4009 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4010 | nla_nest_end(msg, bss); |
| 4011 | |
| 4012 | return genlmsg_end(msg, hdr); |
| 4013 | |
| 4014 | nla_put_failure: |
| 4015 | genlmsg_cancel(msg, hdr); |
| 4016 | return -EMSGSIZE; |
| 4017 | } |
| 4018 | |
| 4019 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4020 | struct netlink_callback *cb) |
| 4021 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4022 | struct cfg80211_registered_device *rdev; |
| 4023 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4024 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4025 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4026 | int start = cb->args[1], idx = 0; |
| 4027 | int err; |
| 4028 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4029 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4030 | if (err) |
| 4031 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4032 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4033 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4034 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4035 | wdev_lock(wdev); |
| 4036 | spin_lock_bh(&rdev->bss_lock); |
| 4037 | cfg80211_bss_expire(rdev); |
| 4038 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4039 | cb->seq = rdev->bss_generation; |
| 4040 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4041 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4042 | if (++idx <= start) |
| 4043 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4044 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4045 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4046 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4047 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4048 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4049 | } |
| 4050 | } |
| 4051 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4052 | spin_unlock_bh(&rdev->bss_lock); |
| 4053 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4054 | |
| 4055 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4056 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4057 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4058 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4059 | } |
| 4060 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4061 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4062 | int flags, struct net_device *dev, |
| 4063 | struct survey_info *survey) |
| 4064 | { |
| 4065 | void *hdr; |
| 4066 | struct nlattr *infoattr; |
| 4067 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4068 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4069 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4070 | if (!hdr) |
| 4071 | return -ENOMEM; |
| 4072 | |
| 4073 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4074 | |
| 4075 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4076 | if (!infoattr) |
| 4077 | goto nla_put_failure; |
| 4078 | |
| 4079 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4080 | survey->channel->center_freq); |
| 4081 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4082 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4083 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4084 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4085 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29a | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4086 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4087 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4088 | survey->channel_time); |
| 4089 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4090 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4091 | survey->channel_time_busy); |
| 4092 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4093 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4094 | survey->channel_time_ext_busy); |
| 4095 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4096 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4097 | survey->channel_time_rx); |
| 4098 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4099 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4100 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4101 | |
| 4102 | nla_nest_end(msg, infoattr); |
| 4103 | |
| 4104 | return genlmsg_end(msg, hdr); |
| 4105 | |
| 4106 | nla_put_failure: |
| 4107 | genlmsg_cancel(msg, hdr); |
| 4108 | return -EMSGSIZE; |
| 4109 | } |
| 4110 | |
| 4111 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4112 | struct netlink_callback *cb) |
| 4113 | { |
| 4114 | struct survey_info survey; |
| 4115 | struct cfg80211_registered_device *dev; |
| 4116 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4117 | int survey_idx = cb->args[1]; |
| 4118 | int res; |
| 4119 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4120 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4121 | if (res) |
| 4122 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4123 | |
| 4124 | if (!dev->ops->dump_survey) { |
| 4125 | res = -EOPNOTSUPP; |
| 4126 | goto out_err; |
| 4127 | } |
| 4128 | |
| 4129 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4130 | struct ieee80211_channel *chan; |
| 4131 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4132 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4133 | &survey); |
| 4134 | if (res == -ENOENT) |
| 4135 | break; |
| 4136 | if (res) |
| 4137 | goto out_err; |
| 4138 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4139 | /* Survey without a channel doesn't make sense */ |
| 4140 | if (!survey.channel) { |
| 4141 | res = -EINVAL; |
| 4142 | goto out; |
| 4143 | } |
| 4144 | |
| 4145 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4146 | survey.channel->center_freq); |
| 4147 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4148 | survey_idx++; |
| 4149 | continue; |
| 4150 | } |
| 4151 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4152 | if (nl80211_send_survey(skb, |
| 4153 | NETLINK_CB(cb->skb).pid, |
| 4154 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4155 | netdev, |
| 4156 | &survey) < 0) |
| 4157 | goto out; |
| 4158 | survey_idx++; |
| 4159 | } |
| 4160 | |
| 4161 | out: |
| 4162 | cb->args[1] = survey_idx; |
| 4163 | res = skb->len; |
| 4164 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4165 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4166 | return res; |
| 4167 | } |
| 4168 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4169 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4170 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4171 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4172 | } |
| 4173 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4174 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4175 | { |
| 4176 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4177 | NL80211_WPA_VERSION_2)); |
| 4178 | } |
| 4179 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4180 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4181 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4182 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4183 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4184 | struct ieee80211_channel *chan; |
| 4185 | const u8 *bssid, *ssid, *ie = NULL; |
| 4186 | int err, ssid_len, ie_len = 0; |
| 4187 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4188 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4189 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4190 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4191 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4192 | return -EINVAL; |
| 4193 | |
| 4194 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4195 | return -EINVAL; |
| 4196 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4197 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4198 | return -EINVAL; |
| 4199 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4200 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4201 | return -EINVAL; |
| 4202 | |
| 4203 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4204 | return -EINVAL; |
| 4205 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4206 | err = nl80211_parse_key(info, &key); |
| 4207 | if (err) |
| 4208 | return err; |
| 4209 | |
| 4210 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4211 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4212 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4213 | if (!key.p.key || !key.p.key_len) |
| 4214 | return -EINVAL; |
| 4215 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4216 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4217 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4218 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4219 | return -EINVAL; |
| 4220 | if (key.idx > 4) |
| 4221 | return -EINVAL; |
| 4222 | } else { |
| 4223 | key.p.key_len = 0; |
| 4224 | key.p.key = NULL; |
| 4225 | } |
| 4226 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4227 | if (key.idx >= 0) { |
| 4228 | int i; |
| 4229 | bool ok = false; |
| 4230 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4231 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4232 | ok = true; |
| 4233 | break; |
| 4234 | } |
| 4235 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4236 | if (!ok) |
| 4237 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4238 | } |
| 4239 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4240 | if (!rdev->ops->auth) |
| 4241 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4242 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4243 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4244 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4245 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4246 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4247 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4248 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4249 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4250 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4251 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4252 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4253 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4254 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4255 | |
| 4256 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4257 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4258 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4259 | } |
| 4260 | |
| 4261 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4262 | if (!nl80211_valid_auth_type(auth_type)) |
| 4263 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4264 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4265 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4266 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4267 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4268 | ssid, ssid_len, ie, ie_len, |
| 4269 | key.p.key, key.p.key_len, key.idx, |
| 4270 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4271 | } |
| 4272 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4273 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4274 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4275 | struct cfg80211_crypto_settings *settings, |
| 4276 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4277 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4278 | memset(settings, 0, sizeof(*settings)); |
| 4279 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4280 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4281 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4282 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4283 | u16 proto; |
| 4284 | proto = nla_get_u16( |
| 4285 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4286 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4287 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4288 | proto != ETH_P_PAE) |
| 4289 | return -EINVAL; |
| 4290 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4291 | settings->control_port_no_encrypt = true; |
| 4292 | } else |
| 4293 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4294 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4295 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4296 | void *data; |
| 4297 | int len, i; |
| 4298 | |
| 4299 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4300 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4301 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4302 | |
| 4303 | if (len % sizeof(u32)) |
| 4304 | return -EINVAL; |
| 4305 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4306 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4307 | return -EINVAL; |
| 4308 | |
| 4309 | memcpy(settings->ciphers_pairwise, data, len); |
| 4310 | |
| 4311 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4312 | if (!cfg80211_supported_cipher_suite( |
| 4313 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4314 | settings->ciphers_pairwise[i])) |
| 4315 | return -EINVAL; |
| 4316 | } |
| 4317 | |
| 4318 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4319 | settings->cipher_group = |
| 4320 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4321 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4322 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4323 | return -EINVAL; |
| 4324 | } |
| 4325 | |
| 4326 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4327 | settings->wpa_versions = |
| 4328 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4329 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4330 | return -EINVAL; |
| 4331 | } |
| 4332 | |
| 4333 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4334 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4335 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4336 | |
| 4337 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4338 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4339 | settings->n_akm_suites = len / sizeof(u32); |
| 4340 | |
| 4341 | if (len % sizeof(u32)) |
| 4342 | return -EINVAL; |
| 4343 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4344 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4345 | return -EINVAL; |
| 4346 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4347 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | return 0; |
| 4351 | } |
| 4352 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4353 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4354 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4356 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4357 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4358 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4359 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4360 | int err, ssid_len, ie_len = 0; |
| 4361 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4362 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4363 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4364 | return -EINVAL; |
| 4365 | |
| 4366 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4367 | !info->attrs[NL80211_ATTR_SSID] || |
| 4368 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4369 | return -EINVAL; |
| 4370 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4371 | if (!rdev->ops->assoc) |
| 4372 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4373 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4374 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4375 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4376 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4377 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4378 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4379 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4380 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4381 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4382 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4383 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4384 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4385 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4386 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4387 | |
| 4388 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4389 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4390 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4391 | } |
| 4392 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4393 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4394 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4395 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4396 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4397 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4398 | else if (mfp != NL80211_MFP_NO) |
| 4399 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4400 | } |
| 4401 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4402 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4403 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4404 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4405 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4406 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4407 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4408 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4409 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4410 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4411 | return err; |
| 4412 | } |
| 4413 | |
| 4414 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4415 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4417 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4418 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4419 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4420 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4421 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4422 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4423 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4424 | return -EINVAL; |
| 4425 | |
| 4426 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4427 | return -EINVAL; |
| 4428 | |
| 4429 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4430 | return -EINVAL; |
| 4431 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4432 | if (!rdev->ops->deauth) |
| 4433 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4434 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4435 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4436 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4437 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4438 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4439 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4440 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4441 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4442 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4443 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4444 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4445 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4446 | |
| 4447 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4448 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4449 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4450 | } |
| 4451 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4452 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4453 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4454 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4455 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4459 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4461 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4462 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4463 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4464 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4465 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4466 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4467 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4468 | return -EINVAL; |
| 4469 | |
| 4470 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4471 | return -EINVAL; |
| 4472 | |
| 4473 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4474 | return -EINVAL; |
| 4475 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4476 | if (!rdev->ops->disassoc) |
| 4477 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4478 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4479 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4480 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4481 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4482 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4483 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4484 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4485 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4486 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4487 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4488 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4489 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4490 | |
| 4491 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4492 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4493 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4494 | } |
| 4495 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4496 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4497 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4498 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4499 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4500 | } |
| 4501 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4502 | static bool |
| 4503 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4504 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4505 | int rateval) |
| 4506 | { |
| 4507 | struct wiphy *wiphy = &rdev->wiphy; |
| 4508 | bool found = false; |
| 4509 | int band, i; |
| 4510 | |
| 4511 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4512 | struct ieee80211_supported_band *sband; |
| 4513 | |
| 4514 | sband = wiphy->bands[band]; |
| 4515 | if (!sband) |
| 4516 | continue; |
| 4517 | |
| 4518 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4519 | if (sband->bitrates[i].bitrate == rateval) { |
| 4520 | mcast_rate[band] = i + 1; |
| 4521 | found = true; |
| 4522 | break; |
| 4523 | } |
| 4524 | } |
| 4525 | } |
| 4526 | |
| 4527 | return found; |
| 4528 | } |
| 4529 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4530 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4531 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4533 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4534 | struct cfg80211_ibss_params ibss; |
| 4535 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4536 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4537 | int err; |
| 4538 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4539 | memset(&ibss, 0, sizeof(ibss)); |
| 4540 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4541 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4542 | return -EINVAL; |
| 4543 | |
| 4544 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4545 | !info->attrs[NL80211_ATTR_SSID] || |
| 4546 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4547 | return -EINVAL; |
| 4548 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4549 | ibss.beacon_interval = 100; |
| 4550 | |
| 4551 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4552 | ibss.beacon_interval = |
| 4553 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4554 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4555 | return -EINVAL; |
| 4556 | } |
| 4557 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4558 | if (!rdev->ops->join_ibss) |
| 4559 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4560 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4561 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4562 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4563 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4564 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4565 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4566 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4567 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4568 | |
| 4569 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4570 | return -EINVAL; |
| 4571 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4572 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4573 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4574 | |
| 4575 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4576 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4577 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4578 | } |
| 4579 | |
| 4580 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4581 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4582 | if (!ibss.channel || |
| 4583 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4584 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4585 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4586 | |
| 4587 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4588 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4589 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4590 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4591 | u8 *rates = |
| 4592 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4593 | int n_rates = |
| 4594 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4595 | struct ieee80211_supported_band *sband = |
| 4596 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4597 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4598 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4599 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4600 | &ibss.basic_rates); |
| 4601 | if (err) |
| 4602 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4603 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4604 | |
| 4605 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4606 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4607 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4608 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4609 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4610 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4611 | connkeys = nl80211_parse_connkeys(rdev, |
| 4612 | info->attrs[NL80211_ATTR_KEYS]); |
| 4613 | if (IS_ERR(connkeys)) |
| 4614 | return PTR_ERR(connkeys); |
| 4615 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4616 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4617 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4618 | if (err) |
| 4619 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4620 | return err; |
| 4621 | } |
| 4622 | |
| 4623 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4624 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4626 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4627 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4628 | if (!rdev->ops->leave_ibss) |
| 4629 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4630 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4631 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4632 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4633 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4634 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4635 | } |
| 4636 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4637 | #ifdef CONFIG_NL80211_TESTMODE |
| 4638 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4639 | .name = "testmode", |
| 4640 | }; |
| 4641 | |
| 4642 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4643 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4645 | int err; |
| 4646 | |
| 4647 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4648 | return -EINVAL; |
| 4649 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4650 | err = -EOPNOTSUPP; |
| 4651 | if (rdev->ops->testmode_cmd) { |
| 4652 | rdev->testmode_info = info; |
| 4653 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4654 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4655 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4656 | rdev->testmode_info = NULL; |
| 4657 | } |
| 4658 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4659 | return err; |
| 4660 | } |
| 4661 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4662 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4663 | struct netlink_callback *cb) |
| 4664 | { |
| 4665 | struct cfg80211_registered_device *dev; |
| 4666 | int err; |
| 4667 | long phy_idx; |
| 4668 | void *data = NULL; |
| 4669 | int data_len = 0; |
| 4670 | |
| 4671 | if (cb->args[0]) { |
| 4672 | /* |
| 4673 | * 0 is a valid index, but not valid for args[0], |
| 4674 | * so we need to offset by 1. |
| 4675 | */ |
| 4676 | phy_idx = cb->args[0] - 1; |
| 4677 | } else { |
| 4678 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4679 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4680 | nl80211_policy); |
| 4681 | if (err) |
| 4682 | return err; |
| 4683 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4684 | return -EINVAL; |
| 4685 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4686 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4687 | cb->args[1] = |
| 4688 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4689 | } |
| 4690 | |
| 4691 | if (cb->args[1]) { |
| 4692 | data = nla_data((void *)cb->args[1]); |
| 4693 | data_len = nla_len((void *)cb->args[1]); |
| 4694 | } |
| 4695 | |
| 4696 | mutex_lock(&cfg80211_mutex); |
| 4697 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4698 | if (!dev) { |
| 4699 | mutex_unlock(&cfg80211_mutex); |
| 4700 | return -ENOENT; |
| 4701 | } |
| 4702 | cfg80211_lock_rdev(dev); |
| 4703 | mutex_unlock(&cfg80211_mutex); |
| 4704 | |
| 4705 | if (!dev->ops->testmode_dump) { |
| 4706 | err = -EOPNOTSUPP; |
| 4707 | goto out_err; |
| 4708 | } |
| 4709 | |
| 4710 | while (1) { |
| 4711 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4712 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4713 | NL80211_CMD_TESTMODE); |
| 4714 | struct nlattr *tmdata; |
| 4715 | |
| 4716 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4717 | genlmsg_cancel(skb, hdr); |
| 4718 | break; |
| 4719 | } |
| 4720 | |
| 4721 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4722 | if (!tmdata) { |
| 4723 | genlmsg_cancel(skb, hdr); |
| 4724 | break; |
| 4725 | } |
| 4726 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4727 | data, data_len); |
| 4728 | nla_nest_end(skb, tmdata); |
| 4729 | |
| 4730 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4731 | genlmsg_cancel(skb, hdr); |
| 4732 | break; |
| 4733 | } else if (err) { |
| 4734 | genlmsg_cancel(skb, hdr); |
| 4735 | goto out_err; |
| 4736 | } |
| 4737 | |
| 4738 | genlmsg_end(skb, hdr); |
| 4739 | } |
| 4740 | |
| 4741 | err = skb->len; |
| 4742 | /* see above */ |
| 4743 | cb->args[0] = phy_idx + 1; |
| 4744 | out_err: |
| 4745 | cfg80211_unlock_rdev(dev); |
| 4746 | return err; |
| 4747 | } |
| 4748 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4749 | static struct sk_buff * |
| 4750 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4751 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4752 | { |
| 4753 | struct sk_buff *skb; |
| 4754 | void *hdr; |
| 4755 | struct nlattr *data; |
| 4756 | |
| 4757 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4758 | if (!skb) |
| 4759 | return NULL; |
| 4760 | |
| 4761 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4762 | if (!hdr) { |
| 4763 | kfree_skb(skb); |
| 4764 | return NULL; |
| 4765 | } |
| 4766 | |
| 4767 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4768 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4769 | |
| 4770 | ((void **)skb->cb)[0] = rdev; |
| 4771 | ((void **)skb->cb)[1] = hdr; |
| 4772 | ((void **)skb->cb)[2] = data; |
| 4773 | |
| 4774 | return skb; |
| 4775 | |
| 4776 | nla_put_failure: |
| 4777 | kfree_skb(skb); |
| 4778 | return NULL; |
| 4779 | } |
| 4780 | |
| 4781 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4782 | int approxlen) |
| 4783 | { |
| 4784 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4785 | |
| 4786 | if (WARN_ON(!rdev->testmode_info)) |
| 4787 | return NULL; |
| 4788 | |
| 4789 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4790 | rdev->testmode_info->snd_pid, |
| 4791 | rdev->testmode_info->snd_seq, |
| 4792 | GFP_KERNEL); |
| 4793 | } |
| 4794 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4795 | |
| 4796 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4797 | { |
| 4798 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4799 | void *hdr = ((void **)skb->cb)[1]; |
| 4800 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4801 | |
| 4802 | if (WARN_ON(!rdev->testmode_info)) { |
| 4803 | kfree_skb(skb); |
| 4804 | return -EINVAL; |
| 4805 | } |
| 4806 | |
| 4807 | nla_nest_end(skb, data); |
| 4808 | genlmsg_end(skb, hdr); |
| 4809 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4810 | } |
| 4811 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4812 | |
| 4813 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4814 | int approxlen, gfp_t gfp) |
| 4815 | { |
| 4816 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4817 | |
| 4818 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4819 | } |
| 4820 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4821 | |
| 4822 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4823 | { |
| 4824 | void *hdr = ((void **)skb->cb)[1]; |
| 4825 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4826 | |
| 4827 | nla_nest_end(skb, data); |
| 4828 | genlmsg_end(skb, hdr); |
| 4829 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4830 | } |
| 4831 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4832 | #endif |
| 4833 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4834 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4835 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4837 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4838 | struct cfg80211_connect_params connect; |
| 4839 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4840 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4841 | int err; |
| 4842 | |
| 4843 | memset(&connect, 0, sizeof(connect)); |
| 4844 | |
| 4845 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4846 | return -EINVAL; |
| 4847 | |
| 4848 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4849 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4850 | return -EINVAL; |
| 4851 | |
| 4852 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4853 | connect.auth_type = |
| 4854 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4855 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4856 | return -EINVAL; |
| 4857 | } else |
| 4858 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4859 | |
| 4860 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4861 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4862 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4863 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4864 | if (err) |
| 4865 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4866 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4867 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4868 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4869 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4870 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4871 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4872 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4873 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4874 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4875 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4876 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4877 | |
| 4878 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4879 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4880 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4881 | } |
| 4882 | |
| 4883 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4884 | connect.channel = |
| 4885 | ieee80211_get_channel(wiphy, |
| 4886 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4887 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4888 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4889 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4890 | } |
| 4891 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4892 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4893 | connkeys = nl80211_parse_connkeys(rdev, |
| 4894 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4895 | if (IS_ERR(connkeys)) |
| 4896 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4897 | } |
| 4898 | |
| 4899 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4900 | if (err) |
| 4901 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4902 | return err; |
| 4903 | } |
| 4904 | |
| 4905 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4906 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4908 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4909 | u16 reason; |
| 4910 | |
| 4911 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4912 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4913 | else |
| 4914 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4915 | |
| 4916 | if (reason == 0) |
| 4917 | return -EINVAL; |
| 4918 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4919 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4920 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4921 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4922 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4923 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4924 | } |
| 4925 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4926 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4927 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4929 | struct net *net; |
| 4930 | int err; |
| 4931 | u32 pid; |
| 4932 | |
| 4933 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4934 | return -EINVAL; |
| 4935 | |
| 4936 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4937 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4938 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4939 | if (IS_ERR(net)) |
| 4940 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4941 | |
| 4942 | err = 0; |
| 4943 | |
| 4944 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4945 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4946 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4947 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4948 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4949 | return err; |
| 4950 | } |
| 4951 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4952 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4953 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4955 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4956 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4957 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4958 | struct cfg80211_pmksa pmksa; |
| 4959 | |
| 4960 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4961 | |
| 4962 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4963 | return -EINVAL; |
| 4964 | |
| 4965 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4966 | return -EINVAL; |
| 4967 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4968 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4969 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4970 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4971 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4972 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4973 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4974 | |
| 4975 | switch (info->genlhdr->cmd) { |
| 4976 | case NL80211_CMD_SET_PMKSA: |
| 4977 | rdev_ops = rdev->ops->set_pmksa; |
| 4978 | break; |
| 4979 | case NL80211_CMD_DEL_PMKSA: |
| 4980 | rdev_ops = rdev->ops->del_pmksa; |
| 4981 | break; |
| 4982 | default: |
| 4983 | WARN_ON(1); |
| 4984 | break; |
| 4985 | } |
| 4986 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4987 | if (!rdev_ops) |
| 4988 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4989 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4990 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4994 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4996 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4997 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4998 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4999 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5000 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5001 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5002 | if (!rdev->ops->flush_pmksa) |
| 5003 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5004 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5005 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5006 | } |
| 5007 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5008 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5009 | { |
| 5010 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5011 | struct net_device *dev = info->user_ptr[1]; |
| 5012 | u8 action_code, dialog_token; |
| 5013 | u16 status_code; |
| 5014 | u8 *peer; |
| 5015 | |
| 5016 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5017 | !rdev->ops->tdls_mgmt) |
| 5018 | return -EOPNOTSUPP; |
| 5019 | |
| 5020 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5021 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5022 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5023 | !info->attrs[NL80211_ATTR_IE] || |
| 5024 | !info->attrs[NL80211_ATTR_MAC]) |
| 5025 | return -EINVAL; |
| 5026 | |
| 5027 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5028 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5029 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5030 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5031 | |
| 5032 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5033 | dialog_token, status_code, |
| 5034 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5035 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5036 | } |
| 5037 | |
| 5038 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5039 | { |
| 5040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5041 | struct net_device *dev = info->user_ptr[1]; |
| 5042 | enum nl80211_tdls_operation operation; |
| 5043 | u8 *peer; |
| 5044 | |
| 5045 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5046 | !rdev->ops->tdls_oper) |
| 5047 | return -EOPNOTSUPP; |
| 5048 | |
| 5049 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5050 | !info->attrs[NL80211_ATTR_MAC]) |
| 5051 | return -EINVAL; |
| 5052 | |
| 5053 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5054 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5055 | |
| 5056 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5057 | } |
| 5058 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5059 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5060 | struct genl_info *info) |
| 5061 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5062 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5063 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5064 | struct ieee80211_channel *chan; |
| 5065 | struct sk_buff *msg; |
| 5066 | void *hdr; |
| 5067 | u64 cookie; |
| 5068 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5069 | u32 freq, duration; |
| 5070 | int err; |
| 5071 | |
| 5072 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5073 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5074 | return -EINVAL; |
| 5075 | |
| 5076 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5077 | |
| 5078 | /* |
| 5079 | * We should be on that channel for at least one jiffie, |
| 5080 | * and more than 5 seconds seems excessive. |
| 5081 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5082 | if (!duration || !msecs_to_jiffies(duration) || |
| 5083 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5084 | return -EINVAL; |
| 5085 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5086 | if (!rdev->ops->remain_on_channel) |
| 5087 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5088 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5089 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5090 | channel_type = nla_get_u32( |
| 5091 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5092 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5093 | channel_type != NL80211_CHAN_HT20 && |
| 5094 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5095 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5096 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5100 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5101 | if (chan == NULL) |
| 5102 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5103 | |
| 5104 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5105 | if (!msg) |
| 5106 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5107 | |
| 5108 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5109 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5110 | |
| 5111 | if (IS_ERR(hdr)) { |
| 5112 | err = PTR_ERR(hdr); |
| 5113 | goto free_msg; |
| 5114 | } |
| 5115 | |
| 5116 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5117 | channel_type, duration, &cookie); |
| 5118 | |
| 5119 | if (err) |
| 5120 | goto free_msg; |
| 5121 | |
| 5122 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5123 | |
| 5124 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5125 | |
| 5126 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5127 | |
| 5128 | nla_put_failure: |
| 5129 | err = -ENOBUFS; |
| 5130 | free_msg: |
| 5131 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5132 | return err; |
| 5133 | } |
| 5134 | |
| 5135 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5136 | struct genl_info *info) |
| 5137 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5138 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5139 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5140 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5141 | |
| 5142 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5143 | return -EINVAL; |
| 5144 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5145 | if (!rdev->ops->cancel_remain_on_channel) |
| 5146 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5147 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5148 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5149 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5150 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5151 | } |
| 5152 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5153 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5154 | u8 *rates, u8 rates_len) |
| 5155 | { |
| 5156 | u8 i; |
| 5157 | u32 mask = 0; |
| 5158 | |
| 5159 | for (i = 0; i < rates_len; i++) { |
| 5160 | int rate = (rates[i] & 0x7f) * 5; |
| 5161 | int ridx; |
| 5162 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5163 | struct ieee80211_rate *srate = |
| 5164 | &sband->bitrates[ridx]; |
| 5165 | if (rate == srate->bitrate) { |
| 5166 | mask |= 1 << ridx; |
| 5167 | break; |
| 5168 | } |
| 5169 | } |
| 5170 | if (ridx == sband->n_bitrates) |
| 5171 | return 0; /* rate not found */ |
| 5172 | } |
| 5173 | |
| 5174 | return mask; |
| 5175 | } |
| 5176 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5177 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5178 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5179 | .len = NL80211_MAX_SUPP_RATES }, |
| 5180 | }; |
| 5181 | |
| 5182 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5183 | struct genl_info *info) |
| 5184 | { |
| 5185 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5186 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5187 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5188 | int rem, i; |
| 5189 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5190 | struct nlattr *tx_rates; |
| 5191 | struct ieee80211_supported_band *sband; |
| 5192 | |
| 5193 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5194 | return -EINVAL; |
| 5195 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5196 | if (!rdev->ops->set_bitrate_mask) |
| 5197 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5198 | |
| 5199 | memset(&mask, 0, sizeof(mask)); |
| 5200 | /* Default to all rates enabled */ |
| 5201 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5202 | sband = rdev->wiphy.bands[i]; |
| 5203 | mask.control[i].legacy = |
| 5204 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5205 | } |
| 5206 | |
| 5207 | /* |
| 5208 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5209 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5210 | */ |
| 5211 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5212 | { |
| 5213 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5214 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5215 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5216 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5217 | if (sband == NULL) |
| 5218 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5219 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5220 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5221 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5222 | mask.control[band].legacy = rateset_to_mask( |
| 5223 | sband, |
| 5224 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5225 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5226 | if (mask.control[band].legacy == 0) |
| 5227 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5228 | } |
| 5229 | } |
| 5230 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5231 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5232 | } |
| 5233 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5234 | 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] | 5235 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5237 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5238 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5239 | |
| 5240 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5241 | return -EINVAL; |
| 5242 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5243 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5244 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5245 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5246 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5247 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5248 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5249 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5250 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5251 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5252 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5253 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5254 | |
| 5255 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5256 | if (!rdev->ops->mgmt_tx) |
| 5257 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5258 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5259 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5260 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5261 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5262 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5263 | } |
| 5264 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5265 | 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] | 5266 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5267 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5268 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5269 | struct ieee80211_channel *chan; |
| 5270 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5271 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5272 | u32 freq; |
| 5273 | int err; |
| 5274 | void *hdr; |
| 5275 | u64 cookie; |
| 5276 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5277 | unsigned int wait = 0; |
| 5278 | bool offchan; |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5279 | bool no_cck; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5280 | |
| 5281 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5282 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5283 | return -EINVAL; |
| 5284 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5285 | if (!rdev->ops->mgmt_tx) |
| 5286 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5287 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5288 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5289 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5290 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5291 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5292 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5293 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5294 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5295 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5296 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5297 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5298 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5299 | return -EINVAL; |
| 5300 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5301 | } |
| 5302 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5303 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5304 | channel_type = nla_get_u32( |
| 5305 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5306 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5307 | channel_type != NL80211_CHAN_HT20 && |
| 5308 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5309 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5310 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5311 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5312 | } |
| 5313 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5314 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5315 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5316 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5317 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5318 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5319 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5320 | if (chan == NULL) |
| 5321 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5322 | |
| 5323 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5324 | if (!msg) |
| 5325 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5326 | |
| 5327 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5328 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5329 | |
| 5330 | if (IS_ERR(hdr)) { |
| 5331 | err = PTR_ERR(hdr); |
| 5332 | goto free_msg; |
| 5333 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5334 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5335 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5336 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5337 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5338 | no_cck, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5339 | if (err) |
| 5340 | goto free_msg; |
| 5341 | |
| 5342 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5343 | |
| 5344 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5345 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5346 | |
| 5347 | nla_put_failure: |
| 5348 | err = -ENOBUFS; |
| 5349 | free_msg: |
| 5350 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5351 | return err; |
| 5352 | } |
| 5353 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5354 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5355 | { |
| 5356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5357 | struct net_device *dev = info->user_ptr[1]; |
| 5358 | u64 cookie; |
| 5359 | |
| 5360 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5361 | return -EINVAL; |
| 5362 | |
| 5363 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5364 | return -EOPNOTSUPP; |
| 5365 | |
| 5366 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5367 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5368 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5369 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5370 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5371 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5372 | return -EOPNOTSUPP; |
| 5373 | |
| 5374 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5375 | |
| 5376 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5377 | } |
| 5378 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5379 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5380 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5381 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5382 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5383 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5384 | u8 ps_state; |
| 5385 | bool state; |
| 5386 | int err; |
| 5387 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5388 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5389 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5390 | |
| 5391 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5392 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5393 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5394 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5395 | |
| 5396 | wdev = dev->ieee80211_ptr; |
| 5397 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5398 | if (!rdev->ops->set_power_mgmt) |
| 5399 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5400 | |
| 5401 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5402 | |
| 5403 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5404 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5405 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5406 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5407 | wdev->ps_timeout); |
| 5408 | if (!err) |
| 5409 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5410 | return err; |
| 5411 | } |
| 5412 | |
| 5413 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5414 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5415 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5416 | enum nl80211_ps_state ps_state; |
| 5417 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5418 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5419 | struct sk_buff *msg; |
| 5420 | void *hdr; |
| 5421 | int err; |
| 5422 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5423 | wdev = dev->ieee80211_ptr; |
| 5424 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5425 | if (!rdev->ops->set_power_mgmt) |
| 5426 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5427 | |
| 5428 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5429 | if (!msg) |
| 5430 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5431 | |
| 5432 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5433 | NL80211_CMD_GET_POWER_SAVE); |
| 5434 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5435 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5436 | goto free_msg; |
| 5437 | } |
| 5438 | |
| 5439 | if (wdev->ps) |
| 5440 | ps_state = NL80211_PS_ENABLED; |
| 5441 | else |
| 5442 | ps_state = NL80211_PS_DISABLED; |
| 5443 | |
| 5444 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5445 | |
| 5446 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5447 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5448 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5449 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5450 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5451 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5452 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5453 | return err; |
| 5454 | } |
| 5455 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5456 | static struct nla_policy |
| 5457 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5458 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5459 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5460 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5461 | }; |
| 5462 | |
| 5463 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5464 | s32 threshold, u32 hysteresis) |
| 5465 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5466 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5467 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5468 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5469 | |
| 5470 | if (threshold > 0) |
| 5471 | return -EINVAL; |
| 5472 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5473 | wdev = dev->ieee80211_ptr; |
| 5474 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5475 | if (!rdev->ops->set_cqm_rssi_config) |
| 5476 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5477 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5478 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5479 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5480 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5481 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5482 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5483 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5487 | { |
| 5488 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5489 | struct nlattr *cqm; |
| 5490 | int err; |
| 5491 | |
| 5492 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5493 | if (!cqm) { |
| 5494 | err = -EINVAL; |
| 5495 | goto out; |
| 5496 | } |
| 5497 | |
| 5498 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5499 | nl80211_attr_cqm_policy); |
| 5500 | if (err) |
| 5501 | goto out; |
| 5502 | |
| 5503 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5504 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5505 | s32 threshold; |
| 5506 | u32 hysteresis; |
| 5507 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5508 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5509 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5510 | } else |
| 5511 | err = -EINVAL; |
| 5512 | |
| 5513 | out: |
| 5514 | return err; |
| 5515 | } |
| 5516 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5517 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5518 | { |
| 5519 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5520 | struct net_device *dev = info->user_ptr[1]; |
| 5521 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5522 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5523 | int err; |
| 5524 | |
| 5525 | /* start with default */ |
| 5526 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5527 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5528 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5529 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5530 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5531 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5532 | if (err) |
| 5533 | return err; |
| 5534 | } |
| 5535 | |
| 5536 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5537 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5538 | return -EINVAL; |
| 5539 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5540 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5541 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5542 | |
| 5543 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5544 | /* parse additional setup parameters if given */ |
| 5545 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5546 | if (err) |
| 5547 | return err; |
| 5548 | } |
| 5549 | |
| 5550 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5551 | } |
| 5552 | |
| 5553 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5554 | { |
| 5555 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5556 | struct net_device *dev = info->user_ptr[1]; |
| 5557 | |
| 5558 | return cfg80211_leave_mesh(rdev, dev); |
| 5559 | } |
| 5560 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5561 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5562 | { |
| 5563 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5564 | struct sk_buff *msg; |
| 5565 | void *hdr; |
| 5566 | |
| 5567 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5568 | return -EOPNOTSUPP; |
| 5569 | |
| 5570 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5571 | if (!msg) |
| 5572 | return -ENOMEM; |
| 5573 | |
| 5574 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5575 | NL80211_CMD_GET_WOWLAN); |
| 5576 | if (!hdr) |
| 5577 | goto nla_put_failure; |
| 5578 | |
| 5579 | if (rdev->wowlan) { |
| 5580 | struct nlattr *nl_wowlan; |
| 5581 | |
| 5582 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5583 | if (!nl_wowlan) |
| 5584 | goto nla_put_failure; |
| 5585 | |
| 5586 | if (rdev->wowlan->any) |
| 5587 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5588 | if (rdev->wowlan->disconnect) |
| 5589 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5590 | if (rdev->wowlan->magic_pkt) |
| 5591 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5592 | if (rdev->wowlan->gtk_rekey_failure) |
| 5593 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5594 | if (rdev->wowlan->eap_identity_req) |
| 5595 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5596 | if (rdev->wowlan->four_way_handshake) |
| 5597 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5598 | if (rdev->wowlan->rfkill_release) |
| 5599 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5600 | if (rdev->wowlan->n_patterns) { |
| 5601 | struct nlattr *nl_pats, *nl_pat; |
| 5602 | int i, pat_len; |
| 5603 | |
| 5604 | nl_pats = nla_nest_start(msg, |
| 5605 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5606 | if (!nl_pats) |
| 5607 | goto nla_put_failure; |
| 5608 | |
| 5609 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5610 | nl_pat = nla_nest_start(msg, i + 1); |
| 5611 | if (!nl_pat) |
| 5612 | goto nla_put_failure; |
| 5613 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5614 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5615 | DIV_ROUND_UP(pat_len, 8), |
| 5616 | rdev->wowlan->patterns[i].mask); |
| 5617 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5618 | pat_len, |
| 5619 | rdev->wowlan->patterns[i].pattern); |
| 5620 | nla_nest_end(msg, nl_pat); |
| 5621 | } |
| 5622 | nla_nest_end(msg, nl_pats); |
| 5623 | } |
| 5624 | |
| 5625 | nla_nest_end(msg, nl_wowlan); |
| 5626 | } |
| 5627 | |
| 5628 | genlmsg_end(msg, hdr); |
| 5629 | return genlmsg_reply(msg, info); |
| 5630 | |
| 5631 | nla_put_failure: |
| 5632 | nlmsg_free(msg); |
| 5633 | return -ENOBUFS; |
| 5634 | } |
| 5635 | |
| 5636 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5637 | { |
| 5638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5639 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5640 | struct cfg80211_wowlan no_triggers = {}; |
| 5641 | struct cfg80211_wowlan new_triggers = {}; |
| 5642 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5643 | int err, i; |
| 5644 | |
| 5645 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5646 | return -EOPNOTSUPP; |
| 5647 | |
| 5648 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5649 | goto no_triggers; |
| 5650 | |
| 5651 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5652 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5653 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5654 | nl80211_wowlan_policy); |
| 5655 | if (err) |
| 5656 | return err; |
| 5657 | |
| 5658 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5659 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5660 | return -EINVAL; |
| 5661 | new_triggers.any = true; |
| 5662 | } |
| 5663 | |
| 5664 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5665 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5666 | return -EINVAL; |
| 5667 | new_triggers.disconnect = true; |
| 5668 | } |
| 5669 | |
| 5670 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5671 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5672 | return -EINVAL; |
| 5673 | new_triggers.magic_pkt = true; |
| 5674 | } |
| 5675 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5676 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5677 | return -EINVAL; |
| 5678 | |
| 5679 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5680 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5681 | return -EINVAL; |
| 5682 | new_triggers.gtk_rekey_failure = true; |
| 5683 | } |
| 5684 | |
| 5685 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5686 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5687 | return -EINVAL; |
| 5688 | new_triggers.eap_identity_req = true; |
| 5689 | } |
| 5690 | |
| 5691 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5692 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5693 | return -EINVAL; |
| 5694 | new_triggers.four_way_handshake = true; |
| 5695 | } |
| 5696 | |
| 5697 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5698 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5699 | return -EINVAL; |
| 5700 | new_triggers.rfkill_release = true; |
| 5701 | } |
| 5702 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5703 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5704 | struct nlattr *pat; |
| 5705 | int n_patterns = 0; |
| 5706 | int rem, pat_len, mask_len; |
| 5707 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5708 | |
| 5709 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5710 | rem) |
| 5711 | n_patterns++; |
| 5712 | if (n_patterns > wowlan->n_patterns) |
| 5713 | return -EINVAL; |
| 5714 | |
| 5715 | new_triggers.patterns = kcalloc(n_patterns, |
| 5716 | sizeof(new_triggers.patterns[0]), |
| 5717 | GFP_KERNEL); |
| 5718 | if (!new_triggers.patterns) |
| 5719 | return -ENOMEM; |
| 5720 | |
| 5721 | new_triggers.n_patterns = n_patterns; |
| 5722 | i = 0; |
| 5723 | |
| 5724 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5725 | rem) { |
| 5726 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5727 | nla_data(pat), nla_len(pat), NULL); |
| 5728 | err = -EINVAL; |
| 5729 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5730 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5731 | goto error; |
| 5732 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5733 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5734 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5735 | mask_len) |
| 5736 | goto error; |
| 5737 | if (pat_len > wowlan->pattern_max_len || |
| 5738 | pat_len < wowlan->pattern_min_len) |
| 5739 | goto error; |
| 5740 | |
| 5741 | new_triggers.patterns[i].mask = |
| 5742 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5743 | if (!new_triggers.patterns[i].mask) { |
| 5744 | err = -ENOMEM; |
| 5745 | goto error; |
| 5746 | } |
| 5747 | new_triggers.patterns[i].pattern = |
| 5748 | new_triggers.patterns[i].mask + mask_len; |
| 5749 | memcpy(new_triggers.patterns[i].mask, |
| 5750 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5751 | mask_len); |
| 5752 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5753 | memcpy(new_triggers.patterns[i].pattern, |
| 5754 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5755 | pat_len); |
| 5756 | i++; |
| 5757 | } |
| 5758 | } |
| 5759 | |
| 5760 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5761 | struct cfg80211_wowlan *ntrig; |
| 5762 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5763 | GFP_KERNEL); |
| 5764 | if (!ntrig) { |
| 5765 | err = -ENOMEM; |
| 5766 | goto error; |
| 5767 | } |
| 5768 | cfg80211_rdev_free_wowlan(rdev); |
| 5769 | rdev->wowlan = ntrig; |
| 5770 | } else { |
| 5771 | no_triggers: |
| 5772 | cfg80211_rdev_free_wowlan(rdev); |
| 5773 | rdev->wowlan = NULL; |
| 5774 | } |
| 5775 | |
| 5776 | return 0; |
| 5777 | error: |
| 5778 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5779 | kfree(new_triggers.patterns[i].mask); |
| 5780 | kfree(new_triggers.patterns); |
| 5781 | return err; |
| 5782 | } |
| 5783 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5784 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5785 | { |
| 5786 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5787 | struct net_device *dev = info->user_ptr[1]; |
| 5788 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5789 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5790 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5791 | int err; |
| 5792 | |
| 5793 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5794 | return -EINVAL; |
| 5795 | |
| 5796 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5797 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5798 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5799 | nl80211_rekey_policy); |
| 5800 | if (err) |
| 5801 | return err; |
| 5802 | |
| 5803 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5804 | return -ERANGE; |
| 5805 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5806 | return -ERANGE; |
| 5807 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5808 | return -ERANGE; |
| 5809 | |
| 5810 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5811 | NL80211_KEK_LEN); |
| 5812 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5813 | NL80211_KCK_LEN); |
| 5814 | memcpy(rekey_data.replay_ctr, |
| 5815 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5816 | NL80211_REPLAY_CTR_LEN); |
| 5817 | |
| 5818 | wdev_lock(wdev); |
| 5819 | if (!wdev->current_bss) { |
| 5820 | err = -ENOTCONN; |
| 5821 | goto out; |
| 5822 | } |
| 5823 | |
| 5824 | if (!rdev->ops->set_rekey_data) { |
| 5825 | err = -EOPNOTSUPP; |
| 5826 | goto out; |
| 5827 | } |
| 5828 | |
| 5829 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5830 | out: |
| 5831 | wdev_unlock(wdev); |
| 5832 | return err; |
| 5833 | } |
| 5834 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5835 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5836 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5837 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5838 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5839 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5840 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5841 | |
| 5842 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5843 | struct genl_info *info) |
| 5844 | { |
| 5845 | struct cfg80211_registered_device *rdev; |
| 5846 | struct net_device *dev; |
| 5847 | int err; |
| 5848 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5849 | |
| 5850 | if (rtnl) |
| 5851 | rtnl_lock(); |
| 5852 | |
| 5853 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5854 | rdev = cfg80211_get_dev_from_info(info); |
| 5855 | if (IS_ERR(rdev)) { |
| 5856 | if (rtnl) |
| 5857 | rtnl_unlock(); |
| 5858 | return PTR_ERR(rdev); |
| 5859 | } |
| 5860 | info->user_ptr[0] = rdev; |
| 5861 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5862 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5863 | if (err) { |
| 5864 | if (rtnl) |
| 5865 | rtnl_unlock(); |
| 5866 | return err; |
| 5867 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5868 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5869 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5870 | cfg80211_unlock_rdev(rdev); |
| 5871 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5872 | if (rtnl) |
| 5873 | rtnl_unlock(); |
| 5874 | return -ENETDOWN; |
| 5875 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5876 | info->user_ptr[0] = rdev; |
| 5877 | info->user_ptr[1] = dev; |
| 5878 | } |
| 5879 | |
| 5880 | return 0; |
| 5881 | } |
| 5882 | |
| 5883 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5884 | struct genl_info *info) |
| 5885 | { |
| 5886 | if (info->user_ptr[0]) |
| 5887 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5888 | if (info->user_ptr[1]) |
| 5889 | dev_put(info->user_ptr[1]); |
| 5890 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5891 | rtnl_unlock(); |
| 5892 | } |
| 5893 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5894 | static struct genl_ops nl80211_ops[] = { |
| 5895 | { |
| 5896 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5897 | .doit = nl80211_get_wiphy, |
| 5898 | .dumpit = nl80211_dump_wiphy, |
| 5899 | .policy = nl80211_policy, |
| 5900 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5901 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5902 | }, |
| 5903 | { |
| 5904 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5905 | .doit = nl80211_set_wiphy, |
| 5906 | .policy = nl80211_policy, |
| 5907 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5908 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5909 | }, |
| 5910 | { |
| 5911 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5912 | .doit = nl80211_get_interface, |
| 5913 | .dumpit = nl80211_dump_interface, |
| 5914 | .policy = nl80211_policy, |
| 5915 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5916 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5917 | }, |
| 5918 | { |
| 5919 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5920 | .doit = nl80211_set_interface, |
| 5921 | .policy = nl80211_policy, |
| 5922 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5923 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5924 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5925 | }, |
| 5926 | { |
| 5927 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5928 | .doit = nl80211_new_interface, |
| 5929 | .policy = nl80211_policy, |
| 5930 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5931 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5932 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5933 | }, |
| 5934 | { |
| 5935 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5936 | .doit = nl80211_del_interface, |
| 5937 | .policy = nl80211_policy, |
| 5938 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5939 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5940 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5941 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5942 | { |
| 5943 | .cmd = NL80211_CMD_GET_KEY, |
| 5944 | .doit = nl80211_get_key, |
| 5945 | .policy = nl80211_policy, |
| 5946 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5947 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5948 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5949 | }, |
| 5950 | { |
| 5951 | .cmd = NL80211_CMD_SET_KEY, |
| 5952 | .doit = nl80211_set_key, |
| 5953 | .policy = nl80211_policy, |
| 5954 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5955 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5956 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5957 | }, |
| 5958 | { |
| 5959 | .cmd = NL80211_CMD_NEW_KEY, |
| 5960 | .doit = nl80211_new_key, |
| 5961 | .policy = nl80211_policy, |
| 5962 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5963 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5964 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5965 | }, |
| 5966 | { |
| 5967 | .cmd = NL80211_CMD_DEL_KEY, |
| 5968 | .doit = nl80211_del_key, |
| 5969 | .policy = nl80211_policy, |
| 5970 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5971 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5972 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5973 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5974 | { |
| 5975 | .cmd = NL80211_CMD_SET_BEACON, |
| 5976 | .policy = nl80211_policy, |
| 5977 | .flags = GENL_ADMIN_PERM, |
| 5978 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5979 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5980 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5981 | }, |
| 5982 | { |
| 5983 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5984 | .policy = nl80211_policy, |
| 5985 | .flags = GENL_ADMIN_PERM, |
| 5986 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5987 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5988 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5989 | }, |
| 5990 | { |
| 5991 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5992 | .policy = nl80211_policy, |
| 5993 | .flags = GENL_ADMIN_PERM, |
| 5994 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5995 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5996 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5997 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5998 | { |
| 5999 | .cmd = NL80211_CMD_GET_STATION, |
| 6000 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6001 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6002 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6003 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6004 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6005 | }, |
| 6006 | { |
| 6007 | .cmd = NL80211_CMD_SET_STATION, |
| 6008 | .doit = nl80211_set_station, |
| 6009 | .policy = nl80211_policy, |
| 6010 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6011 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6012 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6013 | }, |
| 6014 | { |
| 6015 | .cmd = NL80211_CMD_NEW_STATION, |
| 6016 | .doit = nl80211_new_station, |
| 6017 | .policy = nl80211_policy, |
| 6018 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6020 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6021 | }, |
| 6022 | { |
| 6023 | .cmd = NL80211_CMD_DEL_STATION, |
| 6024 | .doit = nl80211_del_station, |
| 6025 | .policy = nl80211_policy, |
| 6026 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6027 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6028 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6029 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6030 | { |
| 6031 | .cmd = NL80211_CMD_GET_MPATH, |
| 6032 | .doit = nl80211_get_mpath, |
| 6033 | .dumpit = nl80211_dump_mpath, |
| 6034 | .policy = nl80211_policy, |
| 6035 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6036 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6037 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6038 | }, |
| 6039 | { |
| 6040 | .cmd = NL80211_CMD_SET_MPATH, |
| 6041 | .doit = nl80211_set_mpath, |
| 6042 | .policy = nl80211_policy, |
| 6043 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6044 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6045 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6046 | }, |
| 6047 | { |
| 6048 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6049 | .doit = nl80211_new_mpath, |
| 6050 | .policy = nl80211_policy, |
| 6051 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6052 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6053 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6054 | }, |
| 6055 | { |
| 6056 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6057 | .doit = nl80211_del_mpath, |
| 6058 | .policy = nl80211_policy, |
| 6059 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6060 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6061 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6062 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6063 | { |
| 6064 | .cmd = NL80211_CMD_SET_BSS, |
| 6065 | .doit = nl80211_set_bss, |
| 6066 | .policy = nl80211_policy, |
| 6067 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6068 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6069 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6070 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6071 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6072 | .cmd = NL80211_CMD_GET_REG, |
| 6073 | .doit = nl80211_get_reg, |
| 6074 | .policy = nl80211_policy, |
| 6075 | /* can be retrieved by unprivileged users */ |
| 6076 | }, |
| 6077 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6078 | .cmd = NL80211_CMD_SET_REG, |
| 6079 | .doit = nl80211_set_reg, |
| 6080 | .policy = nl80211_policy, |
| 6081 | .flags = GENL_ADMIN_PERM, |
| 6082 | }, |
| 6083 | { |
| 6084 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6085 | .doit = nl80211_req_set_reg, |
| 6086 | .policy = nl80211_policy, |
| 6087 | .flags = GENL_ADMIN_PERM, |
| 6088 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6089 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6090 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6091 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6092 | .policy = nl80211_policy, |
| 6093 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6094 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6095 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6096 | }, |
| 6097 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6098 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6099 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6100 | .policy = nl80211_policy, |
| 6101 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6102 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6103 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6104 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6105 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6106 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6107 | .doit = nl80211_trigger_scan, |
| 6108 | .policy = nl80211_policy, |
| 6109 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6110 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6111 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6112 | }, |
| 6113 | { |
| 6114 | .cmd = NL80211_CMD_GET_SCAN, |
| 6115 | .policy = nl80211_policy, |
| 6116 | .dumpit = nl80211_dump_scan, |
| 6117 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6118 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6119 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6120 | .doit = nl80211_start_sched_scan, |
| 6121 | .policy = nl80211_policy, |
| 6122 | .flags = GENL_ADMIN_PERM, |
| 6123 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6124 | NL80211_FLAG_NEED_RTNL, |
| 6125 | }, |
| 6126 | { |
| 6127 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6128 | .doit = nl80211_stop_sched_scan, |
| 6129 | .policy = nl80211_policy, |
| 6130 | .flags = GENL_ADMIN_PERM, |
| 6131 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6132 | NL80211_FLAG_NEED_RTNL, |
| 6133 | }, |
| 6134 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6135 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6136 | .doit = nl80211_authenticate, |
| 6137 | .policy = nl80211_policy, |
| 6138 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6139 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6140 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6141 | }, |
| 6142 | { |
| 6143 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6144 | .doit = nl80211_associate, |
| 6145 | .policy = nl80211_policy, |
| 6146 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6147 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6148 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6149 | }, |
| 6150 | { |
| 6151 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6152 | .doit = nl80211_deauthenticate, |
| 6153 | .policy = nl80211_policy, |
| 6154 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6155 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6156 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6157 | }, |
| 6158 | { |
| 6159 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6160 | .doit = nl80211_disassociate, |
| 6161 | .policy = nl80211_policy, |
| 6162 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6163 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6164 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6165 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6166 | { |
| 6167 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6168 | .doit = nl80211_join_ibss, |
| 6169 | .policy = nl80211_policy, |
| 6170 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6171 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6172 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6173 | }, |
| 6174 | { |
| 6175 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6176 | .doit = nl80211_leave_ibss, |
| 6177 | .policy = nl80211_policy, |
| 6178 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6179 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6180 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6181 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6182 | #ifdef CONFIG_NL80211_TESTMODE |
| 6183 | { |
| 6184 | .cmd = NL80211_CMD_TESTMODE, |
| 6185 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6186 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6187 | .policy = nl80211_policy, |
| 6188 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6189 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6190 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6191 | }, |
| 6192 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6193 | { |
| 6194 | .cmd = NL80211_CMD_CONNECT, |
| 6195 | .doit = nl80211_connect, |
| 6196 | .policy = nl80211_policy, |
| 6197 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6198 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6199 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6200 | }, |
| 6201 | { |
| 6202 | .cmd = NL80211_CMD_DISCONNECT, |
| 6203 | .doit = nl80211_disconnect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6208 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6209 | { |
| 6210 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6211 | .doit = nl80211_wiphy_netns, |
| 6212 | .policy = nl80211_policy, |
| 6213 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6214 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6215 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6216 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6217 | { |
| 6218 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6219 | .policy = nl80211_policy, |
| 6220 | .dumpit = nl80211_dump_survey, |
| 6221 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6222 | { |
| 6223 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6224 | .doit = nl80211_setdel_pmksa, |
| 6225 | .policy = nl80211_policy, |
| 6226 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6227 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6228 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6229 | }, |
| 6230 | { |
| 6231 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6232 | .doit = nl80211_setdel_pmksa, |
| 6233 | .policy = nl80211_policy, |
| 6234 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6235 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6236 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6237 | }, |
| 6238 | { |
| 6239 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6240 | .doit = nl80211_flush_pmksa, |
| 6241 | .policy = nl80211_policy, |
| 6242 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6243 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6244 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6245 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6246 | { |
| 6247 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6248 | .doit = nl80211_remain_on_channel, |
| 6249 | .policy = nl80211_policy, |
| 6250 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6251 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6252 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6253 | }, |
| 6254 | { |
| 6255 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6256 | .doit = nl80211_cancel_remain_on_channel, |
| 6257 | .policy = nl80211_policy, |
| 6258 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6259 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6260 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6261 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6262 | { |
| 6263 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6264 | .doit = nl80211_set_tx_bitrate_mask, |
| 6265 | .policy = nl80211_policy, |
| 6266 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6267 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6268 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6269 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6270 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6271 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6272 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6273 | .policy = nl80211_policy, |
| 6274 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6275 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6276 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6277 | }, |
| 6278 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6279 | .cmd = NL80211_CMD_FRAME, |
| 6280 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6281 | .policy = nl80211_policy, |
| 6282 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6283 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6284 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6285 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6286 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6287 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6288 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6289 | .policy = nl80211_policy, |
| 6290 | .flags = GENL_ADMIN_PERM, |
| 6291 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6292 | NL80211_FLAG_NEED_RTNL, |
| 6293 | }, |
| 6294 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6295 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6296 | .doit = nl80211_set_power_save, |
| 6297 | .policy = nl80211_policy, |
| 6298 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6299 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6300 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6301 | }, |
| 6302 | { |
| 6303 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6304 | .doit = nl80211_get_power_save, |
| 6305 | .policy = nl80211_policy, |
| 6306 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6307 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6308 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6309 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6310 | { |
| 6311 | .cmd = NL80211_CMD_SET_CQM, |
| 6312 | .doit = nl80211_set_cqm, |
| 6313 | .policy = nl80211_policy, |
| 6314 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6315 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6316 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6317 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6318 | { |
| 6319 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6320 | .doit = nl80211_set_channel, |
| 6321 | .policy = nl80211_policy, |
| 6322 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6323 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6324 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6325 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6326 | { |
| 6327 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6328 | .doit = nl80211_set_wds_peer, |
| 6329 | .policy = nl80211_policy, |
| 6330 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6331 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6332 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6333 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6334 | { |
| 6335 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6336 | .doit = nl80211_join_mesh, |
| 6337 | .policy = nl80211_policy, |
| 6338 | .flags = GENL_ADMIN_PERM, |
| 6339 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6340 | NL80211_FLAG_NEED_RTNL, |
| 6341 | }, |
| 6342 | { |
| 6343 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6344 | .doit = nl80211_leave_mesh, |
| 6345 | .policy = nl80211_policy, |
| 6346 | .flags = GENL_ADMIN_PERM, |
| 6347 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6348 | NL80211_FLAG_NEED_RTNL, |
| 6349 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6350 | { |
| 6351 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6352 | .doit = nl80211_get_wowlan, |
| 6353 | .policy = nl80211_policy, |
| 6354 | /* can be retrieved by unprivileged users */ |
| 6355 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6356 | NL80211_FLAG_NEED_RTNL, |
| 6357 | }, |
| 6358 | { |
| 6359 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6360 | .doit = nl80211_set_wowlan, |
| 6361 | .policy = nl80211_policy, |
| 6362 | .flags = GENL_ADMIN_PERM, |
| 6363 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6364 | NL80211_FLAG_NEED_RTNL, |
| 6365 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6366 | { |
| 6367 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6368 | .doit = nl80211_set_rekey_data, |
| 6369 | .policy = nl80211_policy, |
| 6370 | .flags = GENL_ADMIN_PERM, |
| 6371 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6372 | NL80211_FLAG_NEED_RTNL, |
| 6373 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6374 | { |
| 6375 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 6376 | .doit = nl80211_tdls_mgmt, |
| 6377 | .policy = nl80211_policy, |
| 6378 | .flags = GENL_ADMIN_PERM, |
| 6379 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6380 | NL80211_FLAG_NEED_RTNL, |
| 6381 | }, |
| 6382 | { |
| 6383 | .cmd = NL80211_CMD_TDLS_OPER, |
| 6384 | .doit = nl80211_tdls_oper, |
| 6385 | .policy = nl80211_policy, |
| 6386 | .flags = GENL_ADMIN_PERM, |
| 6387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6388 | NL80211_FLAG_NEED_RTNL, |
| 6389 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6390 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6391 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6392 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6393 | .name = "mlme", |
| 6394 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6395 | |
| 6396 | /* multicast groups */ |
| 6397 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6398 | .name = "config", |
| 6399 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6400 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6401 | .name = "scan", |
| 6402 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6403 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6404 | .name = "regulatory", |
| 6405 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6406 | |
| 6407 | /* notification functions */ |
| 6408 | |
| 6409 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6410 | { |
| 6411 | struct sk_buff *msg; |
| 6412 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6414 | if (!msg) |
| 6415 | return; |
| 6416 | |
| 6417 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6418 | nlmsg_free(msg); |
| 6419 | return; |
| 6420 | } |
| 6421 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6422 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6423 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6424 | } |
| 6425 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6426 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6427 | struct cfg80211_registered_device *rdev) |
| 6428 | { |
| 6429 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6430 | struct nlattr *nest; |
| 6431 | int i; |
| 6432 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6433 | ASSERT_RDEV_LOCK(rdev); |
| 6434 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6435 | if (WARN_ON(!req)) |
| 6436 | return 0; |
| 6437 | |
| 6438 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6439 | if (!nest) |
| 6440 | goto nla_put_failure; |
| 6441 | for (i = 0; i < req->n_ssids; i++) |
| 6442 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6443 | nla_nest_end(msg, nest); |
| 6444 | |
| 6445 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6446 | if (!nest) |
| 6447 | goto nla_put_failure; |
| 6448 | for (i = 0; i < req->n_channels; i++) |
| 6449 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6450 | nla_nest_end(msg, nest); |
| 6451 | |
| 6452 | if (req->ie) |
| 6453 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6454 | |
| 6455 | return 0; |
| 6456 | nla_put_failure: |
| 6457 | return -ENOBUFS; |
| 6458 | } |
| 6459 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6460 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6461 | struct cfg80211_registered_device *rdev, |
| 6462 | struct net_device *netdev, |
| 6463 | u32 pid, u32 seq, int flags, |
| 6464 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6465 | { |
| 6466 | void *hdr; |
| 6467 | |
| 6468 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6469 | if (!hdr) |
| 6470 | return -1; |
| 6471 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6472 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6473 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6474 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6475 | /* ignore errors and send incomplete event anyway */ |
| 6476 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6477 | |
| 6478 | return genlmsg_end(msg, hdr); |
| 6479 | |
| 6480 | nla_put_failure: |
| 6481 | genlmsg_cancel(msg, hdr); |
| 6482 | return -EMSGSIZE; |
| 6483 | } |
| 6484 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6485 | static int |
| 6486 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6487 | struct cfg80211_registered_device *rdev, |
| 6488 | struct net_device *netdev, |
| 6489 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6490 | { |
| 6491 | void *hdr; |
| 6492 | |
| 6493 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6494 | if (!hdr) |
| 6495 | return -1; |
| 6496 | |
| 6497 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6498 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6499 | |
| 6500 | return genlmsg_end(msg, hdr); |
| 6501 | |
| 6502 | nla_put_failure: |
| 6503 | genlmsg_cancel(msg, hdr); |
| 6504 | return -EMSGSIZE; |
| 6505 | } |
| 6506 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6507 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6508 | struct net_device *netdev) |
| 6509 | { |
| 6510 | struct sk_buff *msg; |
| 6511 | |
| 6512 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6513 | if (!msg) |
| 6514 | return; |
| 6515 | |
| 6516 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6517 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6518 | nlmsg_free(msg); |
| 6519 | return; |
| 6520 | } |
| 6521 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6522 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6523 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6524 | } |
| 6525 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6526 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6527 | struct net_device *netdev) |
| 6528 | { |
| 6529 | struct sk_buff *msg; |
| 6530 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6532 | if (!msg) |
| 6533 | return; |
| 6534 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6535 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6536 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6537 | nlmsg_free(msg); |
| 6538 | return; |
| 6539 | } |
| 6540 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6541 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6542 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6543 | } |
| 6544 | |
| 6545 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6546 | struct net_device *netdev) |
| 6547 | { |
| 6548 | struct sk_buff *msg; |
| 6549 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6550 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6551 | if (!msg) |
| 6552 | return; |
| 6553 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6554 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6555 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6556 | nlmsg_free(msg); |
| 6557 | return; |
| 6558 | } |
| 6559 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6560 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6561 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6562 | } |
| 6563 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6564 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6565 | struct net_device *netdev) |
| 6566 | { |
| 6567 | struct sk_buff *msg; |
| 6568 | |
| 6569 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6570 | if (!msg) |
| 6571 | return; |
| 6572 | |
| 6573 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6574 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6575 | nlmsg_free(msg); |
| 6576 | return; |
| 6577 | } |
| 6578 | |
| 6579 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6580 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6581 | } |
| 6582 | |
| 6583 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6584 | struct net_device *netdev, u32 cmd) |
| 6585 | { |
| 6586 | struct sk_buff *msg; |
| 6587 | |
| 6588 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6589 | if (!msg) |
| 6590 | return; |
| 6591 | |
| 6592 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6593 | nlmsg_free(msg); |
| 6594 | return; |
| 6595 | } |
| 6596 | |
| 6597 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6598 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6599 | } |
| 6600 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6601 | /* |
| 6602 | * This can happen on global regulatory changes or device specific settings |
| 6603 | * based on custom world regulatory domains. |
| 6604 | */ |
| 6605 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6606 | { |
| 6607 | struct sk_buff *msg; |
| 6608 | void *hdr; |
| 6609 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6610 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6611 | if (!msg) |
| 6612 | return; |
| 6613 | |
| 6614 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6615 | if (!hdr) { |
| 6616 | nlmsg_free(msg); |
| 6617 | return; |
| 6618 | } |
| 6619 | |
| 6620 | /* Userspace can always count this one always being set */ |
| 6621 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6622 | |
| 6623 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6624 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6625 | NL80211_REGDOM_TYPE_WORLD); |
| 6626 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6627 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6628 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6629 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6630 | request->intersect) |
| 6631 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6632 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6633 | else { |
| 6634 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6635 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6636 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6637 | } |
| 6638 | |
| 6639 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6640 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6641 | |
| 6642 | if (genlmsg_end(msg, hdr) < 0) { |
| 6643 | nlmsg_free(msg); |
| 6644 | return; |
| 6645 | } |
| 6646 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6647 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6648 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6649 | GFP_ATOMIC); |
| 6650 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6651 | |
| 6652 | return; |
| 6653 | |
| 6654 | nla_put_failure: |
| 6655 | genlmsg_cancel(msg, hdr); |
| 6656 | nlmsg_free(msg); |
| 6657 | } |
| 6658 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6659 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6660 | struct net_device *netdev, |
| 6661 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6662 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6663 | { |
| 6664 | struct sk_buff *msg; |
| 6665 | void *hdr; |
| 6666 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6668 | if (!msg) |
| 6669 | return; |
| 6670 | |
| 6671 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6672 | if (!hdr) { |
| 6673 | nlmsg_free(msg); |
| 6674 | return; |
| 6675 | } |
| 6676 | |
| 6677 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6678 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6679 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6680 | |
| 6681 | if (genlmsg_end(msg, hdr) < 0) { |
| 6682 | nlmsg_free(msg); |
| 6683 | return; |
| 6684 | } |
| 6685 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6686 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6687 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6688 | return; |
| 6689 | |
| 6690 | nla_put_failure: |
| 6691 | genlmsg_cancel(msg, hdr); |
| 6692 | nlmsg_free(msg); |
| 6693 | } |
| 6694 | |
| 6695 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6696 | struct net_device *netdev, const u8 *buf, |
| 6697 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6698 | { |
| 6699 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6700 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6701 | } |
| 6702 | |
| 6703 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6704 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6705 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6706 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6707 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6708 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6709 | } |
| 6710 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6711 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6712 | struct net_device *netdev, const u8 *buf, |
| 6713 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6714 | { |
| 6715 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6716 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6717 | } |
| 6718 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6719 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6720 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6721 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6722 | { |
| 6723 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6724 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6725 | } |
| 6726 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6727 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6728 | struct net_device *netdev, const u8 *buf, |
| 6729 | size_t len, gfp_t gfp) |
| 6730 | { |
| 6731 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6732 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6733 | } |
| 6734 | |
| 6735 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6736 | struct net_device *netdev, const u8 *buf, |
| 6737 | size_t len, gfp_t gfp) |
| 6738 | { |
| 6739 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6740 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6741 | } |
| 6742 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6743 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6744 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6745 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6746 | { |
| 6747 | struct sk_buff *msg; |
| 6748 | void *hdr; |
| 6749 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6750 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6751 | if (!msg) |
| 6752 | return; |
| 6753 | |
| 6754 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6755 | if (!hdr) { |
| 6756 | nlmsg_free(msg); |
| 6757 | return; |
| 6758 | } |
| 6759 | |
| 6760 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6761 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6762 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6763 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6764 | |
| 6765 | if (genlmsg_end(msg, hdr) < 0) { |
| 6766 | nlmsg_free(msg); |
| 6767 | return; |
| 6768 | } |
| 6769 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6770 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6771 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6772 | return; |
| 6773 | |
| 6774 | nla_put_failure: |
| 6775 | genlmsg_cancel(msg, hdr); |
| 6776 | nlmsg_free(msg); |
| 6777 | } |
| 6778 | |
| 6779 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6780 | struct net_device *netdev, const u8 *addr, |
| 6781 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6782 | { |
| 6783 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6784 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6785 | } |
| 6786 | |
| 6787 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6788 | struct net_device *netdev, const u8 *addr, |
| 6789 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6790 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6791 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6792 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6793 | } |
| 6794 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6795 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6796 | struct net_device *netdev, const u8 *bssid, |
| 6797 | const u8 *req_ie, size_t req_ie_len, |
| 6798 | const u8 *resp_ie, size_t resp_ie_len, |
| 6799 | u16 status, gfp_t gfp) |
| 6800 | { |
| 6801 | struct sk_buff *msg; |
| 6802 | void *hdr; |
| 6803 | |
| 6804 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6805 | if (!msg) |
| 6806 | return; |
| 6807 | |
| 6808 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6809 | if (!hdr) { |
| 6810 | nlmsg_free(msg); |
| 6811 | return; |
| 6812 | } |
| 6813 | |
| 6814 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6815 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6816 | if (bssid) |
| 6817 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6818 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6819 | if (req_ie) |
| 6820 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6821 | if (resp_ie) |
| 6822 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6823 | |
| 6824 | if (genlmsg_end(msg, hdr) < 0) { |
| 6825 | nlmsg_free(msg); |
| 6826 | return; |
| 6827 | } |
| 6828 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6829 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6830 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6831 | return; |
| 6832 | |
| 6833 | nla_put_failure: |
| 6834 | genlmsg_cancel(msg, hdr); |
| 6835 | nlmsg_free(msg); |
| 6836 | |
| 6837 | } |
| 6838 | |
| 6839 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6840 | struct net_device *netdev, const u8 *bssid, |
| 6841 | const u8 *req_ie, size_t req_ie_len, |
| 6842 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6843 | { |
| 6844 | struct sk_buff *msg; |
| 6845 | void *hdr; |
| 6846 | |
| 6847 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6848 | if (!msg) |
| 6849 | return; |
| 6850 | |
| 6851 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6852 | if (!hdr) { |
| 6853 | nlmsg_free(msg); |
| 6854 | return; |
| 6855 | } |
| 6856 | |
| 6857 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6858 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6859 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6860 | if (req_ie) |
| 6861 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6862 | if (resp_ie) |
| 6863 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6864 | |
| 6865 | if (genlmsg_end(msg, hdr) < 0) { |
| 6866 | nlmsg_free(msg); |
| 6867 | return; |
| 6868 | } |
| 6869 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6870 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6871 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6872 | return; |
| 6873 | |
| 6874 | nla_put_failure: |
| 6875 | genlmsg_cancel(msg, hdr); |
| 6876 | nlmsg_free(msg); |
| 6877 | |
| 6878 | } |
| 6879 | |
| 6880 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6881 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6882 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6883 | { |
| 6884 | struct sk_buff *msg; |
| 6885 | void *hdr; |
| 6886 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6887 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6888 | if (!msg) |
| 6889 | return; |
| 6890 | |
| 6891 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6892 | if (!hdr) { |
| 6893 | nlmsg_free(msg); |
| 6894 | return; |
| 6895 | } |
| 6896 | |
| 6897 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6898 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6899 | if (from_ap && reason) |
| 6900 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6901 | if (from_ap) |
| 6902 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6903 | if (ie) |
| 6904 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6905 | |
| 6906 | if (genlmsg_end(msg, hdr) < 0) { |
| 6907 | nlmsg_free(msg); |
| 6908 | return; |
| 6909 | } |
| 6910 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6911 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6912 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6913 | return; |
| 6914 | |
| 6915 | nla_put_failure: |
| 6916 | genlmsg_cancel(msg, hdr); |
| 6917 | nlmsg_free(msg); |
| 6918 | |
| 6919 | } |
| 6920 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6921 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6922 | struct net_device *netdev, const u8 *bssid, |
| 6923 | gfp_t gfp) |
| 6924 | { |
| 6925 | struct sk_buff *msg; |
| 6926 | void *hdr; |
| 6927 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6928 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6929 | if (!msg) |
| 6930 | return; |
| 6931 | |
| 6932 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6933 | if (!hdr) { |
| 6934 | nlmsg_free(msg); |
| 6935 | return; |
| 6936 | } |
| 6937 | |
| 6938 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6939 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6940 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6941 | |
| 6942 | if (genlmsg_end(msg, hdr) < 0) { |
| 6943 | nlmsg_free(msg); |
| 6944 | return; |
| 6945 | } |
| 6946 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6947 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6948 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6949 | return; |
| 6950 | |
| 6951 | nla_put_failure: |
| 6952 | genlmsg_cancel(msg, hdr); |
| 6953 | nlmsg_free(msg); |
| 6954 | } |
| 6955 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6956 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6957 | struct net_device *netdev, |
| 6958 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6959 | gfp_t gfp) |
| 6960 | { |
| 6961 | struct sk_buff *msg; |
| 6962 | void *hdr; |
| 6963 | |
| 6964 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6965 | if (!msg) |
| 6966 | return; |
| 6967 | |
| 6968 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6969 | if (!hdr) { |
| 6970 | nlmsg_free(msg); |
| 6971 | return; |
| 6972 | } |
| 6973 | |
| 6974 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6975 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6976 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6977 | if (ie_len && ie) |
| 6978 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6979 | |
| 6980 | if (genlmsg_end(msg, hdr) < 0) { |
| 6981 | nlmsg_free(msg); |
| 6982 | return; |
| 6983 | } |
| 6984 | |
| 6985 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6986 | nl80211_mlme_mcgrp.id, gfp); |
| 6987 | return; |
| 6988 | |
| 6989 | nla_put_failure: |
| 6990 | genlmsg_cancel(msg, hdr); |
| 6991 | nlmsg_free(msg); |
| 6992 | } |
| 6993 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6994 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6995 | struct net_device *netdev, const u8 *addr, |
| 6996 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6997 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6998 | { |
| 6999 | struct sk_buff *msg; |
| 7000 | void *hdr; |
| 7001 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7002 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7003 | if (!msg) |
| 7004 | return; |
| 7005 | |
| 7006 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7007 | if (!hdr) { |
| 7008 | nlmsg_free(msg); |
| 7009 | return; |
| 7010 | } |
| 7011 | |
| 7012 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7013 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7014 | if (addr) |
| 7015 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7016 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 7017 | if (key_id != -1) |
| 7018 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7019 | if (tsc) |
| 7020 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 7021 | |
| 7022 | if (genlmsg_end(msg, hdr) < 0) { |
| 7023 | nlmsg_free(msg); |
| 7024 | return; |
| 7025 | } |
| 7026 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7027 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7028 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7029 | return; |
| 7030 | |
| 7031 | nla_put_failure: |
| 7032 | genlmsg_cancel(msg, hdr); |
| 7033 | nlmsg_free(msg); |
| 7034 | } |
| 7035 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7036 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7037 | struct ieee80211_channel *channel_before, |
| 7038 | struct ieee80211_channel *channel_after) |
| 7039 | { |
| 7040 | struct sk_buff *msg; |
| 7041 | void *hdr; |
| 7042 | struct nlattr *nl_freq; |
| 7043 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7044 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7045 | if (!msg) |
| 7046 | return; |
| 7047 | |
| 7048 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7049 | if (!hdr) { |
| 7050 | nlmsg_free(msg); |
| 7051 | return; |
| 7052 | } |
| 7053 | |
| 7054 | /* |
| 7055 | * Since we are applying the beacon hint to a wiphy we know its |
| 7056 | * wiphy_idx is valid |
| 7057 | */ |
| 7058 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 7059 | |
| 7060 | /* Before */ |
| 7061 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7062 | if (!nl_freq) |
| 7063 | goto nla_put_failure; |
| 7064 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7065 | goto nla_put_failure; |
| 7066 | nla_nest_end(msg, nl_freq); |
| 7067 | |
| 7068 | /* After */ |
| 7069 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7070 | if (!nl_freq) |
| 7071 | goto nla_put_failure; |
| 7072 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7073 | goto nla_put_failure; |
| 7074 | nla_nest_end(msg, nl_freq); |
| 7075 | |
| 7076 | if (genlmsg_end(msg, hdr) < 0) { |
| 7077 | nlmsg_free(msg); |
| 7078 | return; |
| 7079 | } |
| 7080 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7081 | rcu_read_lock(); |
| 7082 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7083 | GFP_ATOMIC); |
| 7084 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7085 | |
| 7086 | return; |
| 7087 | |
| 7088 | nla_put_failure: |
| 7089 | genlmsg_cancel(msg, hdr); |
| 7090 | nlmsg_free(msg); |
| 7091 | } |
| 7092 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7093 | static void nl80211_send_remain_on_chan_event( |
| 7094 | int cmd, struct cfg80211_registered_device *rdev, |
| 7095 | struct net_device *netdev, u64 cookie, |
| 7096 | struct ieee80211_channel *chan, |
| 7097 | enum nl80211_channel_type channel_type, |
| 7098 | unsigned int duration, gfp_t gfp) |
| 7099 | { |
| 7100 | struct sk_buff *msg; |
| 7101 | void *hdr; |
| 7102 | |
| 7103 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7104 | if (!msg) |
| 7105 | return; |
| 7106 | |
| 7107 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7108 | if (!hdr) { |
| 7109 | nlmsg_free(msg); |
| 7110 | return; |
| 7111 | } |
| 7112 | |
| 7113 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7114 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7115 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7116 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7117 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7118 | |
| 7119 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7120 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7121 | |
| 7122 | if (genlmsg_end(msg, hdr) < 0) { |
| 7123 | nlmsg_free(msg); |
| 7124 | return; |
| 7125 | } |
| 7126 | |
| 7127 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7128 | nl80211_mlme_mcgrp.id, gfp); |
| 7129 | return; |
| 7130 | |
| 7131 | nla_put_failure: |
| 7132 | genlmsg_cancel(msg, hdr); |
| 7133 | nlmsg_free(msg); |
| 7134 | } |
| 7135 | |
| 7136 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7137 | struct net_device *netdev, u64 cookie, |
| 7138 | struct ieee80211_channel *chan, |
| 7139 | enum nl80211_channel_type channel_type, |
| 7140 | unsigned int duration, gfp_t gfp) |
| 7141 | { |
| 7142 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7143 | rdev, netdev, cookie, chan, |
| 7144 | channel_type, duration, gfp); |
| 7145 | } |
| 7146 | |
| 7147 | void nl80211_send_remain_on_channel_cancel( |
| 7148 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7149 | u64 cookie, struct ieee80211_channel *chan, |
| 7150 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7151 | { |
| 7152 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7153 | rdev, netdev, cookie, chan, |
| 7154 | channel_type, 0, gfp); |
| 7155 | } |
| 7156 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7157 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7158 | struct net_device *dev, const u8 *mac_addr, |
| 7159 | struct station_info *sinfo, gfp_t gfp) |
| 7160 | { |
| 7161 | struct sk_buff *msg; |
| 7162 | |
| 7163 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7164 | if (!msg) |
| 7165 | return; |
| 7166 | |
| 7167 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 7168 | nlmsg_free(msg); |
| 7169 | return; |
| 7170 | } |
| 7171 | |
| 7172 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7173 | nl80211_mlme_mcgrp.id, gfp); |
| 7174 | } |
| 7175 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7176 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7177 | struct net_device *dev, const u8 *mac_addr, |
| 7178 | gfp_t gfp) |
| 7179 | { |
| 7180 | struct sk_buff *msg; |
| 7181 | void *hdr; |
| 7182 | |
| 7183 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7184 | if (!msg) |
| 7185 | return; |
| 7186 | |
| 7187 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7188 | if (!hdr) { |
| 7189 | nlmsg_free(msg); |
| 7190 | return; |
| 7191 | } |
| 7192 | |
| 7193 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7194 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7195 | |
| 7196 | if (genlmsg_end(msg, hdr) < 0) { |
| 7197 | nlmsg_free(msg); |
| 7198 | return; |
| 7199 | } |
| 7200 | |
| 7201 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7202 | nl80211_mlme_mcgrp.id, gfp); |
| 7203 | return; |
| 7204 | |
| 7205 | nla_put_failure: |
| 7206 | genlmsg_cancel(msg, hdr); |
| 7207 | nlmsg_free(msg); |
| 7208 | } |
| 7209 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7210 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7211 | struct net_device *netdev, u32 nlpid, |
| 7212 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7213 | { |
| 7214 | struct sk_buff *msg; |
| 7215 | void *hdr; |
| 7216 | int err; |
| 7217 | |
| 7218 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7219 | if (!msg) |
| 7220 | return -ENOMEM; |
| 7221 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7222 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7223 | if (!hdr) { |
| 7224 | nlmsg_free(msg); |
| 7225 | return -ENOMEM; |
| 7226 | } |
| 7227 | |
| 7228 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7229 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7230 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7231 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7232 | |
| 7233 | err = genlmsg_end(msg, hdr); |
| 7234 | if (err < 0) { |
| 7235 | nlmsg_free(msg); |
| 7236 | return err; |
| 7237 | } |
| 7238 | |
| 7239 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7240 | if (err < 0) |
| 7241 | return err; |
| 7242 | return 0; |
| 7243 | |
| 7244 | nla_put_failure: |
| 7245 | genlmsg_cancel(msg, hdr); |
| 7246 | nlmsg_free(msg); |
| 7247 | return -ENOBUFS; |
| 7248 | } |
| 7249 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7250 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7251 | struct net_device *netdev, u64 cookie, |
| 7252 | const u8 *buf, size_t len, bool ack, |
| 7253 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7254 | { |
| 7255 | struct sk_buff *msg; |
| 7256 | void *hdr; |
| 7257 | |
| 7258 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7259 | if (!msg) |
| 7260 | return; |
| 7261 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7262 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7263 | if (!hdr) { |
| 7264 | nlmsg_free(msg); |
| 7265 | return; |
| 7266 | } |
| 7267 | |
| 7268 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7269 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7270 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7271 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7272 | if (ack) |
| 7273 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7274 | |
| 7275 | if (genlmsg_end(msg, hdr) < 0) { |
| 7276 | nlmsg_free(msg); |
| 7277 | return; |
| 7278 | } |
| 7279 | |
| 7280 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7281 | return; |
| 7282 | |
| 7283 | nla_put_failure: |
| 7284 | genlmsg_cancel(msg, hdr); |
| 7285 | nlmsg_free(msg); |
| 7286 | } |
| 7287 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7288 | void |
| 7289 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7290 | struct net_device *netdev, |
| 7291 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7292 | gfp_t gfp) |
| 7293 | { |
| 7294 | struct sk_buff *msg; |
| 7295 | struct nlattr *pinfoattr; |
| 7296 | void *hdr; |
| 7297 | |
| 7298 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7299 | if (!msg) |
| 7300 | return; |
| 7301 | |
| 7302 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7303 | if (!hdr) { |
| 7304 | nlmsg_free(msg); |
| 7305 | return; |
| 7306 | } |
| 7307 | |
| 7308 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7309 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7310 | |
| 7311 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7312 | if (!pinfoattr) |
| 7313 | goto nla_put_failure; |
| 7314 | |
| 7315 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7316 | rssi_event); |
| 7317 | |
| 7318 | nla_nest_end(msg, pinfoattr); |
| 7319 | |
| 7320 | if (genlmsg_end(msg, hdr) < 0) { |
| 7321 | nlmsg_free(msg); |
| 7322 | return; |
| 7323 | } |
| 7324 | |
| 7325 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7326 | nl80211_mlme_mcgrp.id, gfp); |
| 7327 | return; |
| 7328 | |
| 7329 | nla_put_failure: |
| 7330 | genlmsg_cancel(msg, hdr); |
| 7331 | nlmsg_free(msg); |
| 7332 | } |
| 7333 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7334 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7335 | struct net_device *netdev, const u8 *bssid, |
| 7336 | const u8 *replay_ctr, gfp_t gfp) |
| 7337 | { |
| 7338 | struct sk_buff *msg; |
| 7339 | struct nlattr *rekey_attr; |
| 7340 | void *hdr; |
| 7341 | |
| 7342 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7343 | if (!msg) |
| 7344 | return; |
| 7345 | |
| 7346 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7347 | if (!hdr) { |
| 7348 | nlmsg_free(msg); |
| 7349 | return; |
| 7350 | } |
| 7351 | |
| 7352 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7353 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7354 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7355 | |
| 7356 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7357 | if (!rekey_attr) |
| 7358 | goto nla_put_failure; |
| 7359 | |
| 7360 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7361 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7362 | |
| 7363 | nla_nest_end(msg, rekey_attr); |
| 7364 | |
| 7365 | if (genlmsg_end(msg, hdr) < 0) { |
| 7366 | nlmsg_free(msg); |
| 7367 | return; |
| 7368 | } |
| 7369 | |
| 7370 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7371 | nl80211_mlme_mcgrp.id, gfp); |
| 7372 | return; |
| 7373 | |
| 7374 | nla_put_failure: |
| 7375 | genlmsg_cancel(msg, hdr); |
| 7376 | nlmsg_free(msg); |
| 7377 | } |
| 7378 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7379 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7380 | struct net_device *netdev, int index, |
| 7381 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7382 | { |
| 7383 | struct sk_buff *msg; |
| 7384 | struct nlattr *attr; |
| 7385 | void *hdr; |
| 7386 | |
| 7387 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7388 | if (!msg) |
| 7389 | return; |
| 7390 | |
| 7391 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7392 | if (!hdr) { |
| 7393 | nlmsg_free(msg); |
| 7394 | return; |
| 7395 | } |
| 7396 | |
| 7397 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7398 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7399 | |
| 7400 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7401 | if (!attr) |
| 7402 | goto nla_put_failure; |
| 7403 | |
| 7404 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7405 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7406 | if (preauth) |
| 7407 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7408 | |
| 7409 | nla_nest_end(msg, attr); |
| 7410 | |
| 7411 | if (genlmsg_end(msg, hdr) < 0) { |
| 7412 | nlmsg_free(msg); |
| 7413 | return; |
| 7414 | } |
| 7415 | |
| 7416 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7417 | nl80211_mlme_mcgrp.id, gfp); |
| 7418 | return; |
| 7419 | |
| 7420 | nla_put_failure: |
| 7421 | genlmsg_cancel(msg, hdr); |
| 7422 | nlmsg_free(msg); |
| 7423 | } |
| 7424 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7425 | void |
| 7426 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7427 | struct net_device *netdev, const u8 *peer, |
| 7428 | u32 num_packets, gfp_t gfp) |
| 7429 | { |
| 7430 | struct sk_buff *msg; |
| 7431 | struct nlattr *pinfoattr; |
| 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_NOTIFY_CQM); |
| 7439 | if (!hdr) { |
| 7440 | nlmsg_free(msg); |
| 7441 | return; |
| 7442 | } |
| 7443 | |
| 7444 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7445 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7446 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7447 | |
| 7448 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7449 | if (!pinfoattr) |
| 7450 | goto nla_put_failure; |
| 7451 | |
| 7452 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7453 | |
| 7454 | nla_nest_end(msg, pinfoattr); |
| 7455 | |
| 7456 | if (genlmsg_end(msg, hdr) < 0) { |
| 7457 | nlmsg_free(msg); |
| 7458 | return; |
| 7459 | } |
| 7460 | |
| 7461 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7462 | nl80211_mlme_mcgrp.id, gfp); |
| 7463 | return; |
| 7464 | |
| 7465 | nla_put_failure: |
| 7466 | genlmsg_cancel(msg, hdr); |
| 7467 | nlmsg_free(msg); |
| 7468 | } |
| 7469 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7470 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7471 | unsigned long state, |
| 7472 | void *_notify) |
| 7473 | { |
| 7474 | struct netlink_notify *notify = _notify; |
| 7475 | struct cfg80211_registered_device *rdev; |
| 7476 | struct wireless_dev *wdev; |
| 7477 | |
| 7478 | if (state != NETLINK_URELEASE) |
| 7479 | return NOTIFY_DONE; |
| 7480 | |
| 7481 | rcu_read_lock(); |
| 7482 | |
| 7483 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 7484 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7485 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7486 | |
| 7487 | rcu_read_unlock(); |
| 7488 | |
| 7489 | return NOTIFY_DONE; |
| 7490 | } |
| 7491 | |
| 7492 | static struct notifier_block nl80211_netlink_notifier = { |
| 7493 | .notifier_call = nl80211_netlink_notify, |
| 7494 | }; |
| 7495 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7496 | /* initialisation/exit functions */ |
| 7497 | |
| 7498 | int nl80211_init(void) |
| 7499 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7500 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7501 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7502 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7503 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7504 | if (err) |
| 7505 | return err; |
| 7506 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7507 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7508 | if (err) |
| 7509 | goto err_out; |
| 7510 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7511 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7512 | if (err) |
| 7513 | goto err_out; |
| 7514 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7515 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7516 | if (err) |
| 7517 | goto err_out; |
| 7518 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7519 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7520 | if (err) |
| 7521 | goto err_out; |
| 7522 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7523 | #ifdef CONFIG_NL80211_TESTMODE |
| 7524 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7525 | if (err) |
| 7526 | goto err_out; |
| 7527 | #endif |
| 7528 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7529 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7530 | if (err) |
| 7531 | goto err_out; |
| 7532 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7533 | return 0; |
| 7534 | err_out: |
| 7535 | genl_unregister_family(&nl80211_fam); |
| 7536 | return err; |
| 7537 | } |
| 7538 | |
| 7539 | void nl80211_exit(void) |
| 7540 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7541 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7542 | genl_unregister_family(&nl80211_fam); |
| 7543 | } |