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 | |
| 92 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 93 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .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 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 135 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 136 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 137 | |
| 138 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 139 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 140 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 141 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 142 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 143 | |
| 144 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 145 | .len = IEEE80211_MAX_SSID_LEN }, |
| 146 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 147 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 148 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 150 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 151 | [NL80211_ATTR_STA_FLAGS2] = { |
| 152 | .len = sizeof(struct nl80211_sta_flag_update), |
| 153 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 154 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 155 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 156 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 157 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 158 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 159 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 160 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 161 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 162 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 163 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 164 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 165 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 166 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 167 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 168 | .len = IEEE80211_MAX_DATA_LEN }, |
| 169 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 171 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 172 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 173 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 174 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 175 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 176 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 177 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 178 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 179 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 180 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 181 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 182 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 183 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 184 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 185 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 186 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 187 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 188 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 189 | .len = IEEE80211_MAX_DATA_LEN }, |
| 190 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 191 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 192 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 193 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 194 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 195 | }; |
| 196 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 197 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 198 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 199 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 200 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 201 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 202 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 203 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 204 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 205 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 206 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 207 | }; |
| 208 | |
| 209 | /* policy for the key default flags */ |
| 210 | static const struct nla_policy |
| 211 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 212 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 213 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 214 | }; |
| 215 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 216 | /* policy for WoWLAN attributes */ |
| 217 | static const struct nla_policy |
| 218 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 219 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 220 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 221 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 222 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 223 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 224 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 225 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 226 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 227 | }; |
| 228 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 229 | /* policy for GTK rekey offload attributes */ |
| 230 | static const struct nla_policy |
| 231 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 232 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 233 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 234 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 235 | }; |
| 236 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 237 | static const struct nla_policy |
| 238 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 239 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 240 | .len = IEEE80211_MAX_SSID_LEN }, |
| 241 | }; |
| 242 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 243 | /* ifidx get helper */ |
| 244 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 245 | { |
| 246 | int res; |
| 247 | |
| 248 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 249 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 250 | nl80211_policy); |
| 251 | if (res) |
| 252 | return res; |
| 253 | |
| 254 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 255 | return -EINVAL; |
| 256 | |
| 257 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 258 | if (!res) |
| 259 | return -EINVAL; |
| 260 | return res; |
| 261 | } |
| 262 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 263 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 264 | struct netlink_callback *cb, |
| 265 | struct cfg80211_registered_device **rdev, |
| 266 | struct net_device **dev) |
| 267 | { |
| 268 | int ifidx = cb->args[0]; |
| 269 | int err; |
| 270 | |
| 271 | if (!ifidx) |
| 272 | ifidx = nl80211_get_ifidx(cb); |
| 273 | if (ifidx < 0) |
| 274 | return ifidx; |
| 275 | |
| 276 | cb->args[0] = ifidx; |
| 277 | |
| 278 | rtnl_lock(); |
| 279 | |
| 280 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 281 | if (!*dev) { |
| 282 | err = -ENODEV; |
| 283 | goto out_rtnl; |
| 284 | } |
| 285 | |
| 286 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 287 | if (IS_ERR(*rdev)) { |
| 288 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 289 | goto out_rtnl; |
| 290 | } |
| 291 | |
| 292 | return 0; |
| 293 | out_rtnl: |
| 294 | rtnl_unlock(); |
| 295 | return err; |
| 296 | } |
| 297 | |
| 298 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 299 | { |
| 300 | cfg80211_unlock_rdev(rdev); |
| 301 | rtnl_unlock(); |
| 302 | } |
| 303 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 304 | /* IE validation */ |
| 305 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 306 | { |
| 307 | const u8 *pos; |
| 308 | int len; |
| 309 | |
| 310 | if (!attr) |
| 311 | return true; |
| 312 | |
| 313 | pos = nla_data(attr); |
| 314 | len = nla_len(attr); |
| 315 | |
| 316 | while (len) { |
| 317 | u8 elemlen; |
| 318 | |
| 319 | if (len < 2) |
| 320 | return false; |
| 321 | len -= 2; |
| 322 | |
| 323 | elemlen = pos[1]; |
| 324 | if (elemlen > len) |
| 325 | return false; |
| 326 | |
| 327 | len -= elemlen; |
| 328 | pos += 2 + elemlen; |
| 329 | } |
| 330 | |
| 331 | return true; |
| 332 | } |
| 333 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 334 | /* message building helper */ |
| 335 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 336 | int flags, u8 cmd) |
| 337 | { |
| 338 | /* since there is no private header just add the generic one */ |
| 339 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 340 | } |
| 341 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 342 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 343 | struct ieee80211_channel *chan) |
| 344 | { |
| 345 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 346 | chan->center_freq); |
| 347 | |
| 348 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 349 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 350 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 351 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 352 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 353 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 354 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 355 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 356 | |
| 357 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 358 | DBM_TO_MBM(chan->max_power)); |
| 359 | |
| 360 | return 0; |
| 361 | |
| 362 | nla_put_failure: |
| 363 | return -ENOBUFS; |
| 364 | } |
| 365 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 366 | /* netlink command implementations */ |
| 367 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 368 | struct key_parse { |
| 369 | struct key_params p; |
| 370 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 371 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 372 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 373 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 374 | }; |
| 375 | |
| 376 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 377 | { |
| 378 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 379 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 380 | nl80211_key_policy); |
| 381 | if (err) |
| 382 | return err; |
| 383 | |
| 384 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 385 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 386 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 387 | if (k->def) { |
| 388 | k->def_uni = true; |
| 389 | k->def_multi = true; |
| 390 | } |
| 391 | if (k->defmgmt) |
| 392 | k->def_multi = true; |
| 393 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 394 | if (tb[NL80211_KEY_IDX]) |
| 395 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 396 | |
| 397 | if (tb[NL80211_KEY_DATA]) { |
| 398 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 399 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 400 | } |
| 401 | |
| 402 | if (tb[NL80211_KEY_SEQ]) { |
| 403 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 404 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 405 | } |
| 406 | |
| 407 | if (tb[NL80211_KEY_CIPHER]) |
| 408 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 409 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 410 | if (tb[NL80211_KEY_TYPE]) { |
| 411 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 412 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 413 | return -EINVAL; |
| 414 | } |
| 415 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 416 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 417 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 418 | int err = nla_parse_nested(kdt, |
| 419 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 420 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 421 | nl80211_key_default_policy); |
| 422 | if (err) |
| 423 | return err; |
| 424 | |
| 425 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 426 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 427 | } |
| 428 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 433 | { |
| 434 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 435 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 436 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 437 | } |
| 438 | |
| 439 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 440 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 441 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 442 | } |
| 443 | |
| 444 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 445 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 446 | |
| 447 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 448 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 449 | |
| 450 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 451 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 452 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 453 | if (k->def) { |
| 454 | k->def_uni = true; |
| 455 | k->def_multi = true; |
| 456 | } |
| 457 | if (k->defmgmt) |
| 458 | k->def_multi = true; |
| 459 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 460 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 461 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 462 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 463 | return -EINVAL; |
| 464 | } |
| 465 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 466 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 467 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 468 | int err = nla_parse_nested( |
| 469 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 470 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 471 | nl80211_key_default_policy); |
| 472 | if (err) |
| 473 | return err; |
| 474 | |
| 475 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 476 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 477 | } |
| 478 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 483 | { |
| 484 | int err; |
| 485 | |
| 486 | memset(k, 0, sizeof(*k)); |
| 487 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 488 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 489 | |
| 490 | if (info->attrs[NL80211_ATTR_KEY]) |
| 491 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 492 | else |
| 493 | err = nl80211_parse_key_old(info, k); |
| 494 | |
| 495 | if (err) |
| 496 | return err; |
| 497 | |
| 498 | if (k->def && k->defmgmt) |
| 499 | return -EINVAL; |
| 500 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 501 | if (k->defmgmt) { |
| 502 | if (k->def_uni || !k->def_multi) |
| 503 | return -EINVAL; |
| 504 | } |
| 505 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 506 | if (k->idx != -1) { |
| 507 | if (k->defmgmt) { |
| 508 | if (k->idx < 4 || k->idx > 5) |
| 509 | return -EINVAL; |
| 510 | } else if (k->def) { |
| 511 | if (k->idx < 0 || k->idx > 3) |
| 512 | return -EINVAL; |
| 513 | } else { |
| 514 | if (k->idx < 0 || k->idx > 5) |
| 515 | return -EINVAL; |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 522 | static struct cfg80211_cached_keys * |
| 523 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 524 | struct nlattr *keys) |
| 525 | { |
| 526 | struct key_parse parse; |
| 527 | struct nlattr *key; |
| 528 | struct cfg80211_cached_keys *result; |
| 529 | int rem, err, def = 0; |
| 530 | |
| 531 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 532 | if (!result) |
| 533 | return ERR_PTR(-ENOMEM); |
| 534 | |
| 535 | result->def = -1; |
| 536 | result->defmgmt = -1; |
| 537 | |
| 538 | nla_for_each_nested(key, keys, rem) { |
| 539 | memset(&parse, 0, sizeof(parse)); |
| 540 | parse.idx = -1; |
| 541 | |
| 542 | err = nl80211_parse_key_new(key, &parse); |
| 543 | if (err) |
| 544 | goto error; |
| 545 | err = -EINVAL; |
| 546 | if (!parse.p.key) |
| 547 | goto error; |
| 548 | if (parse.idx < 0 || parse.idx > 4) |
| 549 | goto error; |
| 550 | if (parse.def) { |
| 551 | if (def) |
| 552 | goto error; |
| 553 | def = 1; |
| 554 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 555 | if (!parse.def_uni || !parse.def_multi) |
| 556 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 557 | } else if (parse.defmgmt) |
| 558 | goto error; |
| 559 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 560 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 561 | if (err) |
| 562 | goto error; |
| 563 | result->params[parse.idx].cipher = parse.p.cipher; |
| 564 | result->params[parse.idx].key_len = parse.p.key_len; |
| 565 | result->params[parse.idx].key = result->data[parse.idx]; |
| 566 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 567 | } |
| 568 | |
| 569 | return result; |
| 570 | error: |
| 571 | kfree(result); |
| 572 | return ERR_PTR(err); |
| 573 | } |
| 574 | |
| 575 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 576 | { |
| 577 | ASSERT_WDEV_LOCK(wdev); |
| 578 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 579 | switch (wdev->iftype) { |
| 580 | case NL80211_IFTYPE_AP: |
| 581 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 582 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 583 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 584 | break; |
| 585 | case NL80211_IFTYPE_ADHOC: |
| 586 | if (!wdev->current_bss) |
| 587 | return -ENOLINK; |
| 588 | break; |
| 589 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 590 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 591 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 592 | return -ENOLINK; |
| 593 | break; |
| 594 | default: |
| 595 | return -EINVAL; |
| 596 | } |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 601 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 602 | { |
| 603 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 604 | int i; |
| 605 | |
| 606 | if (!nl_modes) |
| 607 | goto nla_put_failure; |
| 608 | |
| 609 | i = 0; |
| 610 | while (ifmodes) { |
| 611 | if (ifmodes & 1) |
| 612 | NLA_PUT_FLAG(msg, i); |
| 613 | ifmodes >>= 1; |
| 614 | i++; |
| 615 | } |
| 616 | |
| 617 | nla_nest_end(msg, nl_modes); |
| 618 | return 0; |
| 619 | |
| 620 | nla_put_failure: |
| 621 | return -ENOBUFS; |
| 622 | } |
| 623 | |
| 624 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 625 | struct sk_buff *msg) |
| 626 | { |
| 627 | struct nlattr *nl_combis; |
| 628 | int i, j; |
| 629 | |
| 630 | nl_combis = nla_nest_start(msg, |
| 631 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 632 | if (!nl_combis) |
| 633 | goto nla_put_failure; |
| 634 | |
| 635 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 636 | const struct ieee80211_iface_combination *c; |
| 637 | struct nlattr *nl_combi, *nl_limits; |
| 638 | |
| 639 | c = &wiphy->iface_combinations[i]; |
| 640 | |
| 641 | nl_combi = nla_nest_start(msg, i + 1); |
| 642 | if (!nl_combi) |
| 643 | goto nla_put_failure; |
| 644 | |
| 645 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 646 | if (!nl_limits) |
| 647 | goto nla_put_failure; |
| 648 | |
| 649 | for (j = 0; j < c->n_limits; j++) { |
| 650 | struct nlattr *nl_limit; |
| 651 | |
| 652 | nl_limit = nla_nest_start(msg, j + 1); |
| 653 | if (!nl_limit) |
| 654 | goto nla_put_failure; |
| 655 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 656 | c->limits[j].max); |
| 657 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 658 | c->limits[j].types)) |
| 659 | goto nla_put_failure; |
| 660 | nla_nest_end(msg, nl_limit); |
| 661 | } |
| 662 | |
| 663 | nla_nest_end(msg, nl_limits); |
| 664 | |
| 665 | if (c->beacon_int_infra_match) |
| 666 | NLA_PUT_FLAG(msg, |
| 667 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 668 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 669 | c->num_different_channels); |
| 670 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 671 | c->max_interfaces); |
| 672 | |
| 673 | nla_nest_end(msg, nl_combi); |
| 674 | } |
| 675 | |
| 676 | nla_nest_end(msg, nl_combis); |
| 677 | |
| 678 | return 0; |
| 679 | nla_put_failure: |
| 680 | return -ENOBUFS; |
| 681 | } |
| 682 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 683 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 684 | struct cfg80211_registered_device *dev) |
| 685 | { |
| 686 | void *hdr; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 687 | struct nlattr *nl_bands, *nl_band; |
| 688 | struct nlattr *nl_freqs, *nl_freq; |
| 689 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 690 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 691 | enum ieee80211_band band; |
| 692 | struct ieee80211_channel *chan; |
| 693 | struct ieee80211_rate *rate; |
| 694 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 695 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 696 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 697 | |
| 698 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 699 | if (!hdr) |
| 700 | return -1; |
| 701 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 702 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 703 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 704 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 705 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 706 | cfg80211_rdev_list_generation); |
| 707 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 708 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 709 | dev->wiphy.retry_short); |
| 710 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 711 | dev->wiphy.retry_long); |
| 712 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 713 | dev->wiphy.frag_threshold); |
| 714 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 715 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 716 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 717 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 718 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 719 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 720 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 721 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 722 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 723 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 724 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 725 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 726 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 727 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 728 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 729 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 730 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 731 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 732 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 733 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 734 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 735 | |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 736 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 737 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
| 738 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 739 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 740 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 741 | dev->wiphy.cipher_suites); |
| 742 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 743 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 744 | dev->wiphy.max_num_pmkids); |
| 745 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 746 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 747 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 748 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 749 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 750 | dev->wiphy.available_antennas_tx); |
| 751 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 752 | dev->wiphy.available_antennas_rx); |
| 753 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 754 | if ((dev->wiphy.available_antennas_tx || |
| 755 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 756 | u32 tx_ant = 0, rx_ant = 0; |
| 757 | int res; |
| 758 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 759 | if (!res) { |
| 760 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 761 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 762 | } |
| 763 | } |
| 764 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 765 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 766 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 767 | goto nla_put_failure; |
| 768 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 769 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 770 | if (!nl_bands) |
| 771 | goto nla_put_failure; |
| 772 | |
| 773 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 774 | if (!dev->wiphy.bands[band]) |
| 775 | continue; |
| 776 | |
| 777 | nl_band = nla_nest_start(msg, band); |
| 778 | if (!nl_band) |
| 779 | goto nla_put_failure; |
| 780 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 781 | /* add HT info */ |
| 782 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 783 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 784 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 785 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 786 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 787 | dev->wiphy.bands[band]->ht_cap.cap); |
| 788 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 789 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 790 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 791 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 792 | } |
| 793 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 794 | /* add frequencies */ |
| 795 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 796 | if (!nl_freqs) |
| 797 | goto nla_put_failure; |
| 798 | |
| 799 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 800 | nl_freq = nla_nest_start(msg, i); |
| 801 | if (!nl_freq) |
| 802 | goto nla_put_failure; |
| 803 | |
| 804 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 805 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 806 | if (nl80211_msg_put_channel(msg, chan)) |
| 807 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 808 | |
Johannes Berg | ee688b0 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 809 | nla_nest_end(msg, nl_freq); |
| 810 | } |
| 811 | |
| 812 | nla_nest_end(msg, nl_freqs); |
| 813 | |
| 814 | /* add bitrates */ |
| 815 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 816 | if (!nl_rates) |
| 817 | goto nla_put_failure; |
| 818 | |
| 819 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 820 | nl_rate = nla_nest_start(msg, i); |
| 821 | if (!nl_rate) |
| 822 | goto nla_put_failure; |
| 823 | |
| 824 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 825 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 826 | rate->bitrate); |
| 827 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 828 | NLA_PUT_FLAG(msg, |
| 829 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 830 | |
| 831 | nla_nest_end(msg, nl_rate); |
| 832 | } |
| 833 | |
| 834 | nla_nest_end(msg, nl_rates); |
| 835 | |
| 836 | nla_nest_end(msg, nl_band); |
| 837 | } |
| 838 | nla_nest_end(msg, nl_bands); |
| 839 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 840 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 841 | if (!nl_cmds) |
| 842 | goto nla_put_failure; |
| 843 | |
| 844 | i = 0; |
| 845 | #define CMD(op, n) \ |
| 846 | do { \ |
| 847 | if (dev->ops->op) { \ |
| 848 | i++; \ |
| 849 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 850 | } \ |
| 851 | } while (0) |
| 852 | |
| 853 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 854 | CMD(change_virtual_intf, SET_INTERFACE); |
| 855 | CMD(add_key, NEW_KEY); |
| 856 | CMD(add_beacon, NEW_BEACON); |
| 857 | CMD(add_station, NEW_STATION); |
| 858 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 859 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 860 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 861 | CMD(auth, AUTHENTICATE); |
| 862 | CMD(assoc, ASSOCIATE); |
| 863 | CMD(deauth, DEAUTHENTICATE); |
| 864 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 865 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 866 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 867 | CMD(set_pmksa, SET_PMKSA); |
| 868 | CMD(del_pmksa, DEL_PMKSA); |
| 869 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 870 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 871 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 872 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 873 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 874 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 875 | i++; |
| 876 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 877 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 878 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 879 | CMD(set_wds_peer, SET_WDS_PEER); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 880 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 881 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 882 | |
| 883 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 884 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 885 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 886 | i++; |
| 887 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 888 | } |
| 889 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 890 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 891 | i++; |
| 892 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 893 | } |
| 894 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 895 | nla_nest_end(msg, nl_cmds); |
| 896 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 897 | if (dev->ops->remain_on_channel) |
| 898 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 899 | dev->wiphy.max_remain_on_channel_duration); |
| 900 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 901 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 902 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 903 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 904 | if (mgmt_stypes) { |
| 905 | u16 stypes; |
| 906 | struct nlattr *nl_ftypes, *nl_ifs; |
| 907 | enum nl80211_iftype ift; |
| 908 | |
| 909 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 910 | if (!nl_ifs) |
| 911 | goto nla_put_failure; |
| 912 | |
| 913 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 914 | nl_ftypes = nla_nest_start(msg, ift); |
| 915 | if (!nl_ftypes) |
| 916 | goto nla_put_failure; |
| 917 | i = 0; |
| 918 | stypes = mgmt_stypes[ift].tx; |
| 919 | while (stypes) { |
| 920 | if (stypes & 1) |
| 921 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 922 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 923 | stypes >>= 1; |
| 924 | i++; |
| 925 | } |
| 926 | nla_nest_end(msg, nl_ftypes); |
| 927 | } |
| 928 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 929 | nla_nest_end(msg, nl_ifs); |
| 930 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 931 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 932 | if (!nl_ifs) |
| 933 | goto nla_put_failure; |
| 934 | |
| 935 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 936 | nl_ftypes = nla_nest_start(msg, ift); |
| 937 | if (!nl_ftypes) |
| 938 | goto nla_put_failure; |
| 939 | i = 0; |
| 940 | stypes = mgmt_stypes[ift].rx; |
| 941 | while (stypes) { |
| 942 | if (stypes & 1) |
| 943 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 944 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 945 | stypes >>= 1; |
| 946 | i++; |
| 947 | } |
| 948 | nla_nest_end(msg, nl_ftypes); |
| 949 | } |
| 950 | nla_nest_end(msg, nl_ifs); |
| 951 | } |
| 952 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 953 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 954 | struct nlattr *nl_wowlan; |
| 955 | |
| 956 | nl_wowlan = nla_nest_start(msg, |
| 957 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 958 | if (!nl_wowlan) |
| 959 | goto nla_put_failure; |
| 960 | |
| 961 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 962 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 963 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 964 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 965 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 966 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 967 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 968 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 969 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 970 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 971 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 972 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 973 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 974 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 975 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 976 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 977 | if (dev->wiphy.wowlan.n_patterns) { |
| 978 | struct nl80211_wowlan_pattern_support pat = { |
| 979 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 980 | .min_pattern_len = |
| 981 | dev->wiphy.wowlan.pattern_min_len, |
| 982 | .max_pattern_len = |
| 983 | dev->wiphy.wowlan.pattern_max_len, |
| 984 | }; |
| 985 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 986 | sizeof(pat), &pat); |
| 987 | } |
| 988 | |
| 989 | nla_nest_end(msg, nl_wowlan); |
| 990 | } |
| 991 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 992 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 993 | dev->wiphy.software_iftypes)) |
| 994 | goto nla_put_failure; |
| 995 | |
| 996 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 997 | goto nla_put_failure; |
| 998 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 999 | return genlmsg_end(msg, hdr); |
| 1000 | |
| 1001 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1002 | genlmsg_cancel(msg, hdr); |
| 1003 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1007 | { |
| 1008 | int idx = 0; |
| 1009 | int start = cb->args[0]; |
| 1010 | struct cfg80211_registered_device *dev; |
| 1011 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1012 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1013 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1014 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1015 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1016 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1017 | continue; |
| 1018 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1019 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1020 | dev) < 0) { |
| 1021 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1022 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1023 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1024 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1025 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1026 | |
| 1027 | cb->args[0] = idx; |
| 1028 | |
| 1029 | return skb->len; |
| 1030 | } |
| 1031 | |
| 1032 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1033 | { |
| 1034 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1035 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1036 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1038 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1039 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1040 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1041 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1042 | nlmsg_free(msg); |
| 1043 | return -ENOBUFS; |
| 1044 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1045 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1046 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1047 | } |
| 1048 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1049 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1050 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1051 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1052 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1053 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1054 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1055 | }; |
| 1056 | |
| 1057 | static int parse_txq_params(struct nlattr *tb[], |
| 1058 | struct ieee80211_txq_params *txq_params) |
| 1059 | { |
| 1060 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1061 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1062 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1063 | return -EINVAL; |
| 1064 | |
| 1065 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1066 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1067 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1068 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1069 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1074 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1075 | { |
| 1076 | /* |
| 1077 | * You can only set the channel explicitly for AP, mesh |
| 1078 | * and WDS type interfaces; all others have their channel |
| 1079 | * managed via their respective "establish a connection" |
| 1080 | * command (connect, join, ...) |
| 1081 | * |
| 1082 | * Monitors are special as they are normally slaved to |
| 1083 | * whatever else is going on, so they behave as though |
| 1084 | * you tried setting the wiphy channel itself. |
| 1085 | */ |
| 1086 | return !wdev || |
| 1087 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1088 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1089 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1090 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1091 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1095 | struct wireless_dev *wdev, |
| 1096 | struct genl_info *info) |
| 1097 | { |
| 1098 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1099 | u32 freq; |
| 1100 | int result; |
| 1101 | |
| 1102 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1103 | return -EINVAL; |
| 1104 | |
| 1105 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1106 | return -EOPNOTSUPP; |
| 1107 | |
| 1108 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1109 | channel_type = nla_get_u32(info->attrs[ |
| 1110 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1111 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1112 | channel_type != NL80211_CHAN_HT20 && |
| 1113 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1114 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1115 | return -EINVAL; |
| 1116 | } |
| 1117 | |
| 1118 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1119 | |
| 1120 | mutex_lock(&rdev->devlist_mtx); |
| 1121 | if (wdev) { |
| 1122 | wdev_lock(wdev); |
| 1123 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1124 | wdev_unlock(wdev); |
| 1125 | } else { |
| 1126 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1127 | } |
| 1128 | mutex_unlock(&rdev->devlist_mtx); |
| 1129 | |
| 1130 | return result; |
| 1131 | } |
| 1132 | |
| 1133 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1134 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1135 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1136 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1137 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1138 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1141 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1142 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1143 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1144 | struct net_device *dev = info->user_ptr[1]; |
| 1145 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1146 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1147 | |
| 1148 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1149 | return -EINVAL; |
| 1150 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1151 | if (netif_running(dev)) |
| 1152 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1153 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1154 | if (!rdev->ops->set_wds_peer) |
| 1155 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1156 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1157 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1158 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1159 | |
| 1160 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1161 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1165 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1166 | { |
| 1167 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1168 | struct net_device *netdev = NULL; |
| 1169 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1170 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1171 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1172 | u32 changed; |
| 1173 | u8 retry_short = 0, retry_long = 0; |
| 1174 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1175 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1176 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1177 | /* |
| 1178 | * Try to find the wiphy and netdev. Normally this |
| 1179 | * function shouldn't need the netdev, but this is |
| 1180 | * done for backward compatibility -- previously |
| 1181 | * setting the channel was done per wiphy, but now |
| 1182 | * it is per netdev. Previous userland like hostapd |
| 1183 | * also passed a netdev to set_wiphy, so that it is |
| 1184 | * possible to let that go to the right netdev! |
| 1185 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1186 | mutex_lock(&cfg80211_mutex); |
| 1187 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1188 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1189 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1190 | |
| 1191 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1192 | if (netdev && netdev->ieee80211_ptr) { |
| 1193 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1194 | mutex_lock(&rdev->mtx); |
| 1195 | } else |
| 1196 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1197 | } |
| 1198 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1199 | if (!netdev) { |
| 1200 | rdev = __cfg80211_rdev_from_info(info); |
| 1201 | if (IS_ERR(rdev)) { |
| 1202 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1203 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1204 | } |
| 1205 | wdev = NULL; |
| 1206 | netdev = NULL; |
| 1207 | result = 0; |
| 1208 | |
| 1209 | mutex_lock(&rdev->mtx); |
| 1210 | } else if (netif_running(netdev) && |
| 1211 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1212 | wdev = netdev->ieee80211_ptr; |
| 1213 | else |
| 1214 | wdev = NULL; |
| 1215 | |
| 1216 | /* |
| 1217 | * end workaround code, by now the rdev is available |
| 1218 | * and locked, and wdev may or may not be NULL. |
| 1219 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1220 | |
| 1221 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1222 | result = cfg80211_dev_rename( |
| 1223 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1224 | |
| 1225 | mutex_unlock(&cfg80211_mutex); |
| 1226 | |
| 1227 | if (result) |
| 1228 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1229 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1230 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1231 | struct ieee80211_txq_params txq_params; |
| 1232 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1233 | |
| 1234 | if (!rdev->ops->set_txq_params) { |
| 1235 | result = -EOPNOTSUPP; |
| 1236 | goto bad_res; |
| 1237 | } |
| 1238 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1239 | if (!netdev) { |
| 1240 | result = -EINVAL; |
| 1241 | goto bad_res; |
| 1242 | } |
| 1243 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1244 | nla_for_each_nested(nl_txq_params, |
| 1245 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1246 | rem_txq_params) { |
| 1247 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1248 | nla_data(nl_txq_params), |
| 1249 | nla_len(nl_txq_params), |
| 1250 | txq_params_policy); |
| 1251 | result = parse_txq_params(tb, &txq_params); |
| 1252 | if (result) |
| 1253 | goto bad_res; |
| 1254 | |
| 1255 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1256 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1257 | &txq_params); |
| 1258 | if (result) |
| 1259 | goto bad_res; |
| 1260 | } |
| 1261 | } |
| 1262 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1263 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1264 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1265 | if (result) |
| 1266 | goto bad_res; |
| 1267 | } |
| 1268 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1269 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1270 | enum nl80211_tx_power_setting type; |
| 1271 | int idx, mbm = 0; |
| 1272 | |
| 1273 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1274 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1275 | goto bad_res; |
| 1276 | } |
| 1277 | |
| 1278 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1279 | type = nla_get_u32(info->attrs[idx]); |
| 1280 | |
| 1281 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1282 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1283 | result = -EINVAL; |
| 1284 | goto bad_res; |
| 1285 | } |
| 1286 | |
| 1287 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1288 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1289 | mbm = nla_get_u32(info->attrs[idx]); |
| 1290 | } |
| 1291 | |
| 1292 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1293 | if (result) |
| 1294 | goto bad_res; |
| 1295 | } |
| 1296 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1297 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1298 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1299 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1300 | if ((!rdev->wiphy.available_antennas_tx && |
| 1301 | !rdev->wiphy.available_antennas_rx) || |
| 1302 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1303 | result = -EOPNOTSUPP; |
| 1304 | goto bad_res; |
| 1305 | } |
| 1306 | |
| 1307 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1308 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1309 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1310 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1311 | * available antenna masks, except for the "all" mask */ |
| 1312 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1313 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1314 | result = -EINVAL; |
| 1315 | goto bad_res; |
| 1316 | } |
| 1317 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1318 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1319 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1320 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1321 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1322 | if (result) |
| 1323 | goto bad_res; |
| 1324 | } |
| 1325 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1326 | changed = 0; |
| 1327 | |
| 1328 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1329 | retry_short = nla_get_u8( |
| 1330 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1331 | if (retry_short == 0) { |
| 1332 | result = -EINVAL; |
| 1333 | goto bad_res; |
| 1334 | } |
| 1335 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1336 | } |
| 1337 | |
| 1338 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1339 | retry_long = nla_get_u8( |
| 1340 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1341 | if (retry_long == 0) { |
| 1342 | result = -EINVAL; |
| 1343 | goto bad_res; |
| 1344 | } |
| 1345 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1346 | } |
| 1347 | |
| 1348 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1349 | frag_threshold = nla_get_u32( |
| 1350 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1351 | if (frag_threshold < 256) { |
| 1352 | result = -EINVAL; |
| 1353 | goto bad_res; |
| 1354 | } |
| 1355 | if (frag_threshold != (u32) -1) { |
| 1356 | /* |
| 1357 | * Fragments (apart from the last one) are required to |
| 1358 | * have even length. Make the fragmentation code |
| 1359 | * simpler by stripping LSB should someone try to use |
| 1360 | * odd threshold value. |
| 1361 | */ |
| 1362 | frag_threshold &= ~0x1; |
| 1363 | } |
| 1364 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1365 | } |
| 1366 | |
| 1367 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1368 | rts_threshold = nla_get_u32( |
| 1369 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1370 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1371 | } |
| 1372 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1373 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1374 | coverage_class = nla_get_u8( |
| 1375 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1376 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1377 | } |
| 1378 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1379 | if (changed) { |
| 1380 | u8 old_retry_short, old_retry_long; |
| 1381 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1382 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1383 | |
| 1384 | if (!rdev->ops->set_wiphy_params) { |
| 1385 | result = -EOPNOTSUPP; |
| 1386 | goto bad_res; |
| 1387 | } |
| 1388 | |
| 1389 | old_retry_short = rdev->wiphy.retry_short; |
| 1390 | old_retry_long = rdev->wiphy.retry_long; |
| 1391 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1392 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1393 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1394 | |
| 1395 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1396 | rdev->wiphy.retry_short = retry_short; |
| 1397 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1398 | rdev->wiphy.retry_long = retry_long; |
| 1399 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1400 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1401 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1402 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1403 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1404 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1405 | |
| 1406 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1407 | if (result) { |
| 1408 | rdev->wiphy.retry_short = old_retry_short; |
| 1409 | rdev->wiphy.retry_long = old_retry_long; |
| 1410 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1411 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1412 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1413 | } |
| 1414 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1415 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1416 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1417 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1418 | if (netdev) |
| 1419 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1420 | return result; |
| 1421 | } |
| 1422 | |
| 1423 | |
| 1424 | 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] | 1425 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1426 | struct net_device *dev) |
| 1427 | { |
| 1428 | void *hdr; |
| 1429 | |
| 1430 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1431 | if (!hdr) |
| 1432 | return -1; |
| 1433 | |
| 1434 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1435 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1436 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1437 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1438 | |
| 1439 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1440 | rdev->devlist_generation ^ |
| 1441 | (cfg80211_rdev_list_generation << 2)); |
| 1442 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1443 | return genlmsg_end(msg, hdr); |
| 1444 | |
| 1445 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1446 | genlmsg_cancel(msg, hdr); |
| 1447 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1451 | { |
| 1452 | int wp_idx = 0; |
| 1453 | int if_idx = 0; |
| 1454 | int wp_start = cb->args[0]; |
| 1455 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1456 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1457 | struct wireless_dev *wdev; |
| 1458 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1459 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1460 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1461 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1462 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1463 | if (wp_idx < wp_start) { |
| 1464 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1465 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1466 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1467 | if_idx = 0; |
| 1468 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1469 | mutex_lock(&rdev->devlist_mtx); |
| 1470 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1471 | if (if_idx < if_start) { |
| 1472 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1473 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1474 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1475 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1476 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1477 | rdev, wdev->netdev) < 0) { |
| 1478 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1479 | goto out; |
| 1480 | } |
| 1481 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1482 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1483 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1484 | |
| 1485 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1486 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1487 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1488 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1489 | |
| 1490 | cb->args[0] = wp_idx; |
| 1491 | cb->args[1] = if_idx; |
| 1492 | |
| 1493 | return skb->len; |
| 1494 | } |
| 1495 | |
| 1496 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1497 | { |
| 1498 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1499 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1500 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1501 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1502 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1503 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1504 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1505 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1506 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1507 | dev, netdev) < 0) { |
| 1508 | nlmsg_free(msg); |
| 1509 | return -ENOBUFS; |
| 1510 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1511 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1512 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1513 | } |
| 1514 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1515 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1516 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1517 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1518 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1519 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1520 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1521 | }; |
| 1522 | |
| 1523 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1524 | { |
| 1525 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1526 | int flag; |
| 1527 | |
| 1528 | *mntrflags = 0; |
| 1529 | |
| 1530 | if (!nla) |
| 1531 | return -EINVAL; |
| 1532 | |
| 1533 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1534 | nla, mntr_flags_policy)) |
| 1535 | return -EINVAL; |
| 1536 | |
| 1537 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1538 | if (flags[flag]) |
| 1539 | *mntrflags |= (1<<flag); |
| 1540 | |
| 1541 | return 0; |
| 1542 | } |
| 1543 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1544 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1545 | struct net_device *netdev, u8 use_4addr, |
| 1546 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1547 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1548 | if (!use_4addr) { |
Jiri Pirko | f350a0a | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1549 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1550 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1551 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1552 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1553 | |
| 1554 | switch (iftype) { |
| 1555 | case NL80211_IFTYPE_AP_VLAN: |
| 1556 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1557 | return 0; |
| 1558 | break; |
| 1559 | case NL80211_IFTYPE_STATION: |
| 1560 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1561 | return 0; |
| 1562 | break; |
| 1563 | default: |
| 1564 | break; |
| 1565 | } |
| 1566 | |
| 1567 | return -EOPNOTSUPP; |
| 1568 | } |
| 1569 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1570 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1571 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1573 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1574 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1575 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1576 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1577 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1578 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1579 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1580 | memset(¶ms, 0, sizeof(params)); |
| 1581 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1582 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1583 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1584 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1585 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1586 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1587 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1588 | if (ntype > NL80211_IFTYPE_MAX) |
| 1589 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1590 | } |
| 1591 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1592 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1593 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1594 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1595 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1596 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1597 | if (netif_running(dev)) |
| 1598 | return -EBUSY; |
| 1599 | |
| 1600 | wdev_lock(wdev); |
| 1601 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1602 | IEEE80211_MAX_MESH_ID_LEN); |
| 1603 | wdev->mesh_id_up_len = |
| 1604 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1605 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1606 | wdev->mesh_id_up_len); |
| 1607 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1608 | } |
| 1609 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1610 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1611 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1612 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1613 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1614 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1615 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1616 | } else { |
| 1617 | params.use_4addr = -1; |
| 1618 | } |
| 1619 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1620 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1621 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1622 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1623 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1624 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1625 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1626 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1627 | |
| 1628 | flags = &_flags; |
| 1629 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1630 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1631 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1632 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1633 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1634 | else |
| 1635 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1636 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1637 | if (!err && params.use_4addr != -1) |
| 1638 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1639 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1640 | return err; |
| 1641 | } |
| 1642 | |
| 1643 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1644 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1645 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1646 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1647 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1648 | int err; |
| 1649 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1650 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1651 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1652 | memset(¶ms, 0, sizeof(params)); |
| 1653 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1654 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1655 | return -EINVAL; |
| 1656 | |
| 1657 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1658 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1659 | if (type > NL80211_IFTYPE_MAX) |
| 1660 | return -EINVAL; |
| 1661 | } |
| 1662 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1663 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1664 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1665 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1666 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1667 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1668 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1669 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1670 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1671 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1672 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1673 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1674 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1675 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1676 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1677 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1678 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1679 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1680 | if (IS_ERR(dev)) |
| 1681 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1682 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1683 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1684 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1685 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1686 | |
| 1687 | wdev_lock(wdev); |
| 1688 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1689 | IEEE80211_MAX_MESH_ID_LEN); |
| 1690 | wdev->mesh_id_up_len = |
| 1691 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1692 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1693 | wdev->mesh_id_up_len); |
| 1694 | wdev_unlock(wdev); |
| 1695 | } |
| 1696 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1697 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1701 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1703 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1704 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1705 | if (!rdev->ops->del_virtual_intf) |
| 1706 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1707 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1708 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1709 | } |
| 1710 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1711 | struct get_key_cookie { |
| 1712 | struct sk_buff *msg; |
| 1713 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1714 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1715 | }; |
| 1716 | |
| 1717 | static void get_key_callback(void *c, struct key_params *params) |
| 1718 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1719 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1720 | struct get_key_cookie *cookie = c; |
| 1721 | |
| 1722 | if (params->key) |
| 1723 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1724 | params->key_len, params->key); |
| 1725 | |
| 1726 | if (params->seq) |
| 1727 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1728 | params->seq_len, params->seq); |
| 1729 | |
| 1730 | if (params->cipher) |
| 1731 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1732 | params->cipher); |
| 1733 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1734 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1735 | if (!key) |
| 1736 | goto nla_put_failure; |
| 1737 | |
| 1738 | if (params->key) |
| 1739 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1740 | params->key_len, params->key); |
| 1741 | |
| 1742 | if (params->seq) |
| 1743 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1744 | params->seq_len, params->seq); |
| 1745 | |
| 1746 | if (params->cipher) |
| 1747 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1748 | params->cipher); |
| 1749 | |
| 1750 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1751 | |
| 1752 | nla_nest_end(cookie->msg, key); |
| 1753 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1754 | return; |
| 1755 | nla_put_failure: |
| 1756 | cookie->error = 1; |
| 1757 | } |
| 1758 | |
| 1759 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1760 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1761 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1762 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1763 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1764 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1765 | const u8 *mac_addr = NULL; |
| 1766 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1767 | struct get_key_cookie cookie = { |
| 1768 | .error = 0, |
| 1769 | }; |
| 1770 | void *hdr; |
| 1771 | struct sk_buff *msg; |
| 1772 | |
| 1773 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1774 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1775 | |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1776 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1777 | return -EINVAL; |
| 1778 | |
| 1779 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1780 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1781 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1782 | pairwise = !!mac_addr; |
| 1783 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1784 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1785 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1786 | return -EINVAL; |
| 1787 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1788 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1789 | return -EINVAL; |
| 1790 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1791 | } |
| 1792 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1793 | if (!rdev->ops->get_key) |
| 1794 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1795 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1796 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1797 | if (!msg) |
| 1798 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1799 | |
| 1800 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1801 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1802 | if (IS_ERR(hdr)) |
| 1803 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1804 | |
| 1805 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1806 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1807 | |
| 1808 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1809 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1810 | if (mac_addr) |
| 1811 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1812 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1813 | if (pairwise && mac_addr && |
| 1814 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1815 | return -ENOENT; |
| 1816 | |
| 1817 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1818 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1819 | |
| 1820 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1821 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1822 | |
| 1823 | if (cookie.error) |
| 1824 | goto nla_put_failure; |
| 1825 | |
| 1826 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1827 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1828 | |
| 1829 | nla_put_failure: |
| 1830 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1831 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1832 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1833 | return err; |
| 1834 | } |
| 1835 | |
| 1836 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1837 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1839 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1840 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1841 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1842 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1843 | err = nl80211_parse_key(info, &key); |
| 1844 | if (err) |
| 1845 | return err; |
| 1846 | |
| 1847 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1848 | return -EINVAL; |
| 1849 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1850 | /* only support setting default key */ |
| 1851 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1852 | return -EINVAL; |
| 1853 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1854 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1855 | |
| 1856 | if (key.def) { |
| 1857 | if (!rdev->ops->set_default_key) { |
| 1858 | err = -EOPNOTSUPP; |
| 1859 | goto out; |
| 1860 | } |
| 1861 | |
| 1862 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1863 | if (err) |
| 1864 | goto out; |
| 1865 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1866 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1867 | key.def_uni, key.def_multi); |
| 1868 | |
| 1869 | if (err) |
| 1870 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1871 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1872 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1873 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1874 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1875 | } else { |
| 1876 | if (key.def_uni || !key.def_multi) { |
| 1877 | err = -EINVAL; |
| 1878 | goto out; |
| 1879 | } |
| 1880 | |
| 1881 | if (!rdev->ops->set_default_mgmt_key) { |
| 1882 | err = -EOPNOTSUPP; |
| 1883 | goto out; |
| 1884 | } |
| 1885 | |
| 1886 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1887 | if (err) |
| 1888 | goto out; |
| 1889 | |
| 1890 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1891 | dev, key.idx); |
| 1892 | if (err) |
| 1893 | goto out; |
| 1894 | |
| 1895 | #ifdef CONFIG_CFG80211_WEXT |
| 1896 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1897 | #endif |
| 1898 | } |
| 1899 | |
| 1900 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1901 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1902 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1903 | return err; |
| 1904 | } |
| 1905 | |
| 1906 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1907 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1909 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1910 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1911 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1912 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1913 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1914 | err = nl80211_parse_key(info, &key); |
| 1915 | if (err) |
| 1916 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1917 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1918 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1919 | return -EINVAL; |
| 1920 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1921 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1922 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1923 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1924 | if (key.type == -1) { |
| 1925 | if (mac_addr) |
| 1926 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1927 | else |
| 1928 | key.type = NL80211_KEYTYPE_GROUP; |
| 1929 | } |
| 1930 | |
| 1931 | /* for now */ |
| 1932 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1933 | key.type != NL80211_KEYTYPE_GROUP) |
| 1934 | return -EINVAL; |
| 1935 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1936 | if (!rdev->ops->add_key) |
| 1937 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1938 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1939 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1940 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1941 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1942 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1943 | |
| 1944 | wdev_lock(dev->ieee80211_ptr); |
| 1945 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1946 | if (!err) |
| 1947 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1948 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1949 | mac_addr, &key.p); |
| 1950 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1951 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1952 | return err; |
| 1953 | } |
| 1954 | |
| 1955 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1956 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1958 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1959 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1960 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1961 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1962 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1963 | err = nl80211_parse_key(info, &key); |
| 1964 | if (err) |
| 1965 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1966 | |
| 1967 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1968 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1969 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1970 | if (key.type == -1) { |
| 1971 | if (mac_addr) |
| 1972 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1973 | else |
| 1974 | key.type = NL80211_KEYTYPE_GROUP; |
| 1975 | } |
| 1976 | |
| 1977 | /* for now */ |
| 1978 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1979 | key.type != NL80211_KEYTYPE_GROUP) |
| 1980 | return -EINVAL; |
| 1981 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1982 | if (!rdev->ops->del_key) |
| 1983 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1984 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1985 | wdev_lock(dev->ieee80211_ptr); |
| 1986 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1987 | |
| 1988 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1989 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1990 | err = -ENOENT; |
| 1991 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1992 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1993 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1994 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1995 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1996 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1997 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1998 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1999 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2000 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2001 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2002 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2003 | } |
| 2004 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2005 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2006 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2007 | return err; |
| 2008 | } |
| 2009 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2010 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2011 | { |
| 2012 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 2013 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2015 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2016 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2017 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2018 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2019 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2020 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2021 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2022 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2023 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2024 | return -EINVAL; |
| 2025 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2026 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2027 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2028 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2029 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2030 | memset(¶ms, 0, sizeof(params)); |
| 2031 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2032 | switch (info->genlhdr->cmd) { |
| 2033 | case NL80211_CMD_NEW_BEACON: |
| 2034 | /* these are required for NEW_BEACON */ |
| 2035 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2036 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2037 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2038 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2039 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2040 | params.interval = |
| 2041 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2042 | params.dtim_period = |
| 2043 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2044 | |
| 2045 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2046 | if (err) |
| 2047 | return err; |
| 2048 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2049 | /* |
| 2050 | * In theory, some of these attributes could be required for |
| 2051 | * NEW_BEACON, but since they were not used when the command was |
| 2052 | * originally added, keep them optional for old user space |
| 2053 | * programs to work with drivers that do not need the additional |
| 2054 | * information. |
| 2055 | */ |
| 2056 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2057 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2058 | params.ssid_len = |
| 2059 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2060 | if (params.ssid_len == 0 || |
| 2061 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2062 | return -EINVAL; |
| 2063 | } |
| 2064 | |
| 2065 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2066 | params.hidden_ssid = nla_get_u32( |
| 2067 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2068 | if (params.hidden_ssid != |
| 2069 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2070 | params.hidden_ssid != |
| 2071 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2072 | params.hidden_ssid != |
| 2073 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2074 | return -EINVAL; |
| 2075 | } |
| 2076 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2077 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2078 | |
| 2079 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2080 | params.auth_type = nla_get_u32( |
| 2081 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2082 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2083 | return -EINVAL; |
| 2084 | } else |
| 2085 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2086 | |
| 2087 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2088 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2089 | if (err) |
| 2090 | return err; |
| 2091 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2092 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2093 | break; |
| 2094 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2095 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2096 | break; |
| 2097 | default: |
| 2098 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2099 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2100 | } |
| 2101 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2102 | if (!call) |
| 2103 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2104 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2105 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2106 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2107 | params.head_len = |
| 2108 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2109 | haveinfo = 1; |
| 2110 | } |
| 2111 | |
| 2112 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2113 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2114 | params.tail_len = |
| 2115 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2116 | haveinfo = 1; |
| 2117 | } |
| 2118 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2119 | if (!haveinfo) |
| 2120 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2121 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2122 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2123 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2124 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2125 | } |
| 2126 | |
| 2127 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2128 | params.proberesp_ies = |
| 2129 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2130 | params.proberesp_ies_len = |
| 2131 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2132 | } |
| 2133 | |
| 2134 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2135 | params.assocresp_ies = |
| 2136 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2137 | params.assocresp_ies_len = |
| 2138 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2139 | } |
| 2140 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2141 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2142 | if (!err && params.interval) |
| 2143 | wdev->beacon_interval = params.interval; |
| 2144 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2145 | } |
| 2146 | |
| 2147 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2148 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2150 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2151 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2152 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2153 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2154 | if (!rdev->ops->del_beacon) |
| 2155 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2156 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2157 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2158 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2159 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2160 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2161 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2162 | if (!err) |
| 2163 | wdev->beacon_interval = 0; |
| 2164 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2165 | } |
| 2166 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2167 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2168 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2169 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2170 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2171 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2172 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2173 | }; |
| 2174 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2175 | static int parse_station_flags(struct genl_info *info, |
| 2176 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2177 | { |
| 2178 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2179 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2180 | int flag; |
| 2181 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2182 | /* |
| 2183 | * Try parsing the new attribute first so userspace |
| 2184 | * can specify both for older kernels. |
| 2185 | */ |
| 2186 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2187 | if (nla) { |
| 2188 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2189 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2190 | sta_flags = nla_data(nla); |
| 2191 | params->sta_flags_mask = sta_flags->mask; |
| 2192 | params->sta_flags_set = sta_flags->set; |
| 2193 | if ((params->sta_flags_mask | |
| 2194 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2195 | return -EINVAL; |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
| 2199 | /* if present, parse the old attribute */ |
| 2200 | |
| 2201 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2202 | if (!nla) |
| 2203 | return 0; |
| 2204 | |
| 2205 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2206 | nla, sta_flags_policy)) |
| 2207 | return -EINVAL; |
| 2208 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2209 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2210 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2211 | |
| 2212 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2213 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2214 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2215 | |
| 2216 | return 0; |
| 2217 | } |
| 2218 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2219 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2220 | int attr) |
| 2221 | { |
| 2222 | struct nlattr *rate; |
| 2223 | u16 bitrate; |
| 2224 | |
| 2225 | rate = nla_nest_start(msg, attr); |
| 2226 | if (!rate) |
| 2227 | goto nla_put_failure; |
| 2228 | |
| 2229 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2230 | bitrate = cfg80211_calculate_bitrate(info); |
| 2231 | if (bitrate > 0) |
| 2232 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2233 | |
| 2234 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2235 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2236 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2237 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2238 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2239 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2240 | |
| 2241 | nla_nest_end(msg, rate); |
| 2242 | return true; |
| 2243 | |
| 2244 | nla_put_failure: |
| 2245 | return false; |
| 2246 | } |
| 2247 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2248 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2249 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2250 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2251 | { |
| 2252 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2253 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2254 | |
| 2255 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2256 | if (!hdr) |
| 2257 | return -1; |
| 2258 | |
| 2259 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2260 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2261 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2262 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2263 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2264 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2265 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2266 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2267 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2268 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2269 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2270 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2271 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2272 | sinfo->inactive_time); |
| 2273 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2274 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2275 | sinfo->rx_bytes); |
| 2276 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2277 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2278 | sinfo->tx_bytes); |
| 2279 | if (sinfo->filled & STATION_INFO_LLID) |
| 2280 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2281 | sinfo->llid); |
| 2282 | if (sinfo->filled & STATION_INFO_PLID) |
| 2283 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2284 | sinfo->plid); |
| 2285 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2286 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2287 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2288 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2289 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2290 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2291 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2292 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2293 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2294 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2295 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2296 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2297 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2298 | } |
| 2299 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2300 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2301 | NL80211_STA_INFO_RX_BITRATE)) |
| 2302 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2303 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2304 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2305 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2306 | sinfo->rx_packets); |
| 2307 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2308 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2309 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2310 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2311 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2312 | sinfo->tx_retries); |
| 2313 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2314 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2315 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2316 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2317 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2318 | if (!bss_param) |
| 2319 | goto nla_put_failure; |
| 2320 | |
| 2321 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2322 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2323 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2324 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2325 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2326 | NLA_PUT_FLAG(msg, |
| 2327 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2328 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2329 | sinfo->bss_param.dtim_period); |
| 2330 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2331 | sinfo->bss_param.beacon_interval); |
| 2332 | |
| 2333 | nla_nest_end(msg, bss_param); |
| 2334 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2335 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2336 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2337 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2338 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2339 | sinfo->assoc_req_ies); |
| 2340 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2341 | return genlmsg_end(msg, hdr); |
| 2342 | |
| 2343 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2344 | genlmsg_cancel(msg, hdr); |
| 2345 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2346 | } |
| 2347 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2348 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2349 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2350 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2351 | struct station_info sinfo; |
| 2352 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2353 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2354 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2355 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2356 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2357 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2358 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2359 | if (err) |
| 2360 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2361 | |
| 2362 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2363 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2364 | goto out_err; |
| 2365 | } |
| 2366 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2367 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2368 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2369 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2370 | mac_addr, &sinfo); |
| 2371 | if (err == -ENOENT) |
| 2372 | break; |
| 2373 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2374 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2375 | |
| 2376 | if (nl80211_send_station(skb, |
| 2377 | NETLINK_CB(cb->skb).pid, |
| 2378 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2379 | netdev, mac_addr, |
| 2380 | &sinfo) < 0) |
| 2381 | goto out; |
| 2382 | |
| 2383 | sta_idx++; |
| 2384 | } |
| 2385 | |
| 2386 | |
| 2387 | out: |
| 2388 | cb->args[1] = sta_idx; |
| 2389 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2390 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2391 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2392 | |
| 2393 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2394 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2395 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2396 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2397 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2399 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2400 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2401 | struct sk_buff *msg; |
| 2402 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2403 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2404 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2405 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2406 | |
| 2407 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2408 | return -EINVAL; |
| 2409 | |
| 2410 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2411 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2412 | if (!rdev->ops->get_station) |
| 2413 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2414 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2415 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2416 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2417 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2418 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2419 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2420 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2421 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2422 | |
| 2423 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2424 | dev, mac_addr, &sinfo) < 0) { |
| 2425 | nlmsg_free(msg); |
| 2426 | return -ENOBUFS; |
| 2427 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2428 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2429 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2433 | * 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] | 2434 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2435 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2436 | struct cfg80211_registered_device *rdev, |
| 2437 | struct net_device **vlan) |
| 2438 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2439 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2440 | *vlan = NULL; |
| 2441 | |
| 2442 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2443 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2444 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2445 | if (!*vlan) |
| 2446 | return -ENODEV; |
| 2447 | if (!(*vlan)->ieee80211_ptr) |
| 2448 | return -EINVAL; |
| 2449 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2450 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2451 | if (!netif_running(*vlan)) |
| 2452 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2453 | } |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
| 2457 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2458 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2459 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2460 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2461 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2462 | struct station_parameters params; |
| 2463 | u8 *mac_addr = NULL; |
| 2464 | |
| 2465 | memset(¶ms, 0, sizeof(params)); |
| 2466 | |
| 2467 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2468 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2469 | |
| 2470 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2471 | return -EINVAL; |
| 2472 | |
| 2473 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2474 | return -EINVAL; |
| 2475 | |
| 2476 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2477 | |
| 2478 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2479 | params.supported_rates = |
| 2480 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2481 | params.supported_rates_len = |
| 2482 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2483 | } |
| 2484 | |
| 2485 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2486 | params.listen_interval = |
| 2487 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2488 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2489 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2490 | params.ht_capa = |
| 2491 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2492 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2493 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2494 | return -EINVAL; |
| 2495 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2496 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2497 | params.plink_action = |
| 2498 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2499 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2500 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2501 | params.plink_state = |
| 2502 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2503 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2504 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2505 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2506 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2507 | |
| 2508 | /* validate settings */ |
| 2509 | err = 0; |
| 2510 | |
| 2511 | switch (dev->ieee80211_ptr->iftype) { |
| 2512 | case NL80211_IFTYPE_AP: |
| 2513 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2514 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2515 | /* disallow mesh-specific things */ |
| 2516 | if (params.plink_action) |
| 2517 | err = -EINVAL; |
| 2518 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2519 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2520 | case NL80211_IFTYPE_STATION: |
| 2521 | /* disallow everything but AUTHORIZED flag */ |
| 2522 | if (params.plink_action) |
| 2523 | err = -EINVAL; |
| 2524 | if (params.vlan) |
| 2525 | err = -EINVAL; |
| 2526 | if (params.supported_rates) |
| 2527 | err = -EINVAL; |
| 2528 | if (params.ht_capa) |
| 2529 | err = -EINVAL; |
| 2530 | if (params.listen_interval >= 0) |
| 2531 | err = -EINVAL; |
| 2532 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2533 | err = -EINVAL; |
| 2534 | break; |
| 2535 | case NL80211_IFTYPE_MESH_POINT: |
| 2536 | /* disallow things mesh doesn't support */ |
| 2537 | if (params.vlan) |
| 2538 | err = -EINVAL; |
| 2539 | if (params.ht_capa) |
| 2540 | err = -EINVAL; |
| 2541 | if (params.listen_interval >= 0) |
| 2542 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2543 | if (params.sta_flags_mask & |
| 2544 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2545 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2546 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2547 | err = -EINVAL; |
| 2548 | break; |
| 2549 | default: |
| 2550 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2551 | } |
| 2552 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2553 | if (err) |
| 2554 | goto out; |
| 2555 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2556 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2557 | err = -EOPNOTSUPP; |
| 2558 | goto out; |
| 2559 | } |
| 2560 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2561 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2562 | |
| 2563 | out: |
| 2564 | if (params.vlan) |
| 2565 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2566 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2567 | return err; |
| 2568 | } |
| 2569 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2570 | static struct nla_policy |
| 2571 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2572 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2573 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2574 | }; |
| 2575 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2576 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2577 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2579 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2580 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2581 | struct station_parameters params; |
| 2582 | u8 *mac_addr = NULL; |
| 2583 | |
| 2584 | memset(¶ms, 0, sizeof(params)); |
| 2585 | |
| 2586 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2587 | return -EINVAL; |
| 2588 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2589 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2590 | return -EINVAL; |
| 2591 | |
| 2592 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2593 | return -EINVAL; |
| 2594 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2595 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2596 | return -EINVAL; |
| 2597 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2598 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2599 | params.supported_rates = |
| 2600 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2601 | params.supported_rates_len = |
| 2602 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2603 | params.listen_interval = |
| 2604 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2605 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2606 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2607 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2608 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2609 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2610 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2611 | params.ht_capa = |
| 2612 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2613 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2614 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2615 | params.plink_action = |
| 2616 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2617 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2618 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2619 | return -EINVAL; |
| 2620 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2621 | /* parse WME attributes if sta is WME capable */ |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 2622 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Arik Nemtsov | cd32984 | 2011-09-26 09:36:42 +0300 | [diff] [blame] | 2623 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2624 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2625 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2626 | struct nlattr *nla; |
| 2627 | |
| 2628 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2629 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2630 | nl80211_sta_wme_policy); |
| 2631 | if (err) |
| 2632 | return err; |
| 2633 | |
| 2634 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2635 | params.uapsd_queues = |
| 2636 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2637 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2638 | return -EINVAL; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2639 | |
| 2640 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2641 | params.max_sp = |
| 2642 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2643 | |
| 2644 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2645 | return -EINVAL; |
Johannes Berg | 3b9ce80 | 2011-09-27 20:56:12 +0200 | [diff] [blame^] | 2646 | |
| 2647 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2648 | } |
| 2649 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2650 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2651 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2652 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2653 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2654 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2655 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2656 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2657 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2658 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2659 | |
| 2660 | /* validate settings */ |
| 2661 | err = 0; |
| 2662 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2663 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2664 | err = -EOPNOTSUPP; |
| 2665 | goto out; |
| 2666 | } |
| 2667 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2668 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2669 | |
| 2670 | out: |
| 2671 | if (params.vlan) |
| 2672 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2673 | return err; |
| 2674 | } |
| 2675 | |
| 2676 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2677 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2678 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2679 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2680 | u8 *mac_addr = NULL; |
| 2681 | |
| 2682 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2683 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2684 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2685 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2686 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2687 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2688 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2689 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2690 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | if (!rdev->ops->del_station) |
| 2692 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2693 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2694 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2695 | } |
| 2696 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2697 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2698 | int flags, struct net_device *dev, |
| 2699 | u8 *dst, u8 *next_hop, |
| 2700 | struct mpath_info *pinfo) |
| 2701 | { |
| 2702 | void *hdr; |
| 2703 | struct nlattr *pinfoattr; |
| 2704 | |
| 2705 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2706 | if (!hdr) |
| 2707 | return -1; |
| 2708 | |
| 2709 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2710 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2711 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2712 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2713 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2714 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2715 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2716 | if (!pinfoattr) |
| 2717 | goto nla_put_failure; |
| 2718 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2719 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2720 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2721 | if (pinfo->filled & MPATH_INFO_SN) |
| 2722 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2723 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2724 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2725 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2726 | pinfo->metric); |
| 2727 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2728 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2729 | pinfo->exptime); |
| 2730 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2731 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2732 | pinfo->flags); |
| 2733 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2734 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2735 | pinfo->discovery_timeout); |
| 2736 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2737 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2738 | pinfo->discovery_retries); |
| 2739 | |
| 2740 | nla_nest_end(msg, pinfoattr); |
| 2741 | |
| 2742 | return genlmsg_end(msg, hdr); |
| 2743 | |
| 2744 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2745 | genlmsg_cancel(msg, hdr); |
| 2746 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2750 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2751 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2752 | struct mpath_info pinfo; |
| 2753 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2754 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2755 | u8 dst[ETH_ALEN]; |
| 2756 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2757 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2758 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2759 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2760 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2761 | if (err) |
| 2762 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2763 | |
| 2764 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2765 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2766 | goto out_err; |
| 2767 | } |
| 2768 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2769 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2770 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2771 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2772 | } |
| 2773 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2774 | while (1) { |
| 2775 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2776 | dst, next_hop, &pinfo); |
| 2777 | if (err == -ENOENT) |
| 2778 | break; |
| 2779 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2780 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2781 | |
| 2782 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2783 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2784 | netdev, dst, next_hop, |
| 2785 | &pinfo) < 0) |
| 2786 | goto out; |
| 2787 | |
| 2788 | path_idx++; |
| 2789 | } |
| 2790 | |
| 2791 | |
| 2792 | out: |
| 2793 | cb->args[1] = path_idx; |
| 2794 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2795 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2796 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2797 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2801 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2802 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2803 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2804 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2805 | struct mpath_info pinfo; |
| 2806 | struct sk_buff *msg; |
| 2807 | u8 *dst = NULL; |
| 2808 | u8 next_hop[ETH_ALEN]; |
| 2809 | |
| 2810 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2811 | |
| 2812 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2813 | return -EINVAL; |
| 2814 | |
| 2815 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2816 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2817 | if (!rdev->ops->get_mpath) |
| 2818 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2819 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2820 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2821 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2822 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2823 | 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] | 2824 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2825 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2826 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2827 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2828 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2829 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2830 | |
| 2831 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2832 | dev, dst, next_hop, &pinfo) < 0) { |
| 2833 | nlmsg_free(msg); |
| 2834 | return -ENOBUFS; |
| 2835 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2836 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2837 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2841 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2843 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2844 | u8 *dst = NULL; |
| 2845 | u8 *next_hop = NULL; |
| 2846 | |
| 2847 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2848 | return -EINVAL; |
| 2849 | |
| 2850 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2851 | return -EINVAL; |
| 2852 | |
| 2853 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2854 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2855 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2856 | if (!rdev->ops->change_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; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2861 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2862 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2863 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2864 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2865 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2866 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2868 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2869 | u8 *dst = NULL; |
| 2870 | u8 *next_hop = NULL; |
| 2871 | |
| 2872 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2873 | return -EINVAL; |
| 2874 | |
| 2875 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2876 | return -EINVAL; |
| 2877 | |
| 2878 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2879 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2880 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2881 | if (!rdev->ops->add_mpath) |
| 2882 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2883 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2884 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2885 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2886 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2887 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2891 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2893 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2894 | u8 *dst = NULL; |
| 2895 | |
| 2896 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2897 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2898 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2899 | if (!rdev->ops->del_mpath) |
| 2900 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2901 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2902 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2903 | } |
| 2904 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2905 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2906 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2908 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2909 | struct bss_parameters params; |
| 2910 | |
| 2911 | memset(¶ms, 0, sizeof(params)); |
| 2912 | /* default to not changing parameters */ |
| 2913 | params.use_cts_prot = -1; |
| 2914 | params.use_short_preamble = -1; |
| 2915 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2916 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2917 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2918 | |
| 2919 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2920 | params.use_cts_prot = |
| 2921 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2922 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2923 | params.use_short_preamble = |
| 2924 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2925 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2926 | params.use_short_slot_time = |
| 2927 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2928 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2929 | params.basic_rates = |
| 2930 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2931 | params.basic_rates_len = |
| 2932 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2933 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2934 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2935 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2936 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2937 | params.ht_opmode = |
| 2938 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2939 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2940 | if (!rdev->ops->change_bss) |
| 2941 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2942 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2943 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2944 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2945 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2946 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2947 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2948 | } |
| 2949 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2950 | 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] | 2951 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2952 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2953 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2954 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2955 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2956 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2957 | }; |
| 2958 | |
| 2959 | static int parse_reg_rule(struct nlattr *tb[], |
| 2960 | struct ieee80211_reg_rule *reg_rule) |
| 2961 | { |
| 2962 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2963 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2964 | |
| 2965 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2966 | return -EINVAL; |
| 2967 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2968 | return -EINVAL; |
| 2969 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2970 | return -EINVAL; |
| 2971 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2972 | return -EINVAL; |
| 2973 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2974 | return -EINVAL; |
| 2975 | |
| 2976 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2977 | |
| 2978 | freq_range->start_freq_khz = |
| 2979 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2980 | freq_range->end_freq_khz = |
| 2981 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2982 | freq_range->max_bandwidth_khz = |
| 2983 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2984 | |
| 2985 | power_rule->max_eirp = |
| 2986 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2987 | |
| 2988 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2989 | power_rule->max_antenna_gain = |
| 2990 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2991 | |
| 2992 | return 0; |
| 2993 | } |
| 2994 | |
| 2995 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2996 | { |
| 2997 | int r; |
| 2998 | char *data = NULL; |
| 2999 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3000 | /* |
| 3001 | * You should only get this when cfg80211 hasn't yet initialized |
| 3002 | * completely when built-in to the kernel right between the time |
| 3003 | * window between nl80211_init() and regulatory_init(), if that is |
| 3004 | * even possible. |
| 3005 | */ |
| 3006 | mutex_lock(&cfg80211_mutex); |
| 3007 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3008 | mutex_unlock(&cfg80211_mutex); |
| 3009 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3010 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3011 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3012 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3013 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3014 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3015 | |
| 3016 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3017 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3018 | r = regulatory_hint_user(data); |
| 3019 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3020 | return r; |
| 3021 | } |
| 3022 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3023 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3024 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3025 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3027 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3028 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3029 | struct mesh_config cur_params; |
| 3030 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3031 | void *hdr; |
| 3032 | struct nlattr *pinfoattr; |
| 3033 | struct sk_buff *msg; |
| 3034 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3035 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3036 | return -EOPNOTSUPP; |
| 3037 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3038 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3039 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3040 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3041 | wdev_lock(wdev); |
| 3042 | /* If not connected, get default parameters */ |
| 3043 | if (!wdev->mesh_id_len) |
| 3044 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3045 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3046 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3047 | &cur_params); |
| 3048 | wdev_unlock(wdev); |
| 3049 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3050 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3051 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3052 | |
| 3053 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3054 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3055 | if (!msg) |
| 3056 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3057 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3058 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3059 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3060 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3061 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3062 | if (!pinfoattr) |
| 3063 | goto nla_put_failure; |
| 3064 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3065 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3066 | cur_params.dot11MeshRetryTimeout); |
| 3067 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3068 | cur_params.dot11MeshConfirmTimeout); |
| 3069 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3070 | cur_params.dot11MeshHoldingTimeout); |
| 3071 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3072 | cur_params.dot11MeshMaxPeerLinks); |
| 3073 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3074 | cur_params.dot11MeshMaxRetries); |
| 3075 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3076 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3077 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3078 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3079 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3080 | cur_params.auto_open_plinks); |
| 3081 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3082 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3083 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3084 | cur_params.path_refresh_time); |
| 3085 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3086 | cur_params.min_discovery_timeout); |
| 3087 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3088 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3089 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3090 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 3091 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3092 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3093 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3094 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3095 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3096 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3097 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3098 | cur_params.dot11MeshGateAnnouncementProtocol); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3099 | nla_nest_end(msg, pinfoattr); |
| 3100 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3101 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3102 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3103 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3104 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3105 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3106 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3107 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3110 | 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] | 3111 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3112 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3113 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3114 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3115 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3116 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3117 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3118 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3119 | |
| 3120 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3121 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3122 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3123 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3124 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 3125 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3126 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3127 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3128 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3129 | }; |
| 3130 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3131 | static const struct nla_policy |
| 3132 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3133 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3134 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3135 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3136 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3137 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3138 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3139 | }; |
| 3140 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3141 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3142 | struct mesh_config *cfg, |
| 3143 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3144 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3145 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3146 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3147 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3148 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3149 | do {\ |
| 3150 | if (table[attr_num]) {\ |
| 3151 | cfg->param = nla_fn(table[attr_num]); \ |
| 3152 | mask |= (1 << (attr_num - 1)); \ |
| 3153 | } \ |
| 3154 | } while (0);\ |
| 3155 | |
| 3156 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3157 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3158 | return -EINVAL; |
| 3159 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3160 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3161 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3162 | return -EINVAL; |
| 3163 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3164 | /* This makes sure that there aren't more than 32 mesh config |
| 3165 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3166 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3167 | |
| 3168 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3169 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3170 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3171 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3172 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3174 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3175 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3176 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3177 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3178 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3179 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3180 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3181 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3182 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3183 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3184 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3185 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3186 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3187 | nla_get_u8); |
| 3188 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3189 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3190 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3191 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3192 | nla_get_u16); |
| 3193 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3194 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3195 | nla_get_u32); |
| 3196 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3197 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3198 | nla_get_u16); |
| 3199 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3200 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3201 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3202 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3203 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3204 | dot11MeshHWMPRootMode, mask, |
| 3205 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3206 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3207 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3208 | dot11MeshHWMPRannInterval, mask, |
| 3209 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3210 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3211 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3212 | dot11MeshGateAnnouncementProtocol, mask, |
| 3213 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3214 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3215 | if (mask_out) |
| 3216 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3217 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3218 | return 0; |
| 3219 | |
| 3220 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3221 | } |
| 3222 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3223 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3224 | struct mesh_setup *setup) |
| 3225 | { |
| 3226 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3227 | |
| 3228 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3229 | return -EINVAL; |
| 3230 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3231 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3232 | nl80211_mesh_setup_params_policy)) |
| 3233 | return -EINVAL; |
| 3234 | |
| 3235 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3236 | setup->path_sel_proto = |
| 3237 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3238 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3239 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3240 | |
| 3241 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3242 | setup->path_metric = |
| 3243 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3244 | IEEE80211_PATH_METRIC_VENDOR : |
| 3245 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3246 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3247 | |
| 3248 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3249 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3250 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3251 | if (!is_valid_ie_attr(ieattr)) |
| 3252 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3253 | setup->ie = nla_data(ieattr); |
| 3254 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3255 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3256 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3257 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3258 | |
| 3259 | return 0; |
| 3260 | } |
| 3261 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3262 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3263 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3264 | { |
| 3265 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3266 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3267 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3268 | struct mesh_config cfg; |
| 3269 | u32 mask; |
| 3270 | int err; |
| 3271 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3272 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3273 | return -EOPNOTSUPP; |
| 3274 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3275 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3276 | return -EOPNOTSUPP; |
| 3277 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3278 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3279 | if (err) |
| 3280 | return err; |
| 3281 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3282 | wdev_lock(wdev); |
| 3283 | if (!wdev->mesh_id_len) |
| 3284 | err = -ENOLINK; |
| 3285 | |
| 3286 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3287 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3288 | mask, &cfg); |
| 3289 | |
| 3290 | wdev_unlock(wdev); |
| 3291 | |
| 3292 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3295 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3296 | { |
| 3297 | struct sk_buff *msg; |
| 3298 | void *hdr = NULL; |
| 3299 | struct nlattr *nl_reg_rules; |
| 3300 | unsigned int i; |
| 3301 | int err = -EINVAL; |
| 3302 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3303 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3304 | |
| 3305 | if (!cfg80211_regdomain) |
| 3306 | goto out; |
| 3307 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3308 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3309 | if (!msg) { |
| 3310 | err = -ENOBUFS; |
| 3311 | goto out; |
| 3312 | } |
| 3313 | |
| 3314 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3315 | NL80211_CMD_GET_REG); |
| 3316 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3317 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3318 | |
| 3319 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3320 | cfg80211_regdomain->alpha2); |
| 3321 | |
| 3322 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3323 | if (!nl_reg_rules) |
| 3324 | goto nla_put_failure; |
| 3325 | |
| 3326 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3327 | struct nlattr *nl_reg_rule; |
| 3328 | const struct ieee80211_reg_rule *reg_rule; |
| 3329 | const struct ieee80211_freq_range *freq_range; |
| 3330 | const struct ieee80211_power_rule *power_rule; |
| 3331 | |
| 3332 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3333 | freq_range = ®_rule->freq_range; |
| 3334 | power_rule = ®_rule->power_rule; |
| 3335 | |
| 3336 | nl_reg_rule = nla_nest_start(msg, i); |
| 3337 | if (!nl_reg_rule) |
| 3338 | goto nla_put_failure; |
| 3339 | |
| 3340 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3341 | reg_rule->flags); |
| 3342 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3343 | freq_range->start_freq_khz); |
| 3344 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3345 | freq_range->end_freq_khz); |
| 3346 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3347 | freq_range->max_bandwidth_khz); |
| 3348 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3349 | power_rule->max_antenna_gain); |
| 3350 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3351 | power_rule->max_eirp); |
| 3352 | |
| 3353 | nla_nest_end(msg, nl_reg_rule); |
| 3354 | } |
| 3355 | |
| 3356 | nla_nest_end(msg, nl_reg_rules); |
| 3357 | |
| 3358 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3359 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3360 | goto out; |
| 3361 | |
| 3362 | nla_put_failure: |
| 3363 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3364 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3365 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3366 | err = -EMSGSIZE; |
| 3367 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3368 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3369 | return err; |
| 3370 | } |
| 3371 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3372 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3373 | { |
| 3374 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3375 | struct nlattr *nl_reg_rule; |
| 3376 | char *alpha2 = NULL; |
| 3377 | int rem_reg_rules = 0, r = 0; |
| 3378 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3379 | struct ieee80211_regdomain *rd = NULL; |
| 3380 | |
| 3381 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3382 | return -EINVAL; |
| 3383 | |
| 3384 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3385 | return -EINVAL; |
| 3386 | |
| 3387 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3388 | |
| 3389 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3390 | rem_reg_rules) { |
| 3391 | num_rules++; |
| 3392 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3393 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3396 | mutex_lock(&cfg80211_mutex); |
| 3397 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3398 | if (!reg_is_valid_request(alpha2)) { |
| 3399 | r = -EINVAL; |
| 3400 | goto bad_reg; |
| 3401 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3402 | |
| 3403 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3404 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3405 | |
| 3406 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3407 | if (!rd) { |
| 3408 | r = -ENOMEM; |
| 3409 | goto bad_reg; |
| 3410 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3411 | |
| 3412 | rd->n_reg_rules = num_rules; |
| 3413 | rd->alpha2[0] = alpha2[0]; |
| 3414 | rd->alpha2[1] = alpha2[1]; |
| 3415 | |
| 3416 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3417 | rem_reg_rules) { |
| 3418 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3419 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3420 | reg_rule_policy); |
| 3421 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3422 | if (r) |
| 3423 | goto bad_reg; |
| 3424 | |
| 3425 | rule_idx++; |
| 3426 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3427 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3428 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3429 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3430 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | BUG_ON(rule_idx != num_rules); |
| 3434 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3435 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3436 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3437 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3438 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3439 | return r; |
| 3440 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3441 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3442 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3443 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3444 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3445 | } |
| 3446 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3447 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3448 | { |
| 3449 | struct nlattr *attr1, *attr2; |
| 3450 | int n_channels = 0, tmp1, tmp2; |
| 3451 | |
| 3452 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3453 | n_channels++; |
| 3454 | /* |
| 3455 | * Some hardware has a limited channel list for |
| 3456 | * scanning, and it is pretty much nonsensical |
| 3457 | * to scan for a channel twice, so disallow that |
| 3458 | * and don't require drivers to check that the |
| 3459 | * channel list they get isn't longer than what |
| 3460 | * they can scan, as long as they can scan all |
| 3461 | * the channels they registered at once. |
| 3462 | */ |
| 3463 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3464 | if (attr1 != attr2 && |
| 3465 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3466 | return 0; |
| 3467 | } |
| 3468 | |
| 3469 | return n_channels; |
| 3470 | } |
| 3471 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3472 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3473 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3475 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3476 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3477 | struct nlattr *attr; |
| 3478 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3479 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3480 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3481 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3482 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3483 | return -EINVAL; |
| 3484 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3485 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3486 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3487 | if (!rdev->ops->scan) |
| 3488 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3489 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3490 | if (rdev->scan_req) |
| 3491 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3492 | |
| 3493 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3494 | n_channels = validate_scan_freqs( |
| 3495 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3496 | if (!n_channels) |
| 3497 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3498 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3499 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3500 | n_channels = 0; |
| 3501 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3502 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3503 | if (wiphy->bands[band]) |
| 3504 | n_channels += wiphy->bands[band]->n_channels; |
| 3505 | } |
| 3506 | |
| 3507 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3508 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3509 | n_ssids++; |
| 3510 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3511 | if (n_ssids > wiphy->max_scan_ssids) |
| 3512 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3513 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3514 | if (info->attrs[NL80211_ATTR_IE]) |
| 3515 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3516 | else |
| 3517 | ie_len = 0; |
| 3518 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3519 | if (ie_len > wiphy->max_scan_ie_len) |
| 3520 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3521 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3522 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3523 | + sizeof(*request->ssids) * n_ssids |
| 3524 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3525 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3526 | if (!request) |
| 3527 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3528 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3529 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3530 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3531 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3532 | if (ie_len) { |
| 3533 | if (request->ssids) |
| 3534 | request->ie = (void *)(request->ssids + n_ssids); |
| 3535 | else |
| 3536 | request->ie = (void *)(request->channels + n_channels); |
| 3537 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3538 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3539 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3540 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3541 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3542 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3543 | struct ieee80211_channel *chan; |
| 3544 | |
| 3545 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3546 | |
| 3547 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3548 | err = -EINVAL; |
| 3549 | goto out_free; |
| 3550 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3551 | |
| 3552 | /* ignore disabled channels */ |
| 3553 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3554 | continue; |
| 3555 | |
| 3556 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3557 | i++; |
| 3558 | } |
| 3559 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3560 | enum ieee80211_band band; |
| 3561 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3562 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3563 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3564 | int j; |
| 3565 | if (!wiphy->bands[band]) |
| 3566 | continue; |
| 3567 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3568 | struct ieee80211_channel *chan; |
| 3569 | |
| 3570 | chan = &wiphy->bands[band]->channels[j]; |
| 3571 | |
| 3572 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3573 | continue; |
| 3574 | |
| 3575 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3576 | i++; |
| 3577 | } |
| 3578 | } |
| 3579 | } |
| 3580 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3581 | if (!i) { |
| 3582 | err = -EINVAL; |
| 3583 | goto out_free; |
| 3584 | } |
| 3585 | |
| 3586 | request->n_channels = i; |
| 3587 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3588 | i = 0; |
| 3589 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3590 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3591 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3592 | err = -EINVAL; |
| 3593 | goto out_free; |
| 3594 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3595 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3596 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3597 | i++; |
| 3598 | } |
| 3599 | } |
| 3600 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3601 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3602 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3603 | memcpy((void *)request->ie, |
| 3604 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3605 | request->ie_len); |
| 3606 | } |
| 3607 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3608 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3609 | if (wiphy->bands[i]) |
| 3610 | request->rates[i] = |
| 3611 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3612 | |
| 3613 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3614 | nla_for_each_nested(attr, |
| 3615 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3616 | tmp) { |
| 3617 | enum ieee80211_band band = nla_type(attr); |
| 3618 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3619 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3620 | err = -EINVAL; |
| 3621 | goto out_free; |
| 3622 | } |
| 3623 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3624 | nla_data(attr), |
| 3625 | nla_len(attr), |
| 3626 | &request->rates[band]); |
| 3627 | if (err) |
| 3628 | goto out_free; |
| 3629 | } |
| 3630 | } |
| 3631 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3632 | request->no_cck = |
| 3633 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3634 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3635 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3636 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3637 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3638 | rdev->scan_req = request; |
| 3639 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3640 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3641 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3642 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3643 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3644 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3645 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3646 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3647 | kfree(request); |
| 3648 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3649 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3650 | return err; |
| 3651 | } |
| 3652 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3653 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3654 | struct genl_info *info) |
| 3655 | { |
| 3656 | struct cfg80211_sched_scan_request *request; |
| 3657 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3658 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3659 | struct nlattr *attr; |
| 3660 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3661 | 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] | 3662 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3663 | enum ieee80211_band band; |
| 3664 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3665 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3666 | |
| 3667 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3668 | !rdev->ops->sched_scan_start) |
| 3669 | return -EOPNOTSUPP; |
| 3670 | |
| 3671 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3672 | return -EINVAL; |
| 3673 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3674 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3675 | return -EINVAL; |
| 3676 | |
| 3677 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3678 | if (interval == 0) |
| 3679 | return -EINVAL; |
| 3680 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3681 | wiphy = &rdev->wiphy; |
| 3682 | |
| 3683 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3684 | n_channels = validate_scan_freqs( |
| 3685 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3686 | if (!n_channels) |
| 3687 | return -EINVAL; |
| 3688 | } else { |
| 3689 | n_channels = 0; |
| 3690 | |
| 3691 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3692 | if (wiphy->bands[band]) |
| 3693 | n_channels += wiphy->bands[band]->n_channels; |
| 3694 | } |
| 3695 | |
| 3696 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3697 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3698 | tmp) |
| 3699 | n_ssids++; |
| 3700 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3701 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3702 | return -EINVAL; |
| 3703 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3704 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3705 | nla_for_each_nested(attr, |
| 3706 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3707 | tmp) |
| 3708 | n_match_sets++; |
| 3709 | |
| 3710 | if (n_match_sets > wiphy->max_match_sets) |
| 3711 | return -EINVAL; |
| 3712 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3713 | if (info->attrs[NL80211_ATTR_IE]) |
| 3714 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3715 | else |
| 3716 | ie_len = 0; |
| 3717 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3718 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3719 | return -EINVAL; |
| 3720 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3721 | mutex_lock(&rdev->sched_scan_mtx); |
| 3722 | |
| 3723 | if (rdev->sched_scan_req) { |
| 3724 | err = -EINPROGRESS; |
| 3725 | goto out; |
| 3726 | } |
| 3727 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3728 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3729 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3730 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3731 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3732 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3733 | if (!request) { |
| 3734 | err = -ENOMEM; |
| 3735 | goto out; |
| 3736 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3737 | |
| 3738 | if (n_ssids) |
| 3739 | request->ssids = (void *)&request->channels[n_channels]; |
| 3740 | request->n_ssids = n_ssids; |
| 3741 | if (ie_len) { |
| 3742 | if (request->ssids) |
| 3743 | request->ie = (void *)(request->ssids + n_ssids); |
| 3744 | else |
| 3745 | request->ie = (void *)(request->channels + n_channels); |
| 3746 | } |
| 3747 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3748 | if (n_match_sets) { |
| 3749 | if (request->ie) |
| 3750 | request->match_sets = (void *)(request->ie + ie_len); |
| 3751 | else if (request->ssids) |
| 3752 | request->match_sets = |
| 3753 | (void *)(request->ssids + n_ssids); |
| 3754 | else |
| 3755 | request->match_sets = |
| 3756 | (void *)(request->channels + n_channels); |
| 3757 | } |
| 3758 | request->n_match_sets = n_match_sets; |
| 3759 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3760 | i = 0; |
| 3761 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3762 | /* user specified, bail out if channel not found */ |
| 3763 | nla_for_each_nested(attr, |
| 3764 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3765 | tmp) { |
| 3766 | struct ieee80211_channel *chan; |
| 3767 | |
| 3768 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3769 | |
| 3770 | if (!chan) { |
| 3771 | err = -EINVAL; |
| 3772 | goto out_free; |
| 3773 | } |
| 3774 | |
| 3775 | /* ignore disabled channels */ |
| 3776 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3777 | continue; |
| 3778 | |
| 3779 | request->channels[i] = chan; |
| 3780 | i++; |
| 3781 | } |
| 3782 | } else { |
| 3783 | /* all channels */ |
| 3784 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3785 | int j; |
| 3786 | if (!wiphy->bands[band]) |
| 3787 | continue; |
| 3788 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3789 | struct ieee80211_channel *chan; |
| 3790 | |
| 3791 | chan = &wiphy->bands[band]->channels[j]; |
| 3792 | |
| 3793 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3794 | continue; |
| 3795 | |
| 3796 | request->channels[i] = chan; |
| 3797 | i++; |
| 3798 | } |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | if (!i) { |
| 3803 | err = -EINVAL; |
| 3804 | goto out_free; |
| 3805 | } |
| 3806 | |
| 3807 | request->n_channels = i; |
| 3808 | |
| 3809 | i = 0; |
| 3810 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3811 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3812 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3813 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3814 | err = -EINVAL; |
| 3815 | goto out_free; |
| 3816 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3817 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3818 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3819 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3820 | i++; |
| 3821 | } |
| 3822 | } |
| 3823 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3824 | i = 0; |
| 3825 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 3826 | nla_for_each_nested(attr, |
| 3827 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3828 | tmp) { |
| 3829 | struct nlattr *ssid; |
| 3830 | |
| 3831 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 3832 | nla_data(attr), nla_len(attr), |
| 3833 | nl80211_match_policy); |
| 3834 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 3835 | if (ssid) { |
| 3836 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 3837 | err = -EINVAL; |
| 3838 | goto out_free; |
| 3839 | } |
| 3840 | memcpy(request->match_sets[i].ssid.ssid, |
| 3841 | nla_data(ssid), nla_len(ssid)); |
| 3842 | request->match_sets[i].ssid.ssid_len = |
| 3843 | nla_len(ssid); |
| 3844 | } |
| 3845 | i++; |
| 3846 | } |
| 3847 | } |
| 3848 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3849 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3850 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3851 | memcpy((void *)request->ie, |
| 3852 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3853 | request->ie_len); |
| 3854 | } |
| 3855 | |
| 3856 | request->dev = dev; |
| 3857 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3858 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3859 | |
| 3860 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3861 | if (!err) { |
| 3862 | rdev->sched_scan_req = request; |
| 3863 | nl80211_send_sched_scan(rdev, dev, |
| 3864 | NL80211_CMD_START_SCHED_SCAN); |
| 3865 | goto out; |
| 3866 | } |
| 3867 | |
| 3868 | out_free: |
| 3869 | kfree(request); |
| 3870 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3871 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3872 | return err; |
| 3873 | } |
| 3874 | |
| 3875 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3876 | struct genl_info *info) |
| 3877 | { |
| 3878 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3879 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3880 | |
| 3881 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3882 | !rdev->ops->sched_scan_stop) |
| 3883 | return -EOPNOTSUPP; |
| 3884 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3885 | mutex_lock(&rdev->sched_scan_mtx); |
| 3886 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3887 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3888 | |
| 3889 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3890 | } |
| 3891 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3892 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3893 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3894 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3895 | struct wireless_dev *wdev, |
| 3896 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3897 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3898 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3899 | void *hdr; |
| 3900 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3901 | int i; |
| 3902 | |
| 3903 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3904 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3905 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3906 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3907 | if (!hdr) |
| 3908 | return -1; |
| 3909 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3910 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3911 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3912 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3913 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3914 | |
| 3915 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3916 | if (!bss) |
| 3917 | goto nla_put_failure; |
| 3918 | if (!is_zero_ether_addr(res->bssid)) |
| 3919 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3920 | if (res->information_elements && res->len_information_elements) |
| 3921 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3922 | res->len_information_elements, |
| 3923 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3924 | if (res->beacon_ies && res->len_beacon_ies && |
| 3925 | res->beacon_ies != res->information_elements) |
| 3926 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3927 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3928 | if (res->tsf) |
| 3929 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3930 | if (res->beacon_interval) |
| 3931 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3932 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3933 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3934 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3935 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3936 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3937 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3938 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3939 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3940 | break; |
| 3941 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3942 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3943 | break; |
| 3944 | default: |
| 3945 | break; |
| 3946 | } |
| 3947 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3948 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3949 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3950 | case NL80211_IFTYPE_STATION: |
| 3951 | if (intbss == wdev->current_bss) |
| 3952 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3953 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3954 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3955 | if (intbss != wdev->auth_bsses[i]) |
| 3956 | continue; |
| 3957 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3958 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3959 | break; |
| 3960 | } |
| 3961 | break; |
| 3962 | case NL80211_IFTYPE_ADHOC: |
| 3963 | if (intbss == wdev->current_bss) |
| 3964 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3965 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3966 | break; |
| 3967 | default: |
| 3968 | break; |
| 3969 | } |
| 3970 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3971 | nla_nest_end(msg, bss); |
| 3972 | |
| 3973 | return genlmsg_end(msg, hdr); |
| 3974 | |
| 3975 | nla_put_failure: |
| 3976 | genlmsg_cancel(msg, hdr); |
| 3977 | return -EMSGSIZE; |
| 3978 | } |
| 3979 | |
| 3980 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3981 | struct netlink_callback *cb) |
| 3982 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3983 | struct cfg80211_registered_device *rdev; |
| 3984 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3985 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3986 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3987 | int start = cb->args[1], idx = 0; |
| 3988 | int err; |
| 3989 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3990 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3991 | if (err) |
| 3992 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3993 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3994 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3995 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3996 | wdev_lock(wdev); |
| 3997 | spin_lock_bh(&rdev->bss_lock); |
| 3998 | cfg80211_bss_expire(rdev); |
| 3999 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4000 | cb->seq = rdev->bss_generation; |
| 4001 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4002 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4003 | if (++idx <= start) |
| 4004 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4005 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4006 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4007 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4008 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4009 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4010 | } |
| 4011 | } |
| 4012 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4013 | spin_unlock_bh(&rdev->bss_lock); |
| 4014 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4015 | |
| 4016 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4017 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4018 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4019 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4020 | } |
| 4021 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4022 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4023 | int flags, struct net_device *dev, |
| 4024 | struct survey_info *survey) |
| 4025 | { |
| 4026 | void *hdr; |
| 4027 | struct nlattr *infoattr; |
| 4028 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4029 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4030 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4031 | if (!hdr) |
| 4032 | return -ENOMEM; |
| 4033 | |
| 4034 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4035 | |
| 4036 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4037 | if (!infoattr) |
| 4038 | goto nla_put_failure; |
| 4039 | |
| 4040 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4041 | survey->channel->center_freq); |
| 4042 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4043 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4044 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4045 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4046 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29a | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4047 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4048 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4049 | survey->channel_time); |
| 4050 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4051 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4052 | survey->channel_time_busy); |
| 4053 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4054 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4055 | survey->channel_time_ext_busy); |
| 4056 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4057 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4058 | survey->channel_time_rx); |
| 4059 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4060 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4061 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4062 | |
| 4063 | nla_nest_end(msg, infoattr); |
| 4064 | |
| 4065 | return genlmsg_end(msg, hdr); |
| 4066 | |
| 4067 | nla_put_failure: |
| 4068 | genlmsg_cancel(msg, hdr); |
| 4069 | return -EMSGSIZE; |
| 4070 | } |
| 4071 | |
| 4072 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4073 | struct netlink_callback *cb) |
| 4074 | { |
| 4075 | struct survey_info survey; |
| 4076 | struct cfg80211_registered_device *dev; |
| 4077 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4078 | int survey_idx = cb->args[1]; |
| 4079 | int res; |
| 4080 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4081 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4082 | if (res) |
| 4083 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4084 | |
| 4085 | if (!dev->ops->dump_survey) { |
| 4086 | res = -EOPNOTSUPP; |
| 4087 | goto out_err; |
| 4088 | } |
| 4089 | |
| 4090 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4091 | struct ieee80211_channel *chan; |
| 4092 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4093 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4094 | &survey); |
| 4095 | if (res == -ENOENT) |
| 4096 | break; |
| 4097 | if (res) |
| 4098 | goto out_err; |
| 4099 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4100 | /* Survey without a channel doesn't make sense */ |
| 4101 | if (!survey.channel) { |
| 4102 | res = -EINVAL; |
| 4103 | goto out; |
| 4104 | } |
| 4105 | |
| 4106 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4107 | survey.channel->center_freq); |
| 4108 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4109 | survey_idx++; |
| 4110 | continue; |
| 4111 | } |
| 4112 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4113 | if (nl80211_send_survey(skb, |
| 4114 | NETLINK_CB(cb->skb).pid, |
| 4115 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4116 | netdev, |
| 4117 | &survey) < 0) |
| 4118 | goto out; |
| 4119 | survey_idx++; |
| 4120 | } |
| 4121 | |
| 4122 | out: |
| 4123 | cb->args[1] = survey_idx; |
| 4124 | res = skb->len; |
| 4125 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4126 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4127 | return res; |
| 4128 | } |
| 4129 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4130 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4131 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4132 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4133 | } |
| 4134 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4135 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4136 | { |
| 4137 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4138 | NL80211_WPA_VERSION_2)); |
| 4139 | } |
| 4140 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4141 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4142 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4143 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4144 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4145 | struct ieee80211_channel *chan; |
| 4146 | const u8 *bssid, *ssid, *ie = NULL; |
| 4147 | int err, ssid_len, ie_len = 0; |
| 4148 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4149 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4150 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4151 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4152 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4153 | return -EINVAL; |
| 4154 | |
| 4155 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4156 | return -EINVAL; |
| 4157 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4158 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4159 | return -EINVAL; |
| 4160 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4161 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4162 | return -EINVAL; |
| 4163 | |
| 4164 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4165 | return -EINVAL; |
| 4166 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4167 | err = nl80211_parse_key(info, &key); |
| 4168 | if (err) |
| 4169 | return err; |
| 4170 | |
| 4171 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4172 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4173 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4174 | if (!key.p.key || !key.p.key_len) |
| 4175 | return -EINVAL; |
| 4176 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4177 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4178 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4179 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4180 | return -EINVAL; |
| 4181 | if (key.idx > 4) |
| 4182 | return -EINVAL; |
| 4183 | } else { |
| 4184 | key.p.key_len = 0; |
| 4185 | key.p.key = NULL; |
| 4186 | } |
| 4187 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4188 | if (key.idx >= 0) { |
| 4189 | int i; |
| 4190 | bool ok = false; |
| 4191 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4192 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4193 | ok = true; |
| 4194 | break; |
| 4195 | } |
| 4196 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4197 | if (!ok) |
| 4198 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4199 | } |
| 4200 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4201 | if (!rdev->ops->auth) |
| 4202 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4203 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4204 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4205 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4206 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4207 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4208 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4209 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4210 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4211 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4212 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4213 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4214 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4215 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4216 | |
| 4217 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4218 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4219 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4220 | } |
| 4221 | |
| 4222 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4223 | if (!nl80211_valid_auth_type(auth_type)) |
| 4224 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4225 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4226 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4227 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4228 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4229 | ssid, ssid_len, ie, ie_len, |
| 4230 | key.p.key, key.p.key_len, key.idx, |
| 4231 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4232 | } |
| 4233 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4234 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4235 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4236 | struct cfg80211_crypto_settings *settings, |
| 4237 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4238 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4239 | memset(settings, 0, sizeof(*settings)); |
| 4240 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4241 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4242 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4243 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4244 | u16 proto; |
| 4245 | proto = nla_get_u16( |
| 4246 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4247 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4248 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4249 | proto != ETH_P_PAE) |
| 4250 | return -EINVAL; |
| 4251 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4252 | settings->control_port_no_encrypt = true; |
| 4253 | } else |
| 4254 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4255 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4256 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4257 | void *data; |
| 4258 | int len, i; |
| 4259 | |
| 4260 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4261 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4262 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4263 | |
| 4264 | if (len % sizeof(u32)) |
| 4265 | return -EINVAL; |
| 4266 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4267 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4268 | return -EINVAL; |
| 4269 | |
| 4270 | memcpy(settings->ciphers_pairwise, data, len); |
| 4271 | |
| 4272 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4273 | if (!cfg80211_supported_cipher_suite( |
| 4274 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4275 | settings->ciphers_pairwise[i])) |
| 4276 | return -EINVAL; |
| 4277 | } |
| 4278 | |
| 4279 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4280 | settings->cipher_group = |
| 4281 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4282 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4283 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4284 | return -EINVAL; |
| 4285 | } |
| 4286 | |
| 4287 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4288 | settings->wpa_versions = |
| 4289 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4290 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4291 | return -EINVAL; |
| 4292 | } |
| 4293 | |
| 4294 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4295 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4296 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4297 | |
| 4298 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4299 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4300 | settings->n_akm_suites = len / sizeof(u32); |
| 4301 | |
| 4302 | if (len % sizeof(u32)) |
| 4303 | return -EINVAL; |
| 4304 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4305 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4306 | return -EINVAL; |
| 4307 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4308 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4309 | } |
| 4310 | |
| 4311 | return 0; |
| 4312 | } |
| 4313 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4314 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4315 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4317 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4318 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4319 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4320 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4321 | int err, ssid_len, ie_len = 0; |
| 4322 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4323 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4324 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4325 | return -EINVAL; |
| 4326 | |
| 4327 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4328 | !info->attrs[NL80211_ATTR_SSID] || |
| 4329 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4330 | return -EINVAL; |
| 4331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4332 | if (!rdev->ops->assoc) |
| 4333 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4334 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4335 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4336 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4337 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4338 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4339 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4340 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4341 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4342 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4343 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4344 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4345 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4346 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4347 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4348 | |
| 4349 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4350 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4351 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4352 | } |
| 4353 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4354 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4355 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4356 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4357 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4358 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4359 | else if (mfp != NL80211_MFP_NO) |
| 4360 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4361 | } |
| 4362 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4363 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4364 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4365 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4366 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4367 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4368 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4369 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4370 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4371 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4372 | return err; |
| 4373 | } |
| 4374 | |
| 4375 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4376 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4377 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4378 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4379 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4380 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4381 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4382 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4383 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4384 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4385 | return -EINVAL; |
| 4386 | |
| 4387 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4388 | return -EINVAL; |
| 4389 | |
| 4390 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4391 | return -EINVAL; |
| 4392 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4393 | if (!rdev->ops->deauth) |
| 4394 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4395 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4396 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4397 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4398 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4399 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4400 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4401 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4402 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4403 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4404 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4405 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4406 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4407 | |
| 4408 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4409 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4410 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4411 | } |
| 4412 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4413 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4414 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4415 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4416 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4420 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4421 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4422 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4423 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4424 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4425 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4426 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4427 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4428 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4429 | return -EINVAL; |
| 4430 | |
| 4431 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4432 | return -EINVAL; |
| 4433 | |
| 4434 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4435 | return -EINVAL; |
| 4436 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4437 | if (!rdev->ops->disassoc) |
| 4438 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4439 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4440 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4441 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4442 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4443 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4444 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4445 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4446 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4447 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4448 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4449 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4450 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4451 | |
| 4452 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4453 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4454 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4455 | } |
| 4456 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4457 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4458 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4459 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4460 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4461 | } |
| 4462 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4463 | static bool |
| 4464 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4465 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4466 | int rateval) |
| 4467 | { |
| 4468 | struct wiphy *wiphy = &rdev->wiphy; |
| 4469 | bool found = false; |
| 4470 | int band, i; |
| 4471 | |
| 4472 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4473 | struct ieee80211_supported_band *sband; |
| 4474 | |
| 4475 | sband = wiphy->bands[band]; |
| 4476 | if (!sband) |
| 4477 | continue; |
| 4478 | |
| 4479 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4480 | if (sband->bitrates[i].bitrate == rateval) { |
| 4481 | mcast_rate[band] = i + 1; |
| 4482 | found = true; |
| 4483 | break; |
| 4484 | } |
| 4485 | } |
| 4486 | } |
| 4487 | |
| 4488 | return found; |
| 4489 | } |
| 4490 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4491 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4492 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4494 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4495 | struct cfg80211_ibss_params ibss; |
| 4496 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4497 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4498 | int err; |
| 4499 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4500 | memset(&ibss, 0, sizeof(ibss)); |
| 4501 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4502 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4503 | return -EINVAL; |
| 4504 | |
| 4505 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4506 | !info->attrs[NL80211_ATTR_SSID] || |
| 4507 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4508 | return -EINVAL; |
| 4509 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4510 | ibss.beacon_interval = 100; |
| 4511 | |
| 4512 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4513 | ibss.beacon_interval = |
| 4514 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4515 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4516 | return -EINVAL; |
| 4517 | } |
| 4518 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4519 | if (!rdev->ops->join_ibss) |
| 4520 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4521 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4522 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4523 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4524 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4525 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4526 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4527 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4528 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4529 | |
| 4530 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4531 | return -EINVAL; |
| 4532 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4533 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4534 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4535 | |
| 4536 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4537 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4538 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4539 | } |
| 4540 | |
| 4541 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4542 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4543 | if (!ibss.channel || |
| 4544 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4545 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4546 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4547 | |
| 4548 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4549 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4550 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4551 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4552 | u8 *rates = |
| 4553 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4554 | int n_rates = |
| 4555 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4556 | struct ieee80211_supported_band *sband = |
| 4557 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4558 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4559 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4560 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4561 | &ibss.basic_rates); |
| 4562 | if (err) |
| 4563 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4564 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4565 | |
| 4566 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4567 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4568 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4569 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4570 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4571 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4572 | connkeys = nl80211_parse_connkeys(rdev, |
| 4573 | info->attrs[NL80211_ATTR_KEYS]); |
| 4574 | if (IS_ERR(connkeys)) |
| 4575 | return PTR_ERR(connkeys); |
| 4576 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4577 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4578 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4579 | if (err) |
| 4580 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4581 | return err; |
| 4582 | } |
| 4583 | |
| 4584 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4585 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4586 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4587 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4588 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4589 | if (!rdev->ops->leave_ibss) |
| 4590 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4591 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4592 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4593 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4594 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4595 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4596 | } |
| 4597 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4598 | #ifdef CONFIG_NL80211_TESTMODE |
| 4599 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4600 | .name = "testmode", |
| 4601 | }; |
| 4602 | |
| 4603 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4604 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4605 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4606 | int err; |
| 4607 | |
| 4608 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4609 | return -EINVAL; |
| 4610 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4611 | err = -EOPNOTSUPP; |
| 4612 | if (rdev->ops->testmode_cmd) { |
| 4613 | rdev->testmode_info = info; |
| 4614 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4615 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4616 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4617 | rdev->testmode_info = NULL; |
| 4618 | } |
| 4619 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4620 | return err; |
| 4621 | } |
| 4622 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4623 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4624 | struct netlink_callback *cb) |
| 4625 | { |
| 4626 | struct cfg80211_registered_device *dev; |
| 4627 | int err; |
| 4628 | long phy_idx; |
| 4629 | void *data = NULL; |
| 4630 | int data_len = 0; |
| 4631 | |
| 4632 | if (cb->args[0]) { |
| 4633 | /* |
| 4634 | * 0 is a valid index, but not valid for args[0], |
| 4635 | * so we need to offset by 1. |
| 4636 | */ |
| 4637 | phy_idx = cb->args[0] - 1; |
| 4638 | } else { |
| 4639 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4640 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4641 | nl80211_policy); |
| 4642 | if (err) |
| 4643 | return err; |
| 4644 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4645 | return -EINVAL; |
| 4646 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4647 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4648 | cb->args[1] = |
| 4649 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4650 | } |
| 4651 | |
| 4652 | if (cb->args[1]) { |
| 4653 | data = nla_data((void *)cb->args[1]); |
| 4654 | data_len = nla_len((void *)cb->args[1]); |
| 4655 | } |
| 4656 | |
| 4657 | mutex_lock(&cfg80211_mutex); |
| 4658 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4659 | if (!dev) { |
| 4660 | mutex_unlock(&cfg80211_mutex); |
| 4661 | return -ENOENT; |
| 4662 | } |
| 4663 | cfg80211_lock_rdev(dev); |
| 4664 | mutex_unlock(&cfg80211_mutex); |
| 4665 | |
| 4666 | if (!dev->ops->testmode_dump) { |
| 4667 | err = -EOPNOTSUPP; |
| 4668 | goto out_err; |
| 4669 | } |
| 4670 | |
| 4671 | while (1) { |
| 4672 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4673 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4674 | NL80211_CMD_TESTMODE); |
| 4675 | struct nlattr *tmdata; |
| 4676 | |
| 4677 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4678 | genlmsg_cancel(skb, hdr); |
| 4679 | break; |
| 4680 | } |
| 4681 | |
| 4682 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4683 | if (!tmdata) { |
| 4684 | genlmsg_cancel(skb, hdr); |
| 4685 | break; |
| 4686 | } |
| 4687 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4688 | data, data_len); |
| 4689 | nla_nest_end(skb, tmdata); |
| 4690 | |
| 4691 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4692 | genlmsg_cancel(skb, hdr); |
| 4693 | break; |
| 4694 | } else if (err) { |
| 4695 | genlmsg_cancel(skb, hdr); |
| 4696 | goto out_err; |
| 4697 | } |
| 4698 | |
| 4699 | genlmsg_end(skb, hdr); |
| 4700 | } |
| 4701 | |
| 4702 | err = skb->len; |
| 4703 | /* see above */ |
| 4704 | cb->args[0] = phy_idx + 1; |
| 4705 | out_err: |
| 4706 | cfg80211_unlock_rdev(dev); |
| 4707 | return err; |
| 4708 | } |
| 4709 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4710 | static struct sk_buff * |
| 4711 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4712 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4713 | { |
| 4714 | struct sk_buff *skb; |
| 4715 | void *hdr; |
| 4716 | struct nlattr *data; |
| 4717 | |
| 4718 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4719 | if (!skb) |
| 4720 | return NULL; |
| 4721 | |
| 4722 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4723 | if (!hdr) { |
| 4724 | kfree_skb(skb); |
| 4725 | return NULL; |
| 4726 | } |
| 4727 | |
| 4728 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4729 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4730 | |
| 4731 | ((void **)skb->cb)[0] = rdev; |
| 4732 | ((void **)skb->cb)[1] = hdr; |
| 4733 | ((void **)skb->cb)[2] = data; |
| 4734 | |
| 4735 | return skb; |
| 4736 | |
| 4737 | nla_put_failure: |
| 4738 | kfree_skb(skb); |
| 4739 | return NULL; |
| 4740 | } |
| 4741 | |
| 4742 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4743 | int approxlen) |
| 4744 | { |
| 4745 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4746 | |
| 4747 | if (WARN_ON(!rdev->testmode_info)) |
| 4748 | return NULL; |
| 4749 | |
| 4750 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4751 | rdev->testmode_info->snd_pid, |
| 4752 | rdev->testmode_info->snd_seq, |
| 4753 | GFP_KERNEL); |
| 4754 | } |
| 4755 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4756 | |
| 4757 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4758 | { |
| 4759 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4760 | void *hdr = ((void **)skb->cb)[1]; |
| 4761 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4762 | |
| 4763 | if (WARN_ON(!rdev->testmode_info)) { |
| 4764 | kfree_skb(skb); |
| 4765 | return -EINVAL; |
| 4766 | } |
| 4767 | |
| 4768 | nla_nest_end(skb, data); |
| 4769 | genlmsg_end(skb, hdr); |
| 4770 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4771 | } |
| 4772 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4773 | |
| 4774 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4775 | int approxlen, gfp_t gfp) |
| 4776 | { |
| 4777 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4778 | |
| 4779 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4780 | } |
| 4781 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4782 | |
| 4783 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4784 | { |
| 4785 | void *hdr = ((void **)skb->cb)[1]; |
| 4786 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4787 | |
| 4788 | nla_nest_end(skb, data); |
| 4789 | genlmsg_end(skb, hdr); |
| 4790 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4791 | } |
| 4792 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4793 | #endif |
| 4794 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4795 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4796 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4797 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4798 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4799 | struct cfg80211_connect_params connect; |
| 4800 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4801 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4802 | int err; |
| 4803 | |
| 4804 | memset(&connect, 0, sizeof(connect)); |
| 4805 | |
| 4806 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4807 | return -EINVAL; |
| 4808 | |
| 4809 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4810 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4811 | return -EINVAL; |
| 4812 | |
| 4813 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4814 | connect.auth_type = |
| 4815 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4816 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4817 | return -EINVAL; |
| 4818 | } else |
| 4819 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4820 | |
| 4821 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4822 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4823 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4824 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4825 | if (err) |
| 4826 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4827 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4828 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4829 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4830 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4831 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4832 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4833 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4834 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4835 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4836 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4837 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4838 | |
| 4839 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4840 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4841 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4842 | } |
| 4843 | |
| 4844 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4845 | connect.channel = |
| 4846 | ieee80211_get_channel(wiphy, |
| 4847 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4848 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4849 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4850 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4851 | } |
| 4852 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4853 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4854 | connkeys = nl80211_parse_connkeys(rdev, |
| 4855 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4856 | if (IS_ERR(connkeys)) |
| 4857 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4858 | } |
| 4859 | |
| 4860 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4861 | if (err) |
| 4862 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4863 | return err; |
| 4864 | } |
| 4865 | |
| 4866 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4867 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4868 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4869 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4870 | u16 reason; |
| 4871 | |
| 4872 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4873 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4874 | else |
| 4875 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4876 | |
| 4877 | if (reason == 0) |
| 4878 | return -EINVAL; |
| 4879 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4880 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4881 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4882 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4883 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4884 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4885 | } |
| 4886 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4887 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4888 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4890 | struct net *net; |
| 4891 | int err; |
| 4892 | u32 pid; |
| 4893 | |
| 4894 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4895 | return -EINVAL; |
| 4896 | |
| 4897 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4898 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4899 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4900 | if (IS_ERR(net)) |
| 4901 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4902 | |
| 4903 | err = 0; |
| 4904 | |
| 4905 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4906 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4907 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4908 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4909 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4910 | return err; |
| 4911 | } |
| 4912 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4913 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4914 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4916 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4917 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4918 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4919 | struct cfg80211_pmksa pmksa; |
| 4920 | |
| 4921 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4922 | |
| 4923 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4924 | return -EINVAL; |
| 4925 | |
| 4926 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4927 | return -EINVAL; |
| 4928 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4929 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4930 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4931 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4932 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4933 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4934 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4935 | |
| 4936 | switch (info->genlhdr->cmd) { |
| 4937 | case NL80211_CMD_SET_PMKSA: |
| 4938 | rdev_ops = rdev->ops->set_pmksa; |
| 4939 | break; |
| 4940 | case NL80211_CMD_DEL_PMKSA: |
| 4941 | rdev_ops = rdev->ops->del_pmksa; |
| 4942 | break; |
| 4943 | default: |
| 4944 | WARN_ON(1); |
| 4945 | break; |
| 4946 | } |
| 4947 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4948 | if (!rdev_ops) |
| 4949 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4950 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4951 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4952 | } |
| 4953 | |
| 4954 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4955 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4957 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4958 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4959 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4960 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4961 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4962 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4963 | if (!rdev->ops->flush_pmksa) |
| 4964 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4965 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4966 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4967 | } |
| 4968 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4969 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4970 | struct genl_info *info) |
| 4971 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4972 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4973 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4974 | struct ieee80211_channel *chan; |
| 4975 | struct sk_buff *msg; |
| 4976 | void *hdr; |
| 4977 | u64 cookie; |
| 4978 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4979 | u32 freq, duration; |
| 4980 | int err; |
| 4981 | |
| 4982 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4983 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4984 | return -EINVAL; |
| 4985 | |
| 4986 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4987 | |
| 4988 | /* |
| 4989 | * We should be on that channel for at least one jiffie, |
| 4990 | * and more than 5 seconds seems excessive. |
| 4991 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4992 | if (!duration || !msecs_to_jiffies(duration) || |
| 4993 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4994 | return -EINVAL; |
| 4995 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4996 | if (!rdev->ops->remain_on_channel) |
| 4997 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4998 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4999 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5000 | channel_type = nla_get_u32( |
| 5001 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5002 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5003 | channel_type != NL80211_CHAN_HT20 && |
| 5004 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5005 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5006 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5010 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5011 | if (chan == NULL) |
| 5012 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5013 | |
| 5014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5015 | if (!msg) |
| 5016 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5017 | |
| 5018 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5019 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5020 | |
| 5021 | if (IS_ERR(hdr)) { |
| 5022 | err = PTR_ERR(hdr); |
| 5023 | goto free_msg; |
| 5024 | } |
| 5025 | |
| 5026 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5027 | channel_type, duration, &cookie); |
| 5028 | |
| 5029 | if (err) |
| 5030 | goto free_msg; |
| 5031 | |
| 5032 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5033 | |
| 5034 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5035 | |
| 5036 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5037 | |
| 5038 | nla_put_failure: |
| 5039 | err = -ENOBUFS; |
| 5040 | free_msg: |
| 5041 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5042 | return err; |
| 5043 | } |
| 5044 | |
| 5045 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5046 | struct genl_info *info) |
| 5047 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5048 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5049 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5050 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5051 | |
| 5052 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5053 | return -EINVAL; |
| 5054 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5055 | if (!rdev->ops->cancel_remain_on_channel) |
| 5056 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5057 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5058 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5059 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5060 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5061 | } |
| 5062 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5063 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5064 | u8 *rates, u8 rates_len) |
| 5065 | { |
| 5066 | u8 i; |
| 5067 | u32 mask = 0; |
| 5068 | |
| 5069 | for (i = 0; i < rates_len; i++) { |
| 5070 | int rate = (rates[i] & 0x7f) * 5; |
| 5071 | int ridx; |
| 5072 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5073 | struct ieee80211_rate *srate = |
| 5074 | &sband->bitrates[ridx]; |
| 5075 | if (rate == srate->bitrate) { |
| 5076 | mask |= 1 << ridx; |
| 5077 | break; |
| 5078 | } |
| 5079 | } |
| 5080 | if (ridx == sband->n_bitrates) |
| 5081 | return 0; /* rate not found */ |
| 5082 | } |
| 5083 | |
| 5084 | return mask; |
| 5085 | } |
| 5086 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5087 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5088 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5089 | .len = NL80211_MAX_SUPP_RATES }, |
| 5090 | }; |
| 5091 | |
| 5092 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5093 | struct genl_info *info) |
| 5094 | { |
| 5095 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5097 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5098 | int rem, i; |
| 5099 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5100 | struct nlattr *tx_rates; |
| 5101 | struct ieee80211_supported_band *sband; |
| 5102 | |
| 5103 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5104 | return -EINVAL; |
| 5105 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5106 | if (!rdev->ops->set_bitrate_mask) |
| 5107 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5108 | |
| 5109 | memset(&mask, 0, sizeof(mask)); |
| 5110 | /* Default to all rates enabled */ |
| 5111 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5112 | sband = rdev->wiphy.bands[i]; |
| 5113 | mask.control[i].legacy = |
| 5114 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5115 | } |
| 5116 | |
| 5117 | /* |
| 5118 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5119 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5120 | */ |
| 5121 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5122 | { |
| 5123 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5124 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5125 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5126 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5127 | if (sband == NULL) |
| 5128 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5129 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5130 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5131 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5132 | mask.control[band].legacy = rateset_to_mask( |
| 5133 | sband, |
| 5134 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5135 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5136 | if (mask.control[band].legacy == 0) |
| 5137 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5138 | } |
| 5139 | } |
| 5140 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5141 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5142 | } |
| 5143 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5144 | 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] | 5145 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5147 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5148 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5149 | |
| 5150 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5151 | return -EINVAL; |
| 5152 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5153 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5154 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5155 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5156 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5157 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5158 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5159 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5160 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5161 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5162 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5163 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5164 | |
| 5165 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5166 | if (!rdev->ops->mgmt_tx) |
| 5167 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5168 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5169 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5170 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5171 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5172 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5173 | } |
| 5174 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5175 | 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] | 5176 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5177 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5178 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5179 | struct ieee80211_channel *chan; |
| 5180 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5181 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5182 | u32 freq; |
| 5183 | int err; |
| 5184 | void *hdr; |
| 5185 | u64 cookie; |
| 5186 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5187 | unsigned int wait = 0; |
| 5188 | bool offchan; |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5189 | bool no_cck; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5190 | |
| 5191 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5192 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5193 | return -EINVAL; |
| 5194 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5195 | if (!rdev->ops->mgmt_tx) |
| 5196 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5197 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5198 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5199 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5200 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5201 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5202 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5203 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5204 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5205 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5206 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5207 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5208 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5209 | return -EINVAL; |
| 5210 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5211 | } |
| 5212 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5213 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5214 | channel_type = nla_get_u32( |
| 5215 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5216 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5217 | channel_type != NL80211_CHAN_HT20 && |
| 5218 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5219 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5220 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5221 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5222 | } |
| 5223 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5224 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5225 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5226 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5227 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5228 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5229 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5230 | if (chan == NULL) |
| 5231 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5232 | |
| 5233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5234 | if (!msg) |
| 5235 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5236 | |
| 5237 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5238 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5239 | |
| 5240 | if (IS_ERR(hdr)) { |
| 5241 | err = PTR_ERR(hdr); |
| 5242 | goto free_msg; |
| 5243 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5244 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5245 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5246 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5247 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5248 | no_cck, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5249 | if (err) |
| 5250 | goto free_msg; |
| 5251 | |
| 5252 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5253 | |
| 5254 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5255 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5256 | |
| 5257 | nla_put_failure: |
| 5258 | err = -ENOBUFS; |
| 5259 | free_msg: |
| 5260 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5261 | return err; |
| 5262 | } |
| 5263 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5264 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5265 | { |
| 5266 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5267 | struct net_device *dev = info->user_ptr[1]; |
| 5268 | u64 cookie; |
| 5269 | |
| 5270 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5271 | return -EINVAL; |
| 5272 | |
| 5273 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5274 | return -EOPNOTSUPP; |
| 5275 | |
| 5276 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5277 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5278 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5279 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5280 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5281 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5282 | return -EOPNOTSUPP; |
| 5283 | |
| 5284 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5285 | |
| 5286 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5287 | } |
| 5288 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5289 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5290 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5291 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5292 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5293 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5294 | u8 ps_state; |
| 5295 | bool state; |
| 5296 | int err; |
| 5297 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5298 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5299 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5300 | |
| 5301 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5303 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5304 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5305 | |
| 5306 | wdev = dev->ieee80211_ptr; |
| 5307 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5308 | if (!rdev->ops->set_power_mgmt) |
| 5309 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5310 | |
| 5311 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5312 | |
| 5313 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5314 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5315 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5316 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5317 | wdev->ps_timeout); |
| 5318 | if (!err) |
| 5319 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5320 | return err; |
| 5321 | } |
| 5322 | |
| 5323 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5324 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5325 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5326 | enum nl80211_ps_state ps_state; |
| 5327 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5328 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5329 | struct sk_buff *msg; |
| 5330 | void *hdr; |
| 5331 | int err; |
| 5332 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5333 | wdev = dev->ieee80211_ptr; |
| 5334 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5335 | if (!rdev->ops->set_power_mgmt) |
| 5336 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5337 | |
| 5338 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5339 | if (!msg) |
| 5340 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5341 | |
| 5342 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5343 | NL80211_CMD_GET_POWER_SAVE); |
| 5344 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5345 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5346 | goto free_msg; |
| 5347 | } |
| 5348 | |
| 5349 | if (wdev->ps) |
| 5350 | ps_state = NL80211_PS_ENABLED; |
| 5351 | else |
| 5352 | ps_state = NL80211_PS_DISABLED; |
| 5353 | |
| 5354 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5355 | |
| 5356 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5357 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5358 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5359 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5360 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5361 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5362 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5363 | return err; |
| 5364 | } |
| 5365 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5366 | static struct nla_policy |
| 5367 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5368 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5369 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5370 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5371 | }; |
| 5372 | |
| 5373 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5374 | s32 threshold, u32 hysteresis) |
| 5375 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5376 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5377 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5378 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5379 | |
| 5380 | if (threshold > 0) |
| 5381 | return -EINVAL; |
| 5382 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5383 | wdev = dev->ieee80211_ptr; |
| 5384 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5385 | if (!rdev->ops->set_cqm_rssi_config) |
| 5386 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5387 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5388 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5389 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5390 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5391 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5392 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5393 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5397 | { |
| 5398 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5399 | struct nlattr *cqm; |
| 5400 | int err; |
| 5401 | |
| 5402 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5403 | if (!cqm) { |
| 5404 | err = -EINVAL; |
| 5405 | goto out; |
| 5406 | } |
| 5407 | |
| 5408 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5409 | nl80211_attr_cqm_policy); |
| 5410 | if (err) |
| 5411 | goto out; |
| 5412 | |
| 5413 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5414 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5415 | s32 threshold; |
| 5416 | u32 hysteresis; |
| 5417 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5418 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5419 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5420 | } else |
| 5421 | err = -EINVAL; |
| 5422 | |
| 5423 | out: |
| 5424 | return err; |
| 5425 | } |
| 5426 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5427 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5428 | { |
| 5429 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5430 | struct net_device *dev = info->user_ptr[1]; |
| 5431 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5432 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5433 | int err; |
| 5434 | |
| 5435 | /* start with default */ |
| 5436 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5437 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5438 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5439 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5440 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5441 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5442 | if (err) |
| 5443 | return err; |
| 5444 | } |
| 5445 | |
| 5446 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5447 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5448 | return -EINVAL; |
| 5449 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5450 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5451 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5452 | |
| 5453 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5454 | /* parse additional setup parameters if given */ |
| 5455 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5456 | if (err) |
| 5457 | return err; |
| 5458 | } |
| 5459 | |
| 5460 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5464 | { |
| 5465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5466 | struct net_device *dev = info->user_ptr[1]; |
| 5467 | |
| 5468 | return cfg80211_leave_mesh(rdev, dev); |
| 5469 | } |
| 5470 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5471 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5472 | { |
| 5473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5474 | struct sk_buff *msg; |
| 5475 | void *hdr; |
| 5476 | |
| 5477 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5478 | return -EOPNOTSUPP; |
| 5479 | |
| 5480 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5481 | if (!msg) |
| 5482 | return -ENOMEM; |
| 5483 | |
| 5484 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5485 | NL80211_CMD_GET_WOWLAN); |
| 5486 | if (!hdr) |
| 5487 | goto nla_put_failure; |
| 5488 | |
| 5489 | if (rdev->wowlan) { |
| 5490 | struct nlattr *nl_wowlan; |
| 5491 | |
| 5492 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5493 | if (!nl_wowlan) |
| 5494 | goto nla_put_failure; |
| 5495 | |
| 5496 | if (rdev->wowlan->any) |
| 5497 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5498 | if (rdev->wowlan->disconnect) |
| 5499 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5500 | if (rdev->wowlan->magic_pkt) |
| 5501 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5502 | if (rdev->wowlan->gtk_rekey_failure) |
| 5503 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5504 | if (rdev->wowlan->eap_identity_req) |
| 5505 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5506 | if (rdev->wowlan->four_way_handshake) |
| 5507 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5508 | if (rdev->wowlan->rfkill_release) |
| 5509 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5510 | if (rdev->wowlan->n_patterns) { |
| 5511 | struct nlattr *nl_pats, *nl_pat; |
| 5512 | int i, pat_len; |
| 5513 | |
| 5514 | nl_pats = nla_nest_start(msg, |
| 5515 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5516 | if (!nl_pats) |
| 5517 | goto nla_put_failure; |
| 5518 | |
| 5519 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5520 | nl_pat = nla_nest_start(msg, i + 1); |
| 5521 | if (!nl_pat) |
| 5522 | goto nla_put_failure; |
| 5523 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5524 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5525 | DIV_ROUND_UP(pat_len, 8), |
| 5526 | rdev->wowlan->patterns[i].mask); |
| 5527 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5528 | pat_len, |
| 5529 | rdev->wowlan->patterns[i].pattern); |
| 5530 | nla_nest_end(msg, nl_pat); |
| 5531 | } |
| 5532 | nla_nest_end(msg, nl_pats); |
| 5533 | } |
| 5534 | |
| 5535 | nla_nest_end(msg, nl_wowlan); |
| 5536 | } |
| 5537 | |
| 5538 | genlmsg_end(msg, hdr); |
| 5539 | return genlmsg_reply(msg, info); |
| 5540 | |
| 5541 | nla_put_failure: |
| 5542 | nlmsg_free(msg); |
| 5543 | return -ENOBUFS; |
| 5544 | } |
| 5545 | |
| 5546 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5547 | { |
| 5548 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5549 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5550 | struct cfg80211_wowlan no_triggers = {}; |
| 5551 | struct cfg80211_wowlan new_triggers = {}; |
| 5552 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5553 | int err, i; |
| 5554 | |
| 5555 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5556 | return -EOPNOTSUPP; |
| 5557 | |
| 5558 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5559 | goto no_triggers; |
| 5560 | |
| 5561 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5562 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5563 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5564 | nl80211_wowlan_policy); |
| 5565 | if (err) |
| 5566 | return err; |
| 5567 | |
| 5568 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5569 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5570 | return -EINVAL; |
| 5571 | new_triggers.any = true; |
| 5572 | } |
| 5573 | |
| 5574 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5575 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5576 | return -EINVAL; |
| 5577 | new_triggers.disconnect = true; |
| 5578 | } |
| 5579 | |
| 5580 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5581 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5582 | return -EINVAL; |
| 5583 | new_triggers.magic_pkt = true; |
| 5584 | } |
| 5585 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5586 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5587 | return -EINVAL; |
| 5588 | |
| 5589 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5590 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5591 | return -EINVAL; |
| 5592 | new_triggers.gtk_rekey_failure = true; |
| 5593 | } |
| 5594 | |
| 5595 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5596 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5597 | return -EINVAL; |
| 5598 | new_triggers.eap_identity_req = true; |
| 5599 | } |
| 5600 | |
| 5601 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5602 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5603 | return -EINVAL; |
| 5604 | new_triggers.four_way_handshake = true; |
| 5605 | } |
| 5606 | |
| 5607 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5608 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5609 | return -EINVAL; |
| 5610 | new_triggers.rfkill_release = true; |
| 5611 | } |
| 5612 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5613 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5614 | struct nlattr *pat; |
| 5615 | int n_patterns = 0; |
| 5616 | int rem, pat_len, mask_len; |
| 5617 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5618 | |
| 5619 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5620 | rem) |
| 5621 | n_patterns++; |
| 5622 | if (n_patterns > wowlan->n_patterns) |
| 5623 | return -EINVAL; |
| 5624 | |
| 5625 | new_triggers.patterns = kcalloc(n_patterns, |
| 5626 | sizeof(new_triggers.patterns[0]), |
| 5627 | GFP_KERNEL); |
| 5628 | if (!new_triggers.patterns) |
| 5629 | return -ENOMEM; |
| 5630 | |
| 5631 | new_triggers.n_patterns = n_patterns; |
| 5632 | i = 0; |
| 5633 | |
| 5634 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5635 | rem) { |
| 5636 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5637 | nla_data(pat), nla_len(pat), NULL); |
| 5638 | err = -EINVAL; |
| 5639 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5640 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5641 | goto error; |
| 5642 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5643 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5644 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5645 | mask_len) |
| 5646 | goto error; |
| 5647 | if (pat_len > wowlan->pattern_max_len || |
| 5648 | pat_len < wowlan->pattern_min_len) |
| 5649 | goto error; |
| 5650 | |
| 5651 | new_triggers.patterns[i].mask = |
| 5652 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5653 | if (!new_triggers.patterns[i].mask) { |
| 5654 | err = -ENOMEM; |
| 5655 | goto error; |
| 5656 | } |
| 5657 | new_triggers.patterns[i].pattern = |
| 5658 | new_triggers.patterns[i].mask + mask_len; |
| 5659 | memcpy(new_triggers.patterns[i].mask, |
| 5660 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5661 | mask_len); |
| 5662 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5663 | memcpy(new_triggers.patterns[i].pattern, |
| 5664 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5665 | pat_len); |
| 5666 | i++; |
| 5667 | } |
| 5668 | } |
| 5669 | |
| 5670 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5671 | struct cfg80211_wowlan *ntrig; |
| 5672 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5673 | GFP_KERNEL); |
| 5674 | if (!ntrig) { |
| 5675 | err = -ENOMEM; |
| 5676 | goto error; |
| 5677 | } |
| 5678 | cfg80211_rdev_free_wowlan(rdev); |
| 5679 | rdev->wowlan = ntrig; |
| 5680 | } else { |
| 5681 | no_triggers: |
| 5682 | cfg80211_rdev_free_wowlan(rdev); |
| 5683 | rdev->wowlan = NULL; |
| 5684 | } |
| 5685 | |
| 5686 | return 0; |
| 5687 | error: |
| 5688 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5689 | kfree(new_triggers.patterns[i].mask); |
| 5690 | kfree(new_triggers.patterns); |
| 5691 | return err; |
| 5692 | } |
| 5693 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5694 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5695 | { |
| 5696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5697 | struct net_device *dev = info->user_ptr[1]; |
| 5698 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5699 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5700 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5701 | int err; |
| 5702 | |
| 5703 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5704 | return -EINVAL; |
| 5705 | |
| 5706 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5707 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5708 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5709 | nl80211_rekey_policy); |
| 5710 | if (err) |
| 5711 | return err; |
| 5712 | |
| 5713 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5714 | return -ERANGE; |
| 5715 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5716 | return -ERANGE; |
| 5717 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5718 | return -ERANGE; |
| 5719 | |
| 5720 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5721 | NL80211_KEK_LEN); |
| 5722 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5723 | NL80211_KCK_LEN); |
| 5724 | memcpy(rekey_data.replay_ctr, |
| 5725 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5726 | NL80211_REPLAY_CTR_LEN); |
| 5727 | |
| 5728 | wdev_lock(wdev); |
| 5729 | if (!wdev->current_bss) { |
| 5730 | err = -ENOTCONN; |
| 5731 | goto out; |
| 5732 | } |
| 5733 | |
| 5734 | if (!rdev->ops->set_rekey_data) { |
| 5735 | err = -EOPNOTSUPP; |
| 5736 | goto out; |
| 5737 | } |
| 5738 | |
| 5739 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5740 | out: |
| 5741 | wdev_unlock(wdev); |
| 5742 | return err; |
| 5743 | } |
| 5744 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5745 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5746 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5747 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5748 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5749 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5750 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5751 | |
| 5752 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5753 | struct genl_info *info) |
| 5754 | { |
| 5755 | struct cfg80211_registered_device *rdev; |
| 5756 | struct net_device *dev; |
| 5757 | int err; |
| 5758 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5759 | |
| 5760 | if (rtnl) |
| 5761 | rtnl_lock(); |
| 5762 | |
| 5763 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5764 | rdev = cfg80211_get_dev_from_info(info); |
| 5765 | if (IS_ERR(rdev)) { |
| 5766 | if (rtnl) |
| 5767 | rtnl_unlock(); |
| 5768 | return PTR_ERR(rdev); |
| 5769 | } |
| 5770 | info->user_ptr[0] = rdev; |
| 5771 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5772 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5773 | if (err) { |
| 5774 | if (rtnl) |
| 5775 | rtnl_unlock(); |
| 5776 | return err; |
| 5777 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5778 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5779 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5780 | cfg80211_unlock_rdev(rdev); |
| 5781 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5782 | if (rtnl) |
| 5783 | rtnl_unlock(); |
| 5784 | return -ENETDOWN; |
| 5785 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5786 | info->user_ptr[0] = rdev; |
| 5787 | info->user_ptr[1] = dev; |
| 5788 | } |
| 5789 | |
| 5790 | return 0; |
| 5791 | } |
| 5792 | |
| 5793 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5794 | struct genl_info *info) |
| 5795 | { |
| 5796 | if (info->user_ptr[0]) |
| 5797 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5798 | if (info->user_ptr[1]) |
| 5799 | dev_put(info->user_ptr[1]); |
| 5800 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5801 | rtnl_unlock(); |
| 5802 | } |
| 5803 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5804 | static struct genl_ops nl80211_ops[] = { |
| 5805 | { |
| 5806 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5807 | .doit = nl80211_get_wiphy, |
| 5808 | .dumpit = nl80211_dump_wiphy, |
| 5809 | .policy = nl80211_policy, |
| 5810 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5811 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5812 | }, |
| 5813 | { |
| 5814 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5815 | .doit = nl80211_set_wiphy, |
| 5816 | .policy = nl80211_policy, |
| 5817 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5818 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5819 | }, |
| 5820 | { |
| 5821 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5822 | .doit = nl80211_get_interface, |
| 5823 | .dumpit = nl80211_dump_interface, |
| 5824 | .policy = nl80211_policy, |
| 5825 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5826 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5827 | }, |
| 5828 | { |
| 5829 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5830 | .doit = nl80211_set_interface, |
| 5831 | .policy = nl80211_policy, |
| 5832 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5833 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5834 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5835 | }, |
| 5836 | { |
| 5837 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5838 | .doit = nl80211_new_interface, |
| 5839 | .policy = nl80211_policy, |
| 5840 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5841 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5842 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5843 | }, |
| 5844 | { |
| 5845 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5846 | .doit = nl80211_del_interface, |
| 5847 | .policy = nl80211_policy, |
| 5848 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5849 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5850 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5851 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5852 | { |
| 5853 | .cmd = NL80211_CMD_GET_KEY, |
| 5854 | .doit = nl80211_get_key, |
| 5855 | .policy = nl80211_policy, |
| 5856 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5857 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5858 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5859 | }, |
| 5860 | { |
| 5861 | .cmd = NL80211_CMD_SET_KEY, |
| 5862 | .doit = nl80211_set_key, |
| 5863 | .policy = nl80211_policy, |
| 5864 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5866 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5867 | }, |
| 5868 | { |
| 5869 | .cmd = NL80211_CMD_NEW_KEY, |
| 5870 | .doit = nl80211_new_key, |
| 5871 | .policy = nl80211_policy, |
| 5872 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5873 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5874 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5875 | }, |
| 5876 | { |
| 5877 | .cmd = NL80211_CMD_DEL_KEY, |
| 5878 | .doit = nl80211_del_key, |
| 5879 | .policy = nl80211_policy, |
| 5880 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5881 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5882 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5883 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5884 | { |
| 5885 | .cmd = NL80211_CMD_SET_BEACON, |
| 5886 | .policy = nl80211_policy, |
| 5887 | .flags = GENL_ADMIN_PERM, |
| 5888 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5889 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5890 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5891 | }, |
| 5892 | { |
| 5893 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5894 | .policy = nl80211_policy, |
| 5895 | .flags = GENL_ADMIN_PERM, |
| 5896 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5897 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5898 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5899 | }, |
| 5900 | { |
| 5901 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5902 | .policy = nl80211_policy, |
| 5903 | .flags = GENL_ADMIN_PERM, |
| 5904 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5905 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5906 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5907 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5908 | { |
| 5909 | .cmd = NL80211_CMD_GET_STATION, |
| 5910 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5911 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5912 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5913 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5914 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5915 | }, |
| 5916 | { |
| 5917 | .cmd = NL80211_CMD_SET_STATION, |
| 5918 | .doit = nl80211_set_station, |
| 5919 | .policy = nl80211_policy, |
| 5920 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5921 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5922 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5923 | }, |
| 5924 | { |
| 5925 | .cmd = NL80211_CMD_NEW_STATION, |
| 5926 | .doit = nl80211_new_station, |
| 5927 | .policy = nl80211_policy, |
| 5928 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5929 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5930 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5931 | }, |
| 5932 | { |
| 5933 | .cmd = NL80211_CMD_DEL_STATION, |
| 5934 | .doit = nl80211_del_station, |
| 5935 | .policy = nl80211_policy, |
| 5936 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5937 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5938 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5939 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5940 | { |
| 5941 | .cmd = NL80211_CMD_GET_MPATH, |
| 5942 | .doit = nl80211_get_mpath, |
| 5943 | .dumpit = nl80211_dump_mpath, |
| 5944 | .policy = nl80211_policy, |
| 5945 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5946 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5947 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5948 | }, |
| 5949 | { |
| 5950 | .cmd = NL80211_CMD_SET_MPATH, |
| 5951 | .doit = nl80211_set_mpath, |
| 5952 | .policy = nl80211_policy, |
| 5953 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5954 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5955 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5956 | }, |
| 5957 | { |
| 5958 | .cmd = NL80211_CMD_NEW_MPATH, |
| 5959 | .doit = nl80211_new_mpath, |
| 5960 | .policy = nl80211_policy, |
| 5961 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5962 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5963 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5964 | }, |
| 5965 | { |
| 5966 | .cmd = NL80211_CMD_DEL_MPATH, |
| 5967 | .doit = nl80211_del_mpath, |
| 5968 | .policy = nl80211_policy, |
| 5969 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5970 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5971 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5972 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5973 | { |
| 5974 | .cmd = NL80211_CMD_SET_BSS, |
| 5975 | .doit = nl80211_set_bss, |
| 5976 | .policy = nl80211_policy, |
| 5977 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5978 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5979 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5980 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5981 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5982 | .cmd = NL80211_CMD_GET_REG, |
| 5983 | .doit = nl80211_get_reg, |
| 5984 | .policy = nl80211_policy, |
| 5985 | /* can be retrieved by unprivileged users */ |
| 5986 | }, |
| 5987 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5988 | .cmd = NL80211_CMD_SET_REG, |
| 5989 | .doit = nl80211_set_reg, |
| 5990 | .policy = nl80211_policy, |
| 5991 | .flags = GENL_ADMIN_PERM, |
| 5992 | }, |
| 5993 | { |
| 5994 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 5995 | .doit = nl80211_req_set_reg, |
| 5996 | .policy = nl80211_policy, |
| 5997 | .flags = GENL_ADMIN_PERM, |
| 5998 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5999 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6000 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6001 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6002 | .policy = nl80211_policy, |
| 6003 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6004 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6005 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6006 | }, |
| 6007 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6008 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6009 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6010 | .policy = nl80211_policy, |
| 6011 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6012 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6013 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6014 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6015 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6016 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6017 | .doit = nl80211_trigger_scan, |
| 6018 | .policy = nl80211_policy, |
| 6019 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6020 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6021 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6022 | }, |
| 6023 | { |
| 6024 | .cmd = NL80211_CMD_GET_SCAN, |
| 6025 | .policy = nl80211_policy, |
| 6026 | .dumpit = nl80211_dump_scan, |
| 6027 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6028 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6029 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6030 | .doit = nl80211_start_sched_scan, |
| 6031 | .policy = nl80211_policy, |
| 6032 | .flags = GENL_ADMIN_PERM, |
| 6033 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6034 | NL80211_FLAG_NEED_RTNL, |
| 6035 | }, |
| 6036 | { |
| 6037 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6038 | .doit = nl80211_stop_sched_scan, |
| 6039 | .policy = nl80211_policy, |
| 6040 | .flags = GENL_ADMIN_PERM, |
| 6041 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6042 | NL80211_FLAG_NEED_RTNL, |
| 6043 | }, |
| 6044 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6045 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6046 | .doit = nl80211_authenticate, |
| 6047 | .policy = nl80211_policy, |
| 6048 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6049 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6050 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6051 | }, |
| 6052 | { |
| 6053 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6054 | .doit = nl80211_associate, |
| 6055 | .policy = nl80211_policy, |
| 6056 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6057 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6058 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6059 | }, |
| 6060 | { |
| 6061 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6062 | .doit = nl80211_deauthenticate, |
| 6063 | .policy = nl80211_policy, |
| 6064 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6065 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6066 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6067 | }, |
| 6068 | { |
| 6069 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6070 | .doit = nl80211_disassociate, |
| 6071 | .policy = nl80211_policy, |
| 6072 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6073 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6074 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6075 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6076 | { |
| 6077 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6078 | .doit = nl80211_join_ibss, |
| 6079 | .policy = nl80211_policy, |
| 6080 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6081 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6082 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6083 | }, |
| 6084 | { |
| 6085 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6086 | .doit = nl80211_leave_ibss, |
| 6087 | .policy = nl80211_policy, |
| 6088 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6089 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6090 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6091 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6092 | #ifdef CONFIG_NL80211_TESTMODE |
| 6093 | { |
| 6094 | .cmd = NL80211_CMD_TESTMODE, |
| 6095 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6096 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6097 | .policy = nl80211_policy, |
| 6098 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6099 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6100 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6101 | }, |
| 6102 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6103 | { |
| 6104 | .cmd = NL80211_CMD_CONNECT, |
| 6105 | .doit = nl80211_connect, |
| 6106 | .policy = nl80211_policy, |
| 6107 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6108 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6109 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6110 | }, |
| 6111 | { |
| 6112 | .cmd = NL80211_CMD_DISCONNECT, |
| 6113 | .doit = nl80211_disconnect, |
| 6114 | .policy = nl80211_policy, |
| 6115 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6116 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6117 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6118 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6119 | { |
| 6120 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6121 | .doit = nl80211_wiphy_netns, |
| 6122 | .policy = nl80211_policy, |
| 6123 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6124 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6125 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6126 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6127 | { |
| 6128 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6129 | .policy = nl80211_policy, |
| 6130 | .dumpit = nl80211_dump_survey, |
| 6131 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6132 | { |
| 6133 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6134 | .doit = nl80211_setdel_pmksa, |
| 6135 | .policy = nl80211_policy, |
| 6136 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6137 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6138 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6139 | }, |
| 6140 | { |
| 6141 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6142 | .doit = nl80211_setdel_pmksa, |
| 6143 | .policy = nl80211_policy, |
| 6144 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6145 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6146 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6147 | }, |
| 6148 | { |
| 6149 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6150 | .doit = nl80211_flush_pmksa, |
| 6151 | .policy = nl80211_policy, |
| 6152 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6153 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6154 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6155 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6156 | { |
| 6157 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6158 | .doit = nl80211_remain_on_channel, |
| 6159 | .policy = nl80211_policy, |
| 6160 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6161 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6162 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6163 | }, |
| 6164 | { |
| 6165 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6166 | .doit = nl80211_cancel_remain_on_channel, |
| 6167 | .policy = nl80211_policy, |
| 6168 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6169 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6170 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6171 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6172 | { |
| 6173 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6174 | .doit = nl80211_set_tx_bitrate_mask, |
| 6175 | .policy = nl80211_policy, |
| 6176 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6177 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6178 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6179 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6180 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6181 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6182 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6183 | .policy = nl80211_policy, |
| 6184 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6185 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6186 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6187 | }, |
| 6188 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6189 | .cmd = NL80211_CMD_FRAME, |
| 6190 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6191 | .policy = nl80211_policy, |
| 6192 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6193 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6194 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6195 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6196 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6197 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6198 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6199 | .policy = nl80211_policy, |
| 6200 | .flags = GENL_ADMIN_PERM, |
| 6201 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6202 | NL80211_FLAG_NEED_RTNL, |
| 6203 | }, |
| 6204 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6205 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6206 | .doit = nl80211_set_power_save, |
| 6207 | .policy = nl80211_policy, |
| 6208 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6209 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6210 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6211 | }, |
| 6212 | { |
| 6213 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6214 | .doit = nl80211_get_power_save, |
| 6215 | .policy = nl80211_policy, |
| 6216 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6217 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6218 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6219 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6220 | { |
| 6221 | .cmd = NL80211_CMD_SET_CQM, |
| 6222 | .doit = nl80211_set_cqm, |
| 6223 | .policy = nl80211_policy, |
| 6224 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6225 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6226 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6227 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6228 | { |
| 6229 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6230 | .doit = nl80211_set_channel, |
| 6231 | .policy = nl80211_policy, |
| 6232 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6233 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6234 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6235 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6236 | { |
| 6237 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6238 | .doit = nl80211_set_wds_peer, |
| 6239 | .policy = nl80211_policy, |
| 6240 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6241 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6242 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6243 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6244 | { |
| 6245 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6246 | .doit = nl80211_join_mesh, |
| 6247 | .policy = nl80211_policy, |
| 6248 | .flags = GENL_ADMIN_PERM, |
| 6249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6250 | NL80211_FLAG_NEED_RTNL, |
| 6251 | }, |
| 6252 | { |
| 6253 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6254 | .doit = nl80211_leave_mesh, |
| 6255 | .policy = nl80211_policy, |
| 6256 | .flags = GENL_ADMIN_PERM, |
| 6257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6258 | NL80211_FLAG_NEED_RTNL, |
| 6259 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6260 | { |
| 6261 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6262 | .doit = nl80211_get_wowlan, |
| 6263 | .policy = nl80211_policy, |
| 6264 | /* can be retrieved by unprivileged users */ |
| 6265 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6266 | NL80211_FLAG_NEED_RTNL, |
| 6267 | }, |
| 6268 | { |
| 6269 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6270 | .doit = nl80211_set_wowlan, |
| 6271 | .policy = nl80211_policy, |
| 6272 | .flags = GENL_ADMIN_PERM, |
| 6273 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6274 | NL80211_FLAG_NEED_RTNL, |
| 6275 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6276 | { |
| 6277 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6278 | .doit = nl80211_set_rekey_data, |
| 6279 | .policy = nl80211_policy, |
| 6280 | .flags = GENL_ADMIN_PERM, |
| 6281 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6282 | NL80211_FLAG_NEED_RTNL, |
| 6283 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6284 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6285 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6286 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6287 | .name = "mlme", |
| 6288 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6289 | |
| 6290 | /* multicast groups */ |
| 6291 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6292 | .name = "config", |
| 6293 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6294 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6295 | .name = "scan", |
| 6296 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6297 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6298 | .name = "regulatory", |
| 6299 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6300 | |
| 6301 | /* notification functions */ |
| 6302 | |
| 6303 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6304 | { |
| 6305 | struct sk_buff *msg; |
| 6306 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6307 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6308 | if (!msg) |
| 6309 | return; |
| 6310 | |
| 6311 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6312 | nlmsg_free(msg); |
| 6313 | return; |
| 6314 | } |
| 6315 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6316 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6317 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6318 | } |
| 6319 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6320 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6321 | struct cfg80211_registered_device *rdev) |
| 6322 | { |
| 6323 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6324 | struct nlattr *nest; |
| 6325 | int i; |
| 6326 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6327 | ASSERT_RDEV_LOCK(rdev); |
| 6328 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6329 | if (WARN_ON(!req)) |
| 6330 | return 0; |
| 6331 | |
| 6332 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6333 | if (!nest) |
| 6334 | goto nla_put_failure; |
| 6335 | for (i = 0; i < req->n_ssids; i++) |
| 6336 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6337 | nla_nest_end(msg, nest); |
| 6338 | |
| 6339 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6340 | if (!nest) |
| 6341 | goto nla_put_failure; |
| 6342 | for (i = 0; i < req->n_channels; i++) |
| 6343 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6344 | nla_nest_end(msg, nest); |
| 6345 | |
| 6346 | if (req->ie) |
| 6347 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6348 | |
| 6349 | return 0; |
| 6350 | nla_put_failure: |
| 6351 | return -ENOBUFS; |
| 6352 | } |
| 6353 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6354 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6355 | struct cfg80211_registered_device *rdev, |
| 6356 | struct net_device *netdev, |
| 6357 | u32 pid, u32 seq, int flags, |
| 6358 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6359 | { |
| 6360 | void *hdr; |
| 6361 | |
| 6362 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6363 | if (!hdr) |
| 6364 | return -1; |
| 6365 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6366 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6367 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6368 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6369 | /* ignore errors and send incomplete event anyway */ |
| 6370 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6371 | |
| 6372 | return genlmsg_end(msg, hdr); |
| 6373 | |
| 6374 | nla_put_failure: |
| 6375 | genlmsg_cancel(msg, hdr); |
| 6376 | return -EMSGSIZE; |
| 6377 | } |
| 6378 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6379 | static int |
| 6380 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6381 | struct cfg80211_registered_device *rdev, |
| 6382 | struct net_device *netdev, |
| 6383 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6384 | { |
| 6385 | void *hdr; |
| 6386 | |
| 6387 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6388 | if (!hdr) |
| 6389 | return -1; |
| 6390 | |
| 6391 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6392 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6393 | |
| 6394 | return genlmsg_end(msg, hdr); |
| 6395 | |
| 6396 | nla_put_failure: |
| 6397 | genlmsg_cancel(msg, hdr); |
| 6398 | return -EMSGSIZE; |
| 6399 | } |
| 6400 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6401 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6402 | struct net_device *netdev) |
| 6403 | { |
| 6404 | struct sk_buff *msg; |
| 6405 | |
| 6406 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6407 | if (!msg) |
| 6408 | return; |
| 6409 | |
| 6410 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6411 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6412 | nlmsg_free(msg); |
| 6413 | return; |
| 6414 | } |
| 6415 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6416 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6417 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6418 | } |
| 6419 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6420 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6421 | struct net_device *netdev) |
| 6422 | { |
| 6423 | struct sk_buff *msg; |
| 6424 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6426 | if (!msg) |
| 6427 | return; |
| 6428 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6429 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6430 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6431 | nlmsg_free(msg); |
| 6432 | return; |
| 6433 | } |
| 6434 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6435 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6436 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6437 | } |
| 6438 | |
| 6439 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6440 | struct net_device *netdev) |
| 6441 | { |
| 6442 | struct sk_buff *msg; |
| 6443 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6444 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6445 | if (!msg) |
| 6446 | return; |
| 6447 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6448 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6449 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6450 | nlmsg_free(msg); |
| 6451 | return; |
| 6452 | } |
| 6453 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6454 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6455 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6456 | } |
| 6457 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6458 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6459 | struct net_device *netdev) |
| 6460 | { |
| 6461 | struct sk_buff *msg; |
| 6462 | |
| 6463 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6464 | if (!msg) |
| 6465 | return; |
| 6466 | |
| 6467 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6468 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6469 | nlmsg_free(msg); |
| 6470 | return; |
| 6471 | } |
| 6472 | |
| 6473 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6474 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6475 | } |
| 6476 | |
| 6477 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6478 | struct net_device *netdev, u32 cmd) |
| 6479 | { |
| 6480 | struct sk_buff *msg; |
| 6481 | |
| 6482 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6483 | if (!msg) |
| 6484 | return; |
| 6485 | |
| 6486 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6487 | nlmsg_free(msg); |
| 6488 | return; |
| 6489 | } |
| 6490 | |
| 6491 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6492 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6493 | } |
| 6494 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6495 | /* |
| 6496 | * This can happen on global regulatory changes or device specific settings |
| 6497 | * based on custom world regulatory domains. |
| 6498 | */ |
| 6499 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6500 | { |
| 6501 | struct sk_buff *msg; |
| 6502 | void *hdr; |
| 6503 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6504 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6505 | if (!msg) |
| 6506 | return; |
| 6507 | |
| 6508 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6509 | if (!hdr) { |
| 6510 | nlmsg_free(msg); |
| 6511 | return; |
| 6512 | } |
| 6513 | |
| 6514 | /* Userspace can always count this one always being set */ |
| 6515 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6516 | |
| 6517 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6518 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6519 | NL80211_REGDOM_TYPE_WORLD); |
| 6520 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6521 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6522 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6523 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6524 | request->intersect) |
| 6525 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6526 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6527 | else { |
| 6528 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6529 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6530 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6531 | } |
| 6532 | |
| 6533 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6534 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6535 | |
| 6536 | if (genlmsg_end(msg, hdr) < 0) { |
| 6537 | nlmsg_free(msg); |
| 6538 | return; |
| 6539 | } |
| 6540 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6541 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6542 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6543 | GFP_ATOMIC); |
| 6544 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6545 | |
| 6546 | return; |
| 6547 | |
| 6548 | nla_put_failure: |
| 6549 | genlmsg_cancel(msg, hdr); |
| 6550 | nlmsg_free(msg); |
| 6551 | } |
| 6552 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6553 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6554 | struct net_device *netdev, |
| 6555 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6556 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6557 | { |
| 6558 | struct sk_buff *msg; |
| 6559 | void *hdr; |
| 6560 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6561 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6562 | if (!msg) |
| 6563 | return; |
| 6564 | |
| 6565 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6566 | if (!hdr) { |
| 6567 | nlmsg_free(msg); |
| 6568 | return; |
| 6569 | } |
| 6570 | |
| 6571 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6572 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6573 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6574 | |
| 6575 | if (genlmsg_end(msg, hdr) < 0) { |
| 6576 | nlmsg_free(msg); |
| 6577 | return; |
| 6578 | } |
| 6579 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6580 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6581 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6582 | return; |
| 6583 | |
| 6584 | nla_put_failure: |
| 6585 | genlmsg_cancel(msg, hdr); |
| 6586 | nlmsg_free(msg); |
| 6587 | } |
| 6588 | |
| 6589 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6590 | struct net_device *netdev, const u8 *buf, |
| 6591 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6592 | { |
| 6593 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6594 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6595 | } |
| 6596 | |
| 6597 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6598 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6599 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6600 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6601 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6602 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6603 | } |
| 6604 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6605 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6606 | struct net_device *netdev, const u8 *buf, |
| 6607 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6608 | { |
| 6609 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6610 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6611 | } |
| 6612 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6613 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6614 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6615 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6616 | { |
| 6617 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6618 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6619 | } |
| 6620 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6621 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6622 | struct net_device *netdev, const u8 *buf, |
| 6623 | size_t len, gfp_t gfp) |
| 6624 | { |
| 6625 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6626 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6627 | } |
| 6628 | |
| 6629 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6630 | struct net_device *netdev, const u8 *buf, |
| 6631 | size_t len, gfp_t gfp) |
| 6632 | { |
| 6633 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6634 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6635 | } |
| 6636 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6637 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6638 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6639 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6640 | { |
| 6641 | struct sk_buff *msg; |
| 6642 | void *hdr; |
| 6643 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6644 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6645 | if (!msg) |
| 6646 | return; |
| 6647 | |
| 6648 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6649 | if (!hdr) { |
| 6650 | nlmsg_free(msg); |
| 6651 | return; |
| 6652 | } |
| 6653 | |
| 6654 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6655 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6656 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6657 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6658 | |
| 6659 | if (genlmsg_end(msg, hdr) < 0) { |
| 6660 | nlmsg_free(msg); |
| 6661 | return; |
| 6662 | } |
| 6663 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6664 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6665 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6666 | return; |
| 6667 | |
| 6668 | nla_put_failure: |
| 6669 | genlmsg_cancel(msg, hdr); |
| 6670 | nlmsg_free(msg); |
| 6671 | } |
| 6672 | |
| 6673 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6674 | struct net_device *netdev, const u8 *addr, |
| 6675 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6676 | { |
| 6677 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6678 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6679 | } |
| 6680 | |
| 6681 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6682 | struct net_device *netdev, const u8 *addr, |
| 6683 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6684 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6685 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6686 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6687 | } |
| 6688 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6689 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6690 | struct net_device *netdev, const u8 *bssid, |
| 6691 | const u8 *req_ie, size_t req_ie_len, |
| 6692 | const u8 *resp_ie, size_t resp_ie_len, |
| 6693 | u16 status, gfp_t gfp) |
| 6694 | { |
| 6695 | struct sk_buff *msg; |
| 6696 | void *hdr; |
| 6697 | |
| 6698 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6699 | if (!msg) |
| 6700 | return; |
| 6701 | |
| 6702 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6703 | if (!hdr) { |
| 6704 | nlmsg_free(msg); |
| 6705 | return; |
| 6706 | } |
| 6707 | |
| 6708 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6709 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6710 | if (bssid) |
| 6711 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6712 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6713 | if (req_ie) |
| 6714 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6715 | if (resp_ie) |
| 6716 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6717 | |
| 6718 | if (genlmsg_end(msg, hdr) < 0) { |
| 6719 | nlmsg_free(msg); |
| 6720 | return; |
| 6721 | } |
| 6722 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6723 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6724 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6725 | return; |
| 6726 | |
| 6727 | nla_put_failure: |
| 6728 | genlmsg_cancel(msg, hdr); |
| 6729 | nlmsg_free(msg); |
| 6730 | |
| 6731 | } |
| 6732 | |
| 6733 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6734 | struct net_device *netdev, const u8 *bssid, |
| 6735 | const u8 *req_ie, size_t req_ie_len, |
| 6736 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6737 | { |
| 6738 | struct sk_buff *msg; |
| 6739 | void *hdr; |
| 6740 | |
| 6741 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6742 | if (!msg) |
| 6743 | return; |
| 6744 | |
| 6745 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6746 | if (!hdr) { |
| 6747 | nlmsg_free(msg); |
| 6748 | return; |
| 6749 | } |
| 6750 | |
| 6751 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6752 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6753 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6754 | if (req_ie) |
| 6755 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6756 | if (resp_ie) |
| 6757 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6758 | |
| 6759 | if (genlmsg_end(msg, hdr) < 0) { |
| 6760 | nlmsg_free(msg); |
| 6761 | return; |
| 6762 | } |
| 6763 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6764 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6765 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6766 | return; |
| 6767 | |
| 6768 | nla_put_failure: |
| 6769 | genlmsg_cancel(msg, hdr); |
| 6770 | nlmsg_free(msg); |
| 6771 | |
| 6772 | } |
| 6773 | |
| 6774 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6775 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6776 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6777 | { |
| 6778 | struct sk_buff *msg; |
| 6779 | void *hdr; |
| 6780 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6781 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6782 | if (!msg) |
| 6783 | return; |
| 6784 | |
| 6785 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6786 | if (!hdr) { |
| 6787 | nlmsg_free(msg); |
| 6788 | return; |
| 6789 | } |
| 6790 | |
| 6791 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6792 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6793 | if (from_ap && reason) |
| 6794 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6795 | if (from_ap) |
| 6796 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6797 | if (ie) |
| 6798 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6799 | |
| 6800 | if (genlmsg_end(msg, hdr) < 0) { |
| 6801 | nlmsg_free(msg); |
| 6802 | return; |
| 6803 | } |
| 6804 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6805 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6806 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6807 | return; |
| 6808 | |
| 6809 | nla_put_failure: |
| 6810 | genlmsg_cancel(msg, hdr); |
| 6811 | nlmsg_free(msg); |
| 6812 | |
| 6813 | } |
| 6814 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6815 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6816 | struct net_device *netdev, const u8 *bssid, |
| 6817 | gfp_t gfp) |
| 6818 | { |
| 6819 | struct sk_buff *msg; |
| 6820 | void *hdr; |
| 6821 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6822 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6823 | if (!msg) |
| 6824 | return; |
| 6825 | |
| 6826 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6827 | if (!hdr) { |
| 6828 | nlmsg_free(msg); |
| 6829 | return; |
| 6830 | } |
| 6831 | |
| 6832 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6833 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6834 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6835 | |
| 6836 | if (genlmsg_end(msg, hdr) < 0) { |
| 6837 | nlmsg_free(msg); |
| 6838 | return; |
| 6839 | } |
| 6840 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6841 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6842 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6843 | return; |
| 6844 | |
| 6845 | nla_put_failure: |
| 6846 | genlmsg_cancel(msg, hdr); |
| 6847 | nlmsg_free(msg); |
| 6848 | } |
| 6849 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6850 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6851 | struct net_device *netdev, |
| 6852 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6853 | gfp_t gfp) |
| 6854 | { |
| 6855 | struct sk_buff *msg; |
| 6856 | void *hdr; |
| 6857 | |
| 6858 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6859 | if (!msg) |
| 6860 | return; |
| 6861 | |
| 6862 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6863 | if (!hdr) { |
| 6864 | nlmsg_free(msg); |
| 6865 | return; |
| 6866 | } |
| 6867 | |
| 6868 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6869 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6870 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6871 | if (ie_len && ie) |
| 6872 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6873 | |
| 6874 | if (genlmsg_end(msg, hdr) < 0) { |
| 6875 | nlmsg_free(msg); |
| 6876 | return; |
| 6877 | } |
| 6878 | |
| 6879 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6880 | nl80211_mlme_mcgrp.id, gfp); |
| 6881 | return; |
| 6882 | |
| 6883 | nla_put_failure: |
| 6884 | genlmsg_cancel(msg, hdr); |
| 6885 | nlmsg_free(msg); |
| 6886 | } |
| 6887 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6888 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6889 | struct net_device *netdev, const u8 *addr, |
| 6890 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6891 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6892 | { |
| 6893 | struct sk_buff *msg; |
| 6894 | void *hdr; |
| 6895 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6896 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6897 | if (!msg) |
| 6898 | return; |
| 6899 | |
| 6900 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 6901 | if (!hdr) { |
| 6902 | nlmsg_free(msg); |
| 6903 | return; |
| 6904 | } |
| 6905 | |
| 6906 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6907 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6908 | if (addr) |
| 6909 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6910 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 6911 | if (key_id != -1) |
| 6912 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6913 | if (tsc) |
| 6914 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 6915 | |
| 6916 | if (genlmsg_end(msg, hdr) < 0) { |
| 6917 | nlmsg_free(msg); |
| 6918 | return; |
| 6919 | } |
| 6920 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6921 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6922 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6923 | return; |
| 6924 | |
| 6925 | nla_put_failure: |
| 6926 | genlmsg_cancel(msg, hdr); |
| 6927 | nlmsg_free(msg); |
| 6928 | } |
| 6929 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6930 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 6931 | struct ieee80211_channel *channel_before, |
| 6932 | struct ieee80211_channel *channel_after) |
| 6933 | { |
| 6934 | struct sk_buff *msg; |
| 6935 | void *hdr; |
| 6936 | struct nlattr *nl_freq; |
| 6937 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6938 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6939 | if (!msg) |
| 6940 | return; |
| 6941 | |
| 6942 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 6943 | if (!hdr) { |
| 6944 | nlmsg_free(msg); |
| 6945 | return; |
| 6946 | } |
| 6947 | |
| 6948 | /* |
| 6949 | * Since we are applying the beacon hint to a wiphy we know its |
| 6950 | * wiphy_idx is valid |
| 6951 | */ |
| 6952 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 6953 | |
| 6954 | /* Before */ |
| 6955 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 6956 | if (!nl_freq) |
| 6957 | goto nla_put_failure; |
| 6958 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 6959 | goto nla_put_failure; |
| 6960 | nla_nest_end(msg, nl_freq); |
| 6961 | |
| 6962 | /* After */ |
| 6963 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 6964 | if (!nl_freq) |
| 6965 | goto nla_put_failure; |
| 6966 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 6967 | goto nla_put_failure; |
| 6968 | nla_nest_end(msg, nl_freq); |
| 6969 | |
| 6970 | if (genlmsg_end(msg, hdr) < 0) { |
| 6971 | nlmsg_free(msg); |
| 6972 | return; |
| 6973 | } |
| 6974 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6975 | rcu_read_lock(); |
| 6976 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 6977 | GFP_ATOMIC); |
| 6978 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 6979 | |
| 6980 | return; |
| 6981 | |
| 6982 | nla_put_failure: |
| 6983 | genlmsg_cancel(msg, hdr); |
| 6984 | nlmsg_free(msg); |
| 6985 | } |
| 6986 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6987 | static void nl80211_send_remain_on_chan_event( |
| 6988 | int cmd, struct cfg80211_registered_device *rdev, |
| 6989 | struct net_device *netdev, u64 cookie, |
| 6990 | struct ieee80211_channel *chan, |
| 6991 | enum nl80211_channel_type channel_type, |
| 6992 | unsigned int duration, gfp_t gfp) |
| 6993 | { |
| 6994 | struct sk_buff *msg; |
| 6995 | void *hdr; |
| 6996 | |
| 6997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6998 | if (!msg) |
| 6999 | return; |
| 7000 | |
| 7001 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7002 | if (!hdr) { |
| 7003 | nlmsg_free(msg); |
| 7004 | return; |
| 7005 | } |
| 7006 | |
| 7007 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7008 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7009 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7010 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7011 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7012 | |
| 7013 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7014 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7015 | |
| 7016 | if (genlmsg_end(msg, hdr) < 0) { |
| 7017 | nlmsg_free(msg); |
| 7018 | return; |
| 7019 | } |
| 7020 | |
| 7021 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7022 | nl80211_mlme_mcgrp.id, gfp); |
| 7023 | return; |
| 7024 | |
| 7025 | nla_put_failure: |
| 7026 | genlmsg_cancel(msg, hdr); |
| 7027 | nlmsg_free(msg); |
| 7028 | } |
| 7029 | |
| 7030 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7031 | struct net_device *netdev, u64 cookie, |
| 7032 | struct ieee80211_channel *chan, |
| 7033 | enum nl80211_channel_type channel_type, |
| 7034 | unsigned int duration, gfp_t gfp) |
| 7035 | { |
| 7036 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7037 | rdev, netdev, cookie, chan, |
| 7038 | channel_type, duration, gfp); |
| 7039 | } |
| 7040 | |
| 7041 | void nl80211_send_remain_on_channel_cancel( |
| 7042 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7043 | u64 cookie, struct ieee80211_channel *chan, |
| 7044 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7045 | { |
| 7046 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7047 | rdev, netdev, cookie, chan, |
| 7048 | channel_type, 0, gfp); |
| 7049 | } |
| 7050 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7051 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7052 | struct net_device *dev, const u8 *mac_addr, |
| 7053 | struct station_info *sinfo, gfp_t gfp) |
| 7054 | { |
| 7055 | struct sk_buff *msg; |
| 7056 | |
| 7057 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7058 | if (!msg) |
| 7059 | return; |
| 7060 | |
| 7061 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 7062 | nlmsg_free(msg); |
| 7063 | return; |
| 7064 | } |
| 7065 | |
| 7066 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7067 | nl80211_mlme_mcgrp.id, gfp); |
| 7068 | } |
| 7069 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7070 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7071 | struct net_device *dev, const u8 *mac_addr, |
| 7072 | gfp_t gfp) |
| 7073 | { |
| 7074 | struct sk_buff *msg; |
| 7075 | void *hdr; |
| 7076 | |
| 7077 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7078 | if (!msg) |
| 7079 | return; |
| 7080 | |
| 7081 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7082 | if (!hdr) { |
| 7083 | nlmsg_free(msg); |
| 7084 | return; |
| 7085 | } |
| 7086 | |
| 7087 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7088 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7089 | |
| 7090 | if (genlmsg_end(msg, hdr) < 0) { |
| 7091 | nlmsg_free(msg); |
| 7092 | return; |
| 7093 | } |
| 7094 | |
| 7095 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7096 | nl80211_mlme_mcgrp.id, gfp); |
| 7097 | return; |
| 7098 | |
| 7099 | nla_put_failure: |
| 7100 | genlmsg_cancel(msg, hdr); |
| 7101 | nlmsg_free(msg); |
| 7102 | } |
| 7103 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7104 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7105 | struct net_device *netdev, u32 nlpid, |
| 7106 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7107 | { |
| 7108 | struct sk_buff *msg; |
| 7109 | void *hdr; |
| 7110 | int err; |
| 7111 | |
| 7112 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7113 | if (!msg) |
| 7114 | return -ENOMEM; |
| 7115 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7116 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7117 | if (!hdr) { |
| 7118 | nlmsg_free(msg); |
| 7119 | return -ENOMEM; |
| 7120 | } |
| 7121 | |
| 7122 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7123 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7124 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7125 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7126 | |
| 7127 | err = genlmsg_end(msg, hdr); |
| 7128 | if (err < 0) { |
| 7129 | nlmsg_free(msg); |
| 7130 | return err; |
| 7131 | } |
| 7132 | |
| 7133 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7134 | if (err < 0) |
| 7135 | return err; |
| 7136 | return 0; |
| 7137 | |
| 7138 | nla_put_failure: |
| 7139 | genlmsg_cancel(msg, hdr); |
| 7140 | nlmsg_free(msg); |
| 7141 | return -ENOBUFS; |
| 7142 | } |
| 7143 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7144 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7145 | struct net_device *netdev, u64 cookie, |
| 7146 | const u8 *buf, size_t len, bool ack, |
| 7147 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7148 | { |
| 7149 | struct sk_buff *msg; |
| 7150 | void *hdr; |
| 7151 | |
| 7152 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7153 | if (!msg) |
| 7154 | return; |
| 7155 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7156 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7157 | if (!hdr) { |
| 7158 | nlmsg_free(msg); |
| 7159 | return; |
| 7160 | } |
| 7161 | |
| 7162 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7163 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7164 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7165 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7166 | if (ack) |
| 7167 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7168 | |
| 7169 | if (genlmsg_end(msg, hdr) < 0) { |
| 7170 | nlmsg_free(msg); |
| 7171 | return; |
| 7172 | } |
| 7173 | |
| 7174 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7175 | return; |
| 7176 | |
| 7177 | nla_put_failure: |
| 7178 | genlmsg_cancel(msg, hdr); |
| 7179 | nlmsg_free(msg); |
| 7180 | } |
| 7181 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7182 | void |
| 7183 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7184 | struct net_device *netdev, |
| 7185 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7186 | gfp_t gfp) |
| 7187 | { |
| 7188 | struct sk_buff *msg; |
| 7189 | struct nlattr *pinfoattr; |
| 7190 | void *hdr; |
| 7191 | |
| 7192 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7193 | if (!msg) |
| 7194 | return; |
| 7195 | |
| 7196 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7197 | if (!hdr) { |
| 7198 | nlmsg_free(msg); |
| 7199 | return; |
| 7200 | } |
| 7201 | |
| 7202 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7203 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7204 | |
| 7205 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7206 | if (!pinfoattr) |
| 7207 | goto nla_put_failure; |
| 7208 | |
| 7209 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7210 | rssi_event); |
| 7211 | |
| 7212 | nla_nest_end(msg, pinfoattr); |
| 7213 | |
| 7214 | if (genlmsg_end(msg, hdr) < 0) { |
| 7215 | nlmsg_free(msg); |
| 7216 | return; |
| 7217 | } |
| 7218 | |
| 7219 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7220 | nl80211_mlme_mcgrp.id, gfp); |
| 7221 | return; |
| 7222 | |
| 7223 | nla_put_failure: |
| 7224 | genlmsg_cancel(msg, hdr); |
| 7225 | nlmsg_free(msg); |
| 7226 | } |
| 7227 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7228 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7229 | struct net_device *netdev, const u8 *bssid, |
| 7230 | const u8 *replay_ctr, gfp_t gfp) |
| 7231 | { |
| 7232 | struct sk_buff *msg; |
| 7233 | struct nlattr *rekey_attr; |
| 7234 | void *hdr; |
| 7235 | |
| 7236 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7237 | if (!msg) |
| 7238 | return; |
| 7239 | |
| 7240 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7241 | if (!hdr) { |
| 7242 | nlmsg_free(msg); |
| 7243 | return; |
| 7244 | } |
| 7245 | |
| 7246 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7247 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7248 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7249 | |
| 7250 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7251 | if (!rekey_attr) |
| 7252 | goto nla_put_failure; |
| 7253 | |
| 7254 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7255 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7256 | |
| 7257 | nla_nest_end(msg, rekey_attr); |
| 7258 | |
| 7259 | if (genlmsg_end(msg, hdr) < 0) { |
| 7260 | nlmsg_free(msg); |
| 7261 | return; |
| 7262 | } |
| 7263 | |
| 7264 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7265 | nl80211_mlme_mcgrp.id, gfp); |
| 7266 | return; |
| 7267 | |
| 7268 | nla_put_failure: |
| 7269 | genlmsg_cancel(msg, hdr); |
| 7270 | nlmsg_free(msg); |
| 7271 | } |
| 7272 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7273 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7274 | struct net_device *netdev, int index, |
| 7275 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7276 | { |
| 7277 | struct sk_buff *msg; |
| 7278 | struct nlattr *attr; |
| 7279 | void *hdr; |
| 7280 | |
| 7281 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7282 | if (!msg) |
| 7283 | return; |
| 7284 | |
| 7285 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7286 | if (!hdr) { |
| 7287 | nlmsg_free(msg); |
| 7288 | return; |
| 7289 | } |
| 7290 | |
| 7291 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7292 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7293 | |
| 7294 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7295 | if (!attr) |
| 7296 | goto nla_put_failure; |
| 7297 | |
| 7298 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7299 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7300 | if (preauth) |
| 7301 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7302 | |
| 7303 | nla_nest_end(msg, attr); |
| 7304 | |
| 7305 | if (genlmsg_end(msg, hdr) < 0) { |
| 7306 | nlmsg_free(msg); |
| 7307 | return; |
| 7308 | } |
| 7309 | |
| 7310 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7311 | nl80211_mlme_mcgrp.id, gfp); |
| 7312 | return; |
| 7313 | |
| 7314 | nla_put_failure: |
| 7315 | genlmsg_cancel(msg, hdr); |
| 7316 | nlmsg_free(msg); |
| 7317 | } |
| 7318 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7319 | void |
| 7320 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7321 | struct net_device *netdev, const u8 *peer, |
| 7322 | u32 num_packets, gfp_t gfp) |
| 7323 | { |
| 7324 | struct sk_buff *msg; |
| 7325 | struct nlattr *pinfoattr; |
| 7326 | void *hdr; |
| 7327 | |
| 7328 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7329 | if (!msg) |
| 7330 | return; |
| 7331 | |
| 7332 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7333 | if (!hdr) { |
| 7334 | nlmsg_free(msg); |
| 7335 | return; |
| 7336 | } |
| 7337 | |
| 7338 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7339 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7340 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7341 | |
| 7342 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7343 | if (!pinfoattr) |
| 7344 | goto nla_put_failure; |
| 7345 | |
| 7346 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7347 | |
| 7348 | nla_nest_end(msg, pinfoattr); |
| 7349 | |
| 7350 | if (genlmsg_end(msg, hdr) < 0) { |
| 7351 | nlmsg_free(msg); |
| 7352 | return; |
| 7353 | } |
| 7354 | |
| 7355 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7356 | nl80211_mlme_mcgrp.id, gfp); |
| 7357 | return; |
| 7358 | |
| 7359 | nla_put_failure: |
| 7360 | genlmsg_cancel(msg, hdr); |
| 7361 | nlmsg_free(msg); |
| 7362 | } |
| 7363 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7364 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7365 | unsigned long state, |
| 7366 | void *_notify) |
| 7367 | { |
| 7368 | struct netlink_notify *notify = _notify; |
| 7369 | struct cfg80211_registered_device *rdev; |
| 7370 | struct wireless_dev *wdev; |
| 7371 | |
| 7372 | if (state != NETLINK_URELEASE) |
| 7373 | return NOTIFY_DONE; |
| 7374 | |
| 7375 | rcu_read_lock(); |
| 7376 | |
| 7377 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 7378 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7379 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7380 | |
| 7381 | rcu_read_unlock(); |
| 7382 | |
| 7383 | return NOTIFY_DONE; |
| 7384 | } |
| 7385 | |
| 7386 | static struct notifier_block nl80211_netlink_notifier = { |
| 7387 | .notifier_call = nl80211_netlink_notify, |
| 7388 | }; |
| 7389 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7390 | /* initialisation/exit functions */ |
| 7391 | |
| 7392 | int nl80211_init(void) |
| 7393 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7394 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7395 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7396 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7397 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7398 | if (err) |
| 7399 | return err; |
| 7400 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7401 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7402 | if (err) |
| 7403 | goto err_out; |
| 7404 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7405 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7406 | if (err) |
| 7407 | goto err_out; |
| 7408 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7409 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7410 | if (err) |
| 7411 | goto err_out; |
| 7412 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7413 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7414 | if (err) |
| 7415 | goto err_out; |
| 7416 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7417 | #ifdef CONFIG_NL80211_TESTMODE |
| 7418 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7419 | if (err) |
| 7420 | goto err_out; |
| 7421 | #endif |
| 7422 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7423 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7424 | if (err) |
| 7425 | goto err_out; |
| 7426 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7427 | return 0; |
| 7428 | err_out: |
| 7429 | genl_unregister_family(&nl80211_fam); |
| 7430 | return err; |
| 7431 | } |
| 7432 | |
| 7433 | void nl80211_exit(void) |
| 7434 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7435 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7436 | genl_unregister_family(&nl80211_fam); |
| 7437 | } |