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 | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 101 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 102 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 103 | |
| 104 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 105 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 106 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 107 | .len = IEEE80211_MAX_DATA_LEN }, |
| 108 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 109 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 110 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 111 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 112 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 113 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 114 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 115 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 116 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 117 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 118 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 119 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 120 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 121 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 122 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 123 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 124 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 125 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 126 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 127 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 128 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 129 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 130 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 131 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 132 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 133 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 134 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 135 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 136 | |
| 137 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 138 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 139 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 140 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 141 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 142 | |
| 143 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 144 | .len = IEEE80211_MAX_SSID_LEN }, |
| 145 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 146 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 147 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 150 | [NL80211_ATTR_STA_FLAGS2] = { |
| 151 | .len = sizeof(struct nl80211_sta_flag_update), |
| 152 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 153 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 154 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 155 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 156 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 157 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 158 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 159 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 160 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 161 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 162 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 163 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 164 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 166 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 167 | .len = IEEE80211_MAX_DATA_LEN }, |
| 168 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 169 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 171 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 172 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 173 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 174 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 175 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 176 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 177 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 178 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 179 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 180 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 181 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 182 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 183 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 184 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 185 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 186 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 187 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 188 | .len = IEEE80211_MAX_DATA_LEN }, |
| 189 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 190 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 191 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 192 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 193 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 194 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 195 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 196 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 197 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 198 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 199 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 200 | }; |
| 201 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 202 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 203 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 204 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 205 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 206 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 207 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 208 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 209 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 210 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 211 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 212 | }; |
| 213 | |
| 214 | /* policy for the key default flags */ |
| 215 | static const struct nla_policy |
| 216 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 217 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 218 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 219 | }; |
| 220 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 221 | /* policy for WoWLAN attributes */ |
| 222 | static const struct nla_policy |
| 223 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 224 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 225 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 226 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 227 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 228 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 229 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 230 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 231 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 232 | }; |
| 233 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 234 | /* policy for GTK rekey offload attributes */ |
| 235 | static const struct nla_policy |
| 236 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 237 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 238 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 239 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 240 | }; |
| 241 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 242 | static const struct nla_policy |
| 243 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 244 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 245 | .len = IEEE80211_MAX_SSID_LEN }, |
| 246 | }; |
| 247 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 248 | /* ifidx get helper */ |
| 249 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 250 | { |
| 251 | int res; |
| 252 | |
| 253 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 254 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 255 | nl80211_policy); |
| 256 | if (res) |
| 257 | return res; |
| 258 | |
| 259 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 260 | return -EINVAL; |
| 261 | |
| 262 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 263 | if (!res) |
| 264 | return -EINVAL; |
| 265 | return res; |
| 266 | } |
| 267 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 268 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 269 | struct netlink_callback *cb, |
| 270 | struct cfg80211_registered_device **rdev, |
| 271 | struct net_device **dev) |
| 272 | { |
| 273 | int ifidx = cb->args[0]; |
| 274 | int err; |
| 275 | |
| 276 | if (!ifidx) |
| 277 | ifidx = nl80211_get_ifidx(cb); |
| 278 | if (ifidx < 0) |
| 279 | return ifidx; |
| 280 | |
| 281 | cb->args[0] = ifidx; |
| 282 | |
| 283 | rtnl_lock(); |
| 284 | |
| 285 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 286 | if (!*dev) { |
| 287 | err = -ENODEV; |
| 288 | goto out_rtnl; |
| 289 | } |
| 290 | |
| 291 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 292 | if (IS_ERR(*rdev)) { |
| 293 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 294 | goto out_rtnl; |
| 295 | } |
| 296 | |
| 297 | return 0; |
| 298 | out_rtnl: |
| 299 | rtnl_unlock(); |
| 300 | return err; |
| 301 | } |
| 302 | |
| 303 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 304 | { |
| 305 | cfg80211_unlock_rdev(rdev); |
| 306 | rtnl_unlock(); |
| 307 | } |
| 308 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 309 | /* IE validation */ |
| 310 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 311 | { |
| 312 | const u8 *pos; |
| 313 | int len; |
| 314 | |
| 315 | if (!attr) |
| 316 | return true; |
| 317 | |
| 318 | pos = nla_data(attr); |
| 319 | len = nla_len(attr); |
| 320 | |
| 321 | while (len) { |
| 322 | u8 elemlen; |
| 323 | |
| 324 | if (len < 2) |
| 325 | return false; |
| 326 | len -= 2; |
| 327 | |
| 328 | elemlen = pos[1]; |
| 329 | if (elemlen > len) |
| 330 | return false; |
| 331 | |
| 332 | len -= elemlen; |
| 333 | pos += 2 + elemlen; |
| 334 | } |
| 335 | |
| 336 | return true; |
| 337 | } |
| 338 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 339 | /* message building helper */ |
| 340 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 341 | int flags, u8 cmd) |
| 342 | { |
| 343 | /* since there is no private header just add the generic one */ |
| 344 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 345 | } |
| 346 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 347 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 348 | struct ieee80211_channel *chan) |
| 349 | { |
| 350 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 351 | chan->center_freq); |
| 352 | |
| 353 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 354 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 355 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 356 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 357 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 358 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 359 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 360 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 361 | |
| 362 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 363 | DBM_TO_MBM(chan->max_power)); |
| 364 | |
| 365 | return 0; |
| 366 | |
| 367 | nla_put_failure: |
| 368 | return -ENOBUFS; |
| 369 | } |
| 370 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 371 | /* netlink command implementations */ |
| 372 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 373 | struct key_parse { |
| 374 | struct key_params p; |
| 375 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 376 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 377 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 378 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 379 | }; |
| 380 | |
| 381 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 382 | { |
| 383 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 384 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 385 | nl80211_key_policy); |
| 386 | if (err) |
| 387 | return err; |
| 388 | |
| 389 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 390 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 391 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 392 | if (k->def) { |
| 393 | k->def_uni = true; |
| 394 | k->def_multi = true; |
| 395 | } |
| 396 | if (k->defmgmt) |
| 397 | k->def_multi = true; |
| 398 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 399 | if (tb[NL80211_KEY_IDX]) |
| 400 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 401 | |
| 402 | if (tb[NL80211_KEY_DATA]) { |
| 403 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 404 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 405 | } |
| 406 | |
| 407 | if (tb[NL80211_KEY_SEQ]) { |
| 408 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 409 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 410 | } |
| 411 | |
| 412 | if (tb[NL80211_KEY_CIPHER]) |
| 413 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 414 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 415 | if (tb[NL80211_KEY_TYPE]) { |
| 416 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 417 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 421 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 422 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 423 | int err = nla_parse_nested(kdt, |
| 424 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 425 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 426 | nl80211_key_default_policy); |
| 427 | if (err) |
| 428 | return err; |
| 429 | |
| 430 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 431 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 432 | } |
| 433 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 438 | { |
| 439 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 440 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 441 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 442 | } |
| 443 | |
| 444 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 445 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 446 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 447 | } |
| 448 | |
| 449 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 450 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 451 | |
| 452 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 453 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 454 | |
| 455 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 456 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 457 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 458 | if (k->def) { |
| 459 | k->def_uni = true; |
| 460 | k->def_multi = true; |
| 461 | } |
| 462 | if (k->defmgmt) |
| 463 | k->def_multi = true; |
| 464 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 465 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 466 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 467 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 468 | return -EINVAL; |
| 469 | } |
| 470 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 471 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 472 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 473 | int err = nla_parse_nested( |
| 474 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 475 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 476 | nl80211_key_default_policy); |
| 477 | if (err) |
| 478 | return err; |
| 479 | |
| 480 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 481 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 482 | } |
| 483 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 488 | { |
| 489 | int err; |
| 490 | |
| 491 | memset(k, 0, sizeof(*k)); |
| 492 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 493 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 494 | |
| 495 | if (info->attrs[NL80211_ATTR_KEY]) |
| 496 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 497 | else |
| 498 | err = nl80211_parse_key_old(info, k); |
| 499 | |
| 500 | if (err) |
| 501 | return err; |
| 502 | |
| 503 | if (k->def && k->defmgmt) |
| 504 | return -EINVAL; |
| 505 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 506 | if (k->defmgmt) { |
| 507 | if (k->def_uni || !k->def_multi) |
| 508 | return -EINVAL; |
| 509 | } |
| 510 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 511 | if (k->idx != -1) { |
| 512 | if (k->defmgmt) { |
| 513 | if (k->idx < 4 || k->idx > 5) |
| 514 | return -EINVAL; |
| 515 | } else if (k->def) { |
| 516 | if (k->idx < 0 || k->idx > 3) |
| 517 | return -EINVAL; |
| 518 | } else { |
| 519 | if (k->idx < 0 || k->idx > 5) |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 527 | static struct cfg80211_cached_keys * |
| 528 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 529 | struct nlattr *keys) |
| 530 | { |
| 531 | struct key_parse parse; |
| 532 | struct nlattr *key; |
| 533 | struct cfg80211_cached_keys *result; |
| 534 | int rem, err, def = 0; |
| 535 | |
| 536 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 537 | if (!result) |
| 538 | return ERR_PTR(-ENOMEM); |
| 539 | |
| 540 | result->def = -1; |
| 541 | result->defmgmt = -1; |
| 542 | |
| 543 | nla_for_each_nested(key, keys, rem) { |
| 544 | memset(&parse, 0, sizeof(parse)); |
| 545 | parse.idx = -1; |
| 546 | |
| 547 | err = nl80211_parse_key_new(key, &parse); |
| 548 | if (err) |
| 549 | goto error; |
| 550 | err = -EINVAL; |
| 551 | if (!parse.p.key) |
| 552 | goto error; |
| 553 | if (parse.idx < 0 || parse.idx > 4) |
| 554 | goto error; |
| 555 | if (parse.def) { |
| 556 | if (def) |
| 557 | goto error; |
| 558 | def = 1; |
| 559 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 560 | if (!parse.def_uni || !parse.def_multi) |
| 561 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 562 | } else if (parse.defmgmt) |
| 563 | goto error; |
| 564 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 565 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 566 | if (err) |
| 567 | goto error; |
| 568 | result->params[parse.idx].cipher = parse.p.cipher; |
| 569 | result->params[parse.idx].key_len = parse.p.key_len; |
| 570 | result->params[parse.idx].key = result->data[parse.idx]; |
| 571 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 572 | } |
| 573 | |
| 574 | return result; |
| 575 | error: |
| 576 | kfree(result); |
| 577 | return ERR_PTR(err); |
| 578 | } |
| 579 | |
| 580 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 581 | { |
| 582 | ASSERT_WDEV_LOCK(wdev); |
| 583 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 584 | switch (wdev->iftype) { |
| 585 | case NL80211_IFTYPE_AP: |
| 586 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 587 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 588 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 589 | break; |
| 590 | case NL80211_IFTYPE_ADHOC: |
| 591 | if (!wdev->current_bss) |
| 592 | return -ENOLINK; |
| 593 | break; |
| 594 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 595 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 596 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 597 | return -ENOLINK; |
| 598 | break; |
| 599 | default: |
| 600 | return -EINVAL; |
| 601 | } |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 606 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 607 | { |
| 608 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 609 | int i; |
| 610 | |
| 611 | if (!nl_modes) |
| 612 | goto nla_put_failure; |
| 613 | |
| 614 | i = 0; |
| 615 | while (ifmodes) { |
| 616 | if (ifmodes & 1) |
| 617 | NLA_PUT_FLAG(msg, i); |
| 618 | ifmodes >>= 1; |
| 619 | i++; |
| 620 | } |
| 621 | |
| 622 | nla_nest_end(msg, nl_modes); |
| 623 | return 0; |
| 624 | |
| 625 | nla_put_failure: |
| 626 | return -ENOBUFS; |
| 627 | } |
| 628 | |
| 629 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 630 | struct sk_buff *msg) |
| 631 | { |
| 632 | struct nlattr *nl_combis; |
| 633 | int i, j; |
| 634 | |
| 635 | nl_combis = nla_nest_start(msg, |
| 636 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 637 | if (!nl_combis) |
| 638 | goto nla_put_failure; |
| 639 | |
| 640 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 641 | const struct ieee80211_iface_combination *c; |
| 642 | struct nlattr *nl_combi, *nl_limits; |
| 643 | |
| 644 | c = &wiphy->iface_combinations[i]; |
| 645 | |
| 646 | nl_combi = nla_nest_start(msg, i + 1); |
| 647 | if (!nl_combi) |
| 648 | goto nla_put_failure; |
| 649 | |
| 650 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 651 | if (!nl_limits) |
| 652 | goto nla_put_failure; |
| 653 | |
| 654 | for (j = 0; j < c->n_limits; j++) { |
| 655 | struct nlattr *nl_limit; |
| 656 | |
| 657 | nl_limit = nla_nest_start(msg, j + 1); |
| 658 | if (!nl_limit) |
| 659 | goto nla_put_failure; |
| 660 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 661 | c->limits[j].max); |
| 662 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 663 | c->limits[j].types)) |
| 664 | goto nla_put_failure; |
| 665 | nla_nest_end(msg, nl_limit); |
| 666 | } |
| 667 | |
| 668 | nla_nest_end(msg, nl_limits); |
| 669 | |
| 670 | if (c->beacon_int_infra_match) |
| 671 | NLA_PUT_FLAG(msg, |
| 672 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 673 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 674 | c->num_different_channels); |
| 675 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 676 | c->max_interfaces); |
| 677 | |
| 678 | nla_nest_end(msg, nl_combi); |
| 679 | } |
| 680 | |
| 681 | nla_nest_end(msg, nl_combis); |
| 682 | |
| 683 | return 0; |
| 684 | nla_put_failure: |
| 685 | return -ENOBUFS; |
| 686 | } |
| 687 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 688 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 689 | struct cfg80211_registered_device *dev) |
| 690 | { |
| 691 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 692 | struct nlattr *nl_bands, *nl_band; |
| 693 | struct nlattr *nl_freqs, *nl_freq; |
| 694 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 695 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 696 | enum ieee80211_band band; |
| 697 | struct ieee80211_channel *chan; |
| 698 | struct ieee80211_rate *rate; |
| 699 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 700 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 701 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 702 | |
| 703 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 704 | if (!hdr) |
| 705 | return -1; |
| 706 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 707 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 708 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 709 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 710 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 711 | cfg80211_rdev_list_generation); |
| 712 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 713 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 714 | dev->wiphy.retry_short); |
| 715 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 716 | dev->wiphy.retry_long); |
| 717 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 718 | dev->wiphy.frag_threshold); |
| 719 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 720 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 721 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 722 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 723 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 724 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 725 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 726 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 727 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 728 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 729 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 730 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 731 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 732 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 733 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 734 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 735 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 736 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 737 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 738 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 739 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 740 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 741 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 742 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) |
| 743 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT); |
| 744 | if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) |
| 745 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 746 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 747 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 748 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 749 | dev->wiphy.cipher_suites); |
| 750 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 751 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 752 | dev->wiphy.max_num_pmkids); |
| 753 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 754 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 755 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 756 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 757 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 758 | dev->wiphy.available_antennas_tx); |
| 759 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 760 | dev->wiphy.available_antennas_rx); |
| 761 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 762 | if ((dev->wiphy.available_antennas_tx || |
| 763 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 764 | u32 tx_ant = 0, rx_ant = 0; |
| 765 | int res; |
| 766 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 767 | if (!res) { |
| 768 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 769 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 770 | } |
| 771 | } |
| 772 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 773 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 774 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 775 | goto nla_put_failure; |
| 776 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 777 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 778 | if (!nl_bands) |
| 779 | goto nla_put_failure; |
| 780 | |
| 781 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 782 | if (!dev->wiphy.bands[band]) |
| 783 | continue; |
| 784 | |
| 785 | nl_band = nla_nest_start(msg, band); |
| 786 | if (!nl_band) |
| 787 | goto nla_put_failure; |
| 788 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 789 | /* add HT info */ |
| 790 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 791 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 792 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 793 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 794 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 795 | dev->wiphy.bands[band]->ht_cap.cap); |
| 796 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 797 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 798 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 799 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 800 | } |
| 801 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 802 | /* add frequencies */ |
| 803 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 804 | if (!nl_freqs) |
| 805 | goto nla_put_failure; |
| 806 | |
| 807 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 808 | nl_freq = nla_nest_start(msg, i); |
| 809 | if (!nl_freq) |
| 810 | goto nla_put_failure; |
| 811 | |
| 812 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 813 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 814 | if (nl80211_msg_put_channel(msg, chan)) |
| 815 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 816 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 817 | nla_nest_end(msg, nl_freq); |
| 818 | } |
| 819 | |
| 820 | nla_nest_end(msg, nl_freqs); |
| 821 | |
| 822 | /* add bitrates */ |
| 823 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 824 | if (!nl_rates) |
| 825 | goto nla_put_failure; |
| 826 | |
| 827 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 828 | nl_rate = nla_nest_start(msg, i); |
| 829 | if (!nl_rate) |
| 830 | goto nla_put_failure; |
| 831 | |
| 832 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 833 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 834 | rate->bitrate); |
| 835 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 836 | NLA_PUT_FLAG(msg, |
| 837 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 838 | |
| 839 | nla_nest_end(msg, nl_rate); |
| 840 | } |
| 841 | |
| 842 | nla_nest_end(msg, nl_rates); |
| 843 | |
| 844 | nla_nest_end(msg, nl_band); |
| 845 | } |
| 846 | nla_nest_end(msg, nl_bands); |
| 847 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 848 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 849 | if (!nl_cmds) |
| 850 | goto nla_put_failure; |
| 851 | |
| 852 | i = 0; |
| 853 | #define CMD(op, n) \ |
| 854 | do { \ |
| 855 | if (dev->ops->op) { \ |
| 856 | i++; \ |
| 857 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 858 | } \ |
| 859 | } while (0) |
| 860 | |
| 861 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 862 | CMD(change_virtual_intf, SET_INTERFACE); |
| 863 | CMD(add_key, NEW_KEY); |
| 864 | CMD(add_beacon, NEW_BEACON); |
| 865 | CMD(add_station, NEW_STATION); |
| 866 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 867 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 868 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 869 | CMD(auth, AUTHENTICATE); |
| 870 | CMD(assoc, ASSOCIATE); |
| 871 | CMD(deauth, DEAUTHENTICATE); |
| 872 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 873 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 874 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 875 | CMD(set_pmksa, SET_PMKSA); |
| 876 | CMD(del_pmksa, DEL_PMKSA); |
| 877 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 878 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 879 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 880 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 881 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 882 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 883 | i++; |
| 884 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 885 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 886 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 887 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 888 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 889 | CMD(tdls_mgmt, TDLS_MGMT); |
| 890 | CMD(tdls_oper, TDLS_OPER); |
| 891 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 892 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 893 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 894 | CMD(probe_client, PROBE_CLIENT); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 895 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 896 | i++; |
| 897 | NLA_PUT_U32(msg, i, NL80211_CMD_REGISTER_BEACONS); |
| 898 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 899 | |
| 900 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 901 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 902 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 903 | i++; |
| 904 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 905 | } |
| 906 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 907 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 908 | i++; |
| 909 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 910 | } |
| 911 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 912 | nla_nest_end(msg, nl_cmds); |
| 913 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 914 | if (dev->ops->remain_on_channel) |
| 915 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 916 | dev->wiphy.max_remain_on_channel_duration); |
| 917 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 918 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 919 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 920 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 921 | if (mgmt_stypes) { |
| 922 | u16 stypes; |
| 923 | struct nlattr *nl_ftypes, *nl_ifs; |
| 924 | enum nl80211_iftype ift; |
| 925 | |
| 926 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 927 | if (!nl_ifs) |
| 928 | goto nla_put_failure; |
| 929 | |
| 930 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 931 | nl_ftypes = nla_nest_start(msg, ift); |
| 932 | if (!nl_ftypes) |
| 933 | goto nla_put_failure; |
| 934 | i = 0; |
| 935 | stypes = mgmt_stypes[ift].tx; |
| 936 | while (stypes) { |
| 937 | if (stypes & 1) |
| 938 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 939 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 940 | stypes >>= 1; |
| 941 | i++; |
| 942 | } |
| 943 | nla_nest_end(msg, nl_ftypes); |
| 944 | } |
| 945 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 946 | nla_nest_end(msg, nl_ifs); |
| 947 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 948 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 949 | if (!nl_ifs) |
| 950 | goto nla_put_failure; |
| 951 | |
| 952 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 953 | nl_ftypes = nla_nest_start(msg, ift); |
| 954 | if (!nl_ftypes) |
| 955 | goto nla_put_failure; |
| 956 | i = 0; |
| 957 | stypes = mgmt_stypes[ift].rx; |
| 958 | while (stypes) { |
| 959 | if (stypes & 1) |
| 960 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 961 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 962 | stypes >>= 1; |
| 963 | i++; |
| 964 | } |
| 965 | nla_nest_end(msg, nl_ftypes); |
| 966 | } |
| 967 | nla_nest_end(msg, nl_ifs); |
| 968 | } |
| 969 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 970 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 971 | struct nlattr *nl_wowlan; |
| 972 | |
| 973 | nl_wowlan = nla_nest_start(msg, |
| 974 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 975 | if (!nl_wowlan) |
| 976 | goto nla_put_failure; |
| 977 | |
| 978 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 979 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 980 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 981 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 982 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 983 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 984 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 985 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 986 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 987 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 988 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 989 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 990 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 991 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 992 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 993 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 994 | if (dev->wiphy.wowlan.n_patterns) { |
| 995 | struct nl80211_wowlan_pattern_support pat = { |
| 996 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 997 | .min_pattern_len = |
| 998 | dev->wiphy.wowlan.pattern_min_len, |
| 999 | .max_pattern_len = |
| 1000 | dev->wiphy.wowlan.pattern_max_len, |
| 1001 | }; |
| 1002 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1003 | sizeof(pat), &pat); |
| 1004 | } |
| 1005 | |
| 1006 | nla_nest_end(msg, nl_wowlan); |
| 1007 | } |
| 1008 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1009 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1010 | dev->wiphy.software_iftypes)) |
| 1011 | goto nla_put_failure; |
| 1012 | |
| 1013 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1014 | goto nla_put_failure; |
| 1015 | |
Johannes Berg | 562a748 | 2011-11-07 12:39:33 +0100 | [diff] [blame] | 1016 | if (dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) |
| 1017 | NLA_PUT_U32(msg, NL80211_ATTR_DEVICE_AP_SME, |
| 1018 | dev->wiphy.ap_sme_capa); |
| 1019 | |
Johannes Berg | 1f074bd | 2011-11-06 14:13:33 +0100 | [diff] [blame] | 1020 | NLA_PUT_U32(msg, NL80211_ATTR_FEATURE_FLAGS, dev->wiphy.features); |
| 1021 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1022 | return genlmsg_end(msg, hdr); |
| 1023 | |
| 1024 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1025 | genlmsg_cancel(msg, hdr); |
| 1026 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1030 | { |
| 1031 | int idx = 0; |
| 1032 | int start = cb->args[0]; |
| 1033 | struct cfg80211_registered_device *dev; |
| 1034 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1035 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1036 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1037 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1038 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1039 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1040 | continue; |
| 1041 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1042 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1043 | dev) < 0) { |
| 1044 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1045 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1046 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1047 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1048 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1049 | |
| 1050 | cb->args[0] = idx; |
| 1051 | |
| 1052 | return skb->len; |
| 1053 | } |
| 1054 | |
| 1055 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1056 | { |
| 1057 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1058 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1059 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1060 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1061 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1062 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1063 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1064 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1065 | nlmsg_free(msg); |
| 1066 | return -ENOBUFS; |
| 1067 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1068 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1069 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1070 | } |
| 1071 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1072 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1073 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1074 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1075 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1076 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1077 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1078 | }; |
| 1079 | |
| 1080 | static int parse_txq_params(struct nlattr *tb[], |
| 1081 | struct ieee80211_txq_params *txq_params) |
| 1082 | { |
| 1083 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1084 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1085 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1086 | return -EINVAL; |
| 1087 | |
| 1088 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1089 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1090 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1091 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1092 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1093 | |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1097 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1098 | { |
| 1099 | /* |
| 1100 | * You can only set the channel explicitly for AP, mesh |
| 1101 | * and WDS type interfaces; all others have their channel |
| 1102 | * managed via their respective "establish a connection" |
| 1103 | * command (connect, join, ...) |
| 1104 | * |
| 1105 | * Monitors are special as they are normally slaved to |
| 1106 | * whatever else is going on, so they behave as though |
| 1107 | * you tried setting the wiphy channel itself. |
| 1108 | */ |
| 1109 | return !wdev || |
| 1110 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1111 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1112 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1113 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1114 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1118 | struct wireless_dev *wdev, |
| 1119 | struct genl_info *info) |
| 1120 | { |
| 1121 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1122 | u32 freq; |
| 1123 | int result; |
| 1124 | |
| 1125 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1126 | return -EINVAL; |
| 1127 | |
| 1128 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1129 | return -EOPNOTSUPP; |
| 1130 | |
| 1131 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1132 | channel_type = nla_get_u32(info->attrs[ |
| 1133 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1134 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1135 | channel_type != NL80211_CHAN_HT20 && |
| 1136 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1137 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1138 | return -EINVAL; |
| 1139 | } |
| 1140 | |
| 1141 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1142 | |
| 1143 | mutex_lock(&rdev->devlist_mtx); |
| 1144 | if (wdev) { |
| 1145 | wdev_lock(wdev); |
| 1146 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1147 | wdev_unlock(wdev); |
| 1148 | } else { |
| 1149 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1150 | } |
| 1151 | mutex_unlock(&rdev->devlist_mtx); |
| 1152 | |
| 1153 | return result; |
| 1154 | } |
| 1155 | |
| 1156 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1157 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1159 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1160 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1161 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1162 | } |
| 1163 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1164 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1165 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1167 | struct net_device *dev = info->user_ptr[1]; |
| 1168 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1169 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1170 | |
| 1171 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1172 | return -EINVAL; |
| 1173 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1174 | if (netif_running(dev)) |
| 1175 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1176 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1177 | if (!rdev->ops->set_wds_peer) |
| 1178 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1179 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1180 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1181 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1182 | |
| 1183 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1184 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1188 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1189 | { |
| 1190 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1191 | struct net_device *netdev = NULL; |
| 1192 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1193 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1194 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1195 | u32 changed; |
| 1196 | u8 retry_short = 0, retry_long = 0; |
| 1197 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1198 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1199 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1200 | /* |
| 1201 | * Try to find the wiphy and netdev. Normally this |
| 1202 | * function shouldn't need the netdev, but this is |
| 1203 | * done for backward compatibility -- previously |
| 1204 | * setting the channel was done per wiphy, but now |
| 1205 | * it is per netdev. Previous userland like hostapd |
| 1206 | * also passed a netdev to set_wiphy, so that it is |
| 1207 | * possible to let that go to the right netdev! |
| 1208 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1209 | mutex_lock(&cfg80211_mutex); |
| 1210 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1211 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1212 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1213 | |
| 1214 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1215 | if (netdev && netdev->ieee80211_ptr) { |
| 1216 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1217 | mutex_lock(&rdev->mtx); |
| 1218 | } else |
| 1219 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1220 | } |
| 1221 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1222 | if (!netdev) { |
| 1223 | rdev = __cfg80211_rdev_from_info(info); |
| 1224 | if (IS_ERR(rdev)) { |
| 1225 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1226 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1227 | } |
| 1228 | wdev = NULL; |
| 1229 | netdev = NULL; |
| 1230 | result = 0; |
| 1231 | |
| 1232 | mutex_lock(&rdev->mtx); |
| 1233 | } else if (netif_running(netdev) && |
| 1234 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1235 | wdev = netdev->ieee80211_ptr; |
| 1236 | else |
| 1237 | wdev = NULL; |
| 1238 | |
| 1239 | /* |
| 1240 | * end workaround code, by now the rdev is available |
| 1241 | * and locked, and wdev may or may not be NULL. |
| 1242 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1243 | |
| 1244 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1245 | result = cfg80211_dev_rename( |
| 1246 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1247 | |
| 1248 | mutex_unlock(&cfg80211_mutex); |
| 1249 | |
| 1250 | if (result) |
| 1251 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1252 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1253 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1254 | struct ieee80211_txq_params txq_params; |
| 1255 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1256 | |
| 1257 | if (!rdev->ops->set_txq_params) { |
| 1258 | result = -EOPNOTSUPP; |
| 1259 | goto bad_res; |
| 1260 | } |
| 1261 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1262 | if (!netdev) { |
| 1263 | result = -EINVAL; |
| 1264 | goto bad_res; |
| 1265 | } |
| 1266 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 1267 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1268 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 1269 | result = -EINVAL; |
| 1270 | goto bad_res; |
| 1271 | } |
| 1272 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1273 | nla_for_each_nested(nl_txq_params, |
| 1274 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1275 | rem_txq_params) { |
| 1276 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1277 | nla_data(nl_txq_params), |
| 1278 | nla_len(nl_txq_params), |
| 1279 | txq_params_policy); |
| 1280 | result = parse_txq_params(tb, &txq_params); |
| 1281 | if (result) |
| 1282 | goto bad_res; |
| 1283 | |
| 1284 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1285 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1286 | &txq_params); |
| 1287 | if (result) |
| 1288 | goto bad_res; |
| 1289 | } |
| 1290 | } |
| 1291 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1292 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1293 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1294 | if (result) |
| 1295 | goto bad_res; |
| 1296 | } |
| 1297 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1298 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1299 | enum nl80211_tx_power_setting type; |
| 1300 | int idx, mbm = 0; |
| 1301 | |
| 1302 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1303 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1304 | goto bad_res; |
| 1305 | } |
| 1306 | |
| 1307 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1308 | type = nla_get_u32(info->attrs[idx]); |
| 1309 | |
| 1310 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1311 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1312 | result = -EINVAL; |
| 1313 | goto bad_res; |
| 1314 | } |
| 1315 | |
| 1316 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1317 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1318 | mbm = nla_get_u32(info->attrs[idx]); |
| 1319 | } |
| 1320 | |
| 1321 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1322 | if (result) |
| 1323 | goto bad_res; |
| 1324 | } |
| 1325 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1326 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1327 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1328 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1329 | if ((!rdev->wiphy.available_antennas_tx && |
| 1330 | !rdev->wiphy.available_antennas_rx) || |
| 1331 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1332 | result = -EOPNOTSUPP; |
| 1333 | goto bad_res; |
| 1334 | } |
| 1335 | |
| 1336 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1337 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1338 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1339 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1340 | * available antenna masks, except for the "all" mask */ |
| 1341 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1342 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1343 | result = -EINVAL; |
| 1344 | goto bad_res; |
| 1345 | } |
| 1346 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1347 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1348 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1349 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1350 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1351 | if (result) |
| 1352 | goto bad_res; |
| 1353 | } |
| 1354 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1355 | changed = 0; |
| 1356 | |
| 1357 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1358 | retry_short = nla_get_u8( |
| 1359 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1360 | if (retry_short == 0) { |
| 1361 | result = -EINVAL; |
| 1362 | goto bad_res; |
| 1363 | } |
| 1364 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1365 | } |
| 1366 | |
| 1367 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1368 | retry_long = nla_get_u8( |
| 1369 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1370 | if (retry_long == 0) { |
| 1371 | result = -EINVAL; |
| 1372 | goto bad_res; |
| 1373 | } |
| 1374 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1375 | } |
| 1376 | |
| 1377 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1378 | frag_threshold = nla_get_u32( |
| 1379 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1380 | if (frag_threshold < 256) { |
| 1381 | result = -EINVAL; |
| 1382 | goto bad_res; |
| 1383 | } |
| 1384 | if (frag_threshold != (u32) -1) { |
| 1385 | /* |
| 1386 | * Fragments (apart from the last one) are required to |
| 1387 | * have even length. Make the fragmentation code |
| 1388 | * simpler by stripping LSB should someone try to use |
| 1389 | * odd threshold value. |
| 1390 | */ |
| 1391 | frag_threshold &= ~0x1; |
| 1392 | } |
| 1393 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1394 | } |
| 1395 | |
| 1396 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1397 | rts_threshold = nla_get_u32( |
| 1398 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1399 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1400 | } |
| 1401 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1402 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1403 | coverage_class = nla_get_u8( |
| 1404 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1405 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1406 | } |
| 1407 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1408 | if (changed) { |
| 1409 | u8 old_retry_short, old_retry_long; |
| 1410 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1411 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1412 | |
| 1413 | if (!rdev->ops->set_wiphy_params) { |
| 1414 | result = -EOPNOTSUPP; |
| 1415 | goto bad_res; |
| 1416 | } |
| 1417 | |
| 1418 | old_retry_short = rdev->wiphy.retry_short; |
| 1419 | old_retry_long = rdev->wiphy.retry_long; |
| 1420 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1421 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1422 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1423 | |
| 1424 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1425 | rdev->wiphy.retry_short = retry_short; |
| 1426 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1427 | rdev->wiphy.retry_long = retry_long; |
| 1428 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1429 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1430 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1431 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1432 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1433 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1434 | |
| 1435 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1436 | if (result) { |
| 1437 | rdev->wiphy.retry_short = old_retry_short; |
| 1438 | rdev->wiphy.retry_long = old_retry_long; |
| 1439 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1440 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1441 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1442 | } |
| 1443 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1444 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1445 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1446 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1447 | if (netdev) |
| 1448 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1449 | return result; |
| 1450 | } |
| 1451 | |
| 1452 | |
| 1453 | 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] | 1454 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1455 | struct net_device *dev) |
| 1456 | { |
| 1457 | void *hdr; |
| 1458 | |
| 1459 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1460 | if (!hdr) |
| 1461 | return -1; |
| 1462 | |
| 1463 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1464 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1465 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1466 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1467 | |
| 1468 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1469 | rdev->devlist_generation ^ |
| 1470 | (cfg80211_rdev_list_generation << 2)); |
| 1471 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1472 | return genlmsg_end(msg, hdr); |
| 1473 | |
| 1474 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1475 | genlmsg_cancel(msg, hdr); |
| 1476 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1480 | { |
| 1481 | int wp_idx = 0; |
| 1482 | int if_idx = 0; |
| 1483 | int wp_start = cb->args[0]; |
| 1484 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1485 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1486 | struct wireless_dev *wdev; |
| 1487 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1488 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1489 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1490 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1491 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1492 | if (wp_idx < wp_start) { |
| 1493 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1494 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1495 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1496 | if_idx = 0; |
| 1497 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1498 | mutex_lock(&rdev->devlist_mtx); |
| 1499 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1500 | if (if_idx < if_start) { |
| 1501 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1502 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1503 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1504 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1505 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1506 | rdev, wdev->netdev) < 0) { |
| 1507 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1508 | goto out; |
| 1509 | } |
| 1510 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1511 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1512 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1513 | |
| 1514 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1515 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1516 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1517 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1518 | |
| 1519 | cb->args[0] = wp_idx; |
| 1520 | cb->args[1] = if_idx; |
| 1521 | |
| 1522 | return skb->len; |
| 1523 | } |
| 1524 | |
| 1525 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1526 | { |
| 1527 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1528 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1529 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1530 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1531 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1532 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1533 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1534 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1535 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1536 | dev, netdev) < 0) { |
| 1537 | nlmsg_free(msg); |
| 1538 | return -ENOBUFS; |
| 1539 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1540 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1541 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1542 | } |
| 1543 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1544 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1545 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1546 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1547 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1548 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1549 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1550 | }; |
| 1551 | |
| 1552 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1553 | { |
| 1554 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1555 | int flag; |
| 1556 | |
| 1557 | *mntrflags = 0; |
| 1558 | |
| 1559 | if (!nla) |
| 1560 | return -EINVAL; |
| 1561 | |
| 1562 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1563 | nla, mntr_flags_policy)) |
| 1564 | return -EINVAL; |
| 1565 | |
| 1566 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1567 | if (flags[flag]) |
| 1568 | *mntrflags |= (1<<flag); |
| 1569 | |
| 1570 | return 0; |
| 1571 | } |
| 1572 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1573 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1574 | struct net_device *netdev, u8 use_4addr, |
| 1575 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1576 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1577 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1578 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1579 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1580 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1581 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1582 | |
| 1583 | switch (iftype) { |
| 1584 | case NL80211_IFTYPE_AP_VLAN: |
| 1585 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1586 | return 0; |
| 1587 | break; |
| 1588 | case NL80211_IFTYPE_STATION: |
| 1589 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1590 | return 0; |
| 1591 | break; |
| 1592 | default: |
| 1593 | break; |
| 1594 | } |
| 1595 | |
| 1596 | return -EOPNOTSUPP; |
| 1597 | } |
| 1598 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1599 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1600 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1602 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1603 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1604 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1605 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1606 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1607 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1608 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1609 | memset(¶ms, 0, sizeof(params)); |
| 1610 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1611 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1612 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1613 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1614 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1615 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1616 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1617 | if (ntype > NL80211_IFTYPE_MAX) |
| 1618 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1619 | } |
| 1620 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1621 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1622 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1623 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1624 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1625 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1626 | if (netif_running(dev)) |
| 1627 | return -EBUSY; |
| 1628 | |
| 1629 | wdev_lock(wdev); |
| 1630 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1631 | IEEE80211_MAX_MESH_ID_LEN); |
| 1632 | wdev->mesh_id_up_len = |
| 1633 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1634 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1635 | wdev->mesh_id_up_len); |
| 1636 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1637 | } |
| 1638 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1639 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1640 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1641 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1642 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1643 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1644 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1645 | } else { |
| 1646 | params.use_4addr = -1; |
| 1647 | } |
| 1648 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1649 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1650 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1651 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1652 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1653 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1654 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1655 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1656 | |
| 1657 | flags = &_flags; |
| 1658 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1659 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1660 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1661 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1662 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1663 | else |
| 1664 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1665 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1666 | if (!err && params.use_4addr != -1) |
| 1667 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1668 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1669 | return err; |
| 1670 | } |
| 1671 | |
| 1672 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1673 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1675 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1676 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1677 | int err; |
| 1678 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1679 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1680 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1681 | memset(¶ms, 0, sizeof(params)); |
| 1682 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1683 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1684 | return -EINVAL; |
| 1685 | |
| 1686 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1687 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1688 | if (type > NL80211_IFTYPE_MAX) |
| 1689 | return -EINVAL; |
| 1690 | } |
| 1691 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1692 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1693 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1694 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1695 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1696 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1697 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1698 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1699 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1700 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1701 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1702 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1703 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1704 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1705 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1706 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1707 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1708 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1709 | if (IS_ERR(dev)) |
| 1710 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1711 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1712 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1713 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1714 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1715 | |
| 1716 | wdev_lock(wdev); |
| 1717 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1718 | IEEE80211_MAX_MESH_ID_LEN); |
| 1719 | wdev->mesh_id_up_len = |
| 1720 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1721 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1722 | wdev->mesh_id_up_len); |
| 1723 | wdev_unlock(wdev); |
| 1724 | } |
| 1725 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1726 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1730 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1732 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1733 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1734 | if (!rdev->ops->del_virtual_intf) |
| 1735 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1736 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1737 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1738 | } |
| 1739 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1740 | struct get_key_cookie { |
| 1741 | struct sk_buff *msg; |
| 1742 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1743 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1744 | }; |
| 1745 | |
| 1746 | static void get_key_callback(void *c, struct key_params *params) |
| 1747 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1748 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1749 | struct get_key_cookie *cookie = c; |
| 1750 | |
| 1751 | if (params->key) |
| 1752 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1753 | params->key_len, params->key); |
| 1754 | |
| 1755 | if (params->seq) |
| 1756 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1757 | params->seq_len, params->seq); |
| 1758 | |
| 1759 | if (params->cipher) |
| 1760 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1761 | params->cipher); |
| 1762 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1763 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1764 | if (!key) |
| 1765 | goto nla_put_failure; |
| 1766 | |
| 1767 | if (params->key) |
| 1768 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1769 | params->key_len, params->key); |
| 1770 | |
| 1771 | if (params->seq) |
| 1772 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1773 | params->seq_len, params->seq); |
| 1774 | |
| 1775 | if (params->cipher) |
| 1776 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1777 | params->cipher); |
| 1778 | |
| 1779 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1780 | |
| 1781 | nla_nest_end(cookie->msg, key); |
| 1782 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1783 | return; |
| 1784 | nla_put_failure: |
| 1785 | cookie->error = 1; |
| 1786 | } |
| 1787 | |
| 1788 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1789 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1790 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1791 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1792 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1793 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1794 | const u8 *mac_addr = NULL; |
| 1795 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1796 | struct get_key_cookie cookie = { |
| 1797 | .error = 0, |
| 1798 | }; |
| 1799 | void *hdr; |
| 1800 | struct sk_buff *msg; |
| 1801 | |
| 1802 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1803 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1804 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1805 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1806 | return -EINVAL; |
| 1807 | |
| 1808 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1809 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1810 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1811 | pairwise = !!mac_addr; |
| 1812 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1813 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1814 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1815 | return -EINVAL; |
| 1816 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1817 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1818 | return -EINVAL; |
| 1819 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1820 | } |
| 1821 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1822 | if (!rdev->ops->get_key) |
| 1823 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1824 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1825 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1826 | if (!msg) |
| 1827 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1828 | |
| 1829 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1830 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1831 | if (IS_ERR(hdr)) |
| 1832 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1833 | |
| 1834 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1835 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1836 | |
| 1837 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1838 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1839 | if (mac_addr) |
| 1840 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1841 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1842 | if (pairwise && mac_addr && |
| 1843 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1844 | return -ENOENT; |
| 1845 | |
| 1846 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1847 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1848 | |
| 1849 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1850 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1851 | |
| 1852 | if (cookie.error) |
| 1853 | goto nla_put_failure; |
| 1854 | |
| 1855 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1856 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1857 | |
| 1858 | nla_put_failure: |
| 1859 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1860 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1861 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1862 | return err; |
| 1863 | } |
| 1864 | |
| 1865 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1866 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1868 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1869 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1870 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1871 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1872 | err = nl80211_parse_key(info, &key); |
| 1873 | if (err) |
| 1874 | return err; |
| 1875 | |
| 1876 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1877 | return -EINVAL; |
| 1878 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1879 | /* only support setting default key */ |
| 1880 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1881 | return -EINVAL; |
| 1882 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1883 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1884 | |
| 1885 | if (key.def) { |
| 1886 | if (!rdev->ops->set_default_key) { |
| 1887 | err = -EOPNOTSUPP; |
| 1888 | goto out; |
| 1889 | } |
| 1890 | |
| 1891 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1892 | if (err) |
| 1893 | goto out; |
| 1894 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1895 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1896 | key.def_uni, key.def_multi); |
| 1897 | |
| 1898 | if (err) |
| 1899 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1900 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1901 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1902 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1903 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1904 | } else { |
| 1905 | if (key.def_uni || !key.def_multi) { |
| 1906 | err = -EINVAL; |
| 1907 | goto out; |
| 1908 | } |
| 1909 | |
| 1910 | if (!rdev->ops->set_default_mgmt_key) { |
| 1911 | err = -EOPNOTSUPP; |
| 1912 | goto out; |
| 1913 | } |
| 1914 | |
| 1915 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1916 | if (err) |
| 1917 | goto out; |
| 1918 | |
| 1919 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1920 | dev, key.idx); |
| 1921 | if (err) |
| 1922 | goto out; |
| 1923 | |
| 1924 | #ifdef CONFIG_CFG80211_WEXT |
| 1925 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1926 | #endif |
| 1927 | } |
| 1928 | |
| 1929 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1930 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1931 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1932 | return err; |
| 1933 | } |
| 1934 | |
| 1935 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1936 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1937 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1938 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1939 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1940 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1941 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1942 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1943 | err = nl80211_parse_key(info, &key); |
| 1944 | if (err) |
| 1945 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1946 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1947 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1948 | return -EINVAL; |
| 1949 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1950 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1951 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1952 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1953 | if (key.type == -1) { |
| 1954 | if (mac_addr) |
| 1955 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1956 | else |
| 1957 | key.type = NL80211_KEYTYPE_GROUP; |
| 1958 | } |
| 1959 | |
| 1960 | /* for now */ |
| 1961 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1962 | key.type != NL80211_KEYTYPE_GROUP) |
| 1963 | return -EINVAL; |
| 1964 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1965 | if (!rdev->ops->add_key) |
| 1966 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1967 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1968 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1969 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1970 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1971 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1972 | |
| 1973 | wdev_lock(dev->ieee80211_ptr); |
| 1974 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1975 | if (!err) |
| 1976 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1977 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1978 | mac_addr, &key.p); |
| 1979 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1980 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1981 | return err; |
| 1982 | } |
| 1983 | |
| 1984 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1985 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1986 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1987 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1988 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1989 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1990 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1991 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1992 | err = nl80211_parse_key(info, &key); |
| 1993 | if (err) |
| 1994 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1995 | |
| 1996 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1997 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1998 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1999 | if (key.type == -1) { |
| 2000 | if (mac_addr) |
| 2001 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2002 | else |
| 2003 | key.type = NL80211_KEYTYPE_GROUP; |
| 2004 | } |
| 2005 | |
| 2006 | /* for now */ |
| 2007 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2008 | key.type != NL80211_KEYTYPE_GROUP) |
| 2009 | return -EINVAL; |
| 2010 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2011 | if (!rdev->ops->del_key) |
| 2012 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2013 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2014 | wdev_lock(dev->ieee80211_ptr); |
| 2015 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2016 | |
| 2017 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2018 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2019 | err = -ENOENT; |
| 2020 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2021 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2022 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2023 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2024 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2025 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2026 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2027 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2028 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2029 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2030 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2031 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2032 | } |
| 2033 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2034 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2035 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2036 | return err; |
| 2037 | } |
| 2038 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2039 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2040 | { |
| 2041 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 2042 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2044 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2045 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2046 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2047 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2048 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2049 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2050 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2051 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2052 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2053 | return -EINVAL; |
| 2054 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2055 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2056 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2057 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2058 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2059 | memset(¶ms, 0, sizeof(params)); |
| 2060 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2061 | switch (info->genlhdr->cmd) { |
| 2062 | case NL80211_CMD_NEW_BEACON: |
| 2063 | /* these are required for NEW_BEACON */ |
| 2064 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2065 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2066 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2067 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2068 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2069 | params.interval = |
| 2070 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2071 | params.dtim_period = |
| 2072 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2073 | |
| 2074 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2075 | if (err) |
| 2076 | return err; |
| 2077 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2078 | /* |
| 2079 | * In theory, some of these attributes could be required for |
| 2080 | * NEW_BEACON, but since they were not used when the command was |
| 2081 | * originally added, keep them optional for old user space |
| 2082 | * programs to work with drivers that do not need the additional |
| 2083 | * information. |
| 2084 | */ |
| 2085 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2086 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2087 | params.ssid_len = |
| 2088 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2089 | if (params.ssid_len == 0 || |
| 2090 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2091 | return -EINVAL; |
| 2092 | } |
| 2093 | |
| 2094 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2095 | params.hidden_ssid = nla_get_u32( |
| 2096 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2097 | if (params.hidden_ssid != |
| 2098 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2099 | params.hidden_ssid != |
| 2100 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2101 | params.hidden_ssid != |
| 2102 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2103 | return -EINVAL; |
| 2104 | } |
| 2105 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2106 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2107 | |
| 2108 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2109 | params.auth_type = nla_get_u32( |
| 2110 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2111 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2112 | return -EINVAL; |
| 2113 | } else |
| 2114 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2115 | |
| 2116 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2117 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2118 | if (err) |
| 2119 | return err; |
| 2120 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2121 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2122 | break; |
| 2123 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2124 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2125 | break; |
| 2126 | default: |
| 2127 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2128 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2129 | } |
| 2130 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2131 | if (!call) |
| 2132 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2133 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2134 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2135 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2136 | params.head_len = |
| 2137 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2138 | haveinfo = 1; |
| 2139 | } |
| 2140 | |
| 2141 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2142 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2143 | params.tail_len = |
| 2144 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2145 | haveinfo = 1; |
| 2146 | } |
| 2147 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2148 | if (!haveinfo) |
| 2149 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2150 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2151 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2152 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2153 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2154 | } |
| 2155 | |
| 2156 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2157 | params.proberesp_ies = |
| 2158 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2159 | params.proberesp_ies_len = |
| 2160 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2161 | } |
| 2162 | |
| 2163 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2164 | params.assocresp_ies = |
| 2165 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2166 | params.assocresp_ies_len = |
| 2167 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2168 | } |
| 2169 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2170 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2171 | if (!err && params.interval) |
| 2172 | wdev->beacon_interval = params.interval; |
| 2173 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2177 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2178 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2179 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2180 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2181 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2182 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2183 | if (!rdev->ops->del_beacon) |
| 2184 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2185 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2186 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2187 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2188 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2189 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2190 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2191 | if (!err) |
| 2192 | wdev->beacon_interval = 0; |
| 2193 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2194 | } |
| 2195 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2196 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2197 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2198 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2199 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2200 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2201 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2202 | }; |
| 2203 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2204 | static int parse_station_flags(struct genl_info *info, |
| 2205 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2206 | { |
| 2207 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2208 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2209 | int flag; |
| 2210 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2211 | /* |
| 2212 | * Try parsing the new attribute first so userspace |
| 2213 | * can specify both for older kernels. |
| 2214 | */ |
| 2215 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2216 | if (nla) { |
| 2217 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2218 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2219 | sta_flags = nla_data(nla); |
| 2220 | params->sta_flags_mask = sta_flags->mask; |
| 2221 | params->sta_flags_set = sta_flags->set; |
| 2222 | if ((params->sta_flags_mask | |
| 2223 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2224 | return -EINVAL; |
| 2225 | return 0; |
| 2226 | } |
| 2227 | |
| 2228 | /* if present, parse the old attribute */ |
| 2229 | |
| 2230 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2231 | if (!nla) |
| 2232 | return 0; |
| 2233 | |
| 2234 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2235 | nla, sta_flags_policy)) |
| 2236 | return -EINVAL; |
| 2237 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2238 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2239 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2240 | |
| 2241 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2242 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2243 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2244 | |
| 2245 | return 0; |
| 2246 | } |
| 2247 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2248 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2249 | int attr) |
| 2250 | { |
| 2251 | struct nlattr *rate; |
| 2252 | u16 bitrate; |
| 2253 | |
| 2254 | rate = nla_nest_start(msg, attr); |
| 2255 | if (!rate) |
| 2256 | goto nla_put_failure; |
| 2257 | |
| 2258 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2259 | bitrate = cfg80211_calculate_bitrate(info); |
| 2260 | if (bitrate > 0) |
| 2261 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2262 | |
| 2263 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2264 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2265 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2266 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2267 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2268 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2269 | |
| 2270 | nla_nest_end(msg, rate); |
| 2271 | return true; |
| 2272 | |
| 2273 | nla_put_failure: |
| 2274 | return false; |
| 2275 | } |
| 2276 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2277 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2278 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2279 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2280 | { |
| 2281 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2282 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2283 | |
| 2284 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2285 | if (!hdr) |
| 2286 | return -1; |
| 2287 | |
| 2288 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2289 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2290 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2291 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2292 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2293 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2294 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2295 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2296 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2297 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2298 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2299 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2300 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2301 | sinfo->inactive_time); |
| 2302 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2303 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2304 | sinfo->rx_bytes); |
| 2305 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2306 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2307 | sinfo->tx_bytes); |
| 2308 | if (sinfo->filled & STATION_INFO_LLID) |
| 2309 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2310 | sinfo->llid); |
| 2311 | if (sinfo->filled & STATION_INFO_PLID) |
| 2312 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2313 | sinfo->plid); |
| 2314 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2315 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2316 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2317 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2318 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2319 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2320 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2321 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2322 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2323 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2324 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2325 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2326 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2327 | } |
| 2328 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2329 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2330 | NL80211_STA_INFO_RX_BITRATE)) |
| 2331 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2332 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2333 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2334 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2335 | sinfo->rx_packets); |
| 2336 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2337 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2338 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2339 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2340 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2341 | sinfo->tx_retries); |
| 2342 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2343 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2344 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2345 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2346 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2347 | if (!bss_param) |
| 2348 | goto nla_put_failure; |
| 2349 | |
| 2350 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2351 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2352 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2353 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2354 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2355 | NLA_PUT_FLAG(msg, |
| 2356 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2357 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2358 | sinfo->bss_param.dtim_period); |
| 2359 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2360 | sinfo->bss_param.beacon_interval); |
| 2361 | |
| 2362 | nla_nest_end(msg, bss_param); |
| 2363 | } |
Helmut Schaa | bb6e753 | 2011-10-13 16:30:39 +0200 | [diff] [blame] | 2364 | if (sinfo->filled & STATION_INFO_STA_FLAGS) |
| 2365 | NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2366 | sizeof(struct nl80211_sta_flag_update), |
| 2367 | &sinfo->sta_flags); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2368 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2369 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2370 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2371 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2372 | sinfo->assoc_req_ies); |
| 2373 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2374 | return genlmsg_end(msg, hdr); |
| 2375 | |
| 2376 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2377 | genlmsg_cancel(msg, hdr); |
| 2378 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2379 | } |
| 2380 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2381 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2382 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2383 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2384 | struct station_info sinfo; |
| 2385 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2386 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2387 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2388 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2389 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2390 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2391 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2392 | if (err) |
| 2393 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2394 | |
| 2395 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2396 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2397 | goto out_err; |
| 2398 | } |
| 2399 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2400 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2401 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2402 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2403 | mac_addr, &sinfo); |
| 2404 | if (err == -ENOENT) |
| 2405 | break; |
| 2406 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2407 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2408 | |
| 2409 | if (nl80211_send_station(skb, |
| 2410 | NETLINK_CB(cb->skb).pid, |
| 2411 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2412 | netdev, mac_addr, |
| 2413 | &sinfo) < 0) |
| 2414 | goto out; |
| 2415 | |
| 2416 | sta_idx++; |
| 2417 | } |
| 2418 | |
| 2419 | |
| 2420 | out: |
| 2421 | cb->args[1] = sta_idx; |
| 2422 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2423 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2424 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2425 | |
| 2426 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2427 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2428 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2429 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2430 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2432 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2433 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2434 | struct sk_buff *msg; |
| 2435 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2437 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2438 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2439 | |
| 2440 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2441 | return -EINVAL; |
| 2442 | |
| 2443 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2444 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2445 | if (!rdev->ops->get_station) |
| 2446 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2447 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2448 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2449 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2450 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2451 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2452 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2453 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2454 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2455 | |
| 2456 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2457 | dev, mac_addr, &sinfo) < 0) { |
| 2458 | nlmsg_free(msg); |
| 2459 | return -ENOBUFS; |
| 2460 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2461 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2462 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2466 | * 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] | 2467 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2468 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2469 | struct cfg80211_registered_device *rdev, |
| 2470 | struct net_device **vlan) |
| 2471 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2472 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2473 | *vlan = NULL; |
| 2474 | |
| 2475 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2476 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2477 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2478 | if (!*vlan) |
| 2479 | return -ENODEV; |
| 2480 | if (!(*vlan)->ieee80211_ptr) |
| 2481 | return -EINVAL; |
| 2482 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2483 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2484 | if (!netif_running(*vlan)) |
| 2485 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2486 | } |
| 2487 | return 0; |
| 2488 | } |
| 2489 | |
| 2490 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2491 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2493 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2494 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2495 | struct station_parameters params; |
| 2496 | u8 *mac_addr = NULL; |
| 2497 | |
| 2498 | memset(¶ms, 0, sizeof(params)); |
| 2499 | |
| 2500 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2501 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2502 | |
| 2503 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2504 | return -EINVAL; |
| 2505 | |
| 2506 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2507 | return -EINVAL; |
| 2508 | |
| 2509 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2510 | |
| 2511 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2512 | params.supported_rates = |
| 2513 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2514 | params.supported_rates_len = |
| 2515 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2516 | } |
| 2517 | |
| 2518 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2519 | params.listen_interval = |
| 2520 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2521 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2522 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2523 | params.ht_capa = |
| 2524 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2525 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2526 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2527 | return -EINVAL; |
| 2528 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2529 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2530 | params.plink_action = |
| 2531 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2532 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2533 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2534 | params.plink_state = |
| 2535 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2536 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2537 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2538 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2539 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2540 | |
| 2541 | /* validate settings */ |
| 2542 | err = 0; |
| 2543 | |
| 2544 | switch (dev->ieee80211_ptr->iftype) { |
| 2545 | case NL80211_IFTYPE_AP: |
| 2546 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2547 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2548 | /* disallow mesh-specific things */ |
| 2549 | if (params.plink_action) |
| 2550 | err = -EINVAL; |
| 2551 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2552 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2553 | case NL80211_IFTYPE_STATION: |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2554 | /* disallow things sta doesn't support */ |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2555 | if (params.plink_action) |
| 2556 | err = -EINVAL; |
| 2557 | if (params.vlan) |
| 2558 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2559 | if (params.supported_rates && |
| 2560 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2561 | err = -EINVAL; |
| 2562 | if (params.ht_capa) |
| 2563 | err = -EINVAL; |
| 2564 | if (params.listen_interval >= 0) |
| 2565 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2566 | if (params.sta_flags_mask & |
| 2567 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2568 | BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 2569 | err = -EINVAL; |
| 2570 | /* can't change the TDLS bit */ |
| 2571 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2572 | (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2573 | err = -EINVAL; |
| 2574 | break; |
| 2575 | case NL80211_IFTYPE_MESH_POINT: |
| 2576 | /* disallow things mesh doesn't support */ |
| 2577 | if (params.vlan) |
| 2578 | err = -EINVAL; |
| 2579 | if (params.ht_capa) |
| 2580 | err = -EINVAL; |
| 2581 | if (params.listen_interval >= 0) |
| 2582 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2583 | if (params.sta_flags_mask & |
| 2584 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2585 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2586 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2587 | err = -EINVAL; |
| 2588 | break; |
| 2589 | default: |
| 2590 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2591 | } |
| 2592 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2593 | if (err) |
| 2594 | goto out; |
| 2595 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2596 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2597 | err = -EOPNOTSUPP; |
| 2598 | goto out; |
| 2599 | } |
| 2600 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2601 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2602 | |
| 2603 | out: |
| 2604 | if (params.vlan) |
| 2605 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2606 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2607 | return err; |
| 2608 | } |
| 2609 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2610 | static struct nla_policy |
| 2611 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2612 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2613 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2614 | }; |
| 2615 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2616 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2617 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2619 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2620 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2621 | struct station_parameters params; |
| 2622 | u8 *mac_addr = NULL; |
| 2623 | |
| 2624 | memset(¶ms, 0, sizeof(params)); |
| 2625 | |
| 2626 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2627 | return -EINVAL; |
| 2628 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2629 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2630 | return -EINVAL; |
| 2631 | |
| 2632 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2633 | return -EINVAL; |
| 2634 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2635 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2636 | return -EINVAL; |
| 2637 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2638 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2639 | params.supported_rates = |
| 2640 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2641 | params.supported_rates_len = |
| 2642 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2643 | params.listen_interval = |
| 2644 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2645 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2646 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2647 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2648 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2649 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2650 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2651 | params.ht_capa = |
| 2652 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2653 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2654 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2655 | params.plink_action = |
| 2656 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2657 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2658 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2659 | return -EINVAL; |
| 2660 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2661 | /* parse WME attributes if sta is WME capable */ |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 2662 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Arik Nemtsov | cd32984 | 2011-09-26 09:36:42 +0300 | [diff] [blame] | 2663 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2664 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2665 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2666 | struct nlattr *nla; |
| 2667 | |
| 2668 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2669 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2670 | nl80211_sta_wme_policy); |
| 2671 | if (err) |
| 2672 | return err; |
| 2673 | |
| 2674 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2675 | params.uapsd_queues = |
| 2676 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2677 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2678 | return -EINVAL; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2679 | |
| 2680 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2681 | params.max_sp = |
| 2682 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2683 | |
| 2684 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2685 | return -EINVAL; |
Johannes Berg | 3b9ce80 | 2011-09-27 20:56:12 +0200 | [diff] [blame] | 2686 | |
| 2687 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2688 | } |
| 2689 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2690 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2691 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2692 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2693 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO && |
| 2694 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) |
| 2695 | return -EINVAL; |
| 2696 | |
| 2697 | /* |
| 2698 | * Only managed stations can add TDLS peers, and only when the |
| 2699 | * wiphy supports external TDLS setup. |
| 2700 | */ |
| 2701 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION && |
| 2702 | !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2703 | (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 2704 | (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2705 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2706 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2707 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2708 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2709 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2710 | |
| 2711 | /* validate settings */ |
| 2712 | err = 0; |
| 2713 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2714 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2715 | err = -EOPNOTSUPP; |
| 2716 | goto out; |
| 2717 | } |
| 2718 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2719 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2720 | |
| 2721 | out: |
| 2722 | if (params.vlan) |
| 2723 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2724 | return err; |
| 2725 | } |
| 2726 | |
| 2727 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2728 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2729 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2730 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2731 | u8 *mac_addr = NULL; |
| 2732 | |
| 2733 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2734 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2735 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2736 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2737 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2738 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2739 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2740 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2741 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2742 | if (!rdev->ops->del_station) |
| 2743 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2744 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2745 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2746 | } |
| 2747 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2748 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2749 | int flags, struct net_device *dev, |
| 2750 | u8 *dst, u8 *next_hop, |
| 2751 | struct mpath_info *pinfo) |
| 2752 | { |
| 2753 | void *hdr; |
| 2754 | struct nlattr *pinfoattr; |
| 2755 | |
| 2756 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2757 | if (!hdr) |
| 2758 | return -1; |
| 2759 | |
| 2760 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2761 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2762 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2763 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2764 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2765 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2766 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2767 | if (!pinfoattr) |
| 2768 | goto nla_put_failure; |
| 2769 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2770 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2771 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2772 | if (pinfo->filled & MPATH_INFO_SN) |
| 2773 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2774 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2775 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2776 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2777 | pinfo->metric); |
| 2778 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2779 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2780 | pinfo->exptime); |
| 2781 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2782 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2783 | pinfo->flags); |
| 2784 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2785 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2786 | pinfo->discovery_timeout); |
| 2787 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2788 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2789 | pinfo->discovery_retries); |
| 2790 | |
| 2791 | nla_nest_end(msg, pinfoattr); |
| 2792 | |
| 2793 | return genlmsg_end(msg, hdr); |
| 2794 | |
| 2795 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2796 | genlmsg_cancel(msg, hdr); |
| 2797 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2801 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2802 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2803 | struct mpath_info pinfo; |
| 2804 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2805 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2806 | u8 dst[ETH_ALEN]; |
| 2807 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2808 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2809 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2810 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2811 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2812 | if (err) |
| 2813 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2814 | |
| 2815 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2816 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2817 | goto out_err; |
| 2818 | } |
| 2819 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2820 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2821 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2822 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2823 | } |
| 2824 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2825 | while (1) { |
| 2826 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2827 | dst, next_hop, &pinfo); |
| 2828 | if (err == -ENOENT) |
| 2829 | break; |
| 2830 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2831 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2832 | |
| 2833 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2834 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2835 | netdev, dst, next_hop, |
| 2836 | &pinfo) < 0) |
| 2837 | goto out; |
| 2838 | |
| 2839 | path_idx++; |
| 2840 | } |
| 2841 | |
| 2842 | |
| 2843 | out: |
| 2844 | cb->args[1] = path_idx; |
| 2845 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2846 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2847 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2848 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2852 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2853 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2854 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2855 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2856 | struct mpath_info pinfo; |
| 2857 | struct sk_buff *msg; |
| 2858 | u8 *dst = NULL; |
| 2859 | u8 next_hop[ETH_ALEN]; |
| 2860 | |
| 2861 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2862 | |
| 2863 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2864 | return -EINVAL; |
| 2865 | |
| 2866 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2867 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2868 | if (!rdev->ops->get_mpath) |
| 2869 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2870 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2871 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2872 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2873 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2874 | 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] | 2875 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2876 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2877 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2878 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2879 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2880 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2881 | |
| 2882 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2883 | dev, dst, next_hop, &pinfo) < 0) { |
| 2884 | nlmsg_free(msg); |
| 2885 | return -ENOBUFS; |
| 2886 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2887 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2888 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2892 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2893 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2894 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2895 | u8 *dst = NULL; |
| 2896 | u8 *next_hop = NULL; |
| 2897 | |
| 2898 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2899 | return -EINVAL; |
| 2900 | |
| 2901 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2902 | return -EINVAL; |
| 2903 | |
| 2904 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2905 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2906 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2907 | if (!rdev->ops->change_mpath) |
| 2908 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2909 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2910 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2911 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2912 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2913 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2914 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2915 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2916 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2917 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2918 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2919 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2920 | u8 *dst = NULL; |
| 2921 | u8 *next_hop = NULL; |
| 2922 | |
| 2923 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2924 | return -EINVAL; |
| 2925 | |
| 2926 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2927 | return -EINVAL; |
| 2928 | |
| 2929 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2930 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2931 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2932 | if (!rdev->ops->add_mpath) |
| 2933 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2934 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2935 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2936 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2937 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2938 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2942 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2943 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2944 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2945 | u8 *dst = NULL; |
| 2946 | |
| 2947 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2948 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2949 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2950 | if (!rdev->ops->del_mpath) |
| 2951 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2952 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2953 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2954 | } |
| 2955 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2956 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2957 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2958 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2959 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2960 | struct bss_parameters params; |
| 2961 | |
| 2962 | memset(¶ms, 0, sizeof(params)); |
| 2963 | /* default to not changing parameters */ |
| 2964 | params.use_cts_prot = -1; |
| 2965 | params.use_short_preamble = -1; |
| 2966 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2967 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2968 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2969 | |
| 2970 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2971 | params.use_cts_prot = |
| 2972 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2973 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2974 | params.use_short_preamble = |
| 2975 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2976 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2977 | params.use_short_slot_time = |
| 2978 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2979 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2980 | params.basic_rates = |
| 2981 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2982 | params.basic_rates_len = |
| 2983 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2984 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2985 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2986 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2987 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2988 | params.ht_opmode = |
| 2989 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2990 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2991 | if (!rdev->ops->change_bss) |
| 2992 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2993 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2994 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2995 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2996 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2997 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2998 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2999 | } |
| 3000 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3001 | 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] | 3002 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 3003 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 3004 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 3005 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 3006 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 3007 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 3008 | }; |
| 3009 | |
| 3010 | static int parse_reg_rule(struct nlattr *tb[], |
| 3011 | struct ieee80211_reg_rule *reg_rule) |
| 3012 | { |
| 3013 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 3014 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 3015 | |
| 3016 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 3017 | return -EINVAL; |
| 3018 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3019 | return -EINVAL; |
| 3020 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3021 | return -EINVAL; |
| 3022 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3023 | return -EINVAL; |
| 3024 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3025 | return -EINVAL; |
| 3026 | |
| 3027 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3028 | |
| 3029 | freq_range->start_freq_khz = |
| 3030 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3031 | freq_range->end_freq_khz = |
| 3032 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3033 | freq_range->max_bandwidth_khz = |
| 3034 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3035 | |
| 3036 | power_rule->max_eirp = |
| 3037 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3038 | |
| 3039 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3040 | power_rule->max_antenna_gain = |
| 3041 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3042 | |
| 3043 | return 0; |
| 3044 | } |
| 3045 | |
| 3046 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3047 | { |
| 3048 | int r; |
| 3049 | char *data = NULL; |
| 3050 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3051 | /* |
| 3052 | * You should only get this when cfg80211 hasn't yet initialized |
| 3053 | * completely when built-in to the kernel right between the time |
| 3054 | * window between nl80211_init() and regulatory_init(), if that is |
| 3055 | * even possible. |
| 3056 | */ |
| 3057 | mutex_lock(&cfg80211_mutex); |
| 3058 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3059 | mutex_unlock(&cfg80211_mutex); |
| 3060 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3061 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3062 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3063 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3064 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3065 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3066 | |
| 3067 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3068 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3069 | r = regulatory_hint_user(data); |
| 3070 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3071 | return r; |
| 3072 | } |
| 3073 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3074 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3075 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3076 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3077 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3078 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3079 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3080 | struct mesh_config cur_params; |
| 3081 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3082 | void *hdr; |
| 3083 | struct nlattr *pinfoattr; |
| 3084 | struct sk_buff *msg; |
| 3085 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3086 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3087 | return -EOPNOTSUPP; |
| 3088 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3089 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3090 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3091 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3092 | wdev_lock(wdev); |
| 3093 | /* If not connected, get default parameters */ |
| 3094 | if (!wdev->mesh_id_len) |
| 3095 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3096 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3097 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3098 | &cur_params); |
| 3099 | wdev_unlock(wdev); |
| 3100 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3101 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3102 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3103 | |
| 3104 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3105 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3106 | if (!msg) |
| 3107 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3108 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3109 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3110 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3111 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3112 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3113 | if (!pinfoattr) |
| 3114 | goto nla_put_failure; |
| 3115 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3116 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3117 | cur_params.dot11MeshRetryTimeout); |
| 3118 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3119 | cur_params.dot11MeshConfirmTimeout); |
| 3120 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3121 | cur_params.dot11MeshHoldingTimeout); |
| 3122 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3123 | cur_params.dot11MeshMaxPeerLinks); |
| 3124 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3125 | cur_params.dot11MeshMaxRetries); |
| 3126 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3127 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3128 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3129 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3130 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3131 | cur_params.auto_open_plinks); |
| 3132 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3133 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3134 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3135 | cur_params.path_refresh_time); |
| 3136 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3137 | cur_params.min_discovery_timeout); |
| 3138 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3139 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3140 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3141 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 3142 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3143 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3144 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3145 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3146 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3147 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3148 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3149 | cur_params.dot11MeshGateAnnouncementProtocol); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3150 | nla_nest_end(msg, pinfoattr); |
| 3151 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3152 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3153 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3154 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3155 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3156 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3157 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3158 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3161 | 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] | 3162 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3163 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3164 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3165 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3166 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3167 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3168 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3169 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3170 | |
| 3171 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3172 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3173 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3174 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3175 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 3176 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3177 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3178 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3179 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3180 | }; |
| 3181 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3182 | static const struct nla_policy |
| 3183 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3184 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3185 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3186 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3187 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3188 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3189 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3190 | }; |
| 3191 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3192 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3193 | struct mesh_config *cfg, |
| 3194 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3195 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3196 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3197 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3198 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3199 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3200 | do {\ |
| 3201 | if (table[attr_num]) {\ |
| 3202 | cfg->param = nla_fn(table[attr_num]); \ |
| 3203 | mask |= (1 << (attr_num - 1)); \ |
| 3204 | } \ |
| 3205 | } while (0);\ |
| 3206 | |
| 3207 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3208 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3209 | return -EINVAL; |
| 3210 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3211 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3212 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3213 | return -EINVAL; |
| 3214 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3215 | /* This makes sure that there aren't more than 32 mesh config |
| 3216 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3217 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3218 | |
| 3219 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3220 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3221 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3222 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3223 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3224 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3225 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3226 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3227 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3228 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3229 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3230 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3231 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3233 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3234 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3235 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3236 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3237 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3238 | nla_get_u8); |
| 3239 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3240 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3241 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3242 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3243 | nla_get_u16); |
| 3244 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3245 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3246 | nla_get_u32); |
| 3247 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3248 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3249 | nla_get_u16); |
| 3250 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3251 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3252 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3253 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3254 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3255 | dot11MeshHWMPRootMode, mask, |
| 3256 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3257 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3258 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3259 | dot11MeshHWMPRannInterval, mask, |
| 3260 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3261 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3262 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3263 | dot11MeshGateAnnouncementProtocol, mask, |
| 3264 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3265 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3266 | if (mask_out) |
| 3267 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3268 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3269 | return 0; |
| 3270 | |
| 3271 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3272 | } |
| 3273 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3274 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3275 | struct mesh_setup *setup) |
| 3276 | { |
| 3277 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3278 | |
| 3279 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3280 | return -EINVAL; |
| 3281 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3282 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3283 | nl80211_mesh_setup_params_policy)) |
| 3284 | return -EINVAL; |
| 3285 | |
| 3286 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3287 | setup->path_sel_proto = |
| 3288 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3289 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3290 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3291 | |
| 3292 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3293 | setup->path_metric = |
| 3294 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3295 | IEEE80211_PATH_METRIC_VENDOR : |
| 3296 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3297 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3298 | |
| 3299 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3300 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3301 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3302 | if (!is_valid_ie_attr(ieattr)) |
| 3303 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3304 | setup->ie = nla_data(ieattr); |
| 3305 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3306 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3307 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3308 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3309 | |
| 3310 | return 0; |
| 3311 | } |
| 3312 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3313 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3314 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3315 | { |
| 3316 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3317 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3318 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3319 | struct mesh_config cfg; |
| 3320 | u32 mask; |
| 3321 | int err; |
| 3322 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3323 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3324 | return -EOPNOTSUPP; |
| 3325 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3326 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3327 | return -EOPNOTSUPP; |
| 3328 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3329 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3330 | if (err) |
| 3331 | return err; |
| 3332 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3333 | wdev_lock(wdev); |
| 3334 | if (!wdev->mesh_id_len) |
| 3335 | err = -ENOLINK; |
| 3336 | |
| 3337 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3338 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3339 | mask, &cfg); |
| 3340 | |
| 3341 | wdev_unlock(wdev); |
| 3342 | |
| 3343 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3346 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3347 | { |
| 3348 | struct sk_buff *msg; |
| 3349 | void *hdr = NULL; |
| 3350 | struct nlattr *nl_reg_rules; |
| 3351 | unsigned int i; |
| 3352 | int err = -EINVAL; |
| 3353 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3354 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3355 | |
| 3356 | if (!cfg80211_regdomain) |
| 3357 | goto out; |
| 3358 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3359 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3360 | if (!msg) { |
| 3361 | err = -ENOBUFS; |
| 3362 | goto out; |
| 3363 | } |
| 3364 | |
| 3365 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3366 | NL80211_CMD_GET_REG); |
| 3367 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3368 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3369 | |
| 3370 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3371 | cfg80211_regdomain->alpha2); |
| 3372 | |
| 3373 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3374 | if (!nl_reg_rules) |
| 3375 | goto nla_put_failure; |
| 3376 | |
| 3377 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3378 | struct nlattr *nl_reg_rule; |
| 3379 | const struct ieee80211_reg_rule *reg_rule; |
| 3380 | const struct ieee80211_freq_range *freq_range; |
| 3381 | const struct ieee80211_power_rule *power_rule; |
| 3382 | |
| 3383 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3384 | freq_range = ®_rule->freq_range; |
| 3385 | power_rule = ®_rule->power_rule; |
| 3386 | |
| 3387 | nl_reg_rule = nla_nest_start(msg, i); |
| 3388 | if (!nl_reg_rule) |
| 3389 | goto nla_put_failure; |
| 3390 | |
| 3391 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3392 | reg_rule->flags); |
| 3393 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3394 | freq_range->start_freq_khz); |
| 3395 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3396 | freq_range->end_freq_khz); |
| 3397 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3398 | freq_range->max_bandwidth_khz); |
| 3399 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3400 | power_rule->max_antenna_gain); |
| 3401 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3402 | power_rule->max_eirp); |
| 3403 | |
| 3404 | nla_nest_end(msg, nl_reg_rule); |
| 3405 | } |
| 3406 | |
| 3407 | nla_nest_end(msg, nl_reg_rules); |
| 3408 | |
| 3409 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3410 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3411 | goto out; |
| 3412 | |
| 3413 | nla_put_failure: |
| 3414 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3415 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3416 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3417 | err = -EMSGSIZE; |
| 3418 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3419 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3420 | return err; |
| 3421 | } |
| 3422 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3423 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3424 | { |
| 3425 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3426 | struct nlattr *nl_reg_rule; |
| 3427 | char *alpha2 = NULL; |
| 3428 | int rem_reg_rules = 0, r = 0; |
| 3429 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3430 | struct ieee80211_regdomain *rd = NULL; |
| 3431 | |
| 3432 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3433 | return -EINVAL; |
| 3434 | |
| 3435 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3436 | return -EINVAL; |
| 3437 | |
| 3438 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3439 | |
| 3440 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3441 | rem_reg_rules) { |
| 3442 | num_rules++; |
| 3443 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3444 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3445 | } |
| 3446 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3447 | mutex_lock(&cfg80211_mutex); |
| 3448 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3449 | if (!reg_is_valid_request(alpha2)) { |
| 3450 | r = -EINVAL; |
| 3451 | goto bad_reg; |
| 3452 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3453 | |
| 3454 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3455 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3456 | |
| 3457 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3458 | if (!rd) { |
| 3459 | r = -ENOMEM; |
| 3460 | goto bad_reg; |
| 3461 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3462 | |
| 3463 | rd->n_reg_rules = num_rules; |
| 3464 | rd->alpha2[0] = alpha2[0]; |
| 3465 | rd->alpha2[1] = alpha2[1]; |
| 3466 | |
| 3467 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3468 | rem_reg_rules) { |
| 3469 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3470 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3471 | reg_rule_policy); |
| 3472 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3473 | if (r) |
| 3474 | goto bad_reg; |
| 3475 | |
| 3476 | rule_idx++; |
| 3477 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3478 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3479 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3480 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3481 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | BUG_ON(rule_idx != num_rules); |
| 3485 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3486 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3487 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3488 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3489 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3490 | return r; |
| 3491 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3492 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3493 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3494 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3495 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3498 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3499 | { |
| 3500 | struct nlattr *attr1, *attr2; |
| 3501 | int n_channels = 0, tmp1, tmp2; |
| 3502 | |
| 3503 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3504 | n_channels++; |
| 3505 | /* |
| 3506 | * Some hardware has a limited channel list for |
| 3507 | * scanning, and it is pretty much nonsensical |
| 3508 | * to scan for a channel twice, so disallow that |
| 3509 | * and don't require drivers to check that the |
| 3510 | * channel list they get isn't longer than what |
| 3511 | * they can scan, as long as they can scan all |
| 3512 | * the channels they registered at once. |
| 3513 | */ |
| 3514 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3515 | if (attr1 != attr2 && |
| 3516 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3517 | return 0; |
| 3518 | } |
| 3519 | |
| 3520 | return n_channels; |
| 3521 | } |
| 3522 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3523 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3524 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3526 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3527 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3528 | struct nlattr *attr; |
| 3529 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3530 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3531 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3532 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3533 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3534 | return -EINVAL; |
| 3535 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3536 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3538 | if (!rdev->ops->scan) |
| 3539 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3540 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3541 | if (rdev->scan_req) |
| 3542 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3543 | |
| 3544 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3545 | n_channels = validate_scan_freqs( |
| 3546 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3547 | if (!n_channels) |
| 3548 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3549 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3550 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3551 | n_channels = 0; |
| 3552 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3553 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3554 | if (wiphy->bands[band]) |
| 3555 | n_channels += wiphy->bands[band]->n_channels; |
| 3556 | } |
| 3557 | |
| 3558 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3559 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3560 | n_ssids++; |
| 3561 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3562 | if (n_ssids > wiphy->max_scan_ssids) |
| 3563 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3564 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3565 | if (info->attrs[NL80211_ATTR_IE]) |
| 3566 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3567 | else |
| 3568 | ie_len = 0; |
| 3569 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3570 | if (ie_len > wiphy->max_scan_ie_len) |
| 3571 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3572 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3573 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3574 | + sizeof(*request->ssids) * n_ssids |
| 3575 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3576 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3577 | if (!request) |
| 3578 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3579 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3580 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3581 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3582 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3583 | if (ie_len) { |
| 3584 | if (request->ssids) |
| 3585 | request->ie = (void *)(request->ssids + n_ssids); |
| 3586 | else |
| 3587 | request->ie = (void *)(request->channels + n_channels); |
| 3588 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3589 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3590 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3591 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3592 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3593 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3594 | struct ieee80211_channel *chan; |
| 3595 | |
| 3596 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3597 | |
| 3598 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3599 | err = -EINVAL; |
| 3600 | goto out_free; |
| 3601 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3602 | |
| 3603 | /* ignore disabled channels */ |
| 3604 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3605 | continue; |
| 3606 | |
| 3607 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3608 | i++; |
| 3609 | } |
| 3610 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3611 | enum ieee80211_band band; |
| 3612 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3613 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3614 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3615 | int j; |
| 3616 | if (!wiphy->bands[band]) |
| 3617 | continue; |
| 3618 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3619 | struct ieee80211_channel *chan; |
| 3620 | |
| 3621 | chan = &wiphy->bands[band]->channels[j]; |
| 3622 | |
| 3623 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3624 | continue; |
| 3625 | |
| 3626 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3627 | i++; |
| 3628 | } |
| 3629 | } |
| 3630 | } |
| 3631 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3632 | if (!i) { |
| 3633 | err = -EINVAL; |
| 3634 | goto out_free; |
| 3635 | } |
| 3636 | |
| 3637 | request->n_channels = i; |
| 3638 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3639 | i = 0; |
| 3640 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3641 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3642 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3643 | err = -EINVAL; |
| 3644 | goto out_free; |
| 3645 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3646 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3647 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3648 | i++; |
| 3649 | } |
| 3650 | } |
| 3651 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3652 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3653 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3654 | memcpy((void *)request->ie, |
| 3655 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3656 | request->ie_len); |
| 3657 | } |
| 3658 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3659 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3660 | if (wiphy->bands[i]) |
| 3661 | request->rates[i] = |
| 3662 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3663 | |
| 3664 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3665 | nla_for_each_nested(attr, |
| 3666 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3667 | tmp) { |
| 3668 | enum ieee80211_band band = nla_type(attr); |
| 3669 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3670 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3671 | err = -EINVAL; |
| 3672 | goto out_free; |
| 3673 | } |
| 3674 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3675 | nla_data(attr), |
| 3676 | nla_len(attr), |
| 3677 | &request->rates[band]); |
| 3678 | if (err) |
| 3679 | goto out_free; |
| 3680 | } |
| 3681 | } |
| 3682 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3683 | request->no_cck = |
| 3684 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3685 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3686 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3687 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3688 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3689 | rdev->scan_req = request; |
| 3690 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3691 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3692 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3693 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3694 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3695 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3696 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3697 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3698 | kfree(request); |
| 3699 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3700 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3701 | return err; |
| 3702 | } |
| 3703 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3704 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3705 | struct genl_info *info) |
| 3706 | { |
| 3707 | struct cfg80211_sched_scan_request *request; |
| 3708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3709 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3710 | struct nlattr *attr; |
| 3711 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3712 | 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] | 3713 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3714 | enum ieee80211_band band; |
| 3715 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3716 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3717 | |
| 3718 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3719 | !rdev->ops->sched_scan_start) |
| 3720 | return -EOPNOTSUPP; |
| 3721 | |
| 3722 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3723 | return -EINVAL; |
| 3724 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3725 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3726 | return -EINVAL; |
| 3727 | |
| 3728 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3729 | if (interval == 0) |
| 3730 | return -EINVAL; |
| 3731 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3732 | wiphy = &rdev->wiphy; |
| 3733 | |
| 3734 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3735 | n_channels = validate_scan_freqs( |
| 3736 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3737 | if (!n_channels) |
| 3738 | return -EINVAL; |
| 3739 | } else { |
| 3740 | n_channels = 0; |
| 3741 | |
| 3742 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3743 | if (wiphy->bands[band]) |
| 3744 | n_channels += wiphy->bands[band]->n_channels; |
| 3745 | } |
| 3746 | |
| 3747 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3748 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3749 | tmp) |
| 3750 | n_ssids++; |
| 3751 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3752 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3753 | return -EINVAL; |
| 3754 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3755 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3756 | nla_for_each_nested(attr, |
| 3757 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3758 | tmp) |
| 3759 | n_match_sets++; |
| 3760 | |
| 3761 | if (n_match_sets > wiphy->max_match_sets) |
| 3762 | return -EINVAL; |
| 3763 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3764 | if (info->attrs[NL80211_ATTR_IE]) |
| 3765 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3766 | else |
| 3767 | ie_len = 0; |
| 3768 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3769 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3770 | return -EINVAL; |
| 3771 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3772 | mutex_lock(&rdev->sched_scan_mtx); |
| 3773 | |
| 3774 | if (rdev->sched_scan_req) { |
| 3775 | err = -EINPROGRESS; |
| 3776 | goto out; |
| 3777 | } |
| 3778 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3779 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3780 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3781 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3782 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3783 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3784 | if (!request) { |
| 3785 | err = -ENOMEM; |
| 3786 | goto out; |
| 3787 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3788 | |
| 3789 | if (n_ssids) |
| 3790 | request->ssids = (void *)&request->channels[n_channels]; |
| 3791 | request->n_ssids = n_ssids; |
| 3792 | if (ie_len) { |
| 3793 | if (request->ssids) |
| 3794 | request->ie = (void *)(request->ssids + n_ssids); |
| 3795 | else |
| 3796 | request->ie = (void *)(request->channels + n_channels); |
| 3797 | } |
| 3798 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3799 | if (n_match_sets) { |
| 3800 | if (request->ie) |
| 3801 | request->match_sets = (void *)(request->ie + ie_len); |
| 3802 | else if (request->ssids) |
| 3803 | request->match_sets = |
| 3804 | (void *)(request->ssids + n_ssids); |
| 3805 | else |
| 3806 | request->match_sets = |
| 3807 | (void *)(request->channels + n_channels); |
| 3808 | } |
| 3809 | request->n_match_sets = n_match_sets; |
| 3810 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3811 | i = 0; |
| 3812 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3813 | /* user specified, bail out if channel not found */ |
| 3814 | nla_for_each_nested(attr, |
| 3815 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3816 | tmp) { |
| 3817 | struct ieee80211_channel *chan; |
| 3818 | |
| 3819 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3820 | |
| 3821 | if (!chan) { |
| 3822 | err = -EINVAL; |
| 3823 | goto out_free; |
| 3824 | } |
| 3825 | |
| 3826 | /* ignore disabled channels */ |
| 3827 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3828 | continue; |
| 3829 | |
| 3830 | request->channels[i] = chan; |
| 3831 | i++; |
| 3832 | } |
| 3833 | } else { |
| 3834 | /* all channels */ |
| 3835 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3836 | int j; |
| 3837 | if (!wiphy->bands[band]) |
| 3838 | continue; |
| 3839 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3840 | struct ieee80211_channel *chan; |
| 3841 | |
| 3842 | chan = &wiphy->bands[band]->channels[j]; |
| 3843 | |
| 3844 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3845 | continue; |
| 3846 | |
| 3847 | request->channels[i] = chan; |
| 3848 | i++; |
| 3849 | } |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | if (!i) { |
| 3854 | err = -EINVAL; |
| 3855 | goto out_free; |
| 3856 | } |
| 3857 | |
| 3858 | request->n_channels = i; |
| 3859 | |
| 3860 | i = 0; |
| 3861 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3862 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3863 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3864 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3865 | err = -EINVAL; |
| 3866 | goto out_free; |
| 3867 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3868 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3869 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3870 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3871 | i++; |
| 3872 | } |
| 3873 | } |
| 3874 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3875 | i = 0; |
| 3876 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 3877 | nla_for_each_nested(attr, |
| 3878 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3879 | tmp) { |
| 3880 | struct nlattr *ssid; |
| 3881 | |
| 3882 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 3883 | nla_data(attr), nla_len(attr), |
| 3884 | nl80211_match_policy); |
| 3885 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 3886 | if (ssid) { |
| 3887 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 3888 | err = -EINVAL; |
| 3889 | goto out_free; |
| 3890 | } |
| 3891 | memcpy(request->match_sets[i].ssid.ssid, |
| 3892 | nla_data(ssid), nla_len(ssid)); |
| 3893 | request->match_sets[i].ssid.ssid_len = |
| 3894 | nla_len(ssid); |
| 3895 | } |
| 3896 | i++; |
| 3897 | } |
| 3898 | } |
| 3899 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3900 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3901 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3902 | memcpy((void *)request->ie, |
| 3903 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3904 | request->ie_len); |
| 3905 | } |
| 3906 | |
| 3907 | request->dev = dev; |
| 3908 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3909 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3910 | |
| 3911 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3912 | if (!err) { |
| 3913 | rdev->sched_scan_req = request; |
| 3914 | nl80211_send_sched_scan(rdev, dev, |
| 3915 | NL80211_CMD_START_SCHED_SCAN); |
| 3916 | goto out; |
| 3917 | } |
| 3918 | |
| 3919 | out_free: |
| 3920 | kfree(request); |
| 3921 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3922 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3923 | return err; |
| 3924 | } |
| 3925 | |
| 3926 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3927 | struct genl_info *info) |
| 3928 | { |
| 3929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3930 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3931 | |
| 3932 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3933 | !rdev->ops->sched_scan_stop) |
| 3934 | return -EOPNOTSUPP; |
| 3935 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3936 | mutex_lock(&rdev->sched_scan_mtx); |
| 3937 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3938 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3939 | |
| 3940 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3941 | } |
| 3942 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3943 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3944 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3945 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3946 | struct wireless_dev *wdev, |
| 3947 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3948 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3949 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3950 | void *hdr; |
| 3951 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3952 | int i; |
| 3953 | |
| 3954 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3955 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3956 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3957 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3958 | if (!hdr) |
| 3959 | return -1; |
| 3960 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3961 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3962 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3963 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3964 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3965 | |
| 3966 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3967 | if (!bss) |
| 3968 | goto nla_put_failure; |
| 3969 | if (!is_zero_ether_addr(res->bssid)) |
| 3970 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3971 | if (res->information_elements && res->len_information_elements) |
| 3972 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3973 | res->len_information_elements, |
| 3974 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3975 | if (res->beacon_ies && res->len_beacon_ies && |
| 3976 | res->beacon_ies != res->information_elements) |
| 3977 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3978 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3979 | if (res->tsf) |
| 3980 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3981 | if (res->beacon_interval) |
| 3982 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3983 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3984 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3985 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3986 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3987 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3988 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3989 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3990 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3991 | break; |
| 3992 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3993 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3994 | break; |
| 3995 | default: |
| 3996 | break; |
| 3997 | } |
| 3998 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3999 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4000 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4001 | case NL80211_IFTYPE_STATION: |
| 4002 | if (intbss == wdev->current_bss) |
| 4003 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4004 | NL80211_BSS_STATUS_ASSOCIATED); |
| 4005 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 4006 | if (intbss != wdev->auth_bsses[i]) |
| 4007 | continue; |
| 4008 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4009 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 4010 | break; |
| 4011 | } |
| 4012 | break; |
| 4013 | case NL80211_IFTYPE_ADHOC: |
| 4014 | if (intbss == wdev->current_bss) |
| 4015 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 4016 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 4017 | break; |
| 4018 | default: |
| 4019 | break; |
| 4020 | } |
| 4021 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4022 | nla_nest_end(msg, bss); |
| 4023 | |
| 4024 | return genlmsg_end(msg, hdr); |
| 4025 | |
| 4026 | nla_put_failure: |
| 4027 | genlmsg_cancel(msg, hdr); |
| 4028 | return -EMSGSIZE; |
| 4029 | } |
| 4030 | |
| 4031 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4032 | struct netlink_callback *cb) |
| 4033 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4034 | struct cfg80211_registered_device *rdev; |
| 4035 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4036 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4037 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4038 | int start = cb->args[1], idx = 0; |
| 4039 | int err; |
| 4040 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4041 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4042 | if (err) |
| 4043 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4044 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4045 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4046 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4047 | wdev_lock(wdev); |
| 4048 | spin_lock_bh(&rdev->bss_lock); |
| 4049 | cfg80211_bss_expire(rdev); |
| 4050 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4051 | cb->seq = rdev->bss_generation; |
| 4052 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4053 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4054 | if (++idx <= start) |
| 4055 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4056 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4057 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4058 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4059 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4060 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4061 | } |
| 4062 | } |
| 4063 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4064 | spin_unlock_bh(&rdev->bss_lock); |
| 4065 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4066 | |
| 4067 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4068 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4069 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4070 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4071 | } |
| 4072 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4073 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4074 | int flags, struct net_device *dev, |
| 4075 | struct survey_info *survey) |
| 4076 | { |
| 4077 | void *hdr; |
| 4078 | struct nlattr *infoattr; |
| 4079 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4080 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4081 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4082 | if (!hdr) |
| 4083 | return -ENOMEM; |
| 4084 | |
| 4085 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4086 | |
| 4087 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4088 | if (!infoattr) |
| 4089 | goto nla_put_failure; |
| 4090 | |
| 4091 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4092 | survey->channel->center_freq); |
| 4093 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4094 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4095 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4096 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4097 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4098 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4099 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4100 | survey->channel_time); |
| 4101 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4102 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4103 | survey->channel_time_busy); |
| 4104 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4105 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4106 | survey->channel_time_ext_busy); |
| 4107 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4108 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4109 | survey->channel_time_rx); |
| 4110 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4111 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4112 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4113 | |
| 4114 | nla_nest_end(msg, infoattr); |
| 4115 | |
| 4116 | return genlmsg_end(msg, hdr); |
| 4117 | |
| 4118 | nla_put_failure: |
| 4119 | genlmsg_cancel(msg, hdr); |
| 4120 | return -EMSGSIZE; |
| 4121 | } |
| 4122 | |
| 4123 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4124 | struct netlink_callback *cb) |
| 4125 | { |
| 4126 | struct survey_info survey; |
| 4127 | struct cfg80211_registered_device *dev; |
| 4128 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4129 | int survey_idx = cb->args[1]; |
| 4130 | int res; |
| 4131 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4132 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4133 | if (res) |
| 4134 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4135 | |
| 4136 | if (!dev->ops->dump_survey) { |
| 4137 | res = -EOPNOTSUPP; |
| 4138 | goto out_err; |
| 4139 | } |
| 4140 | |
| 4141 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4142 | struct ieee80211_channel *chan; |
| 4143 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4144 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4145 | &survey); |
| 4146 | if (res == -ENOENT) |
| 4147 | break; |
| 4148 | if (res) |
| 4149 | goto out_err; |
| 4150 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4151 | /* Survey without a channel doesn't make sense */ |
| 4152 | if (!survey.channel) { |
| 4153 | res = -EINVAL; |
| 4154 | goto out; |
| 4155 | } |
| 4156 | |
| 4157 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4158 | survey.channel->center_freq); |
| 4159 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4160 | survey_idx++; |
| 4161 | continue; |
| 4162 | } |
| 4163 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4164 | if (nl80211_send_survey(skb, |
| 4165 | NETLINK_CB(cb->skb).pid, |
| 4166 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4167 | netdev, |
| 4168 | &survey) < 0) |
| 4169 | goto out; |
| 4170 | survey_idx++; |
| 4171 | } |
| 4172 | |
| 4173 | out: |
| 4174 | cb->args[1] = survey_idx; |
| 4175 | res = skb->len; |
| 4176 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4177 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4178 | return res; |
| 4179 | } |
| 4180 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4181 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4182 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4183 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4184 | } |
| 4185 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4186 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4187 | { |
| 4188 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4189 | NL80211_WPA_VERSION_2)); |
| 4190 | } |
| 4191 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4192 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4193 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4194 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4195 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4196 | struct ieee80211_channel *chan; |
| 4197 | const u8 *bssid, *ssid, *ie = NULL; |
| 4198 | int err, ssid_len, ie_len = 0; |
| 4199 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4200 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4201 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4202 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4203 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4204 | return -EINVAL; |
| 4205 | |
| 4206 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4207 | return -EINVAL; |
| 4208 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4209 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4210 | return -EINVAL; |
| 4211 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4212 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4213 | return -EINVAL; |
| 4214 | |
| 4215 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4216 | return -EINVAL; |
| 4217 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4218 | err = nl80211_parse_key(info, &key); |
| 4219 | if (err) |
| 4220 | return err; |
| 4221 | |
| 4222 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4223 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4224 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4225 | if (!key.p.key || !key.p.key_len) |
| 4226 | return -EINVAL; |
| 4227 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4228 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4229 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4230 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4231 | return -EINVAL; |
| 4232 | if (key.idx > 4) |
| 4233 | return -EINVAL; |
| 4234 | } else { |
| 4235 | key.p.key_len = 0; |
| 4236 | key.p.key = NULL; |
| 4237 | } |
| 4238 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4239 | if (key.idx >= 0) { |
| 4240 | int i; |
| 4241 | bool ok = false; |
| 4242 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4243 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4244 | ok = true; |
| 4245 | break; |
| 4246 | } |
| 4247 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4248 | if (!ok) |
| 4249 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4250 | } |
| 4251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4252 | if (!rdev->ops->auth) |
| 4253 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4254 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4255 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4256 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4257 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4258 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4259 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4260 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4261 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4262 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4263 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4264 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4265 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4266 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4267 | |
| 4268 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4269 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4270 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4271 | } |
| 4272 | |
| 4273 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4274 | if (!nl80211_valid_auth_type(auth_type)) |
| 4275 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4276 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4277 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4278 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4279 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4280 | ssid, ssid_len, ie, ie_len, |
| 4281 | key.p.key, key.p.key_len, key.idx, |
| 4282 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4283 | } |
| 4284 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4285 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4286 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4287 | struct cfg80211_crypto_settings *settings, |
| 4288 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4289 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4290 | memset(settings, 0, sizeof(*settings)); |
| 4291 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4292 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4293 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4294 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4295 | u16 proto; |
| 4296 | proto = nla_get_u16( |
| 4297 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4298 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4299 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4300 | proto != ETH_P_PAE) |
| 4301 | return -EINVAL; |
| 4302 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4303 | settings->control_port_no_encrypt = true; |
| 4304 | } else |
| 4305 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4306 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4307 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4308 | void *data; |
| 4309 | int len, i; |
| 4310 | |
| 4311 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4312 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4313 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4314 | |
| 4315 | if (len % sizeof(u32)) |
| 4316 | return -EINVAL; |
| 4317 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4318 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4319 | return -EINVAL; |
| 4320 | |
| 4321 | memcpy(settings->ciphers_pairwise, data, len); |
| 4322 | |
| 4323 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4324 | if (!cfg80211_supported_cipher_suite( |
| 4325 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4326 | settings->ciphers_pairwise[i])) |
| 4327 | return -EINVAL; |
| 4328 | } |
| 4329 | |
| 4330 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4331 | settings->cipher_group = |
| 4332 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4333 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4334 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4335 | return -EINVAL; |
| 4336 | } |
| 4337 | |
| 4338 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4339 | settings->wpa_versions = |
| 4340 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4341 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4342 | return -EINVAL; |
| 4343 | } |
| 4344 | |
| 4345 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4346 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4347 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4348 | |
| 4349 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4350 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4351 | settings->n_akm_suites = len / sizeof(u32); |
| 4352 | |
| 4353 | if (len % sizeof(u32)) |
| 4354 | return -EINVAL; |
| 4355 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4356 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4357 | return -EINVAL; |
| 4358 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4359 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | return 0; |
| 4363 | } |
| 4364 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4365 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4366 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4367 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4368 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4369 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4370 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4371 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4372 | int err, ssid_len, ie_len = 0; |
| 4373 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4374 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4375 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4376 | return -EINVAL; |
| 4377 | |
| 4378 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4379 | !info->attrs[NL80211_ATTR_SSID] || |
| 4380 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4381 | return -EINVAL; |
| 4382 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4383 | if (!rdev->ops->assoc) |
| 4384 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4385 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4386 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4387 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4388 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4389 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4390 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4391 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4392 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4393 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4394 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4395 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4396 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4397 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4398 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4399 | |
| 4400 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4401 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4402 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4403 | } |
| 4404 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4405 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4406 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4407 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4408 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4409 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4410 | else if (mfp != NL80211_MFP_NO) |
| 4411 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4412 | } |
| 4413 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4414 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4415 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4416 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4417 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4418 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4419 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4420 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4421 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4422 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4423 | return err; |
| 4424 | } |
| 4425 | |
| 4426 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4427 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4428 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4429 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4430 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4431 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4432 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4433 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4434 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4435 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4436 | return -EINVAL; |
| 4437 | |
| 4438 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4439 | return -EINVAL; |
| 4440 | |
| 4441 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4442 | return -EINVAL; |
| 4443 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4444 | if (!rdev->ops->deauth) |
| 4445 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4446 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4447 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4448 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4449 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4450 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4451 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4452 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4453 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4454 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4455 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4456 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4457 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4458 | |
| 4459 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4460 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4461 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4462 | } |
| 4463 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4464 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4465 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4466 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4467 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4468 | } |
| 4469 | |
| 4470 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4471 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4472 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4473 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4474 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4475 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4476 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4477 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4478 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4479 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4480 | return -EINVAL; |
| 4481 | |
| 4482 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4483 | return -EINVAL; |
| 4484 | |
| 4485 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4486 | return -EINVAL; |
| 4487 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4488 | if (!rdev->ops->disassoc) |
| 4489 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4490 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4491 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4492 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4493 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4494 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4495 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4496 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4497 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4498 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4499 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4500 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4501 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4502 | |
| 4503 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4504 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4505 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4506 | } |
| 4507 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4508 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4509 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4510 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4511 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4512 | } |
| 4513 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4514 | static bool |
| 4515 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4516 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4517 | int rateval) |
| 4518 | { |
| 4519 | struct wiphy *wiphy = &rdev->wiphy; |
| 4520 | bool found = false; |
| 4521 | int band, i; |
| 4522 | |
| 4523 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4524 | struct ieee80211_supported_band *sband; |
| 4525 | |
| 4526 | sband = wiphy->bands[band]; |
| 4527 | if (!sband) |
| 4528 | continue; |
| 4529 | |
| 4530 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4531 | if (sband->bitrates[i].bitrate == rateval) { |
| 4532 | mcast_rate[band] = i + 1; |
| 4533 | found = true; |
| 4534 | break; |
| 4535 | } |
| 4536 | } |
| 4537 | } |
| 4538 | |
| 4539 | return found; |
| 4540 | } |
| 4541 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4542 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4543 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4545 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4546 | struct cfg80211_ibss_params ibss; |
| 4547 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4548 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4549 | int err; |
| 4550 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4551 | memset(&ibss, 0, sizeof(ibss)); |
| 4552 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4553 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4554 | return -EINVAL; |
| 4555 | |
| 4556 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4557 | !info->attrs[NL80211_ATTR_SSID] || |
| 4558 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4559 | return -EINVAL; |
| 4560 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4561 | ibss.beacon_interval = 100; |
| 4562 | |
| 4563 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4564 | ibss.beacon_interval = |
| 4565 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4566 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4567 | return -EINVAL; |
| 4568 | } |
| 4569 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4570 | if (!rdev->ops->join_ibss) |
| 4571 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4572 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4573 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4574 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4575 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4576 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4577 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4578 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4579 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4580 | |
| 4581 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4582 | return -EINVAL; |
| 4583 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4584 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4585 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4586 | |
| 4587 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4588 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4589 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4590 | } |
| 4591 | |
| 4592 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4593 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4594 | if (!ibss.channel || |
| 4595 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4596 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4597 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4598 | |
| 4599 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4600 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4601 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4602 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4603 | u8 *rates = |
| 4604 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4605 | int n_rates = |
| 4606 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4607 | struct ieee80211_supported_band *sband = |
| 4608 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4609 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4610 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4611 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4612 | &ibss.basic_rates); |
| 4613 | if (err) |
| 4614 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4615 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4616 | |
| 4617 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4618 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4619 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4620 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4621 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4622 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4623 | connkeys = nl80211_parse_connkeys(rdev, |
| 4624 | info->attrs[NL80211_ATTR_KEYS]); |
| 4625 | if (IS_ERR(connkeys)) |
| 4626 | return PTR_ERR(connkeys); |
| 4627 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4628 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4629 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4630 | if (err) |
| 4631 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4632 | return err; |
| 4633 | } |
| 4634 | |
| 4635 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4636 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4638 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4639 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4640 | if (!rdev->ops->leave_ibss) |
| 4641 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4642 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4643 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4644 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4645 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4646 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4647 | } |
| 4648 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4649 | #ifdef CONFIG_NL80211_TESTMODE |
| 4650 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4651 | .name = "testmode", |
| 4652 | }; |
| 4653 | |
| 4654 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4655 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4657 | int err; |
| 4658 | |
| 4659 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4660 | return -EINVAL; |
| 4661 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4662 | err = -EOPNOTSUPP; |
| 4663 | if (rdev->ops->testmode_cmd) { |
| 4664 | rdev->testmode_info = info; |
| 4665 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4666 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4667 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4668 | rdev->testmode_info = NULL; |
| 4669 | } |
| 4670 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4671 | return err; |
| 4672 | } |
| 4673 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4674 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4675 | struct netlink_callback *cb) |
| 4676 | { |
| 4677 | struct cfg80211_registered_device *dev; |
| 4678 | int err; |
| 4679 | long phy_idx; |
| 4680 | void *data = NULL; |
| 4681 | int data_len = 0; |
| 4682 | |
| 4683 | if (cb->args[0]) { |
| 4684 | /* |
| 4685 | * 0 is a valid index, but not valid for args[0], |
| 4686 | * so we need to offset by 1. |
| 4687 | */ |
| 4688 | phy_idx = cb->args[0] - 1; |
| 4689 | } else { |
| 4690 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4691 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4692 | nl80211_policy); |
| 4693 | if (err) |
| 4694 | return err; |
| 4695 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4696 | return -EINVAL; |
| 4697 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4698 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4699 | cb->args[1] = |
| 4700 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4701 | } |
| 4702 | |
| 4703 | if (cb->args[1]) { |
| 4704 | data = nla_data((void *)cb->args[1]); |
| 4705 | data_len = nla_len((void *)cb->args[1]); |
| 4706 | } |
| 4707 | |
| 4708 | mutex_lock(&cfg80211_mutex); |
| 4709 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4710 | if (!dev) { |
| 4711 | mutex_unlock(&cfg80211_mutex); |
| 4712 | return -ENOENT; |
| 4713 | } |
| 4714 | cfg80211_lock_rdev(dev); |
| 4715 | mutex_unlock(&cfg80211_mutex); |
| 4716 | |
| 4717 | if (!dev->ops->testmode_dump) { |
| 4718 | err = -EOPNOTSUPP; |
| 4719 | goto out_err; |
| 4720 | } |
| 4721 | |
| 4722 | while (1) { |
| 4723 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4724 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4725 | NL80211_CMD_TESTMODE); |
| 4726 | struct nlattr *tmdata; |
| 4727 | |
| 4728 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4729 | genlmsg_cancel(skb, hdr); |
| 4730 | break; |
| 4731 | } |
| 4732 | |
| 4733 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4734 | if (!tmdata) { |
| 4735 | genlmsg_cancel(skb, hdr); |
| 4736 | break; |
| 4737 | } |
| 4738 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4739 | data, data_len); |
| 4740 | nla_nest_end(skb, tmdata); |
| 4741 | |
| 4742 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4743 | genlmsg_cancel(skb, hdr); |
| 4744 | break; |
| 4745 | } else if (err) { |
| 4746 | genlmsg_cancel(skb, hdr); |
| 4747 | goto out_err; |
| 4748 | } |
| 4749 | |
| 4750 | genlmsg_end(skb, hdr); |
| 4751 | } |
| 4752 | |
| 4753 | err = skb->len; |
| 4754 | /* see above */ |
| 4755 | cb->args[0] = phy_idx + 1; |
| 4756 | out_err: |
| 4757 | cfg80211_unlock_rdev(dev); |
| 4758 | return err; |
| 4759 | } |
| 4760 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4761 | static struct sk_buff * |
| 4762 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4763 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4764 | { |
| 4765 | struct sk_buff *skb; |
| 4766 | void *hdr; |
| 4767 | struct nlattr *data; |
| 4768 | |
| 4769 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4770 | if (!skb) |
| 4771 | return NULL; |
| 4772 | |
| 4773 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4774 | if (!hdr) { |
| 4775 | kfree_skb(skb); |
| 4776 | return NULL; |
| 4777 | } |
| 4778 | |
| 4779 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4780 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4781 | |
| 4782 | ((void **)skb->cb)[0] = rdev; |
| 4783 | ((void **)skb->cb)[1] = hdr; |
| 4784 | ((void **)skb->cb)[2] = data; |
| 4785 | |
| 4786 | return skb; |
| 4787 | |
| 4788 | nla_put_failure: |
| 4789 | kfree_skb(skb); |
| 4790 | return NULL; |
| 4791 | } |
| 4792 | |
| 4793 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4794 | int approxlen) |
| 4795 | { |
| 4796 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4797 | |
| 4798 | if (WARN_ON(!rdev->testmode_info)) |
| 4799 | return NULL; |
| 4800 | |
| 4801 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4802 | rdev->testmode_info->snd_pid, |
| 4803 | rdev->testmode_info->snd_seq, |
| 4804 | GFP_KERNEL); |
| 4805 | } |
| 4806 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4807 | |
| 4808 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4809 | { |
| 4810 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4811 | void *hdr = ((void **)skb->cb)[1]; |
| 4812 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4813 | |
| 4814 | if (WARN_ON(!rdev->testmode_info)) { |
| 4815 | kfree_skb(skb); |
| 4816 | return -EINVAL; |
| 4817 | } |
| 4818 | |
| 4819 | nla_nest_end(skb, data); |
| 4820 | genlmsg_end(skb, hdr); |
| 4821 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4822 | } |
| 4823 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4824 | |
| 4825 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4826 | int approxlen, gfp_t gfp) |
| 4827 | { |
| 4828 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4829 | |
| 4830 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4831 | } |
| 4832 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4833 | |
| 4834 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4835 | { |
| 4836 | void *hdr = ((void **)skb->cb)[1]; |
| 4837 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4838 | |
| 4839 | nla_nest_end(skb, data); |
| 4840 | genlmsg_end(skb, hdr); |
| 4841 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4842 | } |
| 4843 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4844 | #endif |
| 4845 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4846 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4847 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4849 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4850 | struct cfg80211_connect_params connect; |
| 4851 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4852 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4853 | int err; |
| 4854 | |
| 4855 | memset(&connect, 0, sizeof(connect)); |
| 4856 | |
| 4857 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4858 | return -EINVAL; |
| 4859 | |
| 4860 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4861 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4862 | return -EINVAL; |
| 4863 | |
| 4864 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4865 | connect.auth_type = |
| 4866 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4867 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4868 | return -EINVAL; |
| 4869 | } else |
| 4870 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4871 | |
| 4872 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4873 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4874 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4875 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4876 | if (err) |
| 4877 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4878 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4879 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4880 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4881 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4882 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4883 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4884 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4885 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4886 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4887 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4888 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4889 | |
| 4890 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4891 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4892 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4893 | } |
| 4894 | |
| 4895 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4896 | connect.channel = |
| 4897 | ieee80211_get_channel(wiphy, |
| 4898 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4899 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4900 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4901 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4902 | } |
| 4903 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4904 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4905 | connkeys = nl80211_parse_connkeys(rdev, |
| 4906 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4907 | if (IS_ERR(connkeys)) |
| 4908 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4909 | } |
| 4910 | |
| 4911 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4912 | if (err) |
| 4913 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4914 | return err; |
| 4915 | } |
| 4916 | |
| 4917 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4918 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4920 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4921 | u16 reason; |
| 4922 | |
| 4923 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4924 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4925 | else |
| 4926 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4927 | |
| 4928 | if (reason == 0) |
| 4929 | return -EINVAL; |
| 4930 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4931 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4932 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4933 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4934 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4935 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4936 | } |
| 4937 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4938 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4939 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4941 | struct net *net; |
| 4942 | int err; |
| 4943 | u32 pid; |
| 4944 | |
| 4945 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4946 | return -EINVAL; |
| 4947 | |
| 4948 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4949 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4950 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4951 | if (IS_ERR(net)) |
| 4952 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4953 | |
| 4954 | err = 0; |
| 4955 | |
| 4956 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4957 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4958 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4959 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4960 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4961 | return err; |
| 4962 | } |
| 4963 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4964 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4965 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4967 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4968 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4969 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4970 | struct cfg80211_pmksa pmksa; |
| 4971 | |
| 4972 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4973 | |
| 4974 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4975 | return -EINVAL; |
| 4976 | |
| 4977 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4978 | return -EINVAL; |
| 4979 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4980 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4981 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4982 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4983 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4984 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4985 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4986 | |
| 4987 | switch (info->genlhdr->cmd) { |
| 4988 | case NL80211_CMD_SET_PMKSA: |
| 4989 | rdev_ops = rdev->ops->set_pmksa; |
| 4990 | break; |
| 4991 | case NL80211_CMD_DEL_PMKSA: |
| 4992 | rdev_ops = rdev->ops->del_pmksa; |
| 4993 | break; |
| 4994 | default: |
| 4995 | WARN_ON(1); |
| 4996 | break; |
| 4997 | } |
| 4998 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4999 | if (!rdev_ops) |
| 5000 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5001 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5002 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 5006 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5008 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5009 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5010 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5011 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5012 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5013 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5014 | if (!rdev->ops->flush_pmksa) |
| 5015 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5016 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5017 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5018 | } |
| 5019 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5020 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5021 | { |
| 5022 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5023 | struct net_device *dev = info->user_ptr[1]; |
| 5024 | u8 action_code, dialog_token; |
| 5025 | u16 status_code; |
| 5026 | u8 *peer; |
| 5027 | |
| 5028 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5029 | !rdev->ops->tdls_mgmt) |
| 5030 | return -EOPNOTSUPP; |
| 5031 | |
| 5032 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5033 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5034 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5035 | !info->attrs[NL80211_ATTR_IE] || |
| 5036 | !info->attrs[NL80211_ATTR_MAC]) |
| 5037 | return -EINVAL; |
| 5038 | |
| 5039 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5040 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5041 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5042 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5043 | |
| 5044 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5045 | dialog_token, status_code, |
| 5046 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5047 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5048 | } |
| 5049 | |
| 5050 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5051 | { |
| 5052 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5053 | struct net_device *dev = info->user_ptr[1]; |
| 5054 | enum nl80211_tdls_operation operation; |
| 5055 | u8 *peer; |
| 5056 | |
| 5057 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5058 | !rdev->ops->tdls_oper) |
| 5059 | return -EOPNOTSUPP; |
| 5060 | |
| 5061 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5062 | !info->attrs[NL80211_ATTR_MAC]) |
| 5063 | return -EINVAL; |
| 5064 | |
| 5065 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5066 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5067 | |
| 5068 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5069 | } |
| 5070 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5071 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5072 | struct genl_info *info) |
| 5073 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5075 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5076 | struct ieee80211_channel *chan; |
| 5077 | struct sk_buff *msg; |
| 5078 | void *hdr; |
| 5079 | u64 cookie; |
| 5080 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5081 | u32 freq, duration; |
| 5082 | int err; |
| 5083 | |
| 5084 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5085 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5086 | return -EINVAL; |
| 5087 | |
| 5088 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5089 | |
| 5090 | /* |
| 5091 | * We should be on that channel for at least one jiffie, |
| 5092 | * and more than 5 seconds seems excessive. |
| 5093 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5094 | if (!duration || !msecs_to_jiffies(duration) || |
| 5095 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5096 | return -EINVAL; |
| 5097 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5098 | if (!rdev->ops->remain_on_channel) |
| 5099 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5100 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5101 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5102 | channel_type = nla_get_u32( |
| 5103 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5104 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5105 | channel_type != NL80211_CHAN_HT20 && |
| 5106 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5107 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5108 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5112 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5113 | if (chan == NULL) |
| 5114 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5115 | |
| 5116 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5117 | if (!msg) |
| 5118 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5119 | |
| 5120 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5121 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5122 | |
| 5123 | if (IS_ERR(hdr)) { |
| 5124 | err = PTR_ERR(hdr); |
| 5125 | goto free_msg; |
| 5126 | } |
| 5127 | |
| 5128 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5129 | channel_type, duration, &cookie); |
| 5130 | |
| 5131 | if (err) |
| 5132 | goto free_msg; |
| 5133 | |
| 5134 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5135 | |
| 5136 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5137 | |
| 5138 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5139 | |
| 5140 | nla_put_failure: |
| 5141 | err = -ENOBUFS; |
| 5142 | free_msg: |
| 5143 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5144 | return err; |
| 5145 | } |
| 5146 | |
| 5147 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5148 | struct genl_info *info) |
| 5149 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5151 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5152 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5153 | |
| 5154 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5155 | return -EINVAL; |
| 5156 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5157 | if (!rdev->ops->cancel_remain_on_channel) |
| 5158 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5159 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5160 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5161 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5162 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5163 | } |
| 5164 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5165 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5166 | u8 *rates, u8 rates_len) |
| 5167 | { |
| 5168 | u8 i; |
| 5169 | u32 mask = 0; |
| 5170 | |
| 5171 | for (i = 0; i < rates_len; i++) { |
| 5172 | int rate = (rates[i] & 0x7f) * 5; |
| 5173 | int ridx; |
| 5174 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5175 | struct ieee80211_rate *srate = |
| 5176 | &sband->bitrates[ridx]; |
| 5177 | if (rate == srate->bitrate) { |
| 5178 | mask |= 1 << ridx; |
| 5179 | break; |
| 5180 | } |
| 5181 | } |
| 5182 | if (ridx == sband->n_bitrates) |
| 5183 | return 0; /* rate not found */ |
| 5184 | } |
| 5185 | |
| 5186 | return mask; |
| 5187 | } |
| 5188 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5189 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5190 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5191 | .len = NL80211_MAX_SUPP_RATES }, |
| 5192 | }; |
| 5193 | |
| 5194 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5195 | struct genl_info *info) |
| 5196 | { |
| 5197 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5198 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5199 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5200 | int rem, i; |
| 5201 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5202 | struct nlattr *tx_rates; |
| 5203 | struct ieee80211_supported_band *sband; |
| 5204 | |
| 5205 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5206 | return -EINVAL; |
| 5207 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5208 | if (!rdev->ops->set_bitrate_mask) |
| 5209 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5210 | |
| 5211 | memset(&mask, 0, sizeof(mask)); |
| 5212 | /* Default to all rates enabled */ |
| 5213 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5214 | sband = rdev->wiphy.bands[i]; |
| 5215 | mask.control[i].legacy = |
| 5216 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5217 | } |
| 5218 | |
| 5219 | /* |
| 5220 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5221 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5222 | */ |
| 5223 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5224 | { |
| 5225 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5226 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5227 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5228 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5229 | if (sband == NULL) |
| 5230 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5231 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5232 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5233 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5234 | mask.control[band].legacy = rateset_to_mask( |
| 5235 | sband, |
| 5236 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5237 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5238 | if (mask.control[band].legacy == 0) |
| 5239 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5240 | } |
| 5241 | } |
| 5242 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5243 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5244 | } |
| 5245 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5246 | 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] | 5247 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5248 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5249 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5250 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5251 | |
| 5252 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5253 | return -EINVAL; |
| 5254 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5255 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5256 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5257 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5258 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5259 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5260 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5261 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5262 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5263 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5264 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5265 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5266 | |
| 5267 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5268 | if (!rdev->ops->mgmt_tx) |
| 5269 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5270 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5271 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5272 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5273 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5274 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5275 | } |
| 5276 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5277 | 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] | 5278 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5280 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5281 | struct ieee80211_channel *chan; |
| 5282 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5283 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5284 | u32 freq; |
| 5285 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame^] | 5286 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5287 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5288 | struct sk_buff *msg = NULL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5289 | unsigned int wait = 0; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5290 | bool offchan, no_cck, dont_wait_for_ack; |
| 5291 | |
| 5292 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5293 | |
| 5294 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5295 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5296 | return -EINVAL; |
| 5297 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5298 | if (!rdev->ops->mgmt_tx) |
| 5299 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5300 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5301 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5302 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5303 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5304 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5305 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5306 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5307 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5308 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5309 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5310 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5311 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5312 | return -EINVAL; |
| 5313 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5314 | } |
| 5315 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5316 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5317 | channel_type = nla_get_u32( |
| 5318 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5319 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5320 | channel_type != NL80211_CHAN_HT20 && |
| 5321 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5322 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5323 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5324 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5325 | } |
| 5326 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5327 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5328 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5329 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5330 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5331 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5332 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5333 | if (chan == NULL) |
| 5334 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5335 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5336 | if (!dont_wait_for_ack) { |
| 5337 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5338 | if (!msg) |
| 5339 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5340 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5341 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5342 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5343 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5344 | if (IS_ERR(hdr)) { |
| 5345 | err = PTR_ERR(hdr); |
| 5346 | goto free_msg; |
| 5347 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5348 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5349 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5350 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5351 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5352 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5353 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5354 | no_cck, dont_wait_for_ack, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5355 | if (err) |
| 5356 | goto free_msg; |
| 5357 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5358 | if (msg) { |
| 5359 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5360 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 5361 | genlmsg_end(msg, hdr); |
| 5362 | return genlmsg_reply(msg, info); |
| 5363 | } |
| 5364 | |
| 5365 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5366 | |
| 5367 | nla_put_failure: |
| 5368 | err = -ENOBUFS; |
| 5369 | free_msg: |
| 5370 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5371 | return err; |
| 5372 | } |
| 5373 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5374 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5375 | { |
| 5376 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5377 | struct net_device *dev = info->user_ptr[1]; |
| 5378 | u64 cookie; |
| 5379 | |
| 5380 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5381 | return -EINVAL; |
| 5382 | |
| 5383 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5384 | return -EOPNOTSUPP; |
| 5385 | |
| 5386 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5387 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5388 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5389 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5390 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5391 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5392 | return -EOPNOTSUPP; |
| 5393 | |
| 5394 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5395 | |
| 5396 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5397 | } |
| 5398 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5399 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5400 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5402 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5403 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5404 | u8 ps_state; |
| 5405 | bool state; |
| 5406 | int err; |
| 5407 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5408 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5409 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5410 | |
| 5411 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5412 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5413 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5414 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5415 | |
| 5416 | wdev = dev->ieee80211_ptr; |
| 5417 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5418 | if (!rdev->ops->set_power_mgmt) |
| 5419 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5420 | |
| 5421 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5422 | |
| 5423 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5424 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5425 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5426 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5427 | wdev->ps_timeout); |
| 5428 | if (!err) |
| 5429 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5430 | return err; |
| 5431 | } |
| 5432 | |
| 5433 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5434 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5435 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5436 | enum nl80211_ps_state ps_state; |
| 5437 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5438 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5439 | struct sk_buff *msg; |
| 5440 | void *hdr; |
| 5441 | int err; |
| 5442 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5443 | wdev = dev->ieee80211_ptr; |
| 5444 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5445 | if (!rdev->ops->set_power_mgmt) |
| 5446 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5447 | |
| 5448 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5449 | if (!msg) |
| 5450 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5451 | |
| 5452 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5453 | NL80211_CMD_GET_POWER_SAVE); |
| 5454 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5455 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5456 | goto free_msg; |
| 5457 | } |
| 5458 | |
| 5459 | if (wdev->ps) |
| 5460 | ps_state = NL80211_PS_ENABLED; |
| 5461 | else |
| 5462 | ps_state = NL80211_PS_DISABLED; |
| 5463 | |
| 5464 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5465 | |
| 5466 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5467 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5468 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5469 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5470 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5471 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5472 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5473 | return err; |
| 5474 | } |
| 5475 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5476 | static struct nla_policy |
| 5477 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5478 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5479 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5480 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5481 | }; |
| 5482 | |
| 5483 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5484 | s32 threshold, u32 hysteresis) |
| 5485 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5486 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5487 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5488 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5489 | |
| 5490 | if (threshold > 0) |
| 5491 | return -EINVAL; |
| 5492 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5493 | wdev = dev->ieee80211_ptr; |
| 5494 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5495 | if (!rdev->ops->set_cqm_rssi_config) |
| 5496 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5497 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5498 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5499 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5500 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5501 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5502 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5503 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5504 | } |
| 5505 | |
| 5506 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5507 | { |
| 5508 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5509 | struct nlattr *cqm; |
| 5510 | int err; |
| 5511 | |
| 5512 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5513 | if (!cqm) { |
| 5514 | err = -EINVAL; |
| 5515 | goto out; |
| 5516 | } |
| 5517 | |
| 5518 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5519 | nl80211_attr_cqm_policy); |
| 5520 | if (err) |
| 5521 | goto out; |
| 5522 | |
| 5523 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5524 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5525 | s32 threshold; |
| 5526 | u32 hysteresis; |
| 5527 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5528 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5529 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5530 | } else |
| 5531 | err = -EINVAL; |
| 5532 | |
| 5533 | out: |
| 5534 | return err; |
| 5535 | } |
| 5536 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5537 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5538 | { |
| 5539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5540 | struct net_device *dev = info->user_ptr[1]; |
| 5541 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5542 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5543 | int err; |
| 5544 | |
| 5545 | /* start with default */ |
| 5546 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5547 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5548 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5549 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5550 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5551 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5552 | if (err) |
| 5553 | return err; |
| 5554 | } |
| 5555 | |
| 5556 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5557 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5558 | return -EINVAL; |
| 5559 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5560 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5561 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5562 | |
| 5563 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5564 | /* parse additional setup parameters if given */ |
| 5565 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5566 | if (err) |
| 5567 | return err; |
| 5568 | } |
| 5569 | |
| 5570 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5574 | { |
| 5575 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5576 | struct net_device *dev = info->user_ptr[1]; |
| 5577 | |
| 5578 | return cfg80211_leave_mesh(rdev, dev); |
| 5579 | } |
| 5580 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5581 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5582 | { |
| 5583 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5584 | struct sk_buff *msg; |
| 5585 | void *hdr; |
| 5586 | |
| 5587 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5588 | return -EOPNOTSUPP; |
| 5589 | |
| 5590 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5591 | if (!msg) |
| 5592 | return -ENOMEM; |
| 5593 | |
| 5594 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5595 | NL80211_CMD_GET_WOWLAN); |
| 5596 | if (!hdr) |
| 5597 | goto nla_put_failure; |
| 5598 | |
| 5599 | if (rdev->wowlan) { |
| 5600 | struct nlattr *nl_wowlan; |
| 5601 | |
| 5602 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5603 | if (!nl_wowlan) |
| 5604 | goto nla_put_failure; |
| 5605 | |
| 5606 | if (rdev->wowlan->any) |
| 5607 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5608 | if (rdev->wowlan->disconnect) |
| 5609 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5610 | if (rdev->wowlan->magic_pkt) |
| 5611 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5612 | if (rdev->wowlan->gtk_rekey_failure) |
| 5613 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5614 | if (rdev->wowlan->eap_identity_req) |
| 5615 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5616 | if (rdev->wowlan->four_way_handshake) |
| 5617 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5618 | if (rdev->wowlan->rfkill_release) |
| 5619 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5620 | if (rdev->wowlan->n_patterns) { |
| 5621 | struct nlattr *nl_pats, *nl_pat; |
| 5622 | int i, pat_len; |
| 5623 | |
| 5624 | nl_pats = nla_nest_start(msg, |
| 5625 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5626 | if (!nl_pats) |
| 5627 | goto nla_put_failure; |
| 5628 | |
| 5629 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5630 | nl_pat = nla_nest_start(msg, i + 1); |
| 5631 | if (!nl_pat) |
| 5632 | goto nla_put_failure; |
| 5633 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5634 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5635 | DIV_ROUND_UP(pat_len, 8), |
| 5636 | rdev->wowlan->patterns[i].mask); |
| 5637 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5638 | pat_len, |
| 5639 | rdev->wowlan->patterns[i].pattern); |
| 5640 | nla_nest_end(msg, nl_pat); |
| 5641 | } |
| 5642 | nla_nest_end(msg, nl_pats); |
| 5643 | } |
| 5644 | |
| 5645 | nla_nest_end(msg, nl_wowlan); |
| 5646 | } |
| 5647 | |
| 5648 | genlmsg_end(msg, hdr); |
| 5649 | return genlmsg_reply(msg, info); |
| 5650 | |
| 5651 | nla_put_failure: |
| 5652 | nlmsg_free(msg); |
| 5653 | return -ENOBUFS; |
| 5654 | } |
| 5655 | |
| 5656 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5657 | { |
| 5658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5659 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5660 | struct cfg80211_wowlan no_triggers = {}; |
| 5661 | struct cfg80211_wowlan new_triggers = {}; |
| 5662 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5663 | int err, i; |
| 5664 | |
| 5665 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5666 | return -EOPNOTSUPP; |
| 5667 | |
| 5668 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5669 | goto no_triggers; |
| 5670 | |
| 5671 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5672 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5673 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5674 | nl80211_wowlan_policy); |
| 5675 | if (err) |
| 5676 | return err; |
| 5677 | |
| 5678 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5679 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5680 | return -EINVAL; |
| 5681 | new_triggers.any = true; |
| 5682 | } |
| 5683 | |
| 5684 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5685 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5686 | return -EINVAL; |
| 5687 | new_triggers.disconnect = true; |
| 5688 | } |
| 5689 | |
| 5690 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5691 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5692 | return -EINVAL; |
| 5693 | new_triggers.magic_pkt = true; |
| 5694 | } |
| 5695 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5696 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5697 | return -EINVAL; |
| 5698 | |
| 5699 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5700 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5701 | return -EINVAL; |
| 5702 | new_triggers.gtk_rekey_failure = true; |
| 5703 | } |
| 5704 | |
| 5705 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5706 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5707 | return -EINVAL; |
| 5708 | new_triggers.eap_identity_req = true; |
| 5709 | } |
| 5710 | |
| 5711 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5712 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5713 | return -EINVAL; |
| 5714 | new_triggers.four_way_handshake = true; |
| 5715 | } |
| 5716 | |
| 5717 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5718 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5719 | return -EINVAL; |
| 5720 | new_triggers.rfkill_release = true; |
| 5721 | } |
| 5722 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5723 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5724 | struct nlattr *pat; |
| 5725 | int n_patterns = 0; |
| 5726 | int rem, pat_len, mask_len; |
| 5727 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5728 | |
| 5729 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5730 | rem) |
| 5731 | n_patterns++; |
| 5732 | if (n_patterns > wowlan->n_patterns) |
| 5733 | return -EINVAL; |
| 5734 | |
| 5735 | new_triggers.patterns = kcalloc(n_patterns, |
| 5736 | sizeof(new_triggers.patterns[0]), |
| 5737 | GFP_KERNEL); |
| 5738 | if (!new_triggers.patterns) |
| 5739 | return -ENOMEM; |
| 5740 | |
| 5741 | new_triggers.n_patterns = n_patterns; |
| 5742 | i = 0; |
| 5743 | |
| 5744 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5745 | rem) { |
| 5746 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5747 | nla_data(pat), nla_len(pat), NULL); |
| 5748 | err = -EINVAL; |
| 5749 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5750 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5751 | goto error; |
| 5752 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5753 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5754 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5755 | mask_len) |
| 5756 | goto error; |
| 5757 | if (pat_len > wowlan->pattern_max_len || |
| 5758 | pat_len < wowlan->pattern_min_len) |
| 5759 | goto error; |
| 5760 | |
| 5761 | new_triggers.patterns[i].mask = |
| 5762 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5763 | if (!new_triggers.patterns[i].mask) { |
| 5764 | err = -ENOMEM; |
| 5765 | goto error; |
| 5766 | } |
| 5767 | new_triggers.patterns[i].pattern = |
| 5768 | new_triggers.patterns[i].mask + mask_len; |
| 5769 | memcpy(new_triggers.patterns[i].mask, |
| 5770 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5771 | mask_len); |
| 5772 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5773 | memcpy(new_triggers.patterns[i].pattern, |
| 5774 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5775 | pat_len); |
| 5776 | i++; |
| 5777 | } |
| 5778 | } |
| 5779 | |
| 5780 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5781 | struct cfg80211_wowlan *ntrig; |
| 5782 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5783 | GFP_KERNEL); |
| 5784 | if (!ntrig) { |
| 5785 | err = -ENOMEM; |
| 5786 | goto error; |
| 5787 | } |
| 5788 | cfg80211_rdev_free_wowlan(rdev); |
| 5789 | rdev->wowlan = ntrig; |
| 5790 | } else { |
| 5791 | no_triggers: |
| 5792 | cfg80211_rdev_free_wowlan(rdev); |
| 5793 | rdev->wowlan = NULL; |
| 5794 | } |
| 5795 | |
| 5796 | return 0; |
| 5797 | error: |
| 5798 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5799 | kfree(new_triggers.patterns[i].mask); |
| 5800 | kfree(new_triggers.patterns); |
| 5801 | return err; |
| 5802 | } |
| 5803 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5804 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5805 | { |
| 5806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5807 | struct net_device *dev = info->user_ptr[1]; |
| 5808 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5809 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5810 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5811 | int err; |
| 5812 | |
| 5813 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5814 | return -EINVAL; |
| 5815 | |
| 5816 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5817 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5818 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5819 | nl80211_rekey_policy); |
| 5820 | if (err) |
| 5821 | return err; |
| 5822 | |
| 5823 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5824 | return -ERANGE; |
| 5825 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5826 | return -ERANGE; |
| 5827 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5828 | return -ERANGE; |
| 5829 | |
| 5830 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5831 | NL80211_KEK_LEN); |
| 5832 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5833 | NL80211_KCK_LEN); |
| 5834 | memcpy(rekey_data.replay_ctr, |
| 5835 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5836 | NL80211_REPLAY_CTR_LEN); |
| 5837 | |
| 5838 | wdev_lock(wdev); |
| 5839 | if (!wdev->current_bss) { |
| 5840 | err = -ENOTCONN; |
| 5841 | goto out; |
| 5842 | } |
| 5843 | |
| 5844 | if (!rdev->ops->set_rekey_data) { |
| 5845 | err = -EOPNOTSUPP; |
| 5846 | goto out; |
| 5847 | } |
| 5848 | |
| 5849 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5850 | out: |
| 5851 | wdev_unlock(wdev); |
| 5852 | return err; |
| 5853 | } |
| 5854 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 5855 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 5856 | struct genl_info *info) |
| 5857 | { |
| 5858 | struct net_device *dev = info->user_ptr[1]; |
| 5859 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5860 | |
| 5861 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 5862 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 5863 | return -EINVAL; |
| 5864 | |
| 5865 | if (wdev->ap_unexpected_nlpid) |
| 5866 | return -EBUSY; |
| 5867 | |
| 5868 | wdev->ap_unexpected_nlpid = info->snd_pid; |
| 5869 | return 0; |
| 5870 | } |
| 5871 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 5872 | static int nl80211_probe_client(struct sk_buff *skb, |
| 5873 | struct genl_info *info) |
| 5874 | { |
| 5875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5876 | struct net_device *dev = info->user_ptr[1]; |
| 5877 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5878 | struct sk_buff *msg; |
| 5879 | void *hdr; |
| 5880 | const u8 *addr; |
| 5881 | u64 cookie; |
| 5882 | int err; |
| 5883 | |
| 5884 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 5885 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 5886 | return -EOPNOTSUPP; |
| 5887 | |
| 5888 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5889 | return -EINVAL; |
| 5890 | |
| 5891 | if (!rdev->ops->probe_client) |
| 5892 | return -EOPNOTSUPP; |
| 5893 | |
| 5894 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5895 | if (!msg) |
| 5896 | return -ENOMEM; |
| 5897 | |
| 5898 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5899 | NL80211_CMD_PROBE_CLIENT); |
| 5900 | |
| 5901 | if (IS_ERR(hdr)) { |
| 5902 | err = PTR_ERR(hdr); |
| 5903 | goto free_msg; |
| 5904 | } |
| 5905 | |
| 5906 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5907 | |
| 5908 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); |
| 5909 | if (err) |
| 5910 | goto free_msg; |
| 5911 | |
| 5912 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5913 | |
| 5914 | genlmsg_end(msg, hdr); |
| 5915 | |
| 5916 | return genlmsg_reply(msg, info); |
| 5917 | |
| 5918 | nla_put_failure: |
| 5919 | err = -ENOBUFS; |
| 5920 | free_msg: |
| 5921 | nlmsg_free(msg); |
| 5922 | return err; |
| 5923 | } |
| 5924 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 5925 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 5926 | { |
| 5927 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5928 | |
| 5929 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 5930 | return -EOPNOTSUPP; |
| 5931 | |
| 5932 | if (rdev->ap_beacons_nlpid) |
| 5933 | return -EBUSY; |
| 5934 | |
| 5935 | rdev->ap_beacons_nlpid = info->snd_pid; |
| 5936 | |
| 5937 | return 0; |
| 5938 | } |
| 5939 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5940 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5941 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5942 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5943 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5944 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5945 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5946 | |
| 5947 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5948 | struct genl_info *info) |
| 5949 | { |
| 5950 | struct cfg80211_registered_device *rdev; |
| 5951 | struct net_device *dev; |
| 5952 | int err; |
| 5953 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5954 | |
| 5955 | if (rtnl) |
| 5956 | rtnl_lock(); |
| 5957 | |
| 5958 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5959 | rdev = cfg80211_get_dev_from_info(info); |
| 5960 | if (IS_ERR(rdev)) { |
| 5961 | if (rtnl) |
| 5962 | rtnl_unlock(); |
| 5963 | return PTR_ERR(rdev); |
| 5964 | } |
| 5965 | info->user_ptr[0] = rdev; |
| 5966 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5967 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5968 | if (err) { |
| 5969 | if (rtnl) |
| 5970 | rtnl_unlock(); |
| 5971 | return err; |
| 5972 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5973 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5974 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5975 | cfg80211_unlock_rdev(rdev); |
| 5976 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5977 | if (rtnl) |
| 5978 | rtnl_unlock(); |
| 5979 | return -ENETDOWN; |
| 5980 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5981 | info->user_ptr[0] = rdev; |
| 5982 | info->user_ptr[1] = dev; |
| 5983 | } |
| 5984 | |
| 5985 | return 0; |
| 5986 | } |
| 5987 | |
| 5988 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5989 | struct genl_info *info) |
| 5990 | { |
| 5991 | if (info->user_ptr[0]) |
| 5992 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5993 | if (info->user_ptr[1]) |
| 5994 | dev_put(info->user_ptr[1]); |
| 5995 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5996 | rtnl_unlock(); |
| 5997 | } |
| 5998 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5999 | static struct genl_ops nl80211_ops[] = { |
| 6000 | { |
| 6001 | .cmd = NL80211_CMD_GET_WIPHY, |
| 6002 | .doit = nl80211_get_wiphy, |
| 6003 | .dumpit = nl80211_dump_wiphy, |
| 6004 | .policy = nl80211_policy, |
| 6005 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6006 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6007 | }, |
| 6008 | { |
| 6009 | .cmd = NL80211_CMD_SET_WIPHY, |
| 6010 | .doit = nl80211_set_wiphy, |
| 6011 | .policy = nl80211_policy, |
| 6012 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6013 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6014 | }, |
| 6015 | { |
| 6016 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 6017 | .doit = nl80211_get_interface, |
| 6018 | .dumpit = nl80211_dump_interface, |
| 6019 | .policy = nl80211_policy, |
| 6020 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6021 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6022 | }, |
| 6023 | { |
| 6024 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 6025 | .doit = nl80211_set_interface, |
| 6026 | .policy = nl80211_policy, |
| 6027 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6028 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6029 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6030 | }, |
| 6031 | { |
| 6032 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 6033 | .doit = nl80211_new_interface, |
| 6034 | .policy = nl80211_policy, |
| 6035 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6036 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6037 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6038 | }, |
| 6039 | { |
| 6040 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 6041 | .doit = nl80211_del_interface, |
| 6042 | .policy = nl80211_policy, |
| 6043 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6044 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6045 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6046 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6047 | { |
| 6048 | .cmd = NL80211_CMD_GET_KEY, |
| 6049 | .doit = nl80211_get_key, |
| 6050 | .policy = nl80211_policy, |
| 6051 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6052 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6053 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6054 | }, |
| 6055 | { |
| 6056 | .cmd = NL80211_CMD_SET_KEY, |
| 6057 | .doit = nl80211_set_key, |
| 6058 | .policy = nl80211_policy, |
| 6059 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6060 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6061 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6062 | }, |
| 6063 | { |
| 6064 | .cmd = NL80211_CMD_NEW_KEY, |
| 6065 | .doit = nl80211_new_key, |
| 6066 | .policy = nl80211_policy, |
| 6067 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6068 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6069 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6070 | }, |
| 6071 | { |
| 6072 | .cmd = NL80211_CMD_DEL_KEY, |
| 6073 | .doit = nl80211_del_key, |
| 6074 | .policy = nl80211_policy, |
| 6075 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6076 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6077 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 6078 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6079 | { |
| 6080 | .cmd = NL80211_CMD_SET_BEACON, |
| 6081 | .policy = nl80211_policy, |
| 6082 | .flags = GENL_ADMIN_PERM, |
| 6083 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6084 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6085 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6086 | }, |
| 6087 | { |
| 6088 | .cmd = NL80211_CMD_NEW_BEACON, |
| 6089 | .policy = nl80211_policy, |
| 6090 | .flags = GENL_ADMIN_PERM, |
| 6091 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6092 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6093 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6094 | }, |
| 6095 | { |
| 6096 | .cmd = NL80211_CMD_DEL_BEACON, |
| 6097 | .policy = nl80211_policy, |
| 6098 | .flags = GENL_ADMIN_PERM, |
| 6099 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6100 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6101 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 6102 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6103 | { |
| 6104 | .cmd = NL80211_CMD_GET_STATION, |
| 6105 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6106 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6107 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6108 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6109 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6110 | }, |
| 6111 | { |
| 6112 | .cmd = NL80211_CMD_SET_STATION, |
| 6113 | .doit = nl80211_set_station, |
| 6114 | .policy = nl80211_policy, |
| 6115 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6116 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6117 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6118 | }, |
| 6119 | { |
| 6120 | .cmd = NL80211_CMD_NEW_STATION, |
| 6121 | .doit = nl80211_new_station, |
| 6122 | .policy = nl80211_policy, |
| 6123 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6124 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6125 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6126 | }, |
| 6127 | { |
| 6128 | .cmd = NL80211_CMD_DEL_STATION, |
| 6129 | .doit = nl80211_del_station, |
| 6130 | .policy = nl80211_policy, |
| 6131 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6132 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6133 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6134 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6135 | { |
| 6136 | .cmd = NL80211_CMD_GET_MPATH, |
| 6137 | .doit = nl80211_get_mpath, |
| 6138 | .dumpit = nl80211_dump_mpath, |
| 6139 | .policy = nl80211_policy, |
| 6140 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6141 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6142 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6143 | }, |
| 6144 | { |
| 6145 | .cmd = NL80211_CMD_SET_MPATH, |
| 6146 | .doit = nl80211_set_mpath, |
| 6147 | .policy = nl80211_policy, |
| 6148 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6149 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6150 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6151 | }, |
| 6152 | { |
| 6153 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6154 | .doit = nl80211_new_mpath, |
| 6155 | .policy = nl80211_policy, |
| 6156 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6157 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6158 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6159 | }, |
| 6160 | { |
| 6161 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6162 | .doit = nl80211_del_mpath, |
| 6163 | .policy = nl80211_policy, |
| 6164 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6165 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6166 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6167 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6168 | { |
| 6169 | .cmd = NL80211_CMD_SET_BSS, |
| 6170 | .doit = nl80211_set_bss, |
| 6171 | .policy = nl80211_policy, |
| 6172 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6173 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6174 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6175 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6176 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6177 | .cmd = NL80211_CMD_GET_REG, |
| 6178 | .doit = nl80211_get_reg, |
| 6179 | .policy = nl80211_policy, |
| 6180 | /* can be retrieved by unprivileged users */ |
| 6181 | }, |
| 6182 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6183 | .cmd = NL80211_CMD_SET_REG, |
| 6184 | .doit = nl80211_set_reg, |
| 6185 | .policy = nl80211_policy, |
| 6186 | .flags = GENL_ADMIN_PERM, |
| 6187 | }, |
| 6188 | { |
| 6189 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6190 | .doit = nl80211_req_set_reg, |
| 6191 | .policy = nl80211_policy, |
| 6192 | .flags = GENL_ADMIN_PERM, |
| 6193 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6194 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6195 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6196 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6197 | .policy = nl80211_policy, |
| 6198 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6199 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6200 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6201 | }, |
| 6202 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6203 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6204 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6205 | .policy = nl80211_policy, |
| 6206 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6207 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6208 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6209 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6210 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6211 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6212 | .doit = nl80211_trigger_scan, |
| 6213 | .policy = nl80211_policy, |
| 6214 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6215 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6216 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6217 | }, |
| 6218 | { |
| 6219 | .cmd = NL80211_CMD_GET_SCAN, |
| 6220 | .policy = nl80211_policy, |
| 6221 | .dumpit = nl80211_dump_scan, |
| 6222 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6223 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6224 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6225 | .doit = nl80211_start_sched_scan, |
| 6226 | .policy = nl80211_policy, |
| 6227 | .flags = GENL_ADMIN_PERM, |
| 6228 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6229 | NL80211_FLAG_NEED_RTNL, |
| 6230 | }, |
| 6231 | { |
| 6232 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6233 | .doit = nl80211_stop_sched_scan, |
| 6234 | .policy = nl80211_policy, |
| 6235 | .flags = GENL_ADMIN_PERM, |
| 6236 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6237 | NL80211_FLAG_NEED_RTNL, |
| 6238 | }, |
| 6239 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6240 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6241 | .doit = nl80211_authenticate, |
| 6242 | .policy = nl80211_policy, |
| 6243 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6244 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6245 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6246 | }, |
| 6247 | { |
| 6248 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6249 | .doit = nl80211_associate, |
| 6250 | .policy = nl80211_policy, |
| 6251 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6252 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6253 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6254 | }, |
| 6255 | { |
| 6256 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6257 | .doit = nl80211_deauthenticate, |
| 6258 | .policy = nl80211_policy, |
| 6259 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6260 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6261 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6262 | }, |
| 6263 | { |
| 6264 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6265 | .doit = nl80211_disassociate, |
| 6266 | .policy = nl80211_policy, |
| 6267 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6268 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6269 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6270 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6271 | { |
| 6272 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6273 | .doit = nl80211_join_ibss, |
| 6274 | .policy = nl80211_policy, |
| 6275 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6276 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6277 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6278 | }, |
| 6279 | { |
| 6280 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6281 | .doit = nl80211_leave_ibss, |
| 6282 | .policy = nl80211_policy, |
| 6283 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6284 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6285 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6286 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6287 | #ifdef CONFIG_NL80211_TESTMODE |
| 6288 | { |
| 6289 | .cmd = NL80211_CMD_TESTMODE, |
| 6290 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6291 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6292 | .policy = nl80211_policy, |
| 6293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6294 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6295 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6296 | }, |
| 6297 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6298 | { |
| 6299 | .cmd = NL80211_CMD_CONNECT, |
| 6300 | .doit = nl80211_connect, |
| 6301 | .policy = nl80211_policy, |
| 6302 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6303 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6304 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6305 | }, |
| 6306 | { |
| 6307 | .cmd = NL80211_CMD_DISCONNECT, |
| 6308 | .doit = nl80211_disconnect, |
| 6309 | .policy = nl80211_policy, |
| 6310 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6311 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6312 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6313 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6314 | { |
| 6315 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6316 | .doit = nl80211_wiphy_netns, |
| 6317 | .policy = nl80211_policy, |
| 6318 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6319 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6320 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6321 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6322 | { |
| 6323 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6324 | .policy = nl80211_policy, |
| 6325 | .dumpit = nl80211_dump_survey, |
| 6326 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6327 | { |
| 6328 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6329 | .doit = nl80211_setdel_pmksa, |
| 6330 | .policy = nl80211_policy, |
| 6331 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6332 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6333 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6334 | }, |
| 6335 | { |
| 6336 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6337 | .doit = nl80211_setdel_pmksa, |
| 6338 | .policy = nl80211_policy, |
| 6339 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6340 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6341 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6342 | }, |
| 6343 | { |
| 6344 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6345 | .doit = nl80211_flush_pmksa, |
| 6346 | .policy = nl80211_policy, |
| 6347 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6348 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6349 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6350 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6351 | { |
| 6352 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6353 | .doit = nl80211_remain_on_channel, |
| 6354 | .policy = nl80211_policy, |
| 6355 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6356 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6357 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6358 | }, |
| 6359 | { |
| 6360 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6361 | .doit = nl80211_cancel_remain_on_channel, |
| 6362 | .policy = nl80211_policy, |
| 6363 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6364 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6365 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6366 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6367 | { |
| 6368 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6369 | .doit = nl80211_set_tx_bitrate_mask, |
| 6370 | .policy = nl80211_policy, |
| 6371 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6372 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6373 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6374 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6375 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6376 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6377 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6378 | .policy = nl80211_policy, |
| 6379 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6380 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6381 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6382 | }, |
| 6383 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6384 | .cmd = NL80211_CMD_FRAME, |
| 6385 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6386 | .policy = nl80211_policy, |
| 6387 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6388 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6389 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6390 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6391 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6392 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6393 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6394 | .policy = nl80211_policy, |
| 6395 | .flags = GENL_ADMIN_PERM, |
| 6396 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6397 | NL80211_FLAG_NEED_RTNL, |
| 6398 | }, |
| 6399 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6400 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6401 | .doit = nl80211_set_power_save, |
| 6402 | .policy = nl80211_policy, |
| 6403 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6404 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6405 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6406 | }, |
| 6407 | { |
| 6408 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6409 | .doit = nl80211_get_power_save, |
| 6410 | .policy = nl80211_policy, |
| 6411 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6412 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6413 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6414 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6415 | { |
| 6416 | .cmd = NL80211_CMD_SET_CQM, |
| 6417 | .doit = nl80211_set_cqm, |
| 6418 | .policy = nl80211_policy, |
| 6419 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6420 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6421 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6422 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6423 | { |
| 6424 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6425 | .doit = nl80211_set_channel, |
| 6426 | .policy = nl80211_policy, |
| 6427 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6428 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6429 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6430 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6431 | { |
| 6432 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6433 | .doit = nl80211_set_wds_peer, |
| 6434 | .policy = nl80211_policy, |
| 6435 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6436 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6437 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6438 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6439 | { |
| 6440 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6441 | .doit = nl80211_join_mesh, |
| 6442 | .policy = nl80211_policy, |
| 6443 | .flags = GENL_ADMIN_PERM, |
| 6444 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6445 | NL80211_FLAG_NEED_RTNL, |
| 6446 | }, |
| 6447 | { |
| 6448 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6449 | .doit = nl80211_leave_mesh, |
| 6450 | .policy = nl80211_policy, |
| 6451 | .flags = GENL_ADMIN_PERM, |
| 6452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6453 | NL80211_FLAG_NEED_RTNL, |
| 6454 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6455 | { |
| 6456 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6457 | .doit = nl80211_get_wowlan, |
| 6458 | .policy = nl80211_policy, |
| 6459 | /* can be retrieved by unprivileged users */ |
| 6460 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6461 | NL80211_FLAG_NEED_RTNL, |
| 6462 | }, |
| 6463 | { |
| 6464 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6465 | .doit = nl80211_set_wowlan, |
| 6466 | .policy = nl80211_policy, |
| 6467 | .flags = GENL_ADMIN_PERM, |
| 6468 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6469 | NL80211_FLAG_NEED_RTNL, |
| 6470 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6471 | { |
| 6472 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6473 | .doit = nl80211_set_rekey_data, |
| 6474 | .policy = nl80211_policy, |
| 6475 | .flags = GENL_ADMIN_PERM, |
| 6476 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6477 | NL80211_FLAG_NEED_RTNL, |
| 6478 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6479 | { |
| 6480 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 6481 | .doit = nl80211_tdls_mgmt, |
| 6482 | .policy = nl80211_policy, |
| 6483 | .flags = GENL_ADMIN_PERM, |
| 6484 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6485 | NL80211_FLAG_NEED_RTNL, |
| 6486 | }, |
| 6487 | { |
| 6488 | .cmd = NL80211_CMD_TDLS_OPER, |
| 6489 | .doit = nl80211_tdls_oper, |
| 6490 | .policy = nl80211_policy, |
| 6491 | .flags = GENL_ADMIN_PERM, |
| 6492 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6493 | NL80211_FLAG_NEED_RTNL, |
| 6494 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 6495 | { |
| 6496 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 6497 | .doit = nl80211_register_unexpected_frame, |
| 6498 | .policy = nl80211_policy, |
| 6499 | .flags = GENL_ADMIN_PERM, |
| 6500 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6501 | NL80211_FLAG_NEED_RTNL, |
| 6502 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 6503 | { |
| 6504 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 6505 | .doit = nl80211_probe_client, |
| 6506 | .policy = nl80211_policy, |
| 6507 | .flags = GENL_ADMIN_PERM, |
| 6508 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6509 | NL80211_FLAG_NEED_RTNL, |
| 6510 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 6511 | { |
| 6512 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 6513 | .doit = nl80211_register_beacons, |
| 6514 | .policy = nl80211_policy, |
| 6515 | .flags = GENL_ADMIN_PERM, |
| 6516 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6517 | NL80211_FLAG_NEED_RTNL, |
| 6518 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6519 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6520 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6521 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6522 | .name = "mlme", |
| 6523 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6524 | |
| 6525 | /* multicast groups */ |
| 6526 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6527 | .name = "config", |
| 6528 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6529 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6530 | .name = "scan", |
| 6531 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6532 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6533 | .name = "regulatory", |
| 6534 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6535 | |
| 6536 | /* notification functions */ |
| 6537 | |
| 6538 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6539 | { |
| 6540 | struct sk_buff *msg; |
| 6541 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6542 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6543 | if (!msg) |
| 6544 | return; |
| 6545 | |
| 6546 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6547 | nlmsg_free(msg); |
| 6548 | return; |
| 6549 | } |
| 6550 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6551 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6552 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6553 | } |
| 6554 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6555 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6556 | struct cfg80211_registered_device *rdev) |
| 6557 | { |
| 6558 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6559 | struct nlattr *nest; |
| 6560 | int i; |
| 6561 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6562 | ASSERT_RDEV_LOCK(rdev); |
| 6563 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6564 | if (WARN_ON(!req)) |
| 6565 | return 0; |
| 6566 | |
| 6567 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6568 | if (!nest) |
| 6569 | goto nla_put_failure; |
| 6570 | for (i = 0; i < req->n_ssids; i++) |
| 6571 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6572 | nla_nest_end(msg, nest); |
| 6573 | |
| 6574 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6575 | if (!nest) |
| 6576 | goto nla_put_failure; |
| 6577 | for (i = 0; i < req->n_channels; i++) |
| 6578 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6579 | nla_nest_end(msg, nest); |
| 6580 | |
| 6581 | if (req->ie) |
| 6582 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6583 | |
| 6584 | return 0; |
| 6585 | nla_put_failure: |
| 6586 | return -ENOBUFS; |
| 6587 | } |
| 6588 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6589 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6590 | struct cfg80211_registered_device *rdev, |
| 6591 | struct net_device *netdev, |
| 6592 | u32 pid, u32 seq, int flags, |
| 6593 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6594 | { |
| 6595 | void *hdr; |
| 6596 | |
| 6597 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6598 | if (!hdr) |
| 6599 | return -1; |
| 6600 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6601 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6602 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6603 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6604 | /* ignore errors and send incomplete event anyway */ |
| 6605 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6606 | |
| 6607 | return genlmsg_end(msg, hdr); |
| 6608 | |
| 6609 | nla_put_failure: |
| 6610 | genlmsg_cancel(msg, hdr); |
| 6611 | return -EMSGSIZE; |
| 6612 | } |
| 6613 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6614 | static int |
| 6615 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6616 | struct cfg80211_registered_device *rdev, |
| 6617 | struct net_device *netdev, |
| 6618 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6619 | { |
| 6620 | void *hdr; |
| 6621 | |
| 6622 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6623 | if (!hdr) |
| 6624 | return -1; |
| 6625 | |
| 6626 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6627 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6628 | |
| 6629 | return genlmsg_end(msg, hdr); |
| 6630 | |
| 6631 | nla_put_failure: |
| 6632 | genlmsg_cancel(msg, hdr); |
| 6633 | return -EMSGSIZE; |
| 6634 | } |
| 6635 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6636 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6637 | struct net_device *netdev) |
| 6638 | { |
| 6639 | struct sk_buff *msg; |
| 6640 | |
| 6641 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6642 | if (!msg) |
| 6643 | return; |
| 6644 | |
| 6645 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6646 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6647 | nlmsg_free(msg); |
| 6648 | return; |
| 6649 | } |
| 6650 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6651 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6652 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6653 | } |
| 6654 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6655 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6656 | struct net_device *netdev) |
| 6657 | { |
| 6658 | struct sk_buff *msg; |
| 6659 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6660 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6661 | if (!msg) |
| 6662 | return; |
| 6663 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6664 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6665 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6666 | nlmsg_free(msg); |
| 6667 | return; |
| 6668 | } |
| 6669 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6670 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6671 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6675 | struct net_device *netdev) |
| 6676 | { |
| 6677 | struct sk_buff *msg; |
| 6678 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6680 | if (!msg) |
| 6681 | return; |
| 6682 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6683 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6684 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6685 | nlmsg_free(msg); |
| 6686 | return; |
| 6687 | } |
| 6688 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6689 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6690 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6691 | } |
| 6692 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6693 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6694 | struct net_device *netdev) |
| 6695 | { |
| 6696 | struct sk_buff *msg; |
| 6697 | |
| 6698 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6699 | if (!msg) |
| 6700 | return; |
| 6701 | |
| 6702 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6703 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6704 | nlmsg_free(msg); |
| 6705 | return; |
| 6706 | } |
| 6707 | |
| 6708 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6709 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6710 | } |
| 6711 | |
| 6712 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6713 | struct net_device *netdev, u32 cmd) |
| 6714 | { |
| 6715 | struct sk_buff *msg; |
| 6716 | |
| 6717 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6718 | if (!msg) |
| 6719 | return; |
| 6720 | |
| 6721 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6722 | nlmsg_free(msg); |
| 6723 | return; |
| 6724 | } |
| 6725 | |
| 6726 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6727 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6728 | } |
| 6729 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6730 | /* |
| 6731 | * This can happen on global regulatory changes or device specific settings |
| 6732 | * based on custom world regulatory domains. |
| 6733 | */ |
| 6734 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6735 | { |
| 6736 | struct sk_buff *msg; |
| 6737 | void *hdr; |
| 6738 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6739 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6740 | if (!msg) |
| 6741 | return; |
| 6742 | |
| 6743 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6744 | if (!hdr) { |
| 6745 | nlmsg_free(msg); |
| 6746 | return; |
| 6747 | } |
| 6748 | |
| 6749 | /* Userspace can always count this one always being set */ |
| 6750 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6751 | |
| 6752 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6753 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6754 | NL80211_REGDOM_TYPE_WORLD); |
| 6755 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6756 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6757 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6758 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6759 | request->intersect) |
| 6760 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6761 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6762 | else { |
| 6763 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6764 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6765 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6766 | } |
| 6767 | |
| 6768 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6769 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6770 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6771 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6772 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6773 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6774 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6775 | GFP_ATOMIC); |
| 6776 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6777 | |
| 6778 | return; |
| 6779 | |
| 6780 | nla_put_failure: |
| 6781 | genlmsg_cancel(msg, hdr); |
| 6782 | nlmsg_free(msg); |
| 6783 | } |
| 6784 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6785 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6786 | struct net_device *netdev, |
| 6787 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6788 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6789 | { |
| 6790 | struct sk_buff *msg; |
| 6791 | void *hdr; |
| 6792 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6793 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6794 | if (!msg) |
| 6795 | return; |
| 6796 | |
| 6797 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6798 | if (!hdr) { |
| 6799 | nlmsg_free(msg); |
| 6800 | return; |
| 6801 | } |
| 6802 | |
| 6803 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6804 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6805 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6806 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6807 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6808 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6809 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6810 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6811 | return; |
| 6812 | |
| 6813 | nla_put_failure: |
| 6814 | genlmsg_cancel(msg, hdr); |
| 6815 | nlmsg_free(msg); |
| 6816 | } |
| 6817 | |
| 6818 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6819 | struct net_device *netdev, const u8 *buf, |
| 6820 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6821 | { |
| 6822 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6823 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6827 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6828 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6829 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6830 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6831 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6832 | } |
| 6833 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6834 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6835 | struct net_device *netdev, const u8 *buf, |
| 6836 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6837 | { |
| 6838 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6839 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6840 | } |
| 6841 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6842 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6843 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6844 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6845 | { |
| 6846 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6847 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6848 | } |
| 6849 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6850 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6851 | struct net_device *netdev, const u8 *buf, |
| 6852 | size_t len, gfp_t gfp) |
| 6853 | { |
| 6854 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6855 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6856 | } |
| 6857 | |
| 6858 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6859 | struct net_device *netdev, const u8 *buf, |
| 6860 | size_t len, gfp_t gfp) |
| 6861 | { |
| 6862 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6863 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6864 | } |
| 6865 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6866 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6867 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6868 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6869 | { |
| 6870 | struct sk_buff *msg; |
| 6871 | void *hdr; |
| 6872 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6873 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6874 | if (!msg) |
| 6875 | return; |
| 6876 | |
| 6877 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6878 | if (!hdr) { |
| 6879 | nlmsg_free(msg); |
| 6880 | return; |
| 6881 | } |
| 6882 | |
| 6883 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6884 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6885 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6886 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6887 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6888 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6889 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6890 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6891 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6892 | return; |
| 6893 | |
| 6894 | nla_put_failure: |
| 6895 | genlmsg_cancel(msg, hdr); |
| 6896 | nlmsg_free(msg); |
| 6897 | } |
| 6898 | |
| 6899 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6900 | struct net_device *netdev, const u8 *addr, |
| 6901 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6902 | { |
| 6903 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6904 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6905 | } |
| 6906 | |
| 6907 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6908 | struct net_device *netdev, const u8 *addr, |
| 6909 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6910 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6911 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6912 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6913 | } |
| 6914 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6915 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6916 | struct net_device *netdev, const u8 *bssid, |
| 6917 | const u8 *req_ie, size_t req_ie_len, |
| 6918 | const u8 *resp_ie, size_t resp_ie_len, |
| 6919 | u16 status, gfp_t gfp) |
| 6920 | { |
| 6921 | struct sk_buff *msg; |
| 6922 | void *hdr; |
| 6923 | |
| 6924 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6925 | if (!msg) |
| 6926 | return; |
| 6927 | |
| 6928 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6929 | if (!hdr) { |
| 6930 | nlmsg_free(msg); |
| 6931 | return; |
| 6932 | } |
| 6933 | |
| 6934 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6935 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6936 | if (bssid) |
| 6937 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6938 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6939 | if (req_ie) |
| 6940 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6941 | if (resp_ie) |
| 6942 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6943 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6944 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6945 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6946 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6947 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6948 | return; |
| 6949 | |
| 6950 | nla_put_failure: |
| 6951 | genlmsg_cancel(msg, hdr); |
| 6952 | nlmsg_free(msg); |
| 6953 | |
| 6954 | } |
| 6955 | |
| 6956 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6957 | struct net_device *netdev, const u8 *bssid, |
| 6958 | const u8 *req_ie, size_t req_ie_len, |
| 6959 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6960 | { |
| 6961 | struct sk_buff *msg; |
| 6962 | void *hdr; |
| 6963 | |
| 6964 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6965 | if (!msg) |
| 6966 | return; |
| 6967 | |
| 6968 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6969 | if (!hdr) { |
| 6970 | nlmsg_free(msg); |
| 6971 | return; |
| 6972 | } |
| 6973 | |
| 6974 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6975 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6976 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6977 | if (req_ie) |
| 6978 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6979 | if (resp_ie) |
| 6980 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6981 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 6982 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6983 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6984 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6985 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6986 | return; |
| 6987 | |
| 6988 | nla_put_failure: |
| 6989 | genlmsg_cancel(msg, hdr); |
| 6990 | nlmsg_free(msg); |
| 6991 | |
| 6992 | } |
| 6993 | |
| 6994 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6995 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6996 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6997 | { |
| 6998 | struct sk_buff *msg; |
| 6999 | void *hdr; |
| 7000 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 7001 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7002 | if (!msg) |
| 7003 | return; |
| 7004 | |
| 7005 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 7006 | if (!hdr) { |
| 7007 | nlmsg_free(msg); |
| 7008 | return; |
| 7009 | } |
| 7010 | |
| 7011 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7012 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7013 | if (from_ap && reason) |
| 7014 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 7015 | if (from_ap) |
| 7016 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 7017 | if (ie) |
| 7018 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 7019 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7020 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7021 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7022 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7023 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7024 | return; |
| 7025 | |
| 7026 | nla_put_failure: |
| 7027 | genlmsg_cancel(msg, hdr); |
| 7028 | nlmsg_free(msg); |
| 7029 | |
| 7030 | } |
| 7031 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7032 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 7033 | struct net_device *netdev, const u8 *bssid, |
| 7034 | gfp_t gfp) |
| 7035 | { |
| 7036 | struct sk_buff *msg; |
| 7037 | void *hdr; |
| 7038 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7039 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7040 | if (!msg) |
| 7041 | return; |
| 7042 | |
| 7043 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 7044 | if (!hdr) { |
| 7045 | nlmsg_free(msg); |
| 7046 | return; |
| 7047 | } |
| 7048 | |
| 7049 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7050 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7051 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7052 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7053 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7054 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7055 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7056 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7057 | return; |
| 7058 | |
| 7059 | nla_put_failure: |
| 7060 | genlmsg_cancel(msg, hdr); |
| 7061 | nlmsg_free(msg); |
| 7062 | } |
| 7063 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7064 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 7065 | struct net_device *netdev, |
| 7066 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 7067 | gfp_t gfp) |
| 7068 | { |
| 7069 | struct sk_buff *msg; |
| 7070 | void *hdr; |
| 7071 | |
| 7072 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7073 | if (!msg) |
| 7074 | return; |
| 7075 | |
| 7076 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 7077 | if (!hdr) { |
| 7078 | nlmsg_free(msg); |
| 7079 | return; |
| 7080 | } |
| 7081 | |
| 7082 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7083 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7084 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 7085 | if (ie_len && ie) |
| 7086 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 7087 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7088 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 7089 | |
| 7090 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7091 | nl80211_mlme_mcgrp.id, gfp); |
| 7092 | return; |
| 7093 | |
| 7094 | nla_put_failure: |
| 7095 | genlmsg_cancel(msg, hdr); |
| 7096 | nlmsg_free(msg); |
| 7097 | } |
| 7098 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7099 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 7100 | struct net_device *netdev, const u8 *addr, |
| 7101 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7102 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7103 | { |
| 7104 | struct sk_buff *msg; |
| 7105 | void *hdr; |
| 7106 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 7107 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7108 | if (!msg) |
| 7109 | return; |
| 7110 | |
| 7111 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7112 | if (!hdr) { |
| 7113 | nlmsg_free(msg); |
| 7114 | return; |
| 7115 | } |
| 7116 | |
| 7117 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7118 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7119 | if (addr) |
| 7120 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7121 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 7122 | if (key_id != -1) |
| 7123 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7124 | if (tsc) |
| 7125 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 7126 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7127 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7128 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7129 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7130 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7131 | return; |
| 7132 | |
| 7133 | nla_put_failure: |
| 7134 | genlmsg_cancel(msg, hdr); |
| 7135 | nlmsg_free(msg); |
| 7136 | } |
| 7137 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7138 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7139 | struct ieee80211_channel *channel_before, |
| 7140 | struct ieee80211_channel *channel_after) |
| 7141 | { |
| 7142 | struct sk_buff *msg; |
| 7143 | void *hdr; |
| 7144 | struct nlattr *nl_freq; |
| 7145 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7147 | if (!msg) |
| 7148 | return; |
| 7149 | |
| 7150 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7151 | if (!hdr) { |
| 7152 | nlmsg_free(msg); |
| 7153 | return; |
| 7154 | } |
| 7155 | |
| 7156 | /* |
| 7157 | * Since we are applying the beacon hint to a wiphy we know its |
| 7158 | * wiphy_idx is valid |
| 7159 | */ |
| 7160 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 7161 | |
| 7162 | /* Before */ |
| 7163 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7164 | if (!nl_freq) |
| 7165 | goto nla_put_failure; |
| 7166 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7167 | goto nla_put_failure; |
| 7168 | nla_nest_end(msg, nl_freq); |
| 7169 | |
| 7170 | /* After */ |
| 7171 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7172 | if (!nl_freq) |
| 7173 | goto nla_put_failure; |
| 7174 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7175 | goto nla_put_failure; |
| 7176 | nla_nest_end(msg, nl_freq); |
| 7177 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7178 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7179 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7180 | rcu_read_lock(); |
| 7181 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7182 | GFP_ATOMIC); |
| 7183 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7184 | |
| 7185 | return; |
| 7186 | |
| 7187 | nla_put_failure: |
| 7188 | genlmsg_cancel(msg, hdr); |
| 7189 | nlmsg_free(msg); |
| 7190 | } |
| 7191 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7192 | static void nl80211_send_remain_on_chan_event( |
| 7193 | int cmd, struct cfg80211_registered_device *rdev, |
| 7194 | struct net_device *netdev, u64 cookie, |
| 7195 | struct ieee80211_channel *chan, |
| 7196 | enum nl80211_channel_type channel_type, |
| 7197 | unsigned int duration, gfp_t gfp) |
| 7198 | { |
| 7199 | struct sk_buff *msg; |
| 7200 | void *hdr; |
| 7201 | |
| 7202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7203 | if (!msg) |
| 7204 | return; |
| 7205 | |
| 7206 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7207 | if (!hdr) { |
| 7208 | nlmsg_free(msg); |
| 7209 | return; |
| 7210 | } |
| 7211 | |
| 7212 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7213 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7214 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7215 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7216 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7217 | |
| 7218 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7219 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7220 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7221 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7222 | |
| 7223 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7224 | nl80211_mlme_mcgrp.id, gfp); |
| 7225 | return; |
| 7226 | |
| 7227 | nla_put_failure: |
| 7228 | genlmsg_cancel(msg, hdr); |
| 7229 | nlmsg_free(msg); |
| 7230 | } |
| 7231 | |
| 7232 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7233 | struct net_device *netdev, u64 cookie, |
| 7234 | struct ieee80211_channel *chan, |
| 7235 | enum nl80211_channel_type channel_type, |
| 7236 | unsigned int duration, gfp_t gfp) |
| 7237 | { |
| 7238 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7239 | rdev, netdev, cookie, chan, |
| 7240 | channel_type, duration, gfp); |
| 7241 | } |
| 7242 | |
| 7243 | void nl80211_send_remain_on_channel_cancel( |
| 7244 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7245 | u64 cookie, struct ieee80211_channel *chan, |
| 7246 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7247 | { |
| 7248 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7249 | rdev, netdev, cookie, chan, |
| 7250 | channel_type, 0, gfp); |
| 7251 | } |
| 7252 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7253 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7254 | struct net_device *dev, const u8 *mac_addr, |
| 7255 | struct station_info *sinfo, gfp_t gfp) |
| 7256 | { |
| 7257 | struct sk_buff *msg; |
| 7258 | |
| 7259 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7260 | if (!msg) |
| 7261 | return; |
| 7262 | |
| 7263 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 7264 | nlmsg_free(msg); |
| 7265 | return; |
| 7266 | } |
| 7267 | |
| 7268 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7269 | nl80211_mlme_mcgrp.id, gfp); |
| 7270 | } |
| 7271 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7272 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7273 | struct net_device *dev, const u8 *mac_addr, |
| 7274 | gfp_t gfp) |
| 7275 | { |
| 7276 | struct sk_buff *msg; |
| 7277 | void *hdr; |
| 7278 | |
| 7279 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7280 | if (!msg) |
| 7281 | return; |
| 7282 | |
| 7283 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7284 | if (!hdr) { |
| 7285 | nlmsg_free(msg); |
| 7286 | return; |
| 7287 | } |
| 7288 | |
| 7289 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7290 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7291 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7292 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7293 | |
| 7294 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7295 | nl80211_mlme_mcgrp.id, gfp); |
| 7296 | return; |
| 7297 | |
| 7298 | nla_put_failure: |
| 7299 | genlmsg_cancel(msg, hdr); |
| 7300 | nlmsg_free(msg); |
| 7301 | } |
| 7302 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7303 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 7304 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7305 | { |
| 7306 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7307 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7308 | struct sk_buff *msg; |
| 7309 | void *hdr; |
| 7310 | int err; |
| 7311 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); |
| 7312 | |
| 7313 | if (!nlpid) |
| 7314 | return false; |
| 7315 | |
| 7316 | msg = nlmsg_new(100, gfp); |
| 7317 | if (!msg) |
| 7318 | return true; |
| 7319 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7320 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 7321 | if (!hdr) { |
| 7322 | nlmsg_free(msg); |
| 7323 | return true; |
| 7324 | } |
| 7325 | |
| 7326 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7327 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7328 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7329 | |
| 7330 | err = genlmsg_end(msg, hdr); |
| 7331 | if (err < 0) { |
| 7332 | nlmsg_free(msg); |
| 7333 | return true; |
| 7334 | } |
| 7335 | |
| 7336 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7337 | return true; |
| 7338 | |
| 7339 | nla_put_failure: |
| 7340 | genlmsg_cancel(msg, hdr); |
| 7341 | nlmsg_free(msg); |
| 7342 | return true; |
| 7343 | } |
| 7344 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 7345 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
| 7346 | { |
| 7347 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 7348 | addr, gfp); |
| 7349 | } |
| 7350 | |
| 7351 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, |
| 7352 | const u8 *addr, gfp_t gfp) |
| 7353 | { |
| 7354 | return __nl80211_unexpected_frame(dev, |
| 7355 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 7356 | addr, gfp); |
| 7357 | } |
| 7358 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7359 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7360 | struct net_device *netdev, u32 nlpid, |
| 7361 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7362 | { |
| 7363 | struct sk_buff *msg; |
| 7364 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7365 | |
| 7366 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7367 | if (!msg) |
| 7368 | return -ENOMEM; |
| 7369 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7370 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7371 | if (!hdr) { |
| 7372 | nlmsg_free(msg); |
| 7373 | return -ENOMEM; |
| 7374 | } |
| 7375 | |
| 7376 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7377 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7378 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7379 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7380 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7381 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7382 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7383 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7384 | |
| 7385 | nla_put_failure: |
| 7386 | genlmsg_cancel(msg, hdr); |
| 7387 | nlmsg_free(msg); |
| 7388 | return -ENOBUFS; |
| 7389 | } |
| 7390 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7391 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7392 | struct net_device *netdev, u64 cookie, |
| 7393 | const u8 *buf, size_t len, bool ack, |
| 7394 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7395 | { |
| 7396 | struct sk_buff *msg; |
| 7397 | void *hdr; |
| 7398 | |
| 7399 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7400 | if (!msg) |
| 7401 | return; |
| 7402 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7403 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7404 | if (!hdr) { |
| 7405 | nlmsg_free(msg); |
| 7406 | return; |
| 7407 | } |
| 7408 | |
| 7409 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7410 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7411 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7412 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7413 | if (ack) |
| 7414 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7415 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7416 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7417 | |
| 7418 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7419 | return; |
| 7420 | |
| 7421 | nla_put_failure: |
| 7422 | genlmsg_cancel(msg, hdr); |
| 7423 | nlmsg_free(msg); |
| 7424 | } |
| 7425 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7426 | void |
| 7427 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7428 | struct net_device *netdev, |
| 7429 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7430 | gfp_t gfp) |
| 7431 | { |
| 7432 | struct sk_buff *msg; |
| 7433 | struct nlattr *pinfoattr; |
| 7434 | void *hdr; |
| 7435 | |
| 7436 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7437 | if (!msg) |
| 7438 | return; |
| 7439 | |
| 7440 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7441 | if (!hdr) { |
| 7442 | nlmsg_free(msg); |
| 7443 | return; |
| 7444 | } |
| 7445 | |
| 7446 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7447 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7448 | |
| 7449 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7450 | if (!pinfoattr) |
| 7451 | goto nla_put_failure; |
| 7452 | |
| 7453 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7454 | rssi_event); |
| 7455 | |
| 7456 | nla_nest_end(msg, pinfoattr); |
| 7457 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7458 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7459 | |
| 7460 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7461 | nl80211_mlme_mcgrp.id, gfp); |
| 7462 | return; |
| 7463 | |
| 7464 | nla_put_failure: |
| 7465 | genlmsg_cancel(msg, hdr); |
| 7466 | nlmsg_free(msg); |
| 7467 | } |
| 7468 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7469 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7470 | struct net_device *netdev, const u8 *bssid, |
| 7471 | const u8 *replay_ctr, gfp_t gfp) |
| 7472 | { |
| 7473 | struct sk_buff *msg; |
| 7474 | struct nlattr *rekey_attr; |
| 7475 | void *hdr; |
| 7476 | |
| 7477 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7478 | if (!msg) |
| 7479 | return; |
| 7480 | |
| 7481 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7482 | if (!hdr) { |
| 7483 | nlmsg_free(msg); |
| 7484 | return; |
| 7485 | } |
| 7486 | |
| 7487 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7488 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7489 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7490 | |
| 7491 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7492 | if (!rekey_attr) |
| 7493 | goto nla_put_failure; |
| 7494 | |
| 7495 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7496 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7497 | |
| 7498 | nla_nest_end(msg, rekey_attr); |
| 7499 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7500 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7501 | |
| 7502 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7503 | nl80211_mlme_mcgrp.id, gfp); |
| 7504 | return; |
| 7505 | |
| 7506 | nla_put_failure: |
| 7507 | genlmsg_cancel(msg, hdr); |
| 7508 | nlmsg_free(msg); |
| 7509 | } |
| 7510 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7511 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7512 | struct net_device *netdev, int index, |
| 7513 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7514 | { |
| 7515 | struct sk_buff *msg; |
| 7516 | struct nlattr *attr; |
| 7517 | void *hdr; |
| 7518 | |
| 7519 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7520 | if (!msg) |
| 7521 | return; |
| 7522 | |
| 7523 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7524 | if (!hdr) { |
| 7525 | nlmsg_free(msg); |
| 7526 | return; |
| 7527 | } |
| 7528 | |
| 7529 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7530 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7531 | |
| 7532 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7533 | if (!attr) |
| 7534 | goto nla_put_failure; |
| 7535 | |
| 7536 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7537 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7538 | if (preauth) |
| 7539 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7540 | |
| 7541 | nla_nest_end(msg, attr); |
| 7542 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7543 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7544 | |
| 7545 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7546 | nl80211_mlme_mcgrp.id, gfp); |
| 7547 | return; |
| 7548 | |
| 7549 | nla_put_failure: |
| 7550 | genlmsg_cancel(msg, hdr); |
| 7551 | nlmsg_free(msg); |
| 7552 | } |
| 7553 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7554 | void |
| 7555 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7556 | struct net_device *netdev, const u8 *peer, |
| 7557 | u32 num_packets, gfp_t gfp) |
| 7558 | { |
| 7559 | struct sk_buff *msg; |
| 7560 | struct nlattr *pinfoattr; |
| 7561 | void *hdr; |
| 7562 | |
| 7563 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7564 | if (!msg) |
| 7565 | return; |
| 7566 | |
| 7567 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7568 | if (!hdr) { |
| 7569 | nlmsg_free(msg); |
| 7570 | return; |
| 7571 | } |
| 7572 | |
| 7573 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7574 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7575 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7576 | |
| 7577 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7578 | if (!pinfoattr) |
| 7579 | goto nla_put_failure; |
| 7580 | |
| 7581 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7582 | |
| 7583 | nla_nest_end(msg, pinfoattr); |
| 7584 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 7585 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7586 | |
| 7587 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7588 | nl80211_mlme_mcgrp.id, gfp); |
| 7589 | return; |
| 7590 | |
| 7591 | nla_put_failure: |
| 7592 | genlmsg_cancel(msg, hdr); |
| 7593 | nlmsg_free(msg); |
| 7594 | } |
| 7595 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 7596 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 7597 | u64 cookie, bool acked, gfp_t gfp) |
| 7598 | { |
| 7599 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7600 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); |
| 7601 | struct sk_buff *msg; |
| 7602 | void *hdr; |
| 7603 | int err; |
| 7604 | |
| 7605 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7606 | if (!msg) |
| 7607 | return; |
| 7608 | |
| 7609 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 7610 | if (!hdr) { |
| 7611 | nlmsg_free(msg); |
| 7612 | return; |
| 7613 | } |
| 7614 | |
| 7615 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7616 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7617 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7618 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7619 | if (acked) |
| 7620 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7621 | |
| 7622 | err = genlmsg_end(msg, hdr); |
| 7623 | if (err < 0) { |
| 7624 | nlmsg_free(msg); |
| 7625 | return; |
| 7626 | } |
| 7627 | |
| 7628 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7629 | nl80211_mlme_mcgrp.id, gfp); |
| 7630 | return; |
| 7631 | |
| 7632 | nla_put_failure: |
| 7633 | genlmsg_cancel(msg, hdr); |
| 7634 | nlmsg_free(msg); |
| 7635 | } |
| 7636 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 7637 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7638 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 7639 | const u8 *frame, size_t len, |
| 7640 | int freq, gfp_t gfp) |
| 7641 | { |
| 7642 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 7643 | struct sk_buff *msg; |
| 7644 | void *hdr; |
| 7645 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); |
| 7646 | |
| 7647 | if (!nlpid) |
| 7648 | return; |
| 7649 | |
| 7650 | msg = nlmsg_new(len + 100, gfp); |
| 7651 | if (!msg) |
| 7652 | return; |
| 7653 | |
| 7654 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 7655 | if (!hdr) { |
| 7656 | nlmsg_free(msg); |
| 7657 | return; |
| 7658 | } |
| 7659 | |
| 7660 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7661 | if (freq) |
| 7662 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7663 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, frame); |
| 7664 | |
| 7665 | genlmsg_end(msg, hdr); |
| 7666 | |
| 7667 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7668 | return; |
| 7669 | |
| 7670 | nla_put_failure: |
| 7671 | genlmsg_cancel(msg, hdr); |
| 7672 | nlmsg_free(msg); |
| 7673 | } |
| 7674 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 7675 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7676 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7677 | unsigned long state, |
| 7678 | void *_notify) |
| 7679 | { |
| 7680 | struct netlink_notify *notify = _notify; |
| 7681 | struct cfg80211_registered_device *rdev; |
| 7682 | struct wireless_dev *wdev; |
| 7683 | |
| 7684 | if (state != NETLINK_URELEASE) |
| 7685 | return NOTIFY_DONE; |
| 7686 | |
| 7687 | rcu_read_lock(); |
| 7688 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7689 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7690 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7691 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 7692 | if (rdev->ap_beacons_nlpid == notify->pid) |
| 7693 | rdev->ap_beacons_nlpid = 0; |
| 7694 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7695 | |
| 7696 | rcu_read_unlock(); |
| 7697 | |
| 7698 | return NOTIFY_DONE; |
| 7699 | } |
| 7700 | |
| 7701 | static struct notifier_block nl80211_netlink_notifier = { |
| 7702 | .notifier_call = nl80211_netlink_notify, |
| 7703 | }; |
| 7704 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7705 | /* initialisation/exit functions */ |
| 7706 | |
| 7707 | int nl80211_init(void) |
| 7708 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7709 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7710 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7711 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7712 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7713 | if (err) |
| 7714 | return err; |
| 7715 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7716 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7717 | if (err) |
| 7718 | goto err_out; |
| 7719 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7720 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7721 | if (err) |
| 7722 | goto err_out; |
| 7723 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7724 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7725 | if (err) |
| 7726 | goto err_out; |
| 7727 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7728 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7729 | if (err) |
| 7730 | goto err_out; |
| 7731 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7732 | #ifdef CONFIG_NL80211_TESTMODE |
| 7733 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7734 | if (err) |
| 7735 | goto err_out; |
| 7736 | #endif |
| 7737 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7738 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7739 | if (err) |
| 7740 | goto err_out; |
| 7741 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7742 | return 0; |
| 7743 | err_out: |
| 7744 | genl_unregister_family(&nl80211_fam); |
| 7745 | return err; |
| 7746 | } |
| 7747 | |
| 7748 | void nl80211_exit(void) |
| 7749 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7750 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7751 | genl_unregister_family(&nl80211_fam); |
| 7752 | } |