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 | dc6382ce | 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 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 194 | }; |
| 195 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 196 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 197 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 198 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 199 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 200 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 201 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 202 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 203 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 204 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 205 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 206 | }; |
| 207 | |
| 208 | /* policy for the key default flags */ |
| 209 | static const struct nla_policy |
| 210 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 211 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 212 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 213 | }; |
| 214 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 215 | /* policy for WoWLAN attributes */ |
| 216 | static const struct nla_policy |
| 217 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 218 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 219 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 220 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 221 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 222 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 223 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 224 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 225 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 226 | }; |
| 227 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 228 | /* policy for GTK rekey offload attributes */ |
| 229 | static const struct nla_policy |
| 230 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 231 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 232 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 233 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 234 | }; |
| 235 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 236 | static const struct nla_policy |
| 237 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 238 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 239 | .len = IEEE80211_MAX_SSID_LEN }, |
| 240 | }; |
| 241 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 242 | /* ifidx get helper */ |
| 243 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 244 | { |
| 245 | int res; |
| 246 | |
| 247 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 248 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 249 | nl80211_policy); |
| 250 | if (res) |
| 251 | return res; |
| 252 | |
| 253 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 254 | return -EINVAL; |
| 255 | |
| 256 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 257 | if (!res) |
| 258 | return -EINVAL; |
| 259 | return res; |
| 260 | } |
| 261 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 262 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 263 | struct netlink_callback *cb, |
| 264 | struct cfg80211_registered_device **rdev, |
| 265 | struct net_device **dev) |
| 266 | { |
| 267 | int ifidx = cb->args[0]; |
| 268 | int err; |
| 269 | |
| 270 | if (!ifidx) |
| 271 | ifidx = nl80211_get_ifidx(cb); |
| 272 | if (ifidx < 0) |
| 273 | return ifidx; |
| 274 | |
| 275 | cb->args[0] = ifidx; |
| 276 | |
| 277 | rtnl_lock(); |
| 278 | |
| 279 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 280 | if (!*dev) { |
| 281 | err = -ENODEV; |
| 282 | goto out_rtnl; |
| 283 | } |
| 284 | |
| 285 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 286 | if (IS_ERR(*rdev)) { |
| 287 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 288 | goto out_rtnl; |
| 289 | } |
| 290 | |
| 291 | return 0; |
| 292 | out_rtnl: |
| 293 | rtnl_unlock(); |
| 294 | return err; |
| 295 | } |
| 296 | |
| 297 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 298 | { |
| 299 | cfg80211_unlock_rdev(rdev); |
| 300 | rtnl_unlock(); |
| 301 | } |
| 302 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 303 | /* IE validation */ |
| 304 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 305 | { |
| 306 | const u8 *pos; |
| 307 | int len; |
| 308 | |
| 309 | if (!attr) |
| 310 | return true; |
| 311 | |
| 312 | pos = nla_data(attr); |
| 313 | len = nla_len(attr); |
| 314 | |
| 315 | while (len) { |
| 316 | u8 elemlen; |
| 317 | |
| 318 | if (len < 2) |
| 319 | return false; |
| 320 | len -= 2; |
| 321 | |
| 322 | elemlen = pos[1]; |
| 323 | if (elemlen > len) |
| 324 | return false; |
| 325 | |
| 326 | len -= elemlen; |
| 327 | pos += 2 + elemlen; |
| 328 | } |
| 329 | |
| 330 | return true; |
| 331 | } |
| 332 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 333 | /* message building helper */ |
| 334 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 335 | int flags, u8 cmd) |
| 336 | { |
| 337 | /* since there is no private header just add the generic one */ |
| 338 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 339 | } |
| 340 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 341 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 342 | struct ieee80211_channel *chan) |
| 343 | { |
| 344 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 345 | chan->center_freq); |
| 346 | |
| 347 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 348 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 349 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 350 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 351 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 352 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 353 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 354 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 355 | |
| 356 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 357 | DBM_TO_MBM(chan->max_power)); |
| 358 | |
| 359 | return 0; |
| 360 | |
| 361 | nla_put_failure: |
| 362 | return -ENOBUFS; |
| 363 | } |
| 364 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 365 | /* netlink command implementations */ |
| 366 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 367 | struct key_parse { |
| 368 | struct key_params p; |
| 369 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 370 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 371 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 372 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 373 | }; |
| 374 | |
| 375 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 376 | { |
| 377 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 378 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 379 | nl80211_key_policy); |
| 380 | if (err) |
| 381 | return err; |
| 382 | |
| 383 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 384 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 385 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 386 | if (k->def) { |
| 387 | k->def_uni = true; |
| 388 | k->def_multi = true; |
| 389 | } |
| 390 | if (k->defmgmt) |
| 391 | k->def_multi = true; |
| 392 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 393 | if (tb[NL80211_KEY_IDX]) |
| 394 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 395 | |
| 396 | if (tb[NL80211_KEY_DATA]) { |
| 397 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 398 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 399 | } |
| 400 | |
| 401 | if (tb[NL80211_KEY_SEQ]) { |
| 402 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 403 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 404 | } |
| 405 | |
| 406 | if (tb[NL80211_KEY_CIPHER]) |
| 407 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 408 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 409 | if (tb[NL80211_KEY_TYPE]) { |
| 410 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 411 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 415 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 416 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 417 | int err = nla_parse_nested(kdt, |
| 418 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 419 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 420 | nl80211_key_default_policy); |
| 421 | if (err) |
| 422 | return err; |
| 423 | |
| 424 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 425 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 426 | } |
| 427 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 432 | { |
| 433 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 434 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 435 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 436 | } |
| 437 | |
| 438 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 439 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 440 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 441 | } |
| 442 | |
| 443 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 444 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 445 | |
| 446 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 447 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 448 | |
| 449 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 450 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 451 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 452 | if (k->def) { |
| 453 | k->def_uni = true; |
| 454 | k->def_multi = true; |
| 455 | } |
| 456 | if (k->defmgmt) |
| 457 | k->def_multi = true; |
| 458 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 459 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 460 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 461 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 462 | return -EINVAL; |
| 463 | } |
| 464 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 465 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 466 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 467 | int err = nla_parse_nested( |
| 468 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 469 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 470 | nl80211_key_default_policy); |
| 471 | if (err) |
| 472 | return err; |
| 473 | |
| 474 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 475 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 476 | } |
| 477 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 482 | { |
| 483 | int err; |
| 484 | |
| 485 | memset(k, 0, sizeof(*k)); |
| 486 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 487 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 488 | |
| 489 | if (info->attrs[NL80211_ATTR_KEY]) |
| 490 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 491 | else |
| 492 | err = nl80211_parse_key_old(info, k); |
| 493 | |
| 494 | if (err) |
| 495 | return err; |
| 496 | |
| 497 | if (k->def && k->defmgmt) |
| 498 | return -EINVAL; |
| 499 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 500 | if (k->defmgmt) { |
| 501 | if (k->def_uni || !k->def_multi) |
| 502 | return -EINVAL; |
| 503 | } |
| 504 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 505 | if (k->idx != -1) { |
| 506 | if (k->defmgmt) { |
| 507 | if (k->idx < 4 || k->idx > 5) |
| 508 | return -EINVAL; |
| 509 | } else if (k->def) { |
| 510 | if (k->idx < 0 || k->idx > 3) |
| 511 | return -EINVAL; |
| 512 | } else { |
| 513 | if (k->idx < 0 || k->idx > 5) |
| 514 | return -EINVAL; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 521 | static struct cfg80211_cached_keys * |
| 522 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 523 | struct nlattr *keys) |
| 524 | { |
| 525 | struct key_parse parse; |
| 526 | struct nlattr *key; |
| 527 | struct cfg80211_cached_keys *result; |
| 528 | int rem, err, def = 0; |
| 529 | |
| 530 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 531 | if (!result) |
| 532 | return ERR_PTR(-ENOMEM); |
| 533 | |
| 534 | result->def = -1; |
| 535 | result->defmgmt = -1; |
| 536 | |
| 537 | nla_for_each_nested(key, keys, rem) { |
| 538 | memset(&parse, 0, sizeof(parse)); |
| 539 | parse.idx = -1; |
| 540 | |
| 541 | err = nl80211_parse_key_new(key, &parse); |
| 542 | if (err) |
| 543 | goto error; |
| 544 | err = -EINVAL; |
| 545 | if (!parse.p.key) |
| 546 | goto error; |
| 547 | if (parse.idx < 0 || parse.idx > 4) |
| 548 | goto error; |
| 549 | if (parse.def) { |
| 550 | if (def) |
| 551 | goto error; |
| 552 | def = 1; |
| 553 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 554 | if (!parse.def_uni || !parse.def_multi) |
| 555 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 556 | } else if (parse.defmgmt) |
| 557 | goto error; |
| 558 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 559 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 560 | if (err) |
| 561 | goto error; |
| 562 | result->params[parse.idx].cipher = parse.p.cipher; |
| 563 | result->params[parse.idx].key_len = parse.p.key_len; |
| 564 | result->params[parse.idx].key = result->data[parse.idx]; |
| 565 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 566 | } |
| 567 | |
| 568 | return result; |
| 569 | error: |
| 570 | kfree(result); |
| 571 | return ERR_PTR(err); |
| 572 | } |
| 573 | |
| 574 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 575 | { |
| 576 | ASSERT_WDEV_LOCK(wdev); |
| 577 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 578 | switch (wdev->iftype) { |
| 579 | case NL80211_IFTYPE_AP: |
| 580 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 581 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 582 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 583 | break; |
| 584 | case NL80211_IFTYPE_ADHOC: |
| 585 | if (!wdev->current_bss) |
| 586 | return -ENOLINK; |
| 587 | break; |
| 588 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 589 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 590 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 591 | return -ENOLINK; |
| 592 | break; |
| 593 | default: |
| 594 | return -EINVAL; |
| 595 | } |
| 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 600 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 601 | { |
| 602 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 603 | int i; |
| 604 | |
| 605 | if (!nl_modes) |
| 606 | goto nla_put_failure; |
| 607 | |
| 608 | i = 0; |
| 609 | while (ifmodes) { |
| 610 | if (ifmodes & 1) |
| 611 | NLA_PUT_FLAG(msg, i); |
| 612 | ifmodes >>= 1; |
| 613 | i++; |
| 614 | } |
| 615 | |
| 616 | nla_nest_end(msg, nl_modes); |
| 617 | return 0; |
| 618 | |
| 619 | nla_put_failure: |
| 620 | return -ENOBUFS; |
| 621 | } |
| 622 | |
| 623 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 624 | struct sk_buff *msg) |
| 625 | { |
| 626 | struct nlattr *nl_combis; |
| 627 | int i, j; |
| 628 | |
| 629 | nl_combis = nla_nest_start(msg, |
| 630 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 631 | if (!nl_combis) |
| 632 | goto nla_put_failure; |
| 633 | |
| 634 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 635 | const struct ieee80211_iface_combination *c; |
| 636 | struct nlattr *nl_combi, *nl_limits; |
| 637 | |
| 638 | c = &wiphy->iface_combinations[i]; |
| 639 | |
| 640 | nl_combi = nla_nest_start(msg, i + 1); |
| 641 | if (!nl_combi) |
| 642 | goto nla_put_failure; |
| 643 | |
| 644 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 645 | if (!nl_limits) |
| 646 | goto nla_put_failure; |
| 647 | |
| 648 | for (j = 0; j < c->n_limits; j++) { |
| 649 | struct nlattr *nl_limit; |
| 650 | |
| 651 | nl_limit = nla_nest_start(msg, j + 1); |
| 652 | if (!nl_limit) |
| 653 | goto nla_put_failure; |
| 654 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 655 | c->limits[j].max); |
| 656 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 657 | c->limits[j].types)) |
| 658 | goto nla_put_failure; |
| 659 | nla_nest_end(msg, nl_limit); |
| 660 | } |
| 661 | |
| 662 | nla_nest_end(msg, nl_limits); |
| 663 | |
| 664 | if (c->beacon_int_infra_match) |
| 665 | NLA_PUT_FLAG(msg, |
| 666 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 667 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 668 | c->num_different_channels); |
| 669 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 670 | c->max_interfaces); |
| 671 | |
| 672 | nla_nest_end(msg, nl_combi); |
| 673 | } |
| 674 | |
| 675 | nla_nest_end(msg, nl_combis); |
| 676 | |
| 677 | return 0; |
| 678 | nla_put_failure: |
| 679 | return -ENOBUFS; |
| 680 | } |
| 681 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 682 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 683 | struct cfg80211_registered_device *dev) |
| 684 | { |
| 685 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 686 | struct nlattr *nl_bands, *nl_band; |
| 687 | struct nlattr *nl_freqs, *nl_freq; |
| 688 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 689 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 690 | enum ieee80211_band band; |
| 691 | struct ieee80211_channel *chan; |
| 692 | struct ieee80211_rate *rate; |
| 693 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 694 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 695 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 696 | |
| 697 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 698 | if (!hdr) |
| 699 | return -1; |
| 700 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 701 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 702 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 703 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 704 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 705 | cfg80211_rdev_list_generation); |
| 706 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 707 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 708 | dev->wiphy.retry_short); |
| 709 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 710 | dev->wiphy.retry_long); |
| 711 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 712 | dev->wiphy.frag_threshold); |
| 713 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 714 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 715 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 716 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 717 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 718 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 719 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 720 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 721 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 722 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 723 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 724 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 725 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 726 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 727 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 728 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 729 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 730 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 731 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 732 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 733 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 734 | |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 735 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 736 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
| 737 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 738 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 739 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 740 | dev->wiphy.cipher_suites); |
| 741 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 742 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 743 | dev->wiphy.max_num_pmkids); |
| 744 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 745 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 746 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 747 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 748 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 749 | dev->wiphy.available_antennas_tx); |
| 750 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 751 | dev->wiphy.available_antennas_rx); |
| 752 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 753 | if ((dev->wiphy.available_antennas_tx || |
| 754 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 755 | u32 tx_ant = 0, rx_ant = 0; |
| 756 | int res; |
| 757 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 758 | if (!res) { |
| 759 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 760 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 761 | } |
| 762 | } |
| 763 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 764 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 765 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 766 | goto nla_put_failure; |
| 767 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 768 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 769 | if (!nl_bands) |
| 770 | goto nla_put_failure; |
| 771 | |
| 772 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 773 | if (!dev->wiphy.bands[band]) |
| 774 | continue; |
| 775 | |
| 776 | nl_band = nla_nest_start(msg, band); |
| 777 | if (!nl_band) |
| 778 | goto nla_put_failure; |
| 779 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 780 | /* add HT info */ |
| 781 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 782 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 783 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 784 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 785 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 786 | dev->wiphy.bands[band]->ht_cap.cap); |
| 787 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 788 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 789 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 790 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 791 | } |
| 792 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 793 | /* add frequencies */ |
| 794 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 795 | if (!nl_freqs) |
| 796 | goto nla_put_failure; |
| 797 | |
| 798 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 799 | nl_freq = nla_nest_start(msg, i); |
| 800 | if (!nl_freq) |
| 801 | goto nla_put_failure; |
| 802 | |
| 803 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 804 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 805 | if (nl80211_msg_put_channel(msg, chan)) |
| 806 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 807 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 808 | nla_nest_end(msg, nl_freq); |
| 809 | } |
| 810 | |
| 811 | nla_nest_end(msg, nl_freqs); |
| 812 | |
| 813 | /* add bitrates */ |
| 814 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 815 | if (!nl_rates) |
| 816 | goto nla_put_failure; |
| 817 | |
| 818 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 819 | nl_rate = nla_nest_start(msg, i); |
| 820 | if (!nl_rate) |
| 821 | goto nla_put_failure; |
| 822 | |
| 823 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 824 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 825 | rate->bitrate); |
| 826 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 827 | NLA_PUT_FLAG(msg, |
| 828 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 829 | |
| 830 | nla_nest_end(msg, nl_rate); |
| 831 | } |
| 832 | |
| 833 | nla_nest_end(msg, nl_rates); |
| 834 | |
| 835 | nla_nest_end(msg, nl_band); |
| 836 | } |
| 837 | nla_nest_end(msg, nl_bands); |
| 838 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 839 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 840 | if (!nl_cmds) |
| 841 | goto nla_put_failure; |
| 842 | |
| 843 | i = 0; |
| 844 | #define CMD(op, n) \ |
| 845 | do { \ |
| 846 | if (dev->ops->op) { \ |
| 847 | i++; \ |
| 848 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 849 | } \ |
| 850 | } while (0) |
| 851 | |
| 852 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 853 | CMD(change_virtual_intf, SET_INTERFACE); |
| 854 | CMD(add_key, NEW_KEY); |
| 855 | CMD(add_beacon, NEW_BEACON); |
| 856 | CMD(add_station, NEW_STATION); |
| 857 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 858 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 859 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 860 | CMD(auth, AUTHENTICATE); |
| 861 | CMD(assoc, ASSOCIATE); |
| 862 | CMD(deauth, DEAUTHENTICATE); |
| 863 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 864 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 865 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 866 | CMD(set_pmksa, SET_PMKSA); |
| 867 | CMD(del_pmksa, DEL_PMKSA); |
| 868 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 869 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 870 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 871 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 872 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 873 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 874 | i++; |
| 875 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 876 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 877 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 878 | CMD(set_wds_peer, SET_WDS_PEER); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 879 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 880 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 881 | |
| 882 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 883 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 884 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 885 | i++; |
| 886 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 887 | } |
| 888 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 889 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 890 | i++; |
| 891 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 892 | } |
| 893 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 894 | nla_nest_end(msg, nl_cmds); |
| 895 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 896 | if (dev->ops->remain_on_channel) |
| 897 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 898 | dev->wiphy.max_remain_on_channel_duration); |
| 899 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 900 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 901 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 902 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 903 | if (mgmt_stypes) { |
| 904 | u16 stypes; |
| 905 | struct nlattr *nl_ftypes, *nl_ifs; |
| 906 | enum nl80211_iftype ift; |
| 907 | |
| 908 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 909 | if (!nl_ifs) |
| 910 | goto nla_put_failure; |
| 911 | |
| 912 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 913 | nl_ftypes = nla_nest_start(msg, ift); |
| 914 | if (!nl_ftypes) |
| 915 | goto nla_put_failure; |
| 916 | i = 0; |
| 917 | stypes = mgmt_stypes[ift].tx; |
| 918 | while (stypes) { |
| 919 | if (stypes & 1) |
| 920 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 921 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 922 | stypes >>= 1; |
| 923 | i++; |
| 924 | } |
| 925 | nla_nest_end(msg, nl_ftypes); |
| 926 | } |
| 927 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 928 | nla_nest_end(msg, nl_ifs); |
| 929 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 930 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 931 | if (!nl_ifs) |
| 932 | goto nla_put_failure; |
| 933 | |
| 934 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 935 | nl_ftypes = nla_nest_start(msg, ift); |
| 936 | if (!nl_ftypes) |
| 937 | goto nla_put_failure; |
| 938 | i = 0; |
| 939 | stypes = mgmt_stypes[ift].rx; |
| 940 | while (stypes) { |
| 941 | if (stypes & 1) |
| 942 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 943 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 944 | stypes >>= 1; |
| 945 | i++; |
| 946 | } |
| 947 | nla_nest_end(msg, nl_ftypes); |
| 948 | } |
| 949 | nla_nest_end(msg, nl_ifs); |
| 950 | } |
| 951 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 952 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 953 | struct nlattr *nl_wowlan; |
| 954 | |
| 955 | nl_wowlan = nla_nest_start(msg, |
| 956 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 957 | if (!nl_wowlan) |
| 958 | goto nla_put_failure; |
| 959 | |
| 960 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 961 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 962 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 963 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 964 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 965 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 966 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 967 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 968 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 969 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 970 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 971 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 972 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 973 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 974 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 975 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 976 | if (dev->wiphy.wowlan.n_patterns) { |
| 977 | struct nl80211_wowlan_pattern_support pat = { |
| 978 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 979 | .min_pattern_len = |
| 980 | dev->wiphy.wowlan.pattern_min_len, |
| 981 | .max_pattern_len = |
| 982 | dev->wiphy.wowlan.pattern_max_len, |
| 983 | }; |
| 984 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 985 | sizeof(pat), &pat); |
| 986 | } |
| 987 | |
| 988 | nla_nest_end(msg, nl_wowlan); |
| 989 | } |
| 990 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 991 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 992 | dev->wiphy.software_iftypes)) |
| 993 | goto nla_put_failure; |
| 994 | |
| 995 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 996 | goto nla_put_failure; |
| 997 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 998 | return genlmsg_end(msg, hdr); |
| 999 | |
| 1000 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1001 | genlmsg_cancel(msg, hdr); |
| 1002 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1006 | { |
| 1007 | int idx = 0; |
| 1008 | int start = cb->args[0]; |
| 1009 | struct cfg80211_registered_device *dev; |
| 1010 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1011 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1012 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1013 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1014 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1015 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1016 | continue; |
| 1017 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1018 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1019 | dev) < 0) { |
| 1020 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1021 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1022 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1023 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1024 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1025 | |
| 1026 | cb->args[0] = idx; |
| 1027 | |
| 1028 | return skb->len; |
| 1029 | } |
| 1030 | |
| 1031 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1032 | { |
| 1033 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1034 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1035 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1036 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1037 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1038 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1039 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1040 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1041 | nlmsg_free(msg); |
| 1042 | return -ENOBUFS; |
| 1043 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1044 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1045 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1046 | } |
| 1047 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1048 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1049 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1050 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1051 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1052 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1053 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1054 | }; |
| 1055 | |
| 1056 | static int parse_txq_params(struct nlattr *tb[], |
| 1057 | struct ieee80211_txq_params *txq_params) |
| 1058 | { |
| 1059 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1060 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1061 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1062 | return -EINVAL; |
| 1063 | |
| 1064 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1065 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1066 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1067 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1068 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1069 | |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1073 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1074 | { |
| 1075 | /* |
| 1076 | * You can only set the channel explicitly for AP, mesh |
| 1077 | * and WDS type interfaces; all others have their channel |
| 1078 | * managed via their respective "establish a connection" |
| 1079 | * command (connect, join, ...) |
| 1080 | * |
| 1081 | * Monitors are special as they are normally slaved to |
| 1082 | * whatever else is going on, so they behave as though |
| 1083 | * you tried setting the wiphy channel itself. |
| 1084 | */ |
| 1085 | return !wdev || |
| 1086 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1087 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1088 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1089 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1090 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1094 | struct wireless_dev *wdev, |
| 1095 | struct genl_info *info) |
| 1096 | { |
| 1097 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1098 | u32 freq; |
| 1099 | int result; |
| 1100 | |
| 1101 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1102 | return -EINVAL; |
| 1103 | |
| 1104 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1105 | return -EOPNOTSUPP; |
| 1106 | |
| 1107 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1108 | channel_type = nla_get_u32(info->attrs[ |
| 1109 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1110 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1111 | channel_type != NL80211_CHAN_HT20 && |
| 1112 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1113 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1114 | return -EINVAL; |
| 1115 | } |
| 1116 | |
| 1117 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1118 | |
| 1119 | mutex_lock(&rdev->devlist_mtx); |
| 1120 | if (wdev) { |
| 1121 | wdev_lock(wdev); |
| 1122 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1123 | wdev_unlock(wdev); |
| 1124 | } else { |
| 1125 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1126 | } |
| 1127 | mutex_unlock(&rdev->devlist_mtx); |
| 1128 | |
| 1129 | return result; |
| 1130 | } |
| 1131 | |
| 1132 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1133 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1135 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1136 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1137 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1140 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1141 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1142 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1143 | struct net_device *dev = info->user_ptr[1]; |
| 1144 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1145 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1146 | |
| 1147 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1148 | return -EINVAL; |
| 1149 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1150 | if (netif_running(dev)) |
| 1151 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1152 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1153 | if (!rdev->ops->set_wds_peer) |
| 1154 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1155 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1156 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1157 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1158 | |
| 1159 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1160 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1164 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1165 | { |
| 1166 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1167 | struct net_device *netdev = NULL; |
| 1168 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1169 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1170 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1171 | u32 changed; |
| 1172 | u8 retry_short = 0, retry_long = 0; |
| 1173 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1174 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1175 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1176 | /* |
| 1177 | * Try to find the wiphy and netdev. Normally this |
| 1178 | * function shouldn't need the netdev, but this is |
| 1179 | * done for backward compatibility -- previously |
| 1180 | * setting the channel was done per wiphy, but now |
| 1181 | * it is per netdev. Previous userland like hostapd |
| 1182 | * also passed a netdev to set_wiphy, so that it is |
| 1183 | * possible to let that go to the right netdev! |
| 1184 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1185 | mutex_lock(&cfg80211_mutex); |
| 1186 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1187 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1188 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1189 | |
| 1190 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1191 | if (netdev && netdev->ieee80211_ptr) { |
| 1192 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1193 | mutex_lock(&rdev->mtx); |
| 1194 | } else |
| 1195 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1196 | } |
| 1197 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1198 | if (!netdev) { |
| 1199 | rdev = __cfg80211_rdev_from_info(info); |
| 1200 | if (IS_ERR(rdev)) { |
| 1201 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1202 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1203 | } |
| 1204 | wdev = NULL; |
| 1205 | netdev = NULL; |
| 1206 | result = 0; |
| 1207 | |
| 1208 | mutex_lock(&rdev->mtx); |
| 1209 | } else if (netif_running(netdev) && |
| 1210 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1211 | wdev = netdev->ieee80211_ptr; |
| 1212 | else |
| 1213 | wdev = NULL; |
| 1214 | |
| 1215 | /* |
| 1216 | * end workaround code, by now the rdev is available |
| 1217 | * and locked, and wdev may or may not be NULL. |
| 1218 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1219 | |
| 1220 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1221 | result = cfg80211_dev_rename( |
| 1222 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1223 | |
| 1224 | mutex_unlock(&cfg80211_mutex); |
| 1225 | |
| 1226 | if (result) |
| 1227 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1228 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1229 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1230 | struct ieee80211_txq_params txq_params; |
| 1231 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1232 | |
| 1233 | if (!rdev->ops->set_txq_params) { |
| 1234 | result = -EOPNOTSUPP; |
| 1235 | goto bad_res; |
| 1236 | } |
| 1237 | |
| 1238 | nla_for_each_nested(nl_txq_params, |
| 1239 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1240 | rem_txq_params) { |
| 1241 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1242 | nla_data(nl_txq_params), |
| 1243 | nla_len(nl_txq_params), |
| 1244 | txq_params_policy); |
| 1245 | result = parse_txq_params(tb, &txq_params); |
| 1246 | if (result) |
| 1247 | goto bad_res; |
| 1248 | |
| 1249 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 1250 | &txq_params); |
| 1251 | if (result) |
| 1252 | goto bad_res; |
| 1253 | } |
| 1254 | } |
| 1255 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1256 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1257 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1258 | if (result) |
| 1259 | goto bad_res; |
| 1260 | } |
| 1261 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1262 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1263 | enum nl80211_tx_power_setting type; |
| 1264 | int idx, mbm = 0; |
| 1265 | |
| 1266 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1267 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1268 | goto bad_res; |
| 1269 | } |
| 1270 | |
| 1271 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1272 | type = nla_get_u32(info->attrs[idx]); |
| 1273 | |
| 1274 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1275 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1276 | result = -EINVAL; |
| 1277 | goto bad_res; |
| 1278 | } |
| 1279 | |
| 1280 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1281 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1282 | mbm = nla_get_u32(info->attrs[idx]); |
| 1283 | } |
| 1284 | |
| 1285 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1286 | if (result) |
| 1287 | goto bad_res; |
| 1288 | } |
| 1289 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1290 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1291 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1292 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1293 | if ((!rdev->wiphy.available_antennas_tx && |
| 1294 | !rdev->wiphy.available_antennas_rx) || |
| 1295 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1296 | result = -EOPNOTSUPP; |
| 1297 | goto bad_res; |
| 1298 | } |
| 1299 | |
| 1300 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1301 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1302 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1303 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1304 | * available antenna masks, except for the "all" mask */ |
| 1305 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1306 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1307 | result = -EINVAL; |
| 1308 | goto bad_res; |
| 1309 | } |
| 1310 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1311 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1312 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1313 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1314 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1315 | if (result) |
| 1316 | goto bad_res; |
| 1317 | } |
| 1318 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1319 | changed = 0; |
| 1320 | |
| 1321 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1322 | retry_short = nla_get_u8( |
| 1323 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1324 | if (retry_short == 0) { |
| 1325 | result = -EINVAL; |
| 1326 | goto bad_res; |
| 1327 | } |
| 1328 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1329 | } |
| 1330 | |
| 1331 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1332 | retry_long = nla_get_u8( |
| 1333 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1334 | if (retry_long == 0) { |
| 1335 | result = -EINVAL; |
| 1336 | goto bad_res; |
| 1337 | } |
| 1338 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1339 | } |
| 1340 | |
| 1341 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1342 | frag_threshold = nla_get_u32( |
| 1343 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1344 | if (frag_threshold < 256) { |
| 1345 | result = -EINVAL; |
| 1346 | goto bad_res; |
| 1347 | } |
| 1348 | if (frag_threshold != (u32) -1) { |
| 1349 | /* |
| 1350 | * Fragments (apart from the last one) are required to |
| 1351 | * have even length. Make the fragmentation code |
| 1352 | * simpler by stripping LSB should someone try to use |
| 1353 | * odd threshold value. |
| 1354 | */ |
| 1355 | frag_threshold &= ~0x1; |
| 1356 | } |
| 1357 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1358 | } |
| 1359 | |
| 1360 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1361 | rts_threshold = nla_get_u32( |
| 1362 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1363 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1364 | } |
| 1365 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1366 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1367 | coverage_class = nla_get_u8( |
| 1368 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1369 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1370 | } |
| 1371 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1372 | if (changed) { |
| 1373 | u8 old_retry_short, old_retry_long; |
| 1374 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1375 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1376 | |
| 1377 | if (!rdev->ops->set_wiphy_params) { |
| 1378 | result = -EOPNOTSUPP; |
| 1379 | goto bad_res; |
| 1380 | } |
| 1381 | |
| 1382 | old_retry_short = rdev->wiphy.retry_short; |
| 1383 | old_retry_long = rdev->wiphy.retry_long; |
| 1384 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1385 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1386 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1387 | |
| 1388 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1389 | rdev->wiphy.retry_short = retry_short; |
| 1390 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1391 | rdev->wiphy.retry_long = retry_long; |
| 1392 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1393 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1394 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1395 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1396 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1397 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1398 | |
| 1399 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1400 | if (result) { |
| 1401 | rdev->wiphy.retry_short = old_retry_short; |
| 1402 | rdev->wiphy.retry_long = old_retry_long; |
| 1403 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1404 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1405 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1406 | } |
| 1407 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1408 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1409 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1410 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1411 | if (netdev) |
| 1412 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1413 | return result; |
| 1414 | } |
| 1415 | |
| 1416 | |
| 1417 | 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] | 1418 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1419 | struct net_device *dev) |
| 1420 | { |
| 1421 | void *hdr; |
| 1422 | |
| 1423 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1424 | if (!hdr) |
| 1425 | return -1; |
| 1426 | |
| 1427 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1428 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1429 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1430 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1431 | |
| 1432 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1433 | rdev->devlist_generation ^ |
| 1434 | (cfg80211_rdev_list_generation << 2)); |
| 1435 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1436 | return genlmsg_end(msg, hdr); |
| 1437 | |
| 1438 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1439 | genlmsg_cancel(msg, hdr); |
| 1440 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1444 | { |
| 1445 | int wp_idx = 0; |
| 1446 | int if_idx = 0; |
| 1447 | int wp_start = cb->args[0]; |
| 1448 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1449 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1450 | struct wireless_dev *wdev; |
| 1451 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1452 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1453 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1454 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1455 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1456 | if (wp_idx < wp_start) { |
| 1457 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1458 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1459 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1460 | if_idx = 0; |
| 1461 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1462 | mutex_lock(&rdev->devlist_mtx); |
| 1463 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1464 | if (if_idx < if_start) { |
| 1465 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1466 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1467 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1468 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1469 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1470 | rdev, wdev->netdev) < 0) { |
| 1471 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1472 | goto out; |
| 1473 | } |
| 1474 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1475 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1476 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1477 | |
| 1478 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1479 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1480 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1481 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1482 | |
| 1483 | cb->args[0] = wp_idx; |
| 1484 | cb->args[1] = if_idx; |
| 1485 | |
| 1486 | return skb->len; |
| 1487 | } |
| 1488 | |
| 1489 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1490 | { |
| 1491 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1492 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1493 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1494 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1495 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1496 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1497 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1498 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1499 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1500 | dev, netdev) < 0) { |
| 1501 | nlmsg_free(msg); |
| 1502 | return -ENOBUFS; |
| 1503 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1504 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1505 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1506 | } |
| 1507 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1508 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1509 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1510 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1511 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1512 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1513 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1514 | }; |
| 1515 | |
| 1516 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1517 | { |
| 1518 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1519 | int flag; |
| 1520 | |
| 1521 | *mntrflags = 0; |
| 1522 | |
| 1523 | if (!nla) |
| 1524 | return -EINVAL; |
| 1525 | |
| 1526 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1527 | nla, mntr_flags_policy)) |
| 1528 | return -EINVAL; |
| 1529 | |
| 1530 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1531 | if (flags[flag]) |
| 1532 | *mntrflags |= (1<<flag); |
| 1533 | |
| 1534 | return 0; |
| 1535 | } |
| 1536 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1537 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1538 | struct net_device *netdev, u8 use_4addr, |
| 1539 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1540 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1541 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1542 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1543 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1544 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1545 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1546 | |
| 1547 | switch (iftype) { |
| 1548 | case NL80211_IFTYPE_AP_VLAN: |
| 1549 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1550 | return 0; |
| 1551 | break; |
| 1552 | case NL80211_IFTYPE_STATION: |
| 1553 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1554 | return 0; |
| 1555 | break; |
| 1556 | default: |
| 1557 | break; |
| 1558 | } |
| 1559 | |
| 1560 | return -EOPNOTSUPP; |
| 1561 | } |
| 1562 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1563 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1564 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1565 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1566 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1567 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1568 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1569 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1570 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1571 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1572 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1573 | memset(¶ms, 0, sizeof(params)); |
| 1574 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1575 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1576 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1577 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1578 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1579 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1580 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1581 | if (ntype > NL80211_IFTYPE_MAX) |
| 1582 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1583 | } |
| 1584 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1585 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1586 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1587 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1588 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1589 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1590 | if (netif_running(dev)) |
| 1591 | return -EBUSY; |
| 1592 | |
| 1593 | wdev_lock(wdev); |
| 1594 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1595 | IEEE80211_MAX_MESH_ID_LEN); |
| 1596 | wdev->mesh_id_up_len = |
| 1597 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1598 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1599 | wdev->mesh_id_up_len); |
| 1600 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1601 | } |
| 1602 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1603 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1604 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1605 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1606 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1607 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1608 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1609 | } else { |
| 1610 | params.use_4addr = -1; |
| 1611 | } |
| 1612 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1613 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1614 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1615 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1616 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1617 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1618 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1619 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1620 | |
| 1621 | flags = &_flags; |
| 1622 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1623 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1624 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1625 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1626 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1627 | else |
| 1628 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1629 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1630 | if (!err && params.use_4addr != -1) |
| 1631 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1632 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1633 | return err; |
| 1634 | } |
| 1635 | |
| 1636 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1637 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1639 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1640 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1641 | int err; |
| 1642 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1643 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1644 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1645 | memset(¶ms, 0, sizeof(params)); |
| 1646 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1647 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1648 | return -EINVAL; |
| 1649 | |
| 1650 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1651 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1652 | if (type > NL80211_IFTYPE_MAX) |
| 1653 | return -EINVAL; |
| 1654 | } |
| 1655 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1656 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1657 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1658 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1659 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1660 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1661 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1662 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1663 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1664 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1665 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1666 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1667 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1668 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1669 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1670 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1671 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1672 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1673 | if (IS_ERR(dev)) |
| 1674 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1675 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1676 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1677 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1678 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1679 | |
| 1680 | wdev_lock(wdev); |
| 1681 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1682 | IEEE80211_MAX_MESH_ID_LEN); |
| 1683 | wdev->mesh_id_up_len = |
| 1684 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1685 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1686 | wdev->mesh_id_up_len); |
| 1687 | wdev_unlock(wdev); |
| 1688 | } |
| 1689 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1690 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1694 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1696 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1698 | if (!rdev->ops->del_virtual_intf) |
| 1699 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1700 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1701 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1702 | } |
| 1703 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1704 | struct get_key_cookie { |
| 1705 | struct sk_buff *msg; |
| 1706 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1707 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1708 | }; |
| 1709 | |
| 1710 | static void get_key_callback(void *c, struct key_params *params) |
| 1711 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1712 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1713 | struct get_key_cookie *cookie = c; |
| 1714 | |
| 1715 | if (params->key) |
| 1716 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1717 | params->key_len, params->key); |
| 1718 | |
| 1719 | if (params->seq) |
| 1720 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1721 | params->seq_len, params->seq); |
| 1722 | |
| 1723 | if (params->cipher) |
| 1724 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1725 | params->cipher); |
| 1726 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1727 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1728 | if (!key) |
| 1729 | goto nla_put_failure; |
| 1730 | |
| 1731 | if (params->key) |
| 1732 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1733 | params->key_len, params->key); |
| 1734 | |
| 1735 | if (params->seq) |
| 1736 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1737 | params->seq_len, params->seq); |
| 1738 | |
| 1739 | if (params->cipher) |
| 1740 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1741 | params->cipher); |
| 1742 | |
| 1743 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1744 | |
| 1745 | nla_nest_end(cookie->msg, key); |
| 1746 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1747 | return; |
| 1748 | nla_put_failure: |
| 1749 | cookie->error = 1; |
| 1750 | } |
| 1751 | |
| 1752 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1753 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1755 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1756 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1757 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1758 | const u8 *mac_addr = NULL; |
| 1759 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1760 | struct get_key_cookie cookie = { |
| 1761 | .error = 0, |
| 1762 | }; |
| 1763 | void *hdr; |
| 1764 | struct sk_buff *msg; |
| 1765 | |
| 1766 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1767 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1768 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1769 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1770 | return -EINVAL; |
| 1771 | |
| 1772 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1773 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1774 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1775 | pairwise = !!mac_addr; |
| 1776 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1777 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1778 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1779 | return -EINVAL; |
| 1780 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1781 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1782 | return -EINVAL; |
| 1783 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1784 | } |
| 1785 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1786 | if (!rdev->ops->get_key) |
| 1787 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1788 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1789 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1790 | if (!msg) |
| 1791 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1792 | |
| 1793 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1794 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1795 | if (IS_ERR(hdr)) |
| 1796 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1797 | |
| 1798 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1799 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1800 | |
| 1801 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1802 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1803 | if (mac_addr) |
| 1804 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1805 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1806 | if (pairwise && mac_addr && |
| 1807 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1808 | return -ENOENT; |
| 1809 | |
| 1810 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1811 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1812 | |
| 1813 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1814 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1815 | |
| 1816 | if (cookie.error) |
| 1817 | goto nla_put_failure; |
| 1818 | |
| 1819 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1820 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1821 | |
| 1822 | nla_put_failure: |
| 1823 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1824 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1825 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1826 | return err; |
| 1827 | } |
| 1828 | |
| 1829 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1830 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1831 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1832 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1833 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1834 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1835 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1836 | err = nl80211_parse_key(info, &key); |
| 1837 | if (err) |
| 1838 | return err; |
| 1839 | |
| 1840 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1841 | return -EINVAL; |
| 1842 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1843 | /* only support setting default key */ |
| 1844 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1845 | return -EINVAL; |
| 1846 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1847 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1848 | |
| 1849 | if (key.def) { |
| 1850 | if (!rdev->ops->set_default_key) { |
| 1851 | err = -EOPNOTSUPP; |
| 1852 | goto out; |
| 1853 | } |
| 1854 | |
| 1855 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1856 | if (err) |
| 1857 | goto out; |
| 1858 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1859 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1860 | key.def_uni, key.def_multi); |
| 1861 | |
| 1862 | if (err) |
| 1863 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1864 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1865 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1866 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1867 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1868 | } else { |
| 1869 | if (key.def_uni || !key.def_multi) { |
| 1870 | err = -EINVAL; |
| 1871 | goto out; |
| 1872 | } |
| 1873 | |
| 1874 | if (!rdev->ops->set_default_mgmt_key) { |
| 1875 | err = -EOPNOTSUPP; |
| 1876 | goto out; |
| 1877 | } |
| 1878 | |
| 1879 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1880 | if (err) |
| 1881 | goto out; |
| 1882 | |
| 1883 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1884 | dev, key.idx); |
| 1885 | if (err) |
| 1886 | goto out; |
| 1887 | |
| 1888 | #ifdef CONFIG_CFG80211_WEXT |
| 1889 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1890 | #endif |
| 1891 | } |
| 1892 | |
| 1893 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1894 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1895 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1896 | return err; |
| 1897 | } |
| 1898 | |
| 1899 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1900 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1902 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1903 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1904 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1905 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1906 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1907 | err = nl80211_parse_key(info, &key); |
| 1908 | if (err) |
| 1909 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1910 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1911 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1912 | return -EINVAL; |
| 1913 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1914 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1915 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1916 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1917 | if (key.type == -1) { |
| 1918 | if (mac_addr) |
| 1919 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1920 | else |
| 1921 | key.type = NL80211_KEYTYPE_GROUP; |
| 1922 | } |
| 1923 | |
| 1924 | /* for now */ |
| 1925 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1926 | key.type != NL80211_KEYTYPE_GROUP) |
| 1927 | return -EINVAL; |
| 1928 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1929 | if (!rdev->ops->add_key) |
| 1930 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1931 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1932 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1933 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1934 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1935 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1936 | |
| 1937 | wdev_lock(dev->ieee80211_ptr); |
| 1938 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1939 | if (!err) |
| 1940 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1941 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1942 | mac_addr, &key.p); |
| 1943 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1944 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1945 | return err; |
| 1946 | } |
| 1947 | |
| 1948 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1949 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1950 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1951 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1952 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1953 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1954 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1955 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1956 | err = nl80211_parse_key(info, &key); |
| 1957 | if (err) |
| 1958 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1959 | |
| 1960 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1961 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1962 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1963 | if (key.type == -1) { |
| 1964 | if (mac_addr) |
| 1965 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1966 | else |
| 1967 | key.type = NL80211_KEYTYPE_GROUP; |
| 1968 | } |
| 1969 | |
| 1970 | /* for now */ |
| 1971 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1972 | key.type != NL80211_KEYTYPE_GROUP) |
| 1973 | return -EINVAL; |
| 1974 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1975 | if (!rdev->ops->del_key) |
| 1976 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1977 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1978 | wdev_lock(dev->ieee80211_ptr); |
| 1979 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1980 | |
| 1981 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 1982 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1983 | err = -ENOENT; |
| 1984 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1985 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1986 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 1987 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1988 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1989 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1990 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1991 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1992 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1993 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1994 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1995 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1996 | } |
| 1997 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1998 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1999 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2000 | return err; |
| 2001 | } |
| 2002 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2003 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2004 | { |
| 2005 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 2006 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2008 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2009 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2010 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2011 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2012 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2013 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2014 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2015 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2016 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2017 | return -EINVAL; |
| 2018 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2019 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2020 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2021 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2022 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2023 | memset(¶ms, 0, sizeof(params)); |
| 2024 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2025 | switch (info->genlhdr->cmd) { |
| 2026 | case NL80211_CMD_NEW_BEACON: |
| 2027 | /* these are required for NEW_BEACON */ |
| 2028 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2029 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2030 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2031 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2032 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2033 | params.interval = |
| 2034 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2035 | params.dtim_period = |
| 2036 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2037 | |
| 2038 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2039 | if (err) |
| 2040 | return err; |
| 2041 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2042 | /* |
| 2043 | * In theory, some of these attributes could be required for |
| 2044 | * NEW_BEACON, but since they were not used when the command was |
| 2045 | * originally added, keep them optional for old user space |
| 2046 | * programs to work with drivers that do not need the additional |
| 2047 | * information. |
| 2048 | */ |
| 2049 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2050 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2051 | params.ssid_len = |
| 2052 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2053 | if (params.ssid_len == 0 || |
| 2054 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2055 | return -EINVAL; |
| 2056 | } |
| 2057 | |
| 2058 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2059 | params.hidden_ssid = nla_get_u32( |
| 2060 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2061 | if (params.hidden_ssid != |
| 2062 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2063 | params.hidden_ssid != |
| 2064 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2065 | params.hidden_ssid != |
| 2066 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2067 | return -EINVAL; |
| 2068 | } |
| 2069 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2070 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2071 | |
| 2072 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2073 | params.auth_type = nla_get_u32( |
| 2074 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2075 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2076 | return -EINVAL; |
| 2077 | } else |
| 2078 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2079 | |
| 2080 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2081 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2082 | if (err) |
| 2083 | return err; |
| 2084 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2085 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2086 | break; |
| 2087 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2088 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2089 | break; |
| 2090 | default: |
| 2091 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2092 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2093 | } |
| 2094 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2095 | if (!call) |
| 2096 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2097 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2098 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2099 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2100 | params.head_len = |
| 2101 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2102 | haveinfo = 1; |
| 2103 | } |
| 2104 | |
| 2105 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2106 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2107 | params.tail_len = |
| 2108 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2109 | haveinfo = 1; |
| 2110 | } |
| 2111 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2112 | if (!haveinfo) |
| 2113 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2114 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2115 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2116 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2117 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2118 | } |
| 2119 | |
| 2120 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2121 | params.proberesp_ies = |
| 2122 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2123 | params.proberesp_ies_len = |
| 2124 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2125 | } |
| 2126 | |
| 2127 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2128 | params.assocresp_ies = |
| 2129 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2130 | params.assocresp_ies_len = |
| 2131 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2132 | } |
| 2133 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2134 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2135 | if (!err && params.interval) |
| 2136 | wdev->beacon_interval = params.interval; |
| 2137 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2141 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2142 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2143 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2144 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2145 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2146 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2147 | if (!rdev->ops->del_beacon) |
| 2148 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2149 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2150 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2151 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2152 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2153 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2154 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2155 | if (!err) |
| 2156 | wdev->beacon_interval = 0; |
| 2157 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2158 | } |
| 2159 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2160 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2161 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2162 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2163 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2164 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2165 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2166 | }; |
| 2167 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2168 | static int parse_station_flags(struct genl_info *info, |
| 2169 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2170 | { |
| 2171 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2172 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2173 | int flag; |
| 2174 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2175 | /* |
| 2176 | * Try parsing the new attribute first so userspace |
| 2177 | * can specify both for older kernels. |
| 2178 | */ |
| 2179 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2180 | if (nla) { |
| 2181 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2182 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2183 | sta_flags = nla_data(nla); |
| 2184 | params->sta_flags_mask = sta_flags->mask; |
| 2185 | params->sta_flags_set = sta_flags->set; |
| 2186 | if ((params->sta_flags_mask | |
| 2187 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2188 | return -EINVAL; |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
| 2192 | /* if present, parse the old attribute */ |
| 2193 | |
| 2194 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2195 | if (!nla) |
| 2196 | return 0; |
| 2197 | |
| 2198 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2199 | nla, sta_flags_policy)) |
| 2200 | return -EINVAL; |
| 2201 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2202 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2203 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2204 | |
| 2205 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2206 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2207 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2208 | |
| 2209 | return 0; |
| 2210 | } |
| 2211 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2212 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2213 | int attr) |
| 2214 | { |
| 2215 | struct nlattr *rate; |
| 2216 | u16 bitrate; |
| 2217 | |
| 2218 | rate = nla_nest_start(msg, attr); |
| 2219 | if (!rate) |
| 2220 | goto nla_put_failure; |
| 2221 | |
| 2222 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2223 | bitrate = cfg80211_calculate_bitrate(info); |
| 2224 | if (bitrate > 0) |
| 2225 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2226 | |
| 2227 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2228 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2229 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2230 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2231 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2232 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2233 | |
| 2234 | nla_nest_end(msg, rate); |
| 2235 | return true; |
| 2236 | |
| 2237 | nla_put_failure: |
| 2238 | return false; |
| 2239 | } |
| 2240 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2241 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2242 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2243 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2244 | { |
| 2245 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2246 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2247 | |
| 2248 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2249 | if (!hdr) |
| 2250 | return -1; |
| 2251 | |
| 2252 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2253 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2254 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2255 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2256 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2257 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2258 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2259 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2260 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2261 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2262 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2263 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2264 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2265 | sinfo->inactive_time); |
| 2266 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2267 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2268 | sinfo->rx_bytes); |
| 2269 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2270 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2271 | sinfo->tx_bytes); |
| 2272 | if (sinfo->filled & STATION_INFO_LLID) |
| 2273 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2274 | sinfo->llid); |
| 2275 | if (sinfo->filled & STATION_INFO_PLID) |
| 2276 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2277 | sinfo->plid); |
| 2278 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2279 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2280 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2281 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2282 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2283 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2284 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2285 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2286 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2287 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2288 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2289 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2290 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2291 | } |
| 2292 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2293 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2294 | NL80211_STA_INFO_RX_BITRATE)) |
| 2295 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2296 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2297 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2298 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2299 | sinfo->rx_packets); |
| 2300 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2301 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2302 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2303 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2304 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2305 | sinfo->tx_retries); |
| 2306 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2307 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2308 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2309 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2310 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2311 | if (!bss_param) |
| 2312 | goto nla_put_failure; |
| 2313 | |
| 2314 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2315 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2316 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2317 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2318 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2319 | NLA_PUT_FLAG(msg, |
| 2320 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2321 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2322 | sinfo->bss_param.dtim_period); |
| 2323 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2324 | sinfo->bss_param.beacon_interval); |
| 2325 | |
| 2326 | nla_nest_end(msg, bss_param); |
| 2327 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2328 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2329 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2330 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2331 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2332 | sinfo->assoc_req_ies); |
| 2333 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2334 | return genlmsg_end(msg, hdr); |
| 2335 | |
| 2336 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2337 | genlmsg_cancel(msg, hdr); |
| 2338 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2339 | } |
| 2340 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2341 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2342 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2343 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2344 | struct station_info sinfo; |
| 2345 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2346 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2347 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2348 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2349 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2350 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2351 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2352 | if (err) |
| 2353 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2354 | |
| 2355 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2356 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2357 | goto out_err; |
| 2358 | } |
| 2359 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2360 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2361 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2362 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2363 | mac_addr, &sinfo); |
| 2364 | if (err == -ENOENT) |
| 2365 | break; |
| 2366 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2367 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2368 | |
| 2369 | if (nl80211_send_station(skb, |
| 2370 | NETLINK_CB(cb->skb).pid, |
| 2371 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2372 | netdev, mac_addr, |
| 2373 | &sinfo) < 0) |
| 2374 | goto out; |
| 2375 | |
| 2376 | sta_idx++; |
| 2377 | } |
| 2378 | |
| 2379 | |
| 2380 | out: |
| 2381 | cb->args[1] = sta_idx; |
| 2382 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2383 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2384 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2385 | |
| 2386 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2387 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2388 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2389 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2390 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2391 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2392 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2393 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2394 | struct sk_buff *msg; |
| 2395 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2396 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2397 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2398 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2399 | |
| 2400 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2401 | return -EINVAL; |
| 2402 | |
| 2403 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2404 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2405 | if (!rdev->ops->get_station) |
| 2406 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2407 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2408 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2409 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2410 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2411 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2412 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2413 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2414 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2415 | |
| 2416 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2417 | dev, mac_addr, &sinfo) < 0) { |
| 2418 | nlmsg_free(msg); |
| 2419 | return -ENOBUFS; |
| 2420 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2421 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2422 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2426 | * 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] | 2427 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2428 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2429 | struct cfg80211_registered_device *rdev, |
| 2430 | struct net_device **vlan) |
| 2431 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2432 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2433 | *vlan = NULL; |
| 2434 | |
| 2435 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2436 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2437 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2438 | if (!*vlan) |
| 2439 | return -ENODEV; |
| 2440 | if (!(*vlan)->ieee80211_ptr) |
| 2441 | return -EINVAL; |
| 2442 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2443 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2444 | if (!netif_running(*vlan)) |
| 2445 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2446 | } |
| 2447 | return 0; |
| 2448 | } |
| 2449 | |
| 2450 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2451 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2452 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2453 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2454 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2455 | struct station_parameters params; |
| 2456 | u8 *mac_addr = NULL; |
| 2457 | |
| 2458 | memset(¶ms, 0, sizeof(params)); |
| 2459 | |
| 2460 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2461 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2462 | |
| 2463 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2464 | return -EINVAL; |
| 2465 | |
| 2466 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2467 | return -EINVAL; |
| 2468 | |
| 2469 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2470 | |
| 2471 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2472 | params.supported_rates = |
| 2473 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2474 | params.supported_rates_len = |
| 2475 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2476 | } |
| 2477 | |
| 2478 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2479 | params.listen_interval = |
| 2480 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2481 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2482 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2483 | params.ht_capa = |
| 2484 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2485 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2486 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2487 | return -EINVAL; |
| 2488 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2489 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2490 | params.plink_action = |
| 2491 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2492 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2493 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2494 | params.plink_state = |
| 2495 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2496 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2497 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2498 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2499 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2500 | |
| 2501 | /* validate settings */ |
| 2502 | err = 0; |
| 2503 | |
| 2504 | switch (dev->ieee80211_ptr->iftype) { |
| 2505 | case NL80211_IFTYPE_AP: |
| 2506 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2507 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2508 | /* disallow mesh-specific things */ |
| 2509 | if (params.plink_action) |
| 2510 | err = -EINVAL; |
| 2511 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2512 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2513 | case NL80211_IFTYPE_STATION: |
| 2514 | /* disallow everything but AUTHORIZED flag */ |
| 2515 | if (params.plink_action) |
| 2516 | err = -EINVAL; |
| 2517 | if (params.vlan) |
| 2518 | err = -EINVAL; |
| 2519 | if (params.supported_rates) |
| 2520 | err = -EINVAL; |
| 2521 | if (params.ht_capa) |
| 2522 | err = -EINVAL; |
| 2523 | if (params.listen_interval >= 0) |
| 2524 | err = -EINVAL; |
| 2525 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 2526 | err = -EINVAL; |
| 2527 | break; |
| 2528 | case NL80211_IFTYPE_MESH_POINT: |
| 2529 | /* disallow things mesh doesn't support */ |
| 2530 | if (params.vlan) |
| 2531 | err = -EINVAL; |
| 2532 | if (params.ht_capa) |
| 2533 | err = -EINVAL; |
| 2534 | if (params.listen_interval >= 0) |
| 2535 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2536 | if (params.sta_flags_mask & |
| 2537 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2538 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2539 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2540 | err = -EINVAL; |
| 2541 | break; |
| 2542 | default: |
| 2543 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2544 | } |
| 2545 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2546 | if (err) |
| 2547 | goto out; |
| 2548 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2549 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2550 | err = -EOPNOTSUPP; |
| 2551 | goto out; |
| 2552 | } |
| 2553 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2554 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2555 | |
| 2556 | out: |
| 2557 | if (params.vlan) |
| 2558 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2559 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2560 | return err; |
| 2561 | } |
| 2562 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2563 | static struct nla_policy |
| 2564 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2565 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2566 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2567 | }; |
| 2568 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2569 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2570 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2572 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2573 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2574 | struct station_parameters params; |
| 2575 | u8 *mac_addr = NULL; |
| 2576 | |
| 2577 | memset(¶ms, 0, sizeof(params)); |
| 2578 | |
| 2579 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2580 | return -EINVAL; |
| 2581 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2582 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2583 | return -EINVAL; |
| 2584 | |
| 2585 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2586 | return -EINVAL; |
| 2587 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2588 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2589 | return -EINVAL; |
| 2590 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2591 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2592 | params.supported_rates = |
| 2593 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2594 | params.supported_rates_len = |
| 2595 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2596 | params.listen_interval = |
| 2597 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2598 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2599 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2600 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2601 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2602 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2603 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2604 | params.ht_capa = |
| 2605 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2606 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2607 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2608 | params.plink_action = |
| 2609 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2610 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2611 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2612 | return -EINVAL; |
| 2613 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2614 | /* parse WME attributes if sta is WME capable */ |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 2615 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
| 2616 | (params.sta_flags_set & NL80211_STA_FLAG_WME) && |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2617 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2618 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2619 | struct nlattr *nla; |
| 2620 | |
| 2621 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2622 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2623 | nl80211_sta_wme_policy); |
| 2624 | if (err) |
| 2625 | return err; |
| 2626 | |
| 2627 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2628 | params.uapsd_queues = |
| 2629 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2630 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2631 | return -EINVAL; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2632 | |
| 2633 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2634 | params.max_sp = |
| 2635 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2636 | |
| 2637 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2638 | return -EINVAL; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2639 | } |
| 2640 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2641 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2642 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2643 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2644 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2645 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2646 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2647 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2648 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2649 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2650 | |
| 2651 | /* validate settings */ |
| 2652 | err = 0; |
| 2653 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2654 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2655 | err = -EOPNOTSUPP; |
| 2656 | goto out; |
| 2657 | } |
| 2658 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2659 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2660 | |
| 2661 | out: |
| 2662 | if (params.vlan) |
| 2663 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2664 | return err; |
| 2665 | } |
| 2666 | |
| 2667 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2668 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2669 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2670 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2671 | u8 *mac_addr = NULL; |
| 2672 | |
| 2673 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2674 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2675 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2676 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2677 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2678 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2679 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2680 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2681 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2682 | if (!rdev->ops->del_station) |
| 2683 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2684 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2685 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2686 | } |
| 2687 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2688 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2689 | int flags, struct net_device *dev, |
| 2690 | u8 *dst, u8 *next_hop, |
| 2691 | struct mpath_info *pinfo) |
| 2692 | { |
| 2693 | void *hdr; |
| 2694 | struct nlattr *pinfoattr; |
| 2695 | |
| 2696 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2697 | if (!hdr) |
| 2698 | return -1; |
| 2699 | |
| 2700 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2701 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2702 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2703 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2704 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2705 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2706 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2707 | if (!pinfoattr) |
| 2708 | goto nla_put_failure; |
| 2709 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2710 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2711 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2712 | if (pinfo->filled & MPATH_INFO_SN) |
| 2713 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2714 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2715 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2716 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2717 | pinfo->metric); |
| 2718 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2719 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2720 | pinfo->exptime); |
| 2721 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2722 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2723 | pinfo->flags); |
| 2724 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2725 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2726 | pinfo->discovery_timeout); |
| 2727 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2728 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2729 | pinfo->discovery_retries); |
| 2730 | |
| 2731 | nla_nest_end(msg, pinfoattr); |
| 2732 | |
| 2733 | return genlmsg_end(msg, hdr); |
| 2734 | |
| 2735 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2736 | genlmsg_cancel(msg, hdr); |
| 2737 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2741 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2742 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2743 | struct mpath_info pinfo; |
| 2744 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2745 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2746 | u8 dst[ETH_ALEN]; |
| 2747 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2748 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2749 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2750 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2751 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2752 | if (err) |
| 2753 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2754 | |
| 2755 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2756 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2757 | goto out_err; |
| 2758 | } |
| 2759 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2760 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2761 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2762 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2763 | } |
| 2764 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2765 | while (1) { |
| 2766 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2767 | dst, next_hop, &pinfo); |
| 2768 | if (err == -ENOENT) |
| 2769 | break; |
| 2770 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2771 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2772 | |
| 2773 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2774 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2775 | netdev, dst, next_hop, |
| 2776 | &pinfo) < 0) |
| 2777 | goto out; |
| 2778 | |
| 2779 | path_idx++; |
| 2780 | } |
| 2781 | |
| 2782 | |
| 2783 | out: |
| 2784 | cb->args[1] = path_idx; |
| 2785 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2786 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2787 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2788 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2792 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2793 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2794 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2795 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2796 | struct mpath_info pinfo; |
| 2797 | struct sk_buff *msg; |
| 2798 | u8 *dst = NULL; |
| 2799 | u8 next_hop[ETH_ALEN]; |
| 2800 | |
| 2801 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2802 | |
| 2803 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2804 | return -EINVAL; |
| 2805 | |
| 2806 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2807 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2808 | if (!rdev->ops->get_mpath) |
| 2809 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2810 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2811 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2812 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2813 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2814 | 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] | 2815 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2816 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2817 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2818 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2819 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2820 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2821 | |
| 2822 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2823 | dev, dst, next_hop, &pinfo) < 0) { |
| 2824 | nlmsg_free(msg); |
| 2825 | return -ENOBUFS; |
| 2826 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2827 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2828 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2832 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2833 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2834 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2835 | u8 *dst = NULL; |
| 2836 | u8 *next_hop = NULL; |
| 2837 | |
| 2838 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2839 | return -EINVAL; |
| 2840 | |
| 2841 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2842 | return -EINVAL; |
| 2843 | |
| 2844 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2845 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2846 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2847 | if (!rdev->ops->change_mpath) |
| 2848 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2849 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2850 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2851 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2852 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2853 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2854 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2855 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2856 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2857 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2858 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2859 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2860 | u8 *dst = NULL; |
| 2861 | u8 *next_hop = NULL; |
| 2862 | |
| 2863 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2864 | return -EINVAL; |
| 2865 | |
| 2866 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2867 | return -EINVAL; |
| 2868 | |
| 2869 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2870 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2871 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2872 | if (!rdev->ops->add_mpath) |
| 2873 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2874 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2875 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2876 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2877 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2878 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2882 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2883 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2884 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2885 | u8 *dst = NULL; |
| 2886 | |
| 2887 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2888 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2889 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2890 | if (!rdev->ops->del_mpath) |
| 2891 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2892 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2893 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2894 | } |
| 2895 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2896 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2897 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2898 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2899 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2900 | struct bss_parameters params; |
| 2901 | |
| 2902 | memset(¶ms, 0, sizeof(params)); |
| 2903 | /* default to not changing parameters */ |
| 2904 | params.use_cts_prot = -1; |
| 2905 | params.use_short_preamble = -1; |
| 2906 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2907 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2908 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2909 | |
| 2910 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2911 | params.use_cts_prot = |
| 2912 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2913 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2914 | params.use_short_preamble = |
| 2915 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2916 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2917 | params.use_short_slot_time = |
| 2918 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2919 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2920 | params.basic_rates = |
| 2921 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2922 | params.basic_rates_len = |
| 2923 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2924 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2925 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2926 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2927 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2928 | params.ht_opmode = |
| 2929 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2930 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2931 | if (!rdev->ops->change_bss) |
| 2932 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2933 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2934 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2935 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2936 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2938 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2939 | } |
| 2940 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2941 | 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] | 2942 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2943 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2944 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2945 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2946 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2947 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2948 | }; |
| 2949 | |
| 2950 | static int parse_reg_rule(struct nlattr *tb[], |
| 2951 | struct ieee80211_reg_rule *reg_rule) |
| 2952 | { |
| 2953 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2954 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2955 | |
| 2956 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2957 | return -EINVAL; |
| 2958 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2959 | return -EINVAL; |
| 2960 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2961 | return -EINVAL; |
| 2962 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2963 | return -EINVAL; |
| 2964 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2965 | return -EINVAL; |
| 2966 | |
| 2967 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2968 | |
| 2969 | freq_range->start_freq_khz = |
| 2970 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2971 | freq_range->end_freq_khz = |
| 2972 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2973 | freq_range->max_bandwidth_khz = |
| 2974 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2975 | |
| 2976 | power_rule->max_eirp = |
| 2977 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2978 | |
| 2979 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2980 | power_rule->max_antenna_gain = |
| 2981 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2982 | |
| 2983 | return 0; |
| 2984 | } |
| 2985 | |
| 2986 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2987 | { |
| 2988 | int r; |
| 2989 | char *data = NULL; |
| 2990 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2991 | /* |
| 2992 | * You should only get this when cfg80211 hasn't yet initialized |
| 2993 | * completely when built-in to the kernel right between the time |
| 2994 | * window between nl80211_init() and regulatory_init(), if that is |
| 2995 | * even possible. |
| 2996 | */ |
| 2997 | mutex_lock(&cfg80211_mutex); |
| 2998 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2999 | mutex_unlock(&cfg80211_mutex); |
| 3000 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3001 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3002 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3003 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3004 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3005 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3006 | |
| 3007 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3008 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3009 | r = regulatory_hint_user(data); |
| 3010 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3011 | return r; |
| 3012 | } |
| 3013 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3014 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3015 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3016 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3017 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3018 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3019 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3020 | struct mesh_config cur_params; |
| 3021 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3022 | void *hdr; |
| 3023 | struct nlattr *pinfoattr; |
| 3024 | struct sk_buff *msg; |
| 3025 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3026 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3027 | return -EOPNOTSUPP; |
| 3028 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3029 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3030 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3031 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3032 | wdev_lock(wdev); |
| 3033 | /* If not connected, get default parameters */ |
| 3034 | if (!wdev->mesh_id_len) |
| 3035 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3036 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3037 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3038 | &cur_params); |
| 3039 | wdev_unlock(wdev); |
| 3040 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3041 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3042 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3043 | |
| 3044 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3045 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3046 | if (!msg) |
| 3047 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3048 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3049 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3050 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3051 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3052 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3053 | if (!pinfoattr) |
| 3054 | goto nla_put_failure; |
| 3055 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3056 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3057 | cur_params.dot11MeshRetryTimeout); |
| 3058 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3059 | cur_params.dot11MeshConfirmTimeout); |
| 3060 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3061 | cur_params.dot11MeshHoldingTimeout); |
| 3062 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3063 | cur_params.dot11MeshMaxPeerLinks); |
| 3064 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3065 | cur_params.dot11MeshMaxRetries); |
| 3066 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3067 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3068 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3069 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3070 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3071 | cur_params.auto_open_plinks); |
| 3072 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3073 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3074 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3075 | cur_params.path_refresh_time); |
| 3076 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3077 | cur_params.min_discovery_timeout); |
| 3078 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3079 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3080 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3081 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 3082 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3083 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3084 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3085 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3086 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3087 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3088 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3089 | cur_params.dot11MeshGateAnnouncementProtocol); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3090 | nla_nest_end(msg, pinfoattr); |
| 3091 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3092 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3093 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3094 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3095 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3096 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3097 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3098 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3101 | 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] | 3102 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3103 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3104 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3105 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3106 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3107 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3108 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3109 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3110 | |
| 3111 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3112 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3113 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3114 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3115 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 3116 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3117 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3118 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3119 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3120 | }; |
| 3121 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3122 | static const struct nla_policy |
| 3123 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3124 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3125 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3126 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3127 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3128 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3129 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3130 | }; |
| 3131 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3132 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3133 | struct mesh_config *cfg, |
| 3134 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3135 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3136 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3137 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3138 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3139 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3140 | do {\ |
| 3141 | if (table[attr_num]) {\ |
| 3142 | cfg->param = nla_fn(table[attr_num]); \ |
| 3143 | mask |= (1 << (attr_num - 1)); \ |
| 3144 | } \ |
| 3145 | } while (0);\ |
| 3146 | |
| 3147 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3148 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3149 | return -EINVAL; |
| 3150 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3151 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3152 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3153 | return -EINVAL; |
| 3154 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3155 | /* This makes sure that there aren't more than 32 mesh config |
| 3156 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3157 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3158 | |
| 3159 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3160 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3161 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3162 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3163 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3164 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3165 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3166 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3167 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3168 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3169 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3170 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3171 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3172 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3173 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3174 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3175 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3177 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3178 | nla_get_u8); |
| 3179 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3180 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3181 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3182 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3183 | nla_get_u16); |
| 3184 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3185 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3186 | nla_get_u32); |
| 3187 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3188 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3189 | nla_get_u16); |
| 3190 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3191 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3192 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3193 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3194 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3195 | dot11MeshHWMPRootMode, mask, |
| 3196 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3197 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3198 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3199 | dot11MeshHWMPRannInterval, mask, |
| 3200 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3201 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3202 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3203 | dot11MeshGateAnnouncementProtocol, mask, |
| 3204 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3205 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3206 | if (mask_out) |
| 3207 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3208 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3209 | return 0; |
| 3210 | |
| 3211 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3212 | } |
| 3213 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3214 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3215 | struct mesh_setup *setup) |
| 3216 | { |
| 3217 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3218 | |
| 3219 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3220 | return -EINVAL; |
| 3221 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3222 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3223 | nl80211_mesh_setup_params_policy)) |
| 3224 | return -EINVAL; |
| 3225 | |
| 3226 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3227 | setup->path_sel_proto = |
| 3228 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3229 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3230 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3231 | |
| 3232 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3233 | setup->path_metric = |
| 3234 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3235 | IEEE80211_PATH_METRIC_VENDOR : |
| 3236 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3237 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3238 | |
| 3239 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3240 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3241 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3242 | if (!is_valid_ie_attr(ieattr)) |
| 3243 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3244 | setup->ie = nla_data(ieattr); |
| 3245 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3246 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3247 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3248 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3249 | |
| 3250 | return 0; |
| 3251 | } |
| 3252 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3253 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3254 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3255 | { |
| 3256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3257 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3258 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3259 | struct mesh_config cfg; |
| 3260 | u32 mask; |
| 3261 | int err; |
| 3262 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3263 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3264 | return -EOPNOTSUPP; |
| 3265 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3266 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3267 | return -EOPNOTSUPP; |
| 3268 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3269 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3270 | if (err) |
| 3271 | return err; |
| 3272 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3273 | wdev_lock(wdev); |
| 3274 | if (!wdev->mesh_id_len) |
| 3275 | err = -ENOLINK; |
| 3276 | |
| 3277 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3278 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3279 | mask, &cfg); |
| 3280 | |
| 3281 | wdev_unlock(wdev); |
| 3282 | |
| 3283 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3286 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3287 | { |
| 3288 | struct sk_buff *msg; |
| 3289 | void *hdr = NULL; |
| 3290 | struct nlattr *nl_reg_rules; |
| 3291 | unsigned int i; |
| 3292 | int err = -EINVAL; |
| 3293 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3294 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3295 | |
| 3296 | if (!cfg80211_regdomain) |
| 3297 | goto out; |
| 3298 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3299 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3300 | if (!msg) { |
| 3301 | err = -ENOBUFS; |
| 3302 | goto out; |
| 3303 | } |
| 3304 | |
| 3305 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3306 | NL80211_CMD_GET_REG); |
| 3307 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3308 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3309 | |
| 3310 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3311 | cfg80211_regdomain->alpha2); |
| 3312 | |
| 3313 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3314 | if (!nl_reg_rules) |
| 3315 | goto nla_put_failure; |
| 3316 | |
| 3317 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3318 | struct nlattr *nl_reg_rule; |
| 3319 | const struct ieee80211_reg_rule *reg_rule; |
| 3320 | const struct ieee80211_freq_range *freq_range; |
| 3321 | const struct ieee80211_power_rule *power_rule; |
| 3322 | |
| 3323 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3324 | freq_range = ®_rule->freq_range; |
| 3325 | power_rule = ®_rule->power_rule; |
| 3326 | |
| 3327 | nl_reg_rule = nla_nest_start(msg, i); |
| 3328 | if (!nl_reg_rule) |
| 3329 | goto nla_put_failure; |
| 3330 | |
| 3331 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3332 | reg_rule->flags); |
| 3333 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3334 | freq_range->start_freq_khz); |
| 3335 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3336 | freq_range->end_freq_khz); |
| 3337 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3338 | freq_range->max_bandwidth_khz); |
| 3339 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3340 | power_rule->max_antenna_gain); |
| 3341 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3342 | power_rule->max_eirp); |
| 3343 | |
| 3344 | nla_nest_end(msg, nl_reg_rule); |
| 3345 | } |
| 3346 | |
| 3347 | nla_nest_end(msg, nl_reg_rules); |
| 3348 | |
| 3349 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3350 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3351 | goto out; |
| 3352 | |
| 3353 | nla_put_failure: |
| 3354 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3355 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3356 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3357 | err = -EMSGSIZE; |
| 3358 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3359 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3360 | return err; |
| 3361 | } |
| 3362 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3363 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3364 | { |
| 3365 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3366 | struct nlattr *nl_reg_rule; |
| 3367 | char *alpha2 = NULL; |
| 3368 | int rem_reg_rules = 0, r = 0; |
| 3369 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3370 | struct ieee80211_regdomain *rd = NULL; |
| 3371 | |
| 3372 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3373 | return -EINVAL; |
| 3374 | |
| 3375 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3376 | return -EINVAL; |
| 3377 | |
| 3378 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3379 | |
| 3380 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3381 | rem_reg_rules) { |
| 3382 | num_rules++; |
| 3383 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3384 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3385 | } |
| 3386 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3387 | mutex_lock(&cfg80211_mutex); |
| 3388 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3389 | if (!reg_is_valid_request(alpha2)) { |
| 3390 | r = -EINVAL; |
| 3391 | goto bad_reg; |
| 3392 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3393 | |
| 3394 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3395 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3396 | |
| 3397 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3398 | if (!rd) { |
| 3399 | r = -ENOMEM; |
| 3400 | goto bad_reg; |
| 3401 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3402 | |
| 3403 | rd->n_reg_rules = num_rules; |
| 3404 | rd->alpha2[0] = alpha2[0]; |
| 3405 | rd->alpha2[1] = alpha2[1]; |
| 3406 | |
| 3407 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3408 | rem_reg_rules) { |
| 3409 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3410 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3411 | reg_rule_policy); |
| 3412 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3413 | if (r) |
| 3414 | goto bad_reg; |
| 3415 | |
| 3416 | rule_idx++; |
| 3417 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3418 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3419 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3420 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3421 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | BUG_ON(rule_idx != num_rules); |
| 3425 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3426 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3427 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3428 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3429 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3430 | return r; |
| 3431 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3432 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3433 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3434 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3435 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3438 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3439 | { |
| 3440 | struct nlattr *attr1, *attr2; |
| 3441 | int n_channels = 0, tmp1, tmp2; |
| 3442 | |
| 3443 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3444 | n_channels++; |
| 3445 | /* |
| 3446 | * Some hardware has a limited channel list for |
| 3447 | * scanning, and it is pretty much nonsensical |
| 3448 | * to scan for a channel twice, so disallow that |
| 3449 | * and don't require drivers to check that the |
| 3450 | * channel list they get isn't longer than what |
| 3451 | * they can scan, as long as they can scan all |
| 3452 | * the channels they registered at once. |
| 3453 | */ |
| 3454 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3455 | if (attr1 != attr2 && |
| 3456 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3457 | return 0; |
| 3458 | } |
| 3459 | |
| 3460 | return n_channels; |
| 3461 | } |
| 3462 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3463 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3464 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3466 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3467 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3468 | struct nlattr *attr; |
| 3469 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3470 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3471 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3472 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3473 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3474 | return -EINVAL; |
| 3475 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3476 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3477 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3478 | if (!rdev->ops->scan) |
| 3479 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3480 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3481 | if (rdev->scan_req) |
| 3482 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3483 | |
| 3484 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3485 | n_channels = validate_scan_freqs( |
| 3486 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3487 | if (!n_channels) |
| 3488 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3489 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3490 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3491 | n_channels = 0; |
| 3492 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3493 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3494 | if (wiphy->bands[band]) |
| 3495 | n_channels += wiphy->bands[band]->n_channels; |
| 3496 | } |
| 3497 | |
| 3498 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3499 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3500 | n_ssids++; |
| 3501 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3502 | if (n_ssids > wiphy->max_scan_ssids) |
| 3503 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3504 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3505 | if (info->attrs[NL80211_ATTR_IE]) |
| 3506 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3507 | else |
| 3508 | ie_len = 0; |
| 3509 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3510 | if (ie_len > wiphy->max_scan_ie_len) |
| 3511 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3512 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3513 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3514 | + sizeof(*request->ssids) * n_ssids |
| 3515 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3516 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3517 | if (!request) |
| 3518 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3519 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3520 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3521 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3522 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3523 | if (ie_len) { |
| 3524 | if (request->ssids) |
| 3525 | request->ie = (void *)(request->ssids + n_ssids); |
| 3526 | else |
| 3527 | request->ie = (void *)(request->channels + n_channels); |
| 3528 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3529 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3530 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3531 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3532 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3533 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3534 | struct ieee80211_channel *chan; |
| 3535 | |
| 3536 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3537 | |
| 3538 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3539 | err = -EINVAL; |
| 3540 | goto out_free; |
| 3541 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3542 | |
| 3543 | /* ignore disabled channels */ |
| 3544 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3545 | continue; |
| 3546 | |
| 3547 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3548 | i++; |
| 3549 | } |
| 3550 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3551 | enum ieee80211_band band; |
| 3552 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3553 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3554 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3555 | int j; |
| 3556 | if (!wiphy->bands[band]) |
| 3557 | continue; |
| 3558 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3559 | struct ieee80211_channel *chan; |
| 3560 | |
| 3561 | chan = &wiphy->bands[band]->channels[j]; |
| 3562 | |
| 3563 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3564 | continue; |
| 3565 | |
| 3566 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3567 | i++; |
| 3568 | } |
| 3569 | } |
| 3570 | } |
| 3571 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3572 | if (!i) { |
| 3573 | err = -EINVAL; |
| 3574 | goto out_free; |
| 3575 | } |
| 3576 | |
| 3577 | request->n_channels = i; |
| 3578 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3579 | i = 0; |
| 3580 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3581 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3582 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3583 | err = -EINVAL; |
| 3584 | goto out_free; |
| 3585 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3586 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3587 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3588 | i++; |
| 3589 | } |
| 3590 | } |
| 3591 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3592 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3593 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3594 | memcpy((void *)request->ie, |
| 3595 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3596 | request->ie_len); |
| 3597 | } |
| 3598 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3599 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3600 | if (wiphy->bands[i]) |
| 3601 | request->rates[i] = |
| 3602 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3603 | |
| 3604 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3605 | nla_for_each_nested(attr, |
| 3606 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3607 | tmp) { |
| 3608 | enum ieee80211_band band = nla_type(attr); |
| 3609 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3610 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3611 | err = -EINVAL; |
| 3612 | goto out_free; |
| 3613 | } |
| 3614 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3615 | nla_data(attr), |
| 3616 | nla_len(attr), |
| 3617 | &request->rates[band]); |
| 3618 | if (err) |
| 3619 | goto out_free; |
| 3620 | } |
| 3621 | } |
| 3622 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3623 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3624 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3625 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3626 | rdev->scan_req = request; |
| 3627 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3628 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3629 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3630 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3631 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3632 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3633 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3634 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3635 | kfree(request); |
| 3636 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3637 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3638 | return err; |
| 3639 | } |
| 3640 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3641 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3642 | struct genl_info *info) |
| 3643 | { |
| 3644 | struct cfg80211_sched_scan_request *request; |
| 3645 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3646 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3647 | struct nlattr *attr; |
| 3648 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3649 | 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] | 3650 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3651 | enum ieee80211_band band; |
| 3652 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3653 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3654 | |
| 3655 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3656 | !rdev->ops->sched_scan_start) |
| 3657 | return -EOPNOTSUPP; |
| 3658 | |
| 3659 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3660 | return -EINVAL; |
| 3661 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3662 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3663 | return -EINVAL; |
| 3664 | |
| 3665 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3666 | if (interval == 0) |
| 3667 | return -EINVAL; |
| 3668 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3669 | wiphy = &rdev->wiphy; |
| 3670 | |
| 3671 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3672 | n_channels = validate_scan_freqs( |
| 3673 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3674 | if (!n_channels) |
| 3675 | return -EINVAL; |
| 3676 | } else { |
| 3677 | n_channels = 0; |
| 3678 | |
| 3679 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3680 | if (wiphy->bands[band]) |
| 3681 | n_channels += wiphy->bands[band]->n_channels; |
| 3682 | } |
| 3683 | |
| 3684 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3685 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3686 | tmp) |
| 3687 | n_ssids++; |
| 3688 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3689 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3690 | return -EINVAL; |
| 3691 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3692 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3693 | nla_for_each_nested(attr, |
| 3694 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3695 | tmp) |
| 3696 | n_match_sets++; |
| 3697 | |
| 3698 | if (n_match_sets > wiphy->max_match_sets) |
| 3699 | return -EINVAL; |
| 3700 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3701 | if (info->attrs[NL80211_ATTR_IE]) |
| 3702 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3703 | else |
| 3704 | ie_len = 0; |
| 3705 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3706 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3707 | return -EINVAL; |
| 3708 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3709 | mutex_lock(&rdev->sched_scan_mtx); |
| 3710 | |
| 3711 | if (rdev->sched_scan_req) { |
| 3712 | err = -EINPROGRESS; |
| 3713 | goto out; |
| 3714 | } |
| 3715 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3716 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3717 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3718 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3719 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3720 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3721 | if (!request) { |
| 3722 | err = -ENOMEM; |
| 3723 | goto out; |
| 3724 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3725 | |
| 3726 | if (n_ssids) |
| 3727 | request->ssids = (void *)&request->channels[n_channels]; |
| 3728 | request->n_ssids = n_ssids; |
| 3729 | if (ie_len) { |
| 3730 | if (request->ssids) |
| 3731 | request->ie = (void *)(request->ssids + n_ssids); |
| 3732 | else |
| 3733 | request->ie = (void *)(request->channels + n_channels); |
| 3734 | } |
| 3735 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3736 | if (n_match_sets) { |
| 3737 | if (request->ie) |
| 3738 | request->match_sets = (void *)(request->ie + ie_len); |
| 3739 | else if (request->ssids) |
| 3740 | request->match_sets = |
| 3741 | (void *)(request->ssids + n_ssids); |
| 3742 | else |
| 3743 | request->match_sets = |
| 3744 | (void *)(request->channels + n_channels); |
| 3745 | } |
| 3746 | request->n_match_sets = n_match_sets; |
| 3747 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3748 | i = 0; |
| 3749 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3750 | /* user specified, bail out if channel not found */ |
| 3751 | nla_for_each_nested(attr, |
| 3752 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3753 | tmp) { |
| 3754 | struct ieee80211_channel *chan; |
| 3755 | |
| 3756 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3757 | |
| 3758 | if (!chan) { |
| 3759 | err = -EINVAL; |
| 3760 | goto out_free; |
| 3761 | } |
| 3762 | |
| 3763 | /* ignore disabled channels */ |
| 3764 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3765 | continue; |
| 3766 | |
| 3767 | request->channels[i] = chan; |
| 3768 | i++; |
| 3769 | } |
| 3770 | } else { |
| 3771 | /* all channels */ |
| 3772 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3773 | int j; |
| 3774 | if (!wiphy->bands[band]) |
| 3775 | continue; |
| 3776 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3777 | struct ieee80211_channel *chan; |
| 3778 | |
| 3779 | chan = &wiphy->bands[band]->channels[j]; |
| 3780 | |
| 3781 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3782 | continue; |
| 3783 | |
| 3784 | request->channels[i] = chan; |
| 3785 | i++; |
| 3786 | } |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | if (!i) { |
| 3791 | err = -EINVAL; |
| 3792 | goto out_free; |
| 3793 | } |
| 3794 | |
| 3795 | request->n_channels = i; |
| 3796 | |
| 3797 | i = 0; |
| 3798 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3799 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3800 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3801 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3802 | err = -EINVAL; |
| 3803 | goto out_free; |
| 3804 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3805 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3806 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3807 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3808 | i++; |
| 3809 | } |
| 3810 | } |
| 3811 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3812 | i = 0; |
| 3813 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 3814 | nla_for_each_nested(attr, |
| 3815 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3816 | tmp) { |
| 3817 | struct nlattr *ssid; |
| 3818 | |
| 3819 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 3820 | nla_data(attr), nla_len(attr), |
| 3821 | nl80211_match_policy); |
| 3822 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 3823 | if (ssid) { |
| 3824 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 3825 | err = -EINVAL; |
| 3826 | goto out_free; |
| 3827 | } |
| 3828 | memcpy(request->match_sets[i].ssid.ssid, |
| 3829 | nla_data(ssid), nla_len(ssid)); |
| 3830 | request->match_sets[i].ssid.ssid_len = |
| 3831 | nla_len(ssid); |
| 3832 | } |
| 3833 | i++; |
| 3834 | } |
| 3835 | } |
| 3836 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3837 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3838 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3839 | memcpy((void *)request->ie, |
| 3840 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3841 | request->ie_len); |
| 3842 | } |
| 3843 | |
| 3844 | request->dev = dev; |
| 3845 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3846 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3847 | |
| 3848 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3849 | if (!err) { |
| 3850 | rdev->sched_scan_req = request; |
| 3851 | nl80211_send_sched_scan(rdev, dev, |
| 3852 | NL80211_CMD_START_SCHED_SCAN); |
| 3853 | goto out; |
| 3854 | } |
| 3855 | |
| 3856 | out_free: |
| 3857 | kfree(request); |
| 3858 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3859 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3860 | return err; |
| 3861 | } |
| 3862 | |
| 3863 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3864 | struct genl_info *info) |
| 3865 | { |
| 3866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3867 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3868 | |
| 3869 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3870 | !rdev->ops->sched_scan_stop) |
| 3871 | return -EOPNOTSUPP; |
| 3872 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3873 | mutex_lock(&rdev->sched_scan_mtx); |
| 3874 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3875 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3876 | |
| 3877 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3878 | } |
| 3879 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3880 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3881 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3882 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3883 | struct wireless_dev *wdev, |
| 3884 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3885 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3886 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3887 | void *hdr; |
| 3888 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3889 | int i; |
| 3890 | |
| 3891 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3892 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3893 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3894 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3895 | if (!hdr) |
| 3896 | return -1; |
| 3897 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3898 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3899 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3900 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3901 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3902 | |
| 3903 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3904 | if (!bss) |
| 3905 | goto nla_put_failure; |
| 3906 | if (!is_zero_ether_addr(res->bssid)) |
| 3907 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3908 | if (res->information_elements && res->len_information_elements) |
| 3909 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3910 | res->len_information_elements, |
| 3911 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3912 | if (res->beacon_ies && res->len_beacon_ies && |
| 3913 | res->beacon_ies != res->information_elements) |
| 3914 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3915 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3916 | if (res->tsf) |
| 3917 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3918 | if (res->beacon_interval) |
| 3919 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3920 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3921 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3922 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3923 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3924 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3925 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3926 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3927 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3928 | break; |
| 3929 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3930 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3931 | break; |
| 3932 | default: |
| 3933 | break; |
| 3934 | } |
| 3935 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3936 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3937 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3938 | case NL80211_IFTYPE_STATION: |
| 3939 | if (intbss == wdev->current_bss) |
| 3940 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3941 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3942 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3943 | if (intbss != wdev->auth_bsses[i]) |
| 3944 | continue; |
| 3945 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3946 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3947 | break; |
| 3948 | } |
| 3949 | break; |
| 3950 | case NL80211_IFTYPE_ADHOC: |
| 3951 | if (intbss == wdev->current_bss) |
| 3952 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3953 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3954 | break; |
| 3955 | default: |
| 3956 | break; |
| 3957 | } |
| 3958 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3959 | nla_nest_end(msg, bss); |
| 3960 | |
| 3961 | return genlmsg_end(msg, hdr); |
| 3962 | |
| 3963 | nla_put_failure: |
| 3964 | genlmsg_cancel(msg, hdr); |
| 3965 | return -EMSGSIZE; |
| 3966 | } |
| 3967 | |
| 3968 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3969 | struct netlink_callback *cb) |
| 3970 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3971 | struct cfg80211_registered_device *rdev; |
| 3972 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3973 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3974 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3975 | int start = cb->args[1], idx = 0; |
| 3976 | int err; |
| 3977 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3978 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 3979 | if (err) |
| 3980 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3981 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3982 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3983 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3984 | wdev_lock(wdev); |
| 3985 | spin_lock_bh(&rdev->bss_lock); |
| 3986 | cfg80211_bss_expire(rdev); |
| 3987 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3988 | cb->seq = rdev->bss_generation; |
| 3989 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3990 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3991 | if (++idx <= start) |
| 3992 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3993 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3994 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3995 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3996 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3997 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3998 | } |
| 3999 | } |
| 4000 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4001 | spin_unlock_bh(&rdev->bss_lock); |
| 4002 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4003 | |
| 4004 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4005 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4006 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4007 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4008 | } |
| 4009 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4010 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4011 | int flags, struct net_device *dev, |
| 4012 | struct survey_info *survey) |
| 4013 | { |
| 4014 | void *hdr; |
| 4015 | struct nlattr *infoattr; |
| 4016 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4017 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4018 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4019 | if (!hdr) |
| 4020 | return -ENOMEM; |
| 4021 | |
| 4022 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4023 | |
| 4024 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4025 | if (!infoattr) |
| 4026 | goto nla_put_failure; |
| 4027 | |
| 4028 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4029 | survey->channel->center_freq); |
| 4030 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4031 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4032 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4033 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4034 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4035 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4036 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4037 | survey->channel_time); |
| 4038 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4039 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4040 | survey->channel_time_busy); |
| 4041 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4042 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4043 | survey->channel_time_ext_busy); |
| 4044 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4045 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4046 | survey->channel_time_rx); |
| 4047 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4048 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4049 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4050 | |
| 4051 | nla_nest_end(msg, infoattr); |
| 4052 | |
| 4053 | return genlmsg_end(msg, hdr); |
| 4054 | |
| 4055 | nla_put_failure: |
| 4056 | genlmsg_cancel(msg, hdr); |
| 4057 | return -EMSGSIZE; |
| 4058 | } |
| 4059 | |
| 4060 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4061 | struct netlink_callback *cb) |
| 4062 | { |
| 4063 | struct survey_info survey; |
| 4064 | struct cfg80211_registered_device *dev; |
| 4065 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4066 | int survey_idx = cb->args[1]; |
| 4067 | int res; |
| 4068 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4069 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4070 | if (res) |
| 4071 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4072 | |
| 4073 | if (!dev->ops->dump_survey) { |
| 4074 | res = -EOPNOTSUPP; |
| 4075 | goto out_err; |
| 4076 | } |
| 4077 | |
| 4078 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4079 | struct ieee80211_channel *chan; |
| 4080 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4081 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4082 | &survey); |
| 4083 | if (res == -ENOENT) |
| 4084 | break; |
| 4085 | if (res) |
| 4086 | goto out_err; |
| 4087 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4088 | /* Survey without a channel doesn't make sense */ |
| 4089 | if (!survey.channel) { |
| 4090 | res = -EINVAL; |
| 4091 | goto out; |
| 4092 | } |
| 4093 | |
| 4094 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4095 | survey.channel->center_freq); |
| 4096 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4097 | survey_idx++; |
| 4098 | continue; |
| 4099 | } |
| 4100 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4101 | if (nl80211_send_survey(skb, |
| 4102 | NETLINK_CB(cb->skb).pid, |
| 4103 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4104 | netdev, |
| 4105 | &survey) < 0) |
| 4106 | goto out; |
| 4107 | survey_idx++; |
| 4108 | } |
| 4109 | |
| 4110 | out: |
| 4111 | cb->args[1] = survey_idx; |
| 4112 | res = skb->len; |
| 4113 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4114 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4115 | return res; |
| 4116 | } |
| 4117 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4118 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4119 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4120 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4121 | } |
| 4122 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4123 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4124 | { |
| 4125 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4126 | NL80211_WPA_VERSION_2)); |
| 4127 | } |
| 4128 | |
| 4129 | static bool nl80211_valid_akm_suite(u32 akm) |
| 4130 | { |
| 4131 | return akm == WLAN_AKM_SUITE_8021X || |
| 4132 | akm == WLAN_AKM_SUITE_PSK; |
| 4133 | } |
| 4134 | |
| 4135 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 4136 | { |
| 4137 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 4138 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 4139 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 4140 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 4141 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 4142 | } |
| 4143 | |
| 4144 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4145 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4146 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4148 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4149 | struct ieee80211_channel *chan; |
| 4150 | const u8 *bssid, *ssid, *ie = NULL; |
| 4151 | int err, ssid_len, ie_len = 0; |
| 4152 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4153 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4154 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4155 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4156 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4157 | return -EINVAL; |
| 4158 | |
| 4159 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4160 | return -EINVAL; |
| 4161 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4162 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4163 | return -EINVAL; |
| 4164 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4165 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4166 | return -EINVAL; |
| 4167 | |
| 4168 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4169 | return -EINVAL; |
| 4170 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4171 | err = nl80211_parse_key(info, &key); |
| 4172 | if (err) |
| 4173 | return err; |
| 4174 | |
| 4175 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4176 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4177 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4178 | if (!key.p.key || !key.p.key_len) |
| 4179 | return -EINVAL; |
| 4180 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4181 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4182 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4183 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4184 | return -EINVAL; |
| 4185 | if (key.idx > 4) |
| 4186 | return -EINVAL; |
| 4187 | } else { |
| 4188 | key.p.key_len = 0; |
| 4189 | key.p.key = NULL; |
| 4190 | } |
| 4191 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4192 | if (key.idx >= 0) { |
| 4193 | int i; |
| 4194 | bool ok = false; |
| 4195 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4196 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4197 | ok = true; |
| 4198 | break; |
| 4199 | } |
| 4200 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4201 | if (!ok) |
| 4202 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4203 | } |
| 4204 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4205 | if (!rdev->ops->auth) |
| 4206 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4207 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4208 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4209 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4210 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4211 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4212 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4213 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4214 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4215 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4216 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4217 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4218 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4219 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4220 | |
| 4221 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4222 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4223 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4224 | } |
| 4225 | |
| 4226 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4227 | if (!nl80211_valid_auth_type(auth_type)) |
| 4228 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4229 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4230 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4231 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4232 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4233 | ssid, ssid_len, ie, ie_len, |
| 4234 | key.p.key, key.p.key_len, key.idx, |
| 4235 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4236 | } |
| 4237 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4238 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4239 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4240 | struct cfg80211_crypto_settings *settings, |
| 4241 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4242 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4243 | memset(settings, 0, sizeof(*settings)); |
| 4244 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4245 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4246 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4247 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4248 | u16 proto; |
| 4249 | proto = nla_get_u16( |
| 4250 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4251 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4252 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4253 | proto != ETH_P_PAE) |
| 4254 | return -EINVAL; |
| 4255 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4256 | settings->control_port_no_encrypt = true; |
| 4257 | } else |
| 4258 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4259 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4260 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4261 | void *data; |
| 4262 | int len, i; |
| 4263 | |
| 4264 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4265 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4266 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4267 | |
| 4268 | if (len % sizeof(u32)) |
| 4269 | return -EINVAL; |
| 4270 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4271 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4272 | return -EINVAL; |
| 4273 | |
| 4274 | memcpy(settings->ciphers_pairwise, data, len); |
| 4275 | |
| 4276 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4277 | if (!nl80211_valid_cipher_suite( |
| 4278 | settings->ciphers_pairwise[i])) |
| 4279 | return -EINVAL; |
| 4280 | } |
| 4281 | |
| 4282 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4283 | settings->cipher_group = |
| 4284 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 4285 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 4286 | return -EINVAL; |
| 4287 | } |
| 4288 | |
| 4289 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4290 | settings->wpa_versions = |
| 4291 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4292 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4293 | return -EINVAL; |
| 4294 | } |
| 4295 | |
| 4296 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4297 | void *data; |
| 4298 | int len, i; |
| 4299 | |
| 4300 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4301 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4302 | settings->n_akm_suites = len / sizeof(u32); |
| 4303 | |
| 4304 | if (len % sizeof(u32)) |
| 4305 | return -EINVAL; |
| 4306 | |
| 4307 | memcpy(settings->akm_suites, data, len); |
| 4308 | |
| 4309 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 4310 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 4311 | return -EINVAL; |
| 4312 | } |
| 4313 | |
| 4314 | return 0; |
| 4315 | } |
| 4316 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4317 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4318 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4319 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4320 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4321 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4322 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4323 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4324 | int err, ssid_len, ie_len = 0; |
| 4325 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4326 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4327 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4328 | return -EINVAL; |
| 4329 | |
| 4330 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4331 | !info->attrs[NL80211_ATTR_SSID] || |
| 4332 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4333 | return -EINVAL; |
| 4334 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4335 | if (!rdev->ops->assoc) |
| 4336 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4337 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4338 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4339 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4340 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4341 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4342 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4343 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4344 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4345 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4346 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4347 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4348 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4349 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4350 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4351 | |
| 4352 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4353 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4354 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4355 | } |
| 4356 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4357 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4358 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4359 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4360 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4361 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4362 | else if (mfp != NL80211_MFP_NO) |
| 4363 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4364 | } |
| 4365 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4366 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4367 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4368 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4369 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4370 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4371 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4372 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4373 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4374 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4375 | return err; |
| 4376 | } |
| 4377 | |
| 4378 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4379 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4381 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4382 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4383 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4384 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4385 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4386 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4387 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4388 | return -EINVAL; |
| 4389 | |
| 4390 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4391 | return -EINVAL; |
| 4392 | |
| 4393 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4394 | return -EINVAL; |
| 4395 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4396 | if (!rdev->ops->deauth) |
| 4397 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4398 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4399 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4400 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4401 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4402 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4403 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4404 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4405 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4406 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4407 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4408 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4409 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4410 | |
| 4411 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4412 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4413 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4414 | } |
| 4415 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4416 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4417 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4418 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4419 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4423 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4424 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4425 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4426 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4427 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4428 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4429 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4430 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4431 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4432 | return -EINVAL; |
| 4433 | |
| 4434 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4435 | return -EINVAL; |
| 4436 | |
| 4437 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4438 | return -EINVAL; |
| 4439 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4440 | if (!rdev->ops->disassoc) |
| 4441 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4442 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4443 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4444 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4445 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4446 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4447 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4448 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4449 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4450 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4451 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4452 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4453 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4454 | |
| 4455 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4456 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4457 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4458 | } |
| 4459 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4460 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4461 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4462 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4463 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4464 | } |
| 4465 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4466 | static bool |
| 4467 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4468 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4469 | int rateval) |
| 4470 | { |
| 4471 | struct wiphy *wiphy = &rdev->wiphy; |
| 4472 | bool found = false; |
| 4473 | int band, i; |
| 4474 | |
| 4475 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4476 | struct ieee80211_supported_band *sband; |
| 4477 | |
| 4478 | sband = wiphy->bands[band]; |
| 4479 | if (!sband) |
| 4480 | continue; |
| 4481 | |
| 4482 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4483 | if (sband->bitrates[i].bitrate == rateval) { |
| 4484 | mcast_rate[band] = i + 1; |
| 4485 | found = true; |
| 4486 | break; |
| 4487 | } |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | return found; |
| 4492 | } |
| 4493 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4494 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4495 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4497 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4498 | struct cfg80211_ibss_params ibss; |
| 4499 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4500 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4501 | int err; |
| 4502 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4503 | memset(&ibss, 0, sizeof(ibss)); |
| 4504 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4505 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4506 | return -EINVAL; |
| 4507 | |
| 4508 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4509 | !info->attrs[NL80211_ATTR_SSID] || |
| 4510 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4511 | return -EINVAL; |
| 4512 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4513 | ibss.beacon_interval = 100; |
| 4514 | |
| 4515 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4516 | ibss.beacon_interval = |
| 4517 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4518 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4519 | return -EINVAL; |
| 4520 | } |
| 4521 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4522 | if (!rdev->ops->join_ibss) |
| 4523 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4524 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4526 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4527 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4528 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4529 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4530 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4531 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4532 | |
| 4533 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4534 | return -EINVAL; |
| 4535 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4536 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4537 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4538 | |
| 4539 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4540 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4541 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4542 | } |
| 4543 | |
| 4544 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4545 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4546 | if (!ibss.channel || |
| 4547 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4548 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4549 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4550 | |
| 4551 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4552 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4553 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4554 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4555 | u8 *rates = |
| 4556 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4557 | int n_rates = |
| 4558 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4559 | struct ieee80211_supported_band *sband = |
| 4560 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4561 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4562 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4563 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4564 | &ibss.basic_rates); |
| 4565 | if (err) |
| 4566 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4567 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4568 | |
| 4569 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4570 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4571 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4572 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4573 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4574 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4575 | connkeys = nl80211_parse_connkeys(rdev, |
| 4576 | info->attrs[NL80211_ATTR_KEYS]); |
| 4577 | if (IS_ERR(connkeys)) |
| 4578 | return PTR_ERR(connkeys); |
| 4579 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4580 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4581 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4582 | if (err) |
| 4583 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4584 | return err; |
| 4585 | } |
| 4586 | |
| 4587 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4588 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4589 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4590 | struct net_device *dev = info->user_ptr[1]; |
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 (!rdev->ops->leave_ibss) |
| 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 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4596 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4597 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4598 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4599 | } |
| 4600 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4601 | #ifdef CONFIG_NL80211_TESTMODE |
| 4602 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4603 | .name = "testmode", |
| 4604 | }; |
| 4605 | |
| 4606 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4607 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4608 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4609 | int err; |
| 4610 | |
| 4611 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4612 | return -EINVAL; |
| 4613 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4614 | err = -EOPNOTSUPP; |
| 4615 | if (rdev->ops->testmode_cmd) { |
| 4616 | rdev->testmode_info = info; |
| 4617 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4618 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4619 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4620 | rdev->testmode_info = NULL; |
| 4621 | } |
| 4622 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4623 | return err; |
| 4624 | } |
| 4625 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4626 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4627 | struct netlink_callback *cb) |
| 4628 | { |
| 4629 | struct cfg80211_registered_device *dev; |
| 4630 | int err; |
| 4631 | long phy_idx; |
| 4632 | void *data = NULL; |
| 4633 | int data_len = 0; |
| 4634 | |
| 4635 | if (cb->args[0]) { |
| 4636 | /* |
| 4637 | * 0 is a valid index, but not valid for args[0], |
| 4638 | * so we need to offset by 1. |
| 4639 | */ |
| 4640 | phy_idx = cb->args[0] - 1; |
| 4641 | } else { |
| 4642 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4643 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4644 | nl80211_policy); |
| 4645 | if (err) |
| 4646 | return err; |
| 4647 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4648 | return -EINVAL; |
| 4649 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4650 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4651 | cb->args[1] = |
| 4652 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4653 | } |
| 4654 | |
| 4655 | if (cb->args[1]) { |
| 4656 | data = nla_data((void *)cb->args[1]); |
| 4657 | data_len = nla_len((void *)cb->args[1]); |
| 4658 | } |
| 4659 | |
| 4660 | mutex_lock(&cfg80211_mutex); |
| 4661 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4662 | if (!dev) { |
| 4663 | mutex_unlock(&cfg80211_mutex); |
| 4664 | return -ENOENT; |
| 4665 | } |
| 4666 | cfg80211_lock_rdev(dev); |
| 4667 | mutex_unlock(&cfg80211_mutex); |
| 4668 | |
| 4669 | if (!dev->ops->testmode_dump) { |
| 4670 | err = -EOPNOTSUPP; |
| 4671 | goto out_err; |
| 4672 | } |
| 4673 | |
| 4674 | while (1) { |
| 4675 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4676 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4677 | NL80211_CMD_TESTMODE); |
| 4678 | struct nlattr *tmdata; |
| 4679 | |
| 4680 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4681 | genlmsg_cancel(skb, hdr); |
| 4682 | break; |
| 4683 | } |
| 4684 | |
| 4685 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4686 | if (!tmdata) { |
| 4687 | genlmsg_cancel(skb, hdr); |
| 4688 | break; |
| 4689 | } |
| 4690 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4691 | data, data_len); |
| 4692 | nla_nest_end(skb, tmdata); |
| 4693 | |
| 4694 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4695 | genlmsg_cancel(skb, hdr); |
| 4696 | break; |
| 4697 | } else if (err) { |
| 4698 | genlmsg_cancel(skb, hdr); |
| 4699 | goto out_err; |
| 4700 | } |
| 4701 | |
| 4702 | genlmsg_end(skb, hdr); |
| 4703 | } |
| 4704 | |
| 4705 | err = skb->len; |
| 4706 | /* see above */ |
| 4707 | cb->args[0] = phy_idx + 1; |
| 4708 | out_err: |
| 4709 | cfg80211_unlock_rdev(dev); |
| 4710 | return err; |
| 4711 | } |
| 4712 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4713 | static struct sk_buff * |
| 4714 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4715 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4716 | { |
| 4717 | struct sk_buff *skb; |
| 4718 | void *hdr; |
| 4719 | struct nlattr *data; |
| 4720 | |
| 4721 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4722 | if (!skb) |
| 4723 | return NULL; |
| 4724 | |
| 4725 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4726 | if (!hdr) { |
| 4727 | kfree_skb(skb); |
| 4728 | return NULL; |
| 4729 | } |
| 4730 | |
| 4731 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4732 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4733 | |
| 4734 | ((void **)skb->cb)[0] = rdev; |
| 4735 | ((void **)skb->cb)[1] = hdr; |
| 4736 | ((void **)skb->cb)[2] = data; |
| 4737 | |
| 4738 | return skb; |
| 4739 | |
| 4740 | nla_put_failure: |
| 4741 | kfree_skb(skb); |
| 4742 | return NULL; |
| 4743 | } |
| 4744 | |
| 4745 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4746 | int approxlen) |
| 4747 | { |
| 4748 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4749 | |
| 4750 | if (WARN_ON(!rdev->testmode_info)) |
| 4751 | return NULL; |
| 4752 | |
| 4753 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4754 | rdev->testmode_info->snd_pid, |
| 4755 | rdev->testmode_info->snd_seq, |
| 4756 | GFP_KERNEL); |
| 4757 | } |
| 4758 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4759 | |
| 4760 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4761 | { |
| 4762 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4763 | void *hdr = ((void **)skb->cb)[1]; |
| 4764 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4765 | |
| 4766 | if (WARN_ON(!rdev->testmode_info)) { |
| 4767 | kfree_skb(skb); |
| 4768 | return -EINVAL; |
| 4769 | } |
| 4770 | |
| 4771 | nla_nest_end(skb, data); |
| 4772 | genlmsg_end(skb, hdr); |
| 4773 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4774 | } |
| 4775 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4776 | |
| 4777 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4778 | int approxlen, gfp_t gfp) |
| 4779 | { |
| 4780 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4781 | |
| 4782 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4783 | } |
| 4784 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4785 | |
| 4786 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4787 | { |
| 4788 | void *hdr = ((void **)skb->cb)[1]; |
| 4789 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4790 | |
| 4791 | nla_nest_end(skb, data); |
| 4792 | genlmsg_end(skb, hdr); |
| 4793 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4794 | } |
| 4795 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4796 | #endif |
| 4797 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4798 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4799 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4801 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4802 | struct cfg80211_connect_params connect; |
| 4803 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4804 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4805 | int err; |
| 4806 | |
| 4807 | memset(&connect, 0, sizeof(connect)); |
| 4808 | |
| 4809 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4810 | return -EINVAL; |
| 4811 | |
| 4812 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4813 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4814 | return -EINVAL; |
| 4815 | |
| 4816 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4817 | connect.auth_type = |
| 4818 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4819 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4820 | return -EINVAL; |
| 4821 | } else |
| 4822 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4823 | |
| 4824 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4825 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4826 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4827 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4828 | if (err) |
| 4829 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4830 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4831 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4832 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4833 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4834 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4835 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4836 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4837 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4838 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4839 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4840 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4841 | |
| 4842 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4843 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4844 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4845 | } |
| 4846 | |
| 4847 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4848 | connect.channel = |
| 4849 | ieee80211_get_channel(wiphy, |
| 4850 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4851 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4852 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4853 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4854 | } |
| 4855 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4856 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4857 | connkeys = nl80211_parse_connkeys(rdev, |
| 4858 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4859 | if (IS_ERR(connkeys)) |
| 4860 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4861 | } |
| 4862 | |
| 4863 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4864 | if (err) |
| 4865 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4866 | return err; |
| 4867 | } |
| 4868 | |
| 4869 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4870 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4872 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4873 | u16 reason; |
| 4874 | |
| 4875 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4876 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4877 | else |
| 4878 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4879 | |
| 4880 | if (reason == 0) |
| 4881 | return -EINVAL; |
| 4882 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4883 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4884 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4885 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4886 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4887 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4888 | } |
| 4889 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4890 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4891 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4893 | struct net *net; |
| 4894 | int err; |
| 4895 | u32 pid; |
| 4896 | |
| 4897 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4898 | return -EINVAL; |
| 4899 | |
| 4900 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4901 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4902 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4903 | if (IS_ERR(net)) |
| 4904 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4905 | |
| 4906 | err = 0; |
| 4907 | |
| 4908 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4909 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4910 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4911 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4912 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4913 | return err; |
| 4914 | } |
| 4915 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4916 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4917 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4918 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4919 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4920 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4921 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4922 | struct cfg80211_pmksa pmksa; |
| 4923 | |
| 4924 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4925 | |
| 4926 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4927 | return -EINVAL; |
| 4928 | |
| 4929 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4930 | return -EINVAL; |
| 4931 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4932 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4933 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4934 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4935 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4936 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4937 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4938 | |
| 4939 | switch (info->genlhdr->cmd) { |
| 4940 | case NL80211_CMD_SET_PMKSA: |
| 4941 | rdev_ops = rdev->ops->set_pmksa; |
| 4942 | break; |
| 4943 | case NL80211_CMD_DEL_PMKSA: |
| 4944 | rdev_ops = rdev->ops->del_pmksa; |
| 4945 | break; |
| 4946 | default: |
| 4947 | WARN_ON(1); |
| 4948 | break; |
| 4949 | } |
| 4950 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4951 | if (!rdev_ops) |
| 4952 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4953 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4954 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4958 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4959 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4960 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4961 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4962 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4963 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 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 | if (!rdev->ops->flush_pmksa) |
| 4967 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4968 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4969 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4970 | } |
| 4971 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4972 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 4973 | struct genl_info *info) |
| 4974 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4976 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4977 | struct ieee80211_channel *chan; |
| 4978 | struct sk_buff *msg; |
| 4979 | void *hdr; |
| 4980 | u64 cookie; |
| 4981 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 4982 | u32 freq, duration; |
| 4983 | int err; |
| 4984 | |
| 4985 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4986 | !info->attrs[NL80211_ATTR_DURATION]) |
| 4987 | return -EINVAL; |
| 4988 | |
| 4989 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 4990 | |
| 4991 | /* |
| 4992 | * We should be on that channel for at least one jiffie, |
| 4993 | * and more than 5 seconds seems excessive. |
| 4994 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 4995 | if (!duration || !msecs_to_jiffies(duration) || |
| 4996 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 4997 | return -EINVAL; |
| 4998 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4999 | if (!rdev->ops->remain_on_channel) |
| 5000 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5001 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5002 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5003 | channel_type = nla_get_u32( |
| 5004 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5005 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5006 | channel_type != NL80211_CHAN_HT20 && |
| 5007 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5008 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5009 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5013 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5014 | if (chan == NULL) |
| 5015 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5016 | |
| 5017 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5018 | if (!msg) |
| 5019 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5020 | |
| 5021 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5022 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5023 | |
| 5024 | if (IS_ERR(hdr)) { |
| 5025 | err = PTR_ERR(hdr); |
| 5026 | goto free_msg; |
| 5027 | } |
| 5028 | |
| 5029 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5030 | channel_type, duration, &cookie); |
| 5031 | |
| 5032 | if (err) |
| 5033 | goto free_msg; |
| 5034 | |
| 5035 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5036 | |
| 5037 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5038 | |
| 5039 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5040 | |
| 5041 | nla_put_failure: |
| 5042 | err = -ENOBUFS; |
| 5043 | free_msg: |
| 5044 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5045 | return err; |
| 5046 | } |
| 5047 | |
| 5048 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5049 | struct genl_info *info) |
| 5050 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5052 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5053 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5054 | |
| 5055 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5056 | return -EINVAL; |
| 5057 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5058 | if (!rdev->ops->cancel_remain_on_channel) |
| 5059 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5060 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5061 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5062 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5063 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5064 | } |
| 5065 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5066 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5067 | u8 *rates, u8 rates_len) |
| 5068 | { |
| 5069 | u8 i; |
| 5070 | u32 mask = 0; |
| 5071 | |
| 5072 | for (i = 0; i < rates_len; i++) { |
| 5073 | int rate = (rates[i] & 0x7f) * 5; |
| 5074 | int ridx; |
| 5075 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5076 | struct ieee80211_rate *srate = |
| 5077 | &sband->bitrates[ridx]; |
| 5078 | if (rate == srate->bitrate) { |
| 5079 | mask |= 1 << ridx; |
| 5080 | break; |
| 5081 | } |
| 5082 | } |
| 5083 | if (ridx == sband->n_bitrates) |
| 5084 | return 0; /* rate not found */ |
| 5085 | } |
| 5086 | |
| 5087 | return mask; |
| 5088 | } |
| 5089 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5090 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5091 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5092 | .len = NL80211_MAX_SUPP_RATES }, |
| 5093 | }; |
| 5094 | |
| 5095 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5096 | struct genl_info *info) |
| 5097 | { |
| 5098 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5099 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5100 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5101 | int rem, i; |
| 5102 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5103 | struct nlattr *tx_rates; |
| 5104 | struct ieee80211_supported_band *sband; |
| 5105 | |
| 5106 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5107 | return -EINVAL; |
| 5108 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5109 | if (!rdev->ops->set_bitrate_mask) |
| 5110 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5111 | |
| 5112 | memset(&mask, 0, sizeof(mask)); |
| 5113 | /* Default to all rates enabled */ |
| 5114 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5115 | sband = rdev->wiphy.bands[i]; |
| 5116 | mask.control[i].legacy = |
| 5117 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5118 | } |
| 5119 | |
| 5120 | /* |
| 5121 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5122 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5123 | */ |
| 5124 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5125 | { |
| 5126 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5127 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5128 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5129 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5130 | if (sband == NULL) |
| 5131 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5132 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5133 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5134 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5135 | mask.control[band].legacy = rateset_to_mask( |
| 5136 | sband, |
| 5137 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5138 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5139 | if (mask.control[band].legacy == 0) |
| 5140 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5141 | } |
| 5142 | } |
| 5143 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5144 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5145 | } |
| 5146 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5147 | 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] | 5148 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5150 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5151 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5152 | |
| 5153 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5154 | return -EINVAL; |
| 5155 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5156 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5157 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5158 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5159 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5160 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5161 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5162 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5163 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5164 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5165 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5166 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5167 | |
| 5168 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5169 | if (!rdev->ops->mgmt_tx) |
| 5170 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5171 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5172 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5173 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5174 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5175 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5176 | } |
| 5177 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5178 | 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] | 5179 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5181 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5182 | struct ieee80211_channel *chan; |
| 5183 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5184 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5185 | u32 freq; |
| 5186 | int err; |
| 5187 | void *hdr; |
| 5188 | u64 cookie; |
| 5189 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5190 | unsigned int wait = 0; |
| 5191 | bool offchan; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5192 | |
| 5193 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5194 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5195 | return -EINVAL; |
| 5196 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5197 | if (!rdev->ops->mgmt_tx) |
| 5198 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5199 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5200 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5201 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5202 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5203 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5204 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5205 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5206 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5207 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5208 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5209 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5210 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5211 | return -EINVAL; |
| 5212 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5213 | } |
| 5214 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5215 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5216 | channel_type = nla_get_u32( |
| 5217 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5218 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5219 | channel_type != NL80211_CHAN_HT20 && |
| 5220 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5221 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5222 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5223 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5224 | } |
| 5225 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5226 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 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]), |
| 5248 | &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 | } |