Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 18 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 19 | #include <net/genetlink.h> |
| 20 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 21 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | #include "core.h" |
| 23 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 24 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 26 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
| 27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 28 | struct genl_info *info, |
| 29 | struct cfg80211_crypto_settings *settings, |
| 30 | int cipher_limit); |
| 31 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 33 | struct genl_info *info); |
| 34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 35 | struct genl_info *info); |
| 36 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | /* the netlink family */ |
| 38 | static struct genl_family nl80211_fam = { |
| 39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 40 | .name = "nl80211", /* have users key off the name instead */ |
| 41 | .hdrsize = 0, /* no private header */ |
| 42 | .version = 1, /* no particular meaning now */ |
| 43 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 44 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 45 | .pre_doit = nl80211_pre_doit, |
| 46 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 49 | /* internal helper: get rdev and dev */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 50 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 51 | struct cfg80211_registered_device **rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 52 | struct net_device **dev) |
| 53 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 54 | struct nlattr **attrs = info->attrs; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 55 | int ifindex; |
| 56 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 57 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 58 | return -EINVAL; |
| 59 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 60 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 61 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 62 | if (!*dev) |
| 63 | return -ENODEV; |
| 64 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 65 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 66 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 67 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 68 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | /* policy for the attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 75 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 77 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 78 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 79 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 80 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 81 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 82 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 83 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 84 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 85 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 86 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | |
| 88 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 89 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 90 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 91 | |
| 92 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 93 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 94 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 95 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 96 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 97 | .len = WLAN_MAX_KEY_LEN }, |
| 98 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 99 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 100 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 101 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 102 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 103 | |
| 104 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 105 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 106 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 107 | .len = IEEE80211_MAX_DATA_LEN }, |
| 108 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 109 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 110 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 111 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 112 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 113 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 114 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 115 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 116 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 117 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 118 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 119 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 120 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 121 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 122 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 123 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 124 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 125 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 126 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 127 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 128 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 129 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 130 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 131 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 132 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 133 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 134 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame^] | 135 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 136 | |
| 137 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 138 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 139 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 140 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 141 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 142 | |
| 143 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 144 | .len = IEEE80211_MAX_SSID_LEN }, |
| 145 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 146 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 147 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 148 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 149 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 150 | [NL80211_ATTR_STA_FLAGS2] = { |
| 151 | .len = sizeof(struct nl80211_sta_flag_update), |
| 152 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 153 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 154 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 155 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 156 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 157 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 158 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 159 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 160 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 161 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 162 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 163 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 164 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 165 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 166 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 167 | .len = IEEE80211_MAX_DATA_LEN }, |
| 168 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 169 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 170 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 171 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 172 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 173 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 174 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 175 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 176 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 177 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 178 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 179 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 180 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 181 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 182 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 183 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 184 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 185 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 186 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 187 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 188 | .len = IEEE80211_MAX_DATA_LEN }, |
| 189 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 190 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 191 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 192 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 193 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 194 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 195 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 196 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 197 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 198 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 199 | }; |
| 200 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 201 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 202 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 203 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 204 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 205 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 206 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 207 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 208 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 209 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 210 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 211 | }; |
| 212 | |
| 213 | /* policy for the key default flags */ |
| 214 | static const struct nla_policy |
| 215 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 216 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 217 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 218 | }; |
| 219 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 220 | /* policy for WoWLAN attributes */ |
| 221 | static const struct nla_policy |
| 222 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 223 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 224 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 225 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 226 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 227 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 228 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 229 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 230 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 231 | }; |
| 232 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 233 | /* policy for GTK rekey offload attributes */ |
| 234 | static const struct nla_policy |
| 235 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 236 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 237 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 238 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 239 | }; |
| 240 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 241 | static const struct nla_policy |
| 242 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
| 243 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, |
| 244 | .len = IEEE80211_MAX_SSID_LEN }, |
| 245 | }; |
| 246 | |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 247 | /* ifidx get helper */ |
| 248 | static int nl80211_get_ifidx(struct netlink_callback *cb) |
| 249 | { |
| 250 | int res; |
| 251 | |
| 252 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 253 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 254 | nl80211_policy); |
| 255 | if (res) |
| 256 | return res; |
| 257 | |
| 258 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 259 | return -EINVAL; |
| 260 | |
| 261 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 262 | if (!res) |
| 263 | return -EINVAL; |
| 264 | return res; |
| 265 | } |
| 266 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 267 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
| 268 | struct netlink_callback *cb, |
| 269 | struct cfg80211_registered_device **rdev, |
| 270 | struct net_device **dev) |
| 271 | { |
| 272 | int ifidx = cb->args[0]; |
| 273 | int err; |
| 274 | |
| 275 | if (!ifidx) |
| 276 | ifidx = nl80211_get_ifidx(cb); |
| 277 | if (ifidx < 0) |
| 278 | return ifidx; |
| 279 | |
| 280 | cb->args[0] = ifidx; |
| 281 | |
| 282 | rtnl_lock(); |
| 283 | |
| 284 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
| 285 | if (!*dev) { |
| 286 | err = -ENODEV; |
| 287 | goto out_rtnl; |
| 288 | } |
| 289 | |
| 290 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Felix Fietkau | 3cc25e5 | 2010-10-31 15:31:54 +0100 | [diff] [blame] | 291 | if (IS_ERR(*rdev)) { |
| 292 | err = PTR_ERR(*rdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 293 | goto out_rtnl; |
| 294 | } |
| 295 | |
| 296 | return 0; |
| 297 | out_rtnl: |
| 298 | rtnl_unlock(); |
| 299 | return err; |
| 300 | } |
| 301 | |
| 302 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) |
| 303 | { |
| 304 | cfg80211_unlock_rdev(rdev); |
| 305 | rtnl_unlock(); |
| 306 | } |
| 307 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 308 | /* IE validation */ |
| 309 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 310 | { |
| 311 | const u8 *pos; |
| 312 | int len; |
| 313 | |
| 314 | if (!attr) |
| 315 | return true; |
| 316 | |
| 317 | pos = nla_data(attr); |
| 318 | len = nla_len(attr); |
| 319 | |
| 320 | while (len) { |
| 321 | u8 elemlen; |
| 322 | |
| 323 | if (len < 2) |
| 324 | return false; |
| 325 | len -= 2; |
| 326 | |
| 327 | elemlen = pos[1]; |
| 328 | if (elemlen > len) |
| 329 | return false; |
| 330 | |
| 331 | len -= elemlen; |
| 332 | pos += 2 + elemlen; |
| 333 | } |
| 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 338 | /* message building helper */ |
| 339 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 340 | int flags, u8 cmd) |
| 341 | { |
| 342 | /* since there is no private header just add the generic one */ |
| 343 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 344 | } |
| 345 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 346 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 347 | struct ieee80211_channel *chan) |
| 348 | { |
| 349 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 350 | chan->center_freq); |
| 351 | |
| 352 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 353 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 354 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 355 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 356 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 357 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 358 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 359 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 360 | |
| 361 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 362 | DBM_TO_MBM(chan->max_power)); |
| 363 | |
| 364 | return 0; |
| 365 | |
| 366 | nla_put_failure: |
| 367 | return -ENOBUFS; |
| 368 | } |
| 369 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 370 | /* netlink command implementations */ |
| 371 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 372 | struct key_parse { |
| 373 | struct key_params p; |
| 374 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 375 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 376 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 377 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 381 | { |
| 382 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 383 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 384 | nl80211_key_policy); |
| 385 | if (err) |
| 386 | return err; |
| 387 | |
| 388 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 389 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 390 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 391 | if (k->def) { |
| 392 | k->def_uni = true; |
| 393 | k->def_multi = true; |
| 394 | } |
| 395 | if (k->defmgmt) |
| 396 | k->def_multi = true; |
| 397 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 398 | if (tb[NL80211_KEY_IDX]) |
| 399 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 400 | |
| 401 | if (tb[NL80211_KEY_DATA]) { |
| 402 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 403 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 404 | } |
| 405 | |
| 406 | if (tb[NL80211_KEY_SEQ]) { |
| 407 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 408 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 409 | } |
| 410 | |
| 411 | if (tb[NL80211_KEY_CIPHER]) |
| 412 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 413 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 414 | if (tb[NL80211_KEY_TYPE]) { |
| 415 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 416 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 420 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 421 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 422 | int err = nla_parse_nested(kdt, |
| 423 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 424 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 425 | nl80211_key_default_policy); |
| 426 | if (err) |
| 427 | return err; |
| 428 | |
| 429 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 430 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 431 | } |
| 432 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 437 | { |
| 438 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 439 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 440 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 441 | } |
| 442 | |
| 443 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 444 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 445 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 446 | } |
| 447 | |
| 448 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 449 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 450 | |
| 451 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 452 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 453 | |
| 454 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 455 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 456 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 457 | if (k->def) { |
| 458 | k->def_uni = true; |
| 459 | k->def_multi = true; |
| 460 | } |
| 461 | if (k->defmgmt) |
| 462 | k->def_multi = true; |
| 463 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 464 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 465 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 466 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 467 | return -EINVAL; |
| 468 | } |
| 469 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 470 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 471 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 472 | int err = nla_parse_nested( |
| 473 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 474 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 475 | nl80211_key_default_policy); |
| 476 | if (err) |
| 477 | return err; |
| 478 | |
| 479 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 480 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 481 | } |
| 482 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 487 | { |
| 488 | int err; |
| 489 | |
| 490 | memset(k, 0, sizeof(*k)); |
| 491 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 492 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 493 | |
| 494 | if (info->attrs[NL80211_ATTR_KEY]) |
| 495 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 496 | else |
| 497 | err = nl80211_parse_key_old(info, k); |
| 498 | |
| 499 | if (err) |
| 500 | return err; |
| 501 | |
| 502 | if (k->def && k->defmgmt) |
| 503 | return -EINVAL; |
| 504 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 505 | if (k->defmgmt) { |
| 506 | if (k->def_uni || !k->def_multi) |
| 507 | return -EINVAL; |
| 508 | } |
| 509 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 510 | if (k->idx != -1) { |
| 511 | if (k->defmgmt) { |
| 512 | if (k->idx < 4 || k->idx > 5) |
| 513 | return -EINVAL; |
| 514 | } else if (k->def) { |
| 515 | if (k->idx < 0 || k->idx > 3) |
| 516 | return -EINVAL; |
| 517 | } else { |
| 518 | if (k->idx < 0 || k->idx > 5) |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 526 | static struct cfg80211_cached_keys * |
| 527 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 528 | struct nlattr *keys) |
| 529 | { |
| 530 | struct key_parse parse; |
| 531 | struct nlattr *key; |
| 532 | struct cfg80211_cached_keys *result; |
| 533 | int rem, err, def = 0; |
| 534 | |
| 535 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 536 | if (!result) |
| 537 | return ERR_PTR(-ENOMEM); |
| 538 | |
| 539 | result->def = -1; |
| 540 | result->defmgmt = -1; |
| 541 | |
| 542 | nla_for_each_nested(key, keys, rem) { |
| 543 | memset(&parse, 0, sizeof(parse)); |
| 544 | parse.idx = -1; |
| 545 | |
| 546 | err = nl80211_parse_key_new(key, &parse); |
| 547 | if (err) |
| 548 | goto error; |
| 549 | err = -EINVAL; |
| 550 | if (!parse.p.key) |
| 551 | goto error; |
| 552 | if (parse.idx < 0 || parse.idx > 4) |
| 553 | goto error; |
| 554 | if (parse.def) { |
| 555 | if (def) |
| 556 | goto error; |
| 557 | def = 1; |
| 558 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 559 | if (!parse.def_uni || !parse.def_multi) |
| 560 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 561 | } else if (parse.defmgmt) |
| 562 | goto error; |
| 563 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 564 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 565 | if (err) |
| 566 | goto error; |
| 567 | result->params[parse.idx].cipher = parse.p.cipher; |
| 568 | result->params[parse.idx].key_len = parse.p.key_len; |
| 569 | result->params[parse.idx].key = result->data[parse.idx]; |
| 570 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 571 | } |
| 572 | |
| 573 | return result; |
| 574 | error: |
| 575 | kfree(result); |
| 576 | return ERR_PTR(err); |
| 577 | } |
| 578 | |
| 579 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 580 | { |
| 581 | ASSERT_WDEV_LOCK(wdev); |
| 582 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 583 | switch (wdev->iftype) { |
| 584 | case NL80211_IFTYPE_AP: |
| 585 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 586 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 587 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 588 | break; |
| 589 | case NL80211_IFTYPE_ADHOC: |
| 590 | if (!wdev->current_bss) |
| 591 | return -ENOLINK; |
| 592 | break; |
| 593 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 594 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 595 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 596 | return -ENOLINK; |
| 597 | break; |
| 598 | default: |
| 599 | return -EINVAL; |
| 600 | } |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 605 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 606 | { |
| 607 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 608 | int i; |
| 609 | |
| 610 | if (!nl_modes) |
| 611 | goto nla_put_failure; |
| 612 | |
| 613 | i = 0; |
| 614 | while (ifmodes) { |
| 615 | if (ifmodes & 1) |
| 616 | NLA_PUT_FLAG(msg, i); |
| 617 | ifmodes >>= 1; |
| 618 | i++; |
| 619 | } |
| 620 | |
| 621 | nla_nest_end(msg, nl_modes); |
| 622 | return 0; |
| 623 | |
| 624 | nla_put_failure: |
| 625 | return -ENOBUFS; |
| 626 | } |
| 627 | |
| 628 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
| 629 | struct sk_buff *msg) |
| 630 | { |
| 631 | struct nlattr *nl_combis; |
| 632 | int i, j; |
| 633 | |
| 634 | nl_combis = nla_nest_start(msg, |
| 635 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 636 | if (!nl_combis) |
| 637 | goto nla_put_failure; |
| 638 | |
| 639 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 640 | const struct ieee80211_iface_combination *c; |
| 641 | struct nlattr *nl_combi, *nl_limits; |
| 642 | |
| 643 | c = &wiphy->iface_combinations[i]; |
| 644 | |
| 645 | nl_combi = nla_nest_start(msg, i + 1); |
| 646 | if (!nl_combi) |
| 647 | goto nla_put_failure; |
| 648 | |
| 649 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 650 | if (!nl_limits) |
| 651 | goto nla_put_failure; |
| 652 | |
| 653 | for (j = 0; j < c->n_limits; j++) { |
| 654 | struct nlattr *nl_limit; |
| 655 | |
| 656 | nl_limit = nla_nest_start(msg, j + 1); |
| 657 | if (!nl_limit) |
| 658 | goto nla_put_failure; |
| 659 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, |
| 660 | c->limits[j].max); |
| 661 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 662 | c->limits[j].types)) |
| 663 | goto nla_put_failure; |
| 664 | nla_nest_end(msg, nl_limit); |
| 665 | } |
| 666 | |
| 667 | nla_nest_end(msg, nl_limits); |
| 668 | |
| 669 | if (c->beacon_int_infra_match) |
| 670 | NLA_PUT_FLAG(msg, |
| 671 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); |
| 672 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 673 | c->num_different_channels); |
| 674 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 675 | c->max_interfaces); |
| 676 | |
| 677 | nla_nest_end(msg, nl_combi); |
| 678 | } |
| 679 | |
| 680 | nla_nest_end(msg, nl_combis); |
| 681 | |
| 682 | return 0; |
| 683 | nla_put_failure: |
| 684 | return -ENOBUFS; |
| 685 | } |
| 686 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 687 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 688 | struct cfg80211_registered_device *dev) |
| 689 | { |
| 690 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 691 | struct nlattr *nl_bands, *nl_band; |
| 692 | struct nlattr *nl_freqs, *nl_freq; |
| 693 | struct nlattr *nl_rates, *nl_rate; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 694 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 695 | enum ieee80211_band band; |
| 696 | struct ieee80211_channel *chan; |
| 697 | struct ieee80211_rate *rate; |
| 698 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 699 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
| 700 | dev->wiphy.mgmt_stypes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 701 | |
| 702 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 703 | if (!hdr) |
| 704 | return -1; |
| 705 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 706 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 707 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 708 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 709 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 710 | cfg80211_rdev_list_generation); |
| 711 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 712 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 713 | dev->wiphy.retry_short); |
| 714 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 715 | dev->wiphy.retry_long); |
| 716 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 717 | dev->wiphy.frag_threshold); |
| 718 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 719 | dev->wiphy.rts_threshold); |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 720 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
| 721 | dev->wiphy.coverage_class); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 722 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 723 | dev->wiphy.max_scan_ssids); |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 724 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
| 725 | dev->wiphy.max_sched_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 726 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 727 | dev->wiphy.max_scan_ie_len); |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 728 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
| 729 | dev->wiphy.max_sched_scan_ie_len); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 730 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
| 731 | dev->wiphy.max_match_sets); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 732 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 733 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) |
| 734 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 735 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) |
| 736 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 737 | if (dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) |
| 738 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_AP_UAPSD); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 739 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) |
| 740 | NLA_PUT_FLAG(msg, NL80211_ATTR_ROAM_SUPPORT); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 741 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) |
| 742 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_SUPPORT); |
| 743 | if (dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) |
| 744 | NLA_PUT_FLAG(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP); |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 745 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 746 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 747 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 748 | dev->wiphy.cipher_suites); |
| 749 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 750 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
| 751 | dev->wiphy.max_num_pmkids); |
| 752 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 753 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
| 754 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
| 755 | |
Bruno Randolf | 39fd5de | 2010-12-16 11:30:28 +0900 | [diff] [blame] | 756 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
| 757 | dev->wiphy.available_antennas_tx); |
| 758 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
| 759 | dev->wiphy.available_antennas_rx); |
| 760 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 761 | if ((dev->wiphy.available_antennas_tx || |
| 762 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 763 | u32 tx_ant = 0, rx_ant = 0; |
| 764 | int res; |
| 765 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); |
| 766 | if (!res) { |
| 767 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); |
| 768 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); |
| 769 | } |
| 770 | } |
| 771 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 772 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
| 773 | dev->wiphy.interface_modes)) |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 774 | goto nla_put_failure; |
| 775 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 776 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 777 | if (!nl_bands) |
| 778 | goto nla_put_failure; |
| 779 | |
| 780 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 781 | if (!dev->wiphy.bands[band]) |
| 782 | continue; |
| 783 | |
| 784 | nl_band = nla_nest_start(msg, band); |
| 785 | if (!nl_band) |
| 786 | goto nla_put_failure; |
| 787 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 788 | /* add HT info */ |
| 789 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 790 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 791 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 792 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 793 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 794 | dev->wiphy.bands[band]->ht_cap.cap); |
| 795 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 796 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 797 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 798 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 799 | } |
| 800 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 801 | /* add frequencies */ |
| 802 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 803 | if (!nl_freqs) |
| 804 | goto nla_put_failure; |
| 805 | |
| 806 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 807 | nl_freq = nla_nest_start(msg, i); |
| 808 | if (!nl_freq) |
| 809 | goto nla_put_failure; |
| 810 | |
| 811 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 812 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 813 | if (nl80211_msg_put_channel(msg, chan)) |
| 814 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 815 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 816 | nla_nest_end(msg, nl_freq); |
| 817 | } |
| 818 | |
| 819 | nla_nest_end(msg, nl_freqs); |
| 820 | |
| 821 | /* add bitrates */ |
| 822 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 823 | if (!nl_rates) |
| 824 | goto nla_put_failure; |
| 825 | |
| 826 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 827 | nl_rate = nla_nest_start(msg, i); |
| 828 | if (!nl_rate) |
| 829 | goto nla_put_failure; |
| 830 | |
| 831 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 832 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 833 | rate->bitrate); |
| 834 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 835 | NLA_PUT_FLAG(msg, |
| 836 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 837 | |
| 838 | nla_nest_end(msg, nl_rate); |
| 839 | } |
| 840 | |
| 841 | nla_nest_end(msg, nl_rates); |
| 842 | |
| 843 | nla_nest_end(msg, nl_band); |
| 844 | } |
| 845 | nla_nest_end(msg, nl_bands); |
| 846 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 847 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 848 | if (!nl_cmds) |
| 849 | goto nla_put_failure; |
| 850 | |
| 851 | i = 0; |
| 852 | #define CMD(op, n) \ |
| 853 | do { \ |
| 854 | if (dev->ops->op) { \ |
| 855 | i++; \ |
| 856 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 857 | } \ |
| 858 | } while (0) |
| 859 | |
| 860 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 861 | CMD(change_virtual_intf, SET_INTERFACE); |
| 862 | CMD(add_key, NEW_KEY); |
| 863 | CMD(add_beacon, NEW_BEACON); |
| 864 | CMD(add_station, NEW_STATION); |
| 865 | CMD(add_mpath, NEW_MPATH); |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 866 | CMD(update_mesh_config, SET_MESH_CONFIG); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 867 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 868 | CMD(auth, AUTHENTICATE); |
| 869 | CMD(assoc, ASSOCIATE); |
| 870 | CMD(deauth, DEAUTHENTICATE); |
| 871 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 872 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 873 | CMD(join_mesh, JOIN_MESH); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 874 | CMD(set_pmksa, SET_PMKSA); |
| 875 | CMD(del_pmksa, DEL_PMKSA); |
| 876 | CMD(flush_pmksa, FLUSH_PMKSA); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 877 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 878 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 879 | CMD(mgmt_tx, FRAME); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 880 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 881 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 882 | i++; |
| 883 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 884 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 885 | CMD(set_channel, SET_CHANNEL); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 886 | CMD(set_wds_peer, SET_WDS_PEER); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 887 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 888 | CMD(tdls_mgmt, TDLS_MGMT); |
| 889 | CMD(tdls_oper, TDLS_OPER); |
| 890 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 891 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 892 | CMD(sched_scan_start, START_SCHED_SCAN); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 893 | |
| 894 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 895 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 896 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 897 | i++; |
| 898 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 899 | } |
| 900 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 901 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 902 | i++; |
| 903 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 904 | } |
| 905 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 906 | nla_nest_end(msg, nl_cmds); |
| 907 | |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 908 | if (dev->ops->remain_on_channel) |
| 909 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
| 910 | dev->wiphy.max_remain_on_channel_duration); |
| 911 | |
Jouni Malinen | d2da587 | 2011-08-08 12:10:30 +0300 | [diff] [blame] | 912 | if (dev->ops->mgmt_tx_cancel_wait) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 913 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
| 914 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 915 | if (mgmt_stypes) { |
| 916 | u16 stypes; |
| 917 | struct nlattr *nl_ftypes, *nl_ifs; |
| 918 | enum nl80211_iftype ift; |
| 919 | |
| 920 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 921 | if (!nl_ifs) |
| 922 | goto nla_put_failure; |
| 923 | |
| 924 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 925 | nl_ftypes = nla_nest_start(msg, ift); |
| 926 | if (!nl_ftypes) |
| 927 | goto nla_put_failure; |
| 928 | i = 0; |
| 929 | stypes = mgmt_stypes[ift].tx; |
| 930 | while (stypes) { |
| 931 | if (stypes & 1) |
| 932 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 933 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 934 | stypes >>= 1; |
| 935 | i++; |
| 936 | } |
| 937 | nla_nest_end(msg, nl_ftypes); |
| 938 | } |
| 939 | |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 940 | nla_nest_end(msg, nl_ifs); |
| 941 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 942 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 943 | if (!nl_ifs) |
| 944 | goto nla_put_failure; |
| 945 | |
| 946 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 947 | nl_ftypes = nla_nest_start(msg, ift); |
| 948 | if (!nl_ftypes) |
| 949 | goto nla_put_failure; |
| 950 | i = 0; |
| 951 | stypes = mgmt_stypes[ift].rx; |
| 952 | while (stypes) { |
| 953 | if (stypes & 1) |
| 954 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, |
| 955 | (i << 4) | IEEE80211_FTYPE_MGMT); |
| 956 | stypes >>= 1; |
| 957 | i++; |
| 958 | } |
| 959 | nla_nest_end(msg, nl_ftypes); |
| 960 | } |
| 961 | nla_nest_end(msg, nl_ifs); |
| 962 | } |
| 963 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 964 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
| 965 | struct nlattr *nl_wowlan; |
| 966 | |
| 967 | nl_wowlan = nla_nest_start(msg, |
| 968 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 969 | if (!nl_wowlan) |
| 970 | goto nla_put_failure; |
| 971 | |
| 972 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) |
| 973 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 974 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) |
| 975 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 976 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) |
| 977 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 978 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) |
| 979 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED); |
| 980 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) |
| 981 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 982 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) |
| 983 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 984 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) |
| 985 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 986 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) |
| 987 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 988 | if (dev->wiphy.wowlan.n_patterns) { |
| 989 | struct nl80211_wowlan_pattern_support pat = { |
| 990 | .max_patterns = dev->wiphy.wowlan.n_patterns, |
| 991 | .min_pattern_len = |
| 992 | dev->wiphy.wowlan.pattern_min_len, |
| 993 | .max_pattern_len = |
| 994 | dev->wiphy.wowlan.pattern_max_len, |
| 995 | }; |
| 996 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 997 | sizeof(pat), &pat); |
| 998 | } |
| 999 | |
| 1000 | nla_nest_end(msg, nl_wowlan); |
| 1001 | } |
| 1002 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1003 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
| 1004 | dev->wiphy.software_iftypes)) |
| 1005 | goto nla_put_failure; |
| 1006 | |
| 1007 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) |
| 1008 | goto nla_put_failure; |
| 1009 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1010 | return genlmsg_end(msg, hdr); |
| 1011 | |
| 1012 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1013 | genlmsg_cancel(msg, hdr); |
| 1014 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1018 | { |
| 1019 | int idx = 0; |
| 1020 | int start = cb->args[0]; |
| 1021 | struct cfg80211_registered_device *dev; |
| 1022 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1023 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1024 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1025 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 1026 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1027 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1028 | continue; |
| 1029 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 1030 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1031 | dev) < 0) { |
| 1032 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1033 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 1034 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1035 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1036 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1037 | |
| 1038 | cb->args[0] = idx; |
| 1039 | |
| 1040 | return skb->len; |
| 1041 | } |
| 1042 | |
| 1043 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1044 | { |
| 1045 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1046 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1047 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1048 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1049 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1050 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1051 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1052 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
| 1053 | nlmsg_free(msg); |
| 1054 | return -ENOBUFS; |
| 1055 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1056 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1057 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1060 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1061 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1062 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1063 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1064 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1065 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1066 | }; |
| 1067 | |
| 1068 | static int parse_txq_params(struct nlattr *tb[], |
| 1069 | struct ieee80211_txq_params *txq_params) |
| 1070 | { |
| 1071 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 1072 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1073 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1074 | return -EINVAL; |
| 1075 | |
| 1076 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 1077 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1078 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1079 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1080 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1081 | |
| 1082 | return 0; |
| 1083 | } |
| 1084 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1085 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1086 | { |
| 1087 | /* |
| 1088 | * You can only set the channel explicitly for AP, mesh |
| 1089 | * and WDS type interfaces; all others have their channel |
| 1090 | * managed via their respective "establish a connection" |
| 1091 | * command (connect, join, ...) |
| 1092 | * |
| 1093 | * Monitors are special as they are normally slaved to |
| 1094 | * whatever else is going on, so they behave as though |
| 1095 | * you tried setting the wiphy channel itself. |
| 1096 | */ |
| 1097 | return !wdev || |
| 1098 | wdev->iftype == NL80211_IFTYPE_AP || |
| 1099 | wdev->iftype == NL80211_IFTYPE_WDS || |
| 1100 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1101 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1102 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
| 1106 | struct wireless_dev *wdev, |
| 1107 | struct genl_info *info) |
| 1108 | { |
| 1109 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 1110 | u32 freq; |
| 1111 | int result; |
| 1112 | |
| 1113 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1114 | return -EINVAL; |
| 1115 | |
| 1116 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1117 | return -EOPNOTSUPP; |
| 1118 | |
| 1119 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1120 | channel_type = nla_get_u32(info->attrs[ |
| 1121 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1122 | if (channel_type != NL80211_CHAN_NO_HT && |
| 1123 | channel_type != NL80211_CHAN_HT20 && |
| 1124 | channel_type != NL80211_CHAN_HT40PLUS && |
| 1125 | channel_type != NL80211_CHAN_HT40MINUS) |
| 1126 | return -EINVAL; |
| 1127 | } |
| 1128 | |
| 1129 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1130 | |
| 1131 | mutex_lock(&rdev->devlist_mtx); |
| 1132 | if (wdev) { |
| 1133 | wdev_lock(wdev); |
| 1134 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); |
| 1135 | wdev_unlock(wdev); |
| 1136 | } else { |
| 1137 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); |
| 1138 | } |
| 1139 | mutex_unlock(&rdev->devlist_mtx); |
| 1140 | |
| 1141 | return result; |
| 1142 | } |
| 1143 | |
| 1144 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 1145 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1146 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1147 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1148 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1149 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1150 | } |
| 1151 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1152 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 1153 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1155 | struct net_device *dev = info->user_ptr[1]; |
| 1156 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 1157 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1158 | |
| 1159 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1160 | return -EINVAL; |
| 1161 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1162 | if (netif_running(dev)) |
| 1163 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1164 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1165 | if (!rdev->ops->set_wds_peer) |
| 1166 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1167 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1168 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 1169 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1170 | |
| 1171 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 1172 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1176 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1177 | { |
| 1178 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1179 | struct net_device *netdev = NULL; |
| 1180 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 1181 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1182 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1183 | u32 changed; |
| 1184 | u8 retry_short = 0, retry_long = 0; |
| 1185 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1186 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1187 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1188 | /* |
| 1189 | * Try to find the wiphy and netdev. Normally this |
| 1190 | * function shouldn't need the netdev, but this is |
| 1191 | * done for backward compatibility -- previously |
| 1192 | * setting the channel was done per wiphy, but now |
| 1193 | * it is per netdev. Previous userland like hostapd |
| 1194 | * also passed a netdev to set_wiphy, so that it is |
| 1195 | * possible to let that go to the right netdev! |
| 1196 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1197 | mutex_lock(&cfg80211_mutex); |
| 1198 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1199 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 1200 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 1201 | |
| 1202 | netdev = dev_get_by_index(genl_info_net(info), ifindex); |
| 1203 | if (netdev && netdev->ieee80211_ptr) { |
| 1204 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); |
| 1205 | mutex_lock(&rdev->mtx); |
| 1206 | } else |
| 1207 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1210 | if (!netdev) { |
| 1211 | rdev = __cfg80211_rdev_from_info(info); |
| 1212 | if (IS_ERR(rdev)) { |
| 1213 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1214 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1215 | } |
| 1216 | wdev = NULL; |
| 1217 | netdev = NULL; |
| 1218 | result = 0; |
| 1219 | |
| 1220 | mutex_lock(&rdev->mtx); |
| 1221 | } else if (netif_running(netdev) && |
| 1222 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
| 1223 | wdev = netdev->ieee80211_ptr; |
| 1224 | else |
| 1225 | wdev = NULL; |
| 1226 | |
| 1227 | /* |
| 1228 | * end workaround code, by now the rdev is available |
| 1229 | * and locked, and wdev may or may not be NULL. |
| 1230 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1231 | |
| 1232 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1233 | result = cfg80211_dev_rename( |
| 1234 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1235 | |
| 1236 | mutex_unlock(&cfg80211_mutex); |
| 1237 | |
| 1238 | if (result) |
| 1239 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1240 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1241 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 1242 | struct ieee80211_txq_params txq_params; |
| 1243 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 1244 | |
| 1245 | if (!rdev->ops->set_txq_params) { |
| 1246 | result = -EOPNOTSUPP; |
| 1247 | goto bad_res; |
| 1248 | } |
| 1249 | |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1250 | if (!netdev) { |
| 1251 | result = -EINVAL; |
| 1252 | goto bad_res; |
| 1253 | } |
| 1254 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1255 | nla_for_each_nested(nl_txq_params, |
| 1256 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 1257 | rem_txq_params) { |
| 1258 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 1259 | nla_data(nl_txq_params), |
| 1260 | nla_len(nl_txq_params), |
| 1261 | txq_params_policy); |
| 1262 | result = parse_txq_params(tb, &txq_params); |
| 1263 | if (result) |
| 1264 | goto bad_res; |
| 1265 | |
| 1266 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 1267 | netdev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1268 | &txq_params); |
| 1269 | if (result) |
| 1270 | goto bad_res; |
| 1271 | } |
| 1272 | } |
| 1273 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1274 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1275 | result = __nl80211_set_channel(rdev, wdev, info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1276 | if (result) |
| 1277 | goto bad_res; |
| 1278 | } |
| 1279 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1280 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
| 1281 | enum nl80211_tx_power_setting type; |
| 1282 | int idx, mbm = 0; |
| 1283 | |
| 1284 | if (!rdev->ops->set_tx_power) { |
Jiri Slaby | 60ea385 | 2010-07-07 15:02:46 +0200 | [diff] [blame] | 1285 | result = -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 1286 | goto bad_res; |
| 1287 | } |
| 1288 | |
| 1289 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 1290 | type = nla_get_u32(info->attrs[idx]); |
| 1291 | |
| 1292 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
| 1293 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 1294 | result = -EINVAL; |
| 1295 | goto bad_res; |
| 1296 | } |
| 1297 | |
| 1298 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 1299 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 1300 | mbm = nla_get_u32(info->attrs[idx]); |
| 1301 | } |
| 1302 | |
| 1303 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); |
| 1304 | if (result) |
| 1305 | goto bad_res; |
| 1306 | } |
| 1307 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1308 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 1309 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 1310 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1311 | if ((!rdev->wiphy.available_antennas_tx && |
| 1312 | !rdev->wiphy.available_antennas_rx) || |
| 1313 | !rdev->ops->set_antenna) { |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1314 | result = -EOPNOTSUPP; |
| 1315 | goto bad_res; |
| 1316 | } |
| 1317 | |
| 1318 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 1319 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 1320 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1321 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1322 | * available antenna masks, except for the "all" mask */ |
| 1323 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
| 1324 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1325 | result = -EINVAL; |
| 1326 | goto bad_res; |
| 1327 | } |
| 1328 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 1329 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 1330 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 1331 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 1332 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
| 1333 | if (result) |
| 1334 | goto bad_res; |
| 1335 | } |
| 1336 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1337 | changed = 0; |
| 1338 | |
| 1339 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 1340 | retry_short = nla_get_u8( |
| 1341 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 1342 | if (retry_short == 0) { |
| 1343 | result = -EINVAL; |
| 1344 | goto bad_res; |
| 1345 | } |
| 1346 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 1347 | } |
| 1348 | |
| 1349 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 1350 | retry_long = nla_get_u8( |
| 1351 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 1352 | if (retry_long == 0) { |
| 1353 | result = -EINVAL; |
| 1354 | goto bad_res; |
| 1355 | } |
| 1356 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 1357 | } |
| 1358 | |
| 1359 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 1360 | frag_threshold = nla_get_u32( |
| 1361 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 1362 | if (frag_threshold < 256) { |
| 1363 | result = -EINVAL; |
| 1364 | goto bad_res; |
| 1365 | } |
| 1366 | if (frag_threshold != (u32) -1) { |
| 1367 | /* |
| 1368 | * Fragments (apart from the last one) are required to |
| 1369 | * have even length. Make the fragmentation code |
| 1370 | * simpler by stripping LSB should someone try to use |
| 1371 | * odd threshold value. |
| 1372 | */ |
| 1373 | frag_threshold &= ~0x1; |
| 1374 | } |
| 1375 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 1376 | } |
| 1377 | |
| 1378 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 1379 | rts_threshold = nla_get_u32( |
| 1380 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 1381 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 1382 | } |
| 1383 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1384 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
| 1385 | coverage_class = nla_get_u8( |
| 1386 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 1387 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 1388 | } |
| 1389 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1390 | if (changed) { |
| 1391 | u8 old_retry_short, old_retry_long; |
| 1392 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1393 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1394 | |
| 1395 | if (!rdev->ops->set_wiphy_params) { |
| 1396 | result = -EOPNOTSUPP; |
| 1397 | goto bad_res; |
| 1398 | } |
| 1399 | |
| 1400 | old_retry_short = rdev->wiphy.retry_short; |
| 1401 | old_retry_long = rdev->wiphy.retry_long; |
| 1402 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 1403 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1404 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1405 | |
| 1406 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1407 | rdev->wiphy.retry_short = retry_short; |
| 1408 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1409 | rdev->wiphy.retry_long = retry_long; |
| 1410 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 1411 | rdev->wiphy.frag_threshold = frag_threshold; |
| 1412 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 1413 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1414 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 1415 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1416 | |
| 1417 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 1418 | if (result) { |
| 1419 | rdev->wiphy.retry_short = old_retry_short; |
| 1420 | rdev->wiphy.retry_long = old_retry_long; |
| 1421 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 1422 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 1423 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1424 | } |
| 1425 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1426 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 1427 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 1428 | mutex_unlock(&rdev->mtx); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1429 | if (netdev) |
| 1430 | dev_put(netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1431 | return result; |
| 1432 | } |
| 1433 | |
| 1434 | |
| 1435 | 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] | 1436 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1437 | struct net_device *dev) |
| 1438 | { |
| 1439 | void *hdr; |
| 1440 | |
| 1441 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 1442 | if (!hdr) |
| 1443 | return -1; |
| 1444 | |
| 1445 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1446 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1447 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1448 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1449 | |
| 1450 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 1451 | rdev->devlist_generation ^ |
| 1452 | (cfg80211_rdev_list_generation << 2)); |
| 1453 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1454 | return genlmsg_end(msg, hdr); |
| 1455 | |
| 1456 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1457 | genlmsg_cancel(msg, hdr); |
| 1458 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 1462 | { |
| 1463 | int wp_idx = 0; |
| 1464 | int if_idx = 0; |
| 1465 | int wp_start = cb->args[0]; |
| 1466 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1467 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1468 | struct wireless_dev *wdev; |
| 1469 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1470 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1471 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1472 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1473 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1474 | if (wp_idx < wp_start) { |
| 1475 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1476 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1477 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1478 | if_idx = 0; |
| 1479 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1480 | mutex_lock(&rdev->devlist_mtx); |
| 1481 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1482 | if (if_idx < if_start) { |
| 1483 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1484 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1485 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1486 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 1487 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1488 | rdev, wdev->netdev) < 0) { |
| 1489 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1490 | goto out; |
| 1491 | } |
| 1492 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1493 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1494 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1495 | |
| 1496 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1497 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1498 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1499 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1500 | |
| 1501 | cb->args[0] = wp_idx; |
| 1502 | cb->args[1] = if_idx; |
| 1503 | |
| 1504 | return skb->len; |
| 1505 | } |
| 1506 | |
| 1507 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 1508 | { |
| 1509 | struct sk_buff *msg; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1510 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
| 1511 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1512 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1513 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1514 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1515 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1516 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 1517 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1518 | dev, netdev) < 0) { |
| 1519 | nlmsg_free(msg); |
| 1520 | return -ENOBUFS; |
| 1521 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1522 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1523 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1524 | } |
| 1525 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1526 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 1527 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 1528 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 1529 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 1530 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 1531 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 1532 | }; |
| 1533 | |
| 1534 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 1535 | { |
| 1536 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 1537 | int flag; |
| 1538 | |
| 1539 | *mntrflags = 0; |
| 1540 | |
| 1541 | if (!nla) |
| 1542 | return -EINVAL; |
| 1543 | |
| 1544 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 1545 | nla, mntr_flags_policy)) |
| 1546 | return -EINVAL; |
| 1547 | |
| 1548 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 1549 | if (flags[flag]) |
| 1550 | *mntrflags |= (1<<flag); |
| 1551 | |
| 1552 | return 0; |
| 1553 | } |
| 1554 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1555 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1556 | struct net_device *netdev, u8 use_4addr, |
| 1557 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1558 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1559 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 1560 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1561 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1562 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1563 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1564 | |
| 1565 | switch (iftype) { |
| 1566 | case NL80211_IFTYPE_AP_VLAN: |
| 1567 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 1568 | return 0; |
| 1569 | break; |
| 1570 | case NL80211_IFTYPE_STATION: |
| 1571 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 1572 | return 0; |
| 1573 | break; |
| 1574 | default: |
| 1575 | break; |
| 1576 | } |
| 1577 | |
| 1578 | return -EOPNOTSUPP; |
| 1579 | } |
| 1580 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1581 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 1582 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1583 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1584 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1585 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1586 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1587 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1588 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1589 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1590 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1591 | memset(¶ms, 0, sizeof(params)); |
| 1592 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1593 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1594 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1595 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1596 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 1597 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1598 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1599 | if (ntype > NL80211_IFTYPE_MAX) |
| 1600 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 1601 | } |
| 1602 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1603 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1604 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1605 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1606 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 1607 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1608 | if (netif_running(dev)) |
| 1609 | return -EBUSY; |
| 1610 | |
| 1611 | wdev_lock(wdev); |
| 1612 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1613 | IEEE80211_MAX_MESH_ID_LEN); |
| 1614 | wdev->mesh_id_up_len = |
| 1615 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1616 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1617 | wdev->mesh_id_up_len); |
| 1618 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1621 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 1622 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 1623 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1624 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1625 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1626 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1627 | } else { |
| 1628 | params.use_4addr = -1; |
| 1629 | } |
| 1630 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1631 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1632 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 1633 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1634 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 1635 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1636 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1637 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1638 | |
| 1639 | flags = &_flags; |
| 1640 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1641 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1642 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1643 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1644 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1645 | else |
| 1646 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1647 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1648 | if (!err && params.use_4addr != -1) |
| 1649 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 1650 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1651 | return err; |
| 1652 | } |
| 1653 | |
| 1654 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1655 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1657 | struct vif_params params; |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1658 | struct net_device *dev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1659 | int err; |
| 1660 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1661 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1662 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1663 | memset(¶ms, 0, sizeof(params)); |
| 1664 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1665 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1666 | return -EINVAL; |
| 1667 | |
| 1668 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1669 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1670 | if (type > NL80211_IFTYPE_MAX) |
| 1671 | return -EINVAL; |
| 1672 | } |
| 1673 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1674 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1675 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 1676 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1677 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1678 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1679 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 1680 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1681 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1682 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1683 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 1684 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1685 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1686 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1687 | &flags); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1688 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1689 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1690 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1691 | if (IS_ERR(dev)) |
| 1692 | return PTR_ERR(dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1693 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1694 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1695 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1696 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1697 | |
| 1698 | wdev_lock(wdev); |
| 1699 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 1700 | IEEE80211_MAX_MESH_ID_LEN); |
| 1701 | wdev->mesh_id_up_len = |
| 1702 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1703 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 1704 | wdev->mesh_id_up_len); |
| 1705 | wdev_unlock(wdev); |
| 1706 | } |
| 1707 | |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 1708 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1712 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 1714 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1715 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1716 | if (!rdev->ops->del_virtual_intf) |
| 1717 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1718 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1719 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1720 | } |
| 1721 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1722 | struct get_key_cookie { |
| 1723 | struct sk_buff *msg; |
| 1724 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1725 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1726 | }; |
| 1727 | |
| 1728 | static void get_key_callback(void *c, struct key_params *params) |
| 1729 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1730 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1731 | struct get_key_cookie *cookie = c; |
| 1732 | |
| 1733 | if (params->key) |
| 1734 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1735 | params->key_len, params->key); |
| 1736 | |
| 1737 | if (params->seq) |
| 1738 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1739 | params->seq_len, params->seq); |
| 1740 | |
| 1741 | if (params->cipher) |
| 1742 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1743 | params->cipher); |
| 1744 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1745 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1746 | if (!key) |
| 1747 | goto nla_put_failure; |
| 1748 | |
| 1749 | if (params->key) |
| 1750 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1751 | params->key_len, params->key); |
| 1752 | |
| 1753 | if (params->seq) |
| 1754 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1755 | params->seq_len, params->seq); |
| 1756 | |
| 1757 | if (params->cipher) |
| 1758 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1759 | params->cipher); |
| 1760 | |
| 1761 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1762 | |
| 1763 | nla_nest_end(cookie->msg, key); |
| 1764 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1765 | return; |
| 1766 | nla_put_failure: |
| 1767 | cookie->error = 1; |
| 1768 | } |
| 1769 | |
| 1770 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1771 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1773 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1774 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1775 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1776 | const u8 *mac_addr = NULL; |
| 1777 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1778 | struct get_key_cookie cookie = { |
| 1779 | .error = 0, |
| 1780 | }; |
| 1781 | void *hdr; |
| 1782 | struct sk_buff *msg; |
| 1783 | |
| 1784 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1785 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1786 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1787 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1788 | return -EINVAL; |
| 1789 | |
| 1790 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1791 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1792 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1793 | pairwise = !!mac_addr; |
| 1794 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 1795 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 1796 | if (kt >= NUM_NL80211_KEYTYPES) |
| 1797 | return -EINVAL; |
| 1798 | if (kt != NL80211_KEYTYPE_GROUP && |
| 1799 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 1800 | return -EINVAL; |
| 1801 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 1802 | } |
| 1803 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1804 | if (!rdev->ops->get_key) |
| 1805 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1806 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1807 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1808 | if (!msg) |
| 1809 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1810 | |
| 1811 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1812 | NL80211_CMD_NEW_KEY); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1813 | if (IS_ERR(hdr)) |
| 1814 | return PTR_ERR(hdr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1815 | |
| 1816 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1817 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1818 | |
| 1819 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1820 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1821 | if (mac_addr) |
| 1822 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1823 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1824 | if (pairwise && mac_addr && |
| 1825 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 1826 | return -ENOENT; |
| 1827 | |
| 1828 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, |
| 1829 | mac_addr, &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1830 | |
| 1831 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1832 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1833 | |
| 1834 | if (cookie.error) |
| 1835 | goto nla_put_failure; |
| 1836 | |
| 1837 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1838 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1839 | |
| 1840 | nla_put_failure: |
| 1841 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1842 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1843 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1844 | return err; |
| 1845 | } |
| 1846 | |
| 1847 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1848 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1849 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1850 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1851 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1852 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1853 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1854 | err = nl80211_parse_key(info, &key); |
| 1855 | if (err) |
| 1856 | return err; |
| 1857 | |
| 1858 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1859 | return -EINVAL; |
| 1860 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1861 | /* only support setting default key */ |
| 1862 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1863 | return -EINVAL; |
| 1864 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1865 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1866 | |
| 1867 | if (key.def) { |
| 1868 | if (!rdev->ops->set_default_key) { |
| 1869 | err = -EOPNOTSUPP; |
| 1870 | goto out; |
| 1871 | } |
| 1872 | |
| 1873 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1874 | if (err) |
| 1875 | goto out; |
| 1876 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1877 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
| 1878 | key.def_uni, key.def_multi); |
| 1879 | |
| 1880 | if (err) |
| 1881 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1882 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1883 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1884 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1885 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1886 | } else { |
| 1887 | if (key.def_uni || !key.def_multi) { |
| 1888 | err = -EINVAL; |
| 1889 | goto out; |
| 1890 | } |
| 1891 | |
| 1892 | if (!rdev->ops->set_default_mgmt_key) { |
| 1893 | err = -EOPNOTSUPP; |
| 1894 | goto out; |
| 1895 | } |
| 1896 | |
| 1897 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1898 | if (err) |
| 1899 | goto out; |
| 1900 | |
| 1901 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, |
| 1902 | dev, key.idx); |
| 1903 | if (err) |
| 1904 | goto out; |
| 1905 | |
| 1906 | #ifdef CONFIG_CFG80211_WEXT |
| 1907 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 1908 | #endif |
| 1909 | } |
| 1910 | |
| 1911 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1912 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1913 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1914 | return err; |
| 1915 | } |
| 1916 | |
| 1917 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1918 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1919 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1920 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1921 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1922 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1923 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1924 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1925 | err = nl80211_parse_key(info, &key); |
| 1926 | if (err) |
| 1927 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1928 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1929 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1930 | return -EINVAL; |
| 1931 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1932 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1933 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1934 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1935 | if (key.type == -1) { |
| 1936 | if (mac_addr) |
| 1937 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1938 | else |
| 1939 | key.type = NL80211_KEYTYPE_GROUP; |
| 1940 | } |
| 1941 | |
| 1942 | /* for now */ |
| 1943 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1944 | key.type != NL80211_KEYTYPE_GROUP) |
| 1945 | return -EINVAL; |
| 1946 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1947 | if (!rdev->ops->add_key) |
| 1948 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1949 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1950 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 1951 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 1952 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1953 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1954 | |
| 1955 | wdev_lock(dev->ieee80211_ptr); |
| 1956 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1957 | if (!err) |
| 1958 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1959 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1960 | mac_addr, &key.p); |
| 1961 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1962 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1963 | return err; |
| 1964 | } |
| 1965 | |
| 1966 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1967 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1968 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1969 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1970 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1971 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1972 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1973 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1974 | err = nl80211_parse_key(info, &key); |
| 1975 | if (err) |
| 1976 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1977 | |
| 1978 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1979 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1980 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1981 | if (key.type == -1) { |
| 1982 | if (mac_addr) |
| 1983 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 1984 | else |
| 1985 | key.type = NL80211_KEYTYPE_GROUP; |
| 1986 | } |
| 1987 | |
| 1988 | /* for now */ |
| 1989 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 1990 | key.type != NL80211_KEYTYPE_GROUP) |
| 1991 | return -EINVAL; |
| 1992 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1993 | if (!rdev->ops->del_key) |
| 1994 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1995 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1996 | wdev_lock(dev->ieee80211_ptr); |
| 1997 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1998 | |
| 1999 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 2000 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2001 | err = -ENOENT; |
| 2002 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2003 | if (!err) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2004 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
| 2005 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2006 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2007 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2008 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2009 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2010 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2011 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2012 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2013 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 2014 | } |
| 2015 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2016 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2017 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2018 | return err; |
| 2019 | } |
| 2020 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2021 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2022 | { |
| 2023 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 2024 | struct beacon_parameters *info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2025 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2026 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2027 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2028 | struct beacon_parameters params; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2029 | int haveinfo = 0, err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2030 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2031 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 2032 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || |
| 2033 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 2034 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2035 | return -EINVAL; |
| 2036 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2037 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2038 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2039 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2040 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2041 | memset(¶ms, 0, sizeof(params)); |
| 2042 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2043 | switch (info->genlhdr->cmd) { |
| 2044 | case NL80211_CMD_NEW_BEACON: |
| 2045 | /* these are required for NEW_BEACON */ |
| 2046 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 2047 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2048 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 2049 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2050 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2051 | params.interval = |
| 2052 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 2053 | params.dtim_period = |
| 2054 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 2055 | |
| 2056 | err = cfg80211_validate_beacon_int(rdev, params.interval); |
| 2057 | if (err) |
| 2058 | return err; |
| 2059 | |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 2060 | /* |
| 2061 | * In theory, some of these attributes could be required for |
| 2062 | * NEW_BEACON, but since they were not used when the command was |
| 2063 | * originally added, keep them optional for old user space |
| 2064 | * programs to work with drivers that do not need the additional |
| 2065 | * information. |
| 2066 | */ |
| 2067 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2068 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2069 | params.ssid_len = |
| 2070 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2071 | if (params.ssid_len == 0 || |
| 2072 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 2073 | return -EINVAL; |
| 2074 | } |
| 2075 | |
| 2076 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 2077 | params.hidden_ssid = nla_get_u32( |
| 2078 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 2079 | if (params.hidden_ssid != |
| 2080 | NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 2081 | params.hidden_ssid != |
| 2082 | NL80211_HIDDEN_SSID_ZERO_LEN && |
| 2083 | params.hidden_ssid != |
| 2084 | NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 2085 | return -EINVAL; |
| 2086 | } |
| 2087 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 2088 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 2089 | |
| 2090 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 2091 | params.auth_type = nla_get_u32( |
| 2092 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2093 | if (!nl80211_valid_auth_type(params.auth_type)) |
| 2094 | return -EINVAL; |
| 2095 | } else |
| 2096 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 2097 | |
| 2098 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 2099 | NL80211_MAX_NR_CIPHER_SUITES); |
| 2100 | if (err) |
| 2101 | return err; |
| 2102 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2103 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2104 | break; |
| 2105 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2106 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2107 | break; |
| 2108 | default: |
| 2109 | WARN_ON(1); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2110 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2111 | } |
| 2112 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2113 | if (!call) |
| 2114 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2115 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2116 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 2117 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2118 | params.head_len = |
| 2119 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 2120 | haveinfo = 1; |
| 2121 | } |
| 2122 | |
| 2123 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 2124 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2125 | params.tail_len = |
| 2126 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 2127 | haveinfo = 1; |
| 2128 | } |
| 2129 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2130 | if (!haveinfo) |
| 2131 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2132 | |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 2133 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2134 | params.beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2135 | params.beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2136 | } |
| 2137 | |
| 2138 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
| 2139 | params.proberesp_ies = |
| 2140 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2141 | params.proberesp_ies_len = |
| 2142 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
| 2143 | } |
| 2144 | |
| 2145 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
| 2146 | params.assocresp_ies = |
| 2147 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2148 | params.assocresp_ies_len = |
| 2149 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
| 2150 | } |
| 2151 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2152 | err = call(&rdev->wiphy, dev, ¶ms); |
| 2153 | if (!err && params.interval) |
| 2154 | wdev->beacon_interval = params.interval; |
| 2155 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 2159 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2160 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2161 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2162 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2163 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2164 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2165 | if (!rdev->ops->del_beacon) |
| 2166 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2167 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2168 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2169 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2170 | return -EOPNOTSUPP; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2171 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 2172 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
| 2173 | if (!err) |
| 2174 | wdev->beacon_interval = 0; |
| 2175 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2176 | } |
| 2177 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2178 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 2179 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 2180 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 2181 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 2182 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2183 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2184 | }; |
| 2185 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2186 | static int parse_station_flags(struct genl_info *info, |
| 2187 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2188 | { |
| 2189 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2190 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2191 | int flag; |
| 2192 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2193 | /* |
| 2194 | * Try parsing the new attribute first so userspace |
| 2195 | * can specify both for older kernels. |
| 2196 | */ |
| 2197 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 2198 | if (nla) { |
| 2199 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2200 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2201 | sta_flags = nla_data(nla); |
| 2202 | params->sta_flags_mask = sta_flags->mask; |
| 2203 | params->sta_flags_set = sta_flags->set; |
| 2204 | if ((params->sta_flags_mask | |
| 2205 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 2206 | return -EINVAL; |
| 2207 | return 0; |
| 2208 | } |
| 2209 | |
| 2210 | /* if present, parse the old attribute */ |
| 2211 | |
| 2212 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2213 | if (!nla) |
| 2214 | return 0; |
| 2215 | |
| 2216 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 2217 | nla, sta_flags_policy)) |
| 2218 | return -EINVAL; |
| 2219 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2220 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 2221 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2222 | |
| 2223 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 2224 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2225 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2226 | |
| 2227 | return 0; |
| 2228 | } |
| 2229 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2230 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 2231 | int attr) |
| 2232 | { |
| 2233 | struct nlattr *rate; |
| 2234 | u16 bitrate; |
| 2235 | |
| 2236 | rate = nla_nest_start(msg, attr); |
| 2237 | if (!rate) |
| 2238 | goto nla_put_failure; |
| 2239 | |
| 2240 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 2241 | bitrate = cfg80211_calculate_bitrate(info); |
| 2242 | if (bitrate > 0) |
| 2243 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 2244 | |
| 2245 | if (info->flags & RATE_INFO_FLAGS_MCS) |
| 2246 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); |
| 2247 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 2248 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 2249 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 2250 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 2251 | |
| 2252 | nla_nest_end(msg, rate); |
| 2253 | return true; |
| 2254 | |
| 2255 | nla_put_failure: |
| 2256 | return false; |
| 2257 | } |
| 2258 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2259 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 2260 | int flags, struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 2261 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2262 | { |
| 2263 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2264 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2265 | |
| 2266 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2267 | if (!hdr) |
| 2268 | return -1; |
| 2269 | |
| 2270 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2271 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 2272 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2273 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 2274 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2275 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 2276 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2277 | goto nla_put_failure; |
Mohammed Shafi Shajakhan | ebe27c9 | 2011-04-08 21:24:24 +0530 | [diff] [blame] | 2278 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) |
| 2279 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 2280 | sinfo->connected_time); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2281 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 2282 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 2283 | sinfo->inactive_time); |
| 2284 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 2285 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 2286 | sinfo->rx_bytes); |
| 2287 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 2288 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 2289 | sinfo->tx_bytes); |
| 2290 | if (sinfo->filled & STATION_INFO_LLID) |
| 2291 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 2292 | sinfo->llid); |
| 2293 | if (sinfo->filled & STATION_INFO_PLID) |
| 2294 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 2295 | sinfo->plid); |
| 2296 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 2297 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 2298 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2299 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 2300 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 2301 | sinfo->signal); |
Bruno Randolf | 541a45a | 2010-12-02 19:12:43 +0900 | [diff] [blame] | 2302 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) |
| 2303 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 2304 | sinfo->signal_avg); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2305 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2306 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 2307 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2308 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 2309 | } |
| 2310 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 2311 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 2312 | NL80211_STA_INFO_RX_BITRATE)) |
| 2313 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 2314 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 2315 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 2316 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 2317 | sinfo->rx_packets); |
| 2318 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 2319 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 2320 | sinfo->tx_packets); |
Bruno Randolf | b206b4e | 2010-10-06 18:34:12 +0900 | [diff] [blame] | 2321 | if (sinfo->filled & STATION_INFO_TX_RETRIES) |
| 2322 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 2323 | sinfo->tx_retries); |
| 2324 | if (sinfo->filled & STATION_INFO_TX_FAILED) |
| 2325 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, |
| 2326 | sinfo->tx_failed); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 2327 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 2328 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 2329 | if (!bss_param) |
| 2330 | goto nla_put_failure; |
| 2331 | |
| 2332 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) |
| 2333 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); |
| 2334 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) |
| 2335 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); |
| 2336 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) |
| 2337 | NLA_PUT_FLAG(msg, |
| 2338 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); |
| 2339 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 2340 | sinfo->bss_param.dtim_period); |
| 2341 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 2342 | sinfo->bss_param.beacon_interval); |
| 2343 | |
| 2344 | nla_nest_end(msg, bss_param); |
| 2345 | } |
Helmut Schaa | bb6e753 | 2011-10-13 16:30:39 +0200 | [diff] [blame] | 2346 | if (sinfo->filled & STATION_INFO_STA_FLAGS) |
| 2347 | NLA_PUT(msg, NL80211_STA_INFO_STA_FLAGS, |
| 2348 | sizeof(struct nl80211_sta_flag_update), |
| 2349 | &sinfo->sta_flags); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2350 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2351 | |
Felix Fietkau | 040bdf7 | 2011-08-10 19:00:33 -0600 | [diff] [blame] | 2352 | if (sinfo->filled & STATION_INFO_ASSOC_REQ_IES) |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 2353 | NLA_PUT(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 2354 | sinfo->assoc_req_ies); |
| 2355 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2356 | return genlmsg_end(msg, hdr); |
| 2357 | |
| 2358 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2359 | genlmsg_cancel(msg, hdr); |
| 2360 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2361 | } |
| 2362 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2363 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2364 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2365 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2366 | struct station_info sinfo; |
| 2367 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2368 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2369 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2370 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2371 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2372 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2373 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2374 | if (err) |
| 2375 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2376 | |
| 2377 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2378 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2379 | goto out_err; |
| 2380 | } |
| 2381 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2382 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 2383 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2384 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 2385 | mac_addr, &sinfo); |
| 2386 | if (err == -ENOENT) |
| 2387 | break; |
| 2388 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2389 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2390 | |
| 2391 | if (nl80211_send_station(skb, |
| 2392 | NETLINK_CB(cb->skb).pid, |
| 2393 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2394 | netdev, mac_addr, |
| 2395 | &sinfo) < 0) |
| 2396 | goto out; |
| 2397 | |
| 2398 | sta_idx++; |
| 2399 | } |
| 2400 | |
| 2401 | |
| 2402 | out: |
| 2403 | cb->args[1] = sta_idx; |
| 2404 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2405 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2406 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2407 | |
| 2408 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2409 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2410 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2411 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 2412 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2413 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2414 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2415 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2416 | struct sk_buff *msg; |
| 2417 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2418 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2419 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2420 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2421 | |
| 2422 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2423 | return -EINVAL; |
| 2424 | |
| 2425 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2426 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2427 | if (!rdev->ops->get_station) |
| 2428 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2429 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2430 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2431 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2432 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2433 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2434 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2435 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2436 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2437 | |
| 2438 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2439 | dev, mac_addr, &sinfo) < 0) { |
| 2440 | nlmsg_free(msg); |
| 2441 | return -ENOBUFS; |
| 2442 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 2443 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2444 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2448 | * 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] | 2449 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2450 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2451 | struct cfg80211_registered_device *rdev, |
| 2452 | struct net_device **vlan) |
| 2453 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2454 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2455 | *vlan = NULL; |
| 2456 | |
| 2457 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2458 | *vlan = dev_get_by_index(genl_info_net(info), |
| 2459 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2460 | if (!*vlan) |
| 2461 | return -ENODEV; |
| 2462 | if (!(*vlan)->ieee80211_ptr) |
| 2463 | return -EINVAL; |
| 2464 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 2465 | return -EINVAL; |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 2466 | if (!netif_running(*vlan)) |
| 2467 | return -ENETDOWN; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2468 | } |
| 2469 | return 0; |
| 2470 | } |
| 2471 | |
| 2472 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 2473 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2475 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2476 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2477 | struct station_parameters params; |
| 2478 | u8 *mac_addr = NULL; |
| 2479 | |
| 2480 | memset(¶ms, 0, sizeof(params)); |
| 2481 | |
| 2482 | params.listen_interval = -1; |
Javier Cardona | 57cf804 | 2011-05-13 10:45:43 -0700 | [diff] [blame] | 2483 | params.plink_state = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2484 | |
| 2485 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 2486 | return -EINVAL; |
| 2487 | |
| 2488 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2489 | return -EINVAL; |
| 2490 | |
| 2491 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2492 | |
| 2493 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 2494 | params.supported_rates = |
| 2495 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2496 | params.supported_rates_len = |
| 2497 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2498 | } |
| 2499 | |
| 2500 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2501 | params.listen_interval = |
| 2502 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 2503 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2504 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2505 | params.ht_capa = |
| 2506 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 2507 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2508 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2509 | return -EINVAL; |
| 2510 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2511 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2512 | params.plink_action = |
| 2513 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2514 | |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 2515 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
| 2516 | params.plink_state = |
| 2517 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 2518 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2519 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2520 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2521 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2522 | |
| 2523 | /* validate settings */ |
| 2524 | err = 0; |
| 2525 | |
| 2526 | switch (dev->ieee80211_ptr->iftype) { |
| 2527 | case NL80211_IFTYPE_AP: |
| 2528 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2529 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2530 | /* disallow mesh-specific things */ |
| 2531 | if (params.plink_action) |
| 2532 | err = -EINVAL; |
| 2533 | break; |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2534 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2535 | case NL80211_IFTYPE_STATION: |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2536 | /* disallow things sta doesn't support */ |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2537 | if (params.plink_action) |
| 2538 | err = -EINVAL; |
| 2539 | if (params.vlan) |
| 2540 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2541 | if (params.supported_rates && |
| 2542 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2543 | err = -EINVAL; |
| 2544 | if (params.ht_capa) |
| 2545 | err = -EINVAL; |
| 2546 | if (params.listen_interval >= 0) |
| 2547 | err = -EINVAL; |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2548 | if (params.sta_flags_mask & |
| 2549 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 2550 | BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 2551 | err = -EINVAL; |
| 2552 | /* can't change the TDLS bit */ |
| 2553 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2554 | (params.sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2555 | err = -EINVAL; |
| 2556 | break; |
| 2557 | case NL80211_IFTYPE_MESH_POINT: |
| 2558 | /* disallow things mesh doesn't support */ |
| 2559 | if (params.vlan) |
| 2560 | err = -EINVAL; |
| 2561 | if (params.ht_capa) |
| 2562 | err = -EINVAL; |
| 2563 | if (params.listen_interval >= 0) |
| 2564 | err = -EINVAL; |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2565 | if (params.sta_flags_mask & |
| 2566 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
Thomas Pedersen | 8429828 | 2011-05-03 16:57:13 -0700 | [diff] [blame] | 2567 | BIT(NL80211_STA_FLAG_MFP) | |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 2568 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2569 | err = -EINVAL; |
| 2570 | break; |
| 2571 | default: |
| 2572 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 2573 | } |
| 2574 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2575 | if (err) |
| 2576 | goto out; |
| 2577 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2578 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2579 | err = -EOPNOTSUPP; |
| 2580 | goto out; |
| 2581 | } |
| 2582 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2583 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2584 | |
| 2585 | out: |
| 2586 | if (params.vlan) |
| 2587 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2588 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2589 | return err; |
| 2590 | } |
| 2591 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2592 | static struct nla_policy |
| 2593 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { |
| 2594 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 2595 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 2596 | }; |
| 2597 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2598 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 2599 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2600 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2601 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2602 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2603 | struct station_parameters params; |
| 2604 | u8 *mac_addr = NULL; |
| 2605 | |
| 2606 | memset(¶ms, 0, sizeof(params)); |
| 2607 | |
| 2608 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2609 | return -EINVAL; |
| 2610 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2611 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 2612 | return -EINVAL; |
| 2613 | |
| 2614 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 2615 | return -EINVAL; |
| 2616 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2617 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 2618 | return -EINVAL; |
| 2619 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2620 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2621 | params.supported_rates = |
| 2622 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2623 | params.supported_rates_len = |
| 2624 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 2625 | params.listen_interval = |
| 2626 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2627 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2628 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 2629 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 2630 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 2631 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 2632 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 2633 | params.ht_capa = |
| 2634 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2635 | |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2636 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 2637 | params.plink_action = |
| 2638 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 2639 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 2640 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2641 | return -EINVAL; |
| 2642 | |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2643 | /* parse WME attributes if sta is WME capable */ |
Eliad Peller | cedb541 | 2011-08-31 11:29:43 +0300 | [diff] [blame] | 2644 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Arik Nemtsov | cd32984 | 2011-09-26 09:36:42 +0300 | [diff] [blame] | 2645 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2646 | info->attrs[NL80211_ATTR_STA_WME]) { |
| 2647 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 2648 | struct nlattr *nla; |
| 2649 | |
| 2650 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 2651 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 2652 | nl80211_sta_wme_policy); |
| 2653 | if (err) |
| 2654 | return err; |
| 2655 | |
| 2656 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 2657 | params.uapsd_queues = |
| 2658 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2659 | if (params.uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 2660 | return -EINVAL; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2661 | |
| 2662 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 2663 | params.max_sp = |
| 2664 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 2665 | |
| 2666 | if (params.max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 2667 | return -EINVAL; |
Johannes Berg | 3b9ce80 | 2011-09-27 20:56:12 +0200 | [diff] [blame] | 2668 | |
| 2669 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 2670 | } |
| 2671 | |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2672 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2673 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 2674 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 2675 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO && |
| 2676 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) |
| 2677 | return -EINVAL; |
| 2678 | |
| 2679 | /* |
| 2680 | * Only managed stations can add TDLS peers, and only when the |
| 2681 | * wiphy supports external TDLS setup. |
| 2682 | */ |
| 2683 | if (dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION && |
| 2684 | !((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 2685 | (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
| 2686 | (rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2687 | return -EINVAL; |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 2688 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2689 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2690 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2691 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 2692 | |
| 2693 | /* validate settings */ |
| 2694 | err = 0; |
| 2695 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2696 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2697 | err = -EOPNOTSUPP; |
| 2698 | goto out; |
| 2699 | } |
| 2700 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2701 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2702 | |
| 2703 | out: |
| 2704 | if (params.vlan) |
| 2705 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2706 | return err; |
| 2707 | } |
| 2708 | |
| 2709 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2710 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2712 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2713 | u8 *mac_addr = NULL; |
| 2714 | |
| 2715 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2716 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2717 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2718 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 2719 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2720 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2721 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2722 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2723 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2724 | if (!rdev->ops->del_station) |
| 2725 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2726 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2727 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2728 | } |
| 2729 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2730 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2731 | int flags, struct net_device *dev, |
| 2732 | u8 *dst, u8 *next_hop, |
| 2733 | struct mpath_info *pinfo) |
| 2734 | { |
| 2735 | void *hdr; |
| 2736 | struct nlattr *pinfoattr; |
| 2737 | |
| 2738 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2739 | if (!hdr) |
| 2740 | return -1; |
| 2741 | |
| 2742 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2743 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2744 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2745 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2746 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2747 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2748 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2749 | if (!pinfoattr) |
| 2750 | goto nla_put_failure; |
| 2751 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2752 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2753 | pinfo->frame_qlen); |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 2754 | if (pinfo->filled & MPATH_INFO_SN) |
| 2755 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, |
| 2756 | pinfo->sn); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2757 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2758 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2759 | pinfo->metric); |
| 2760 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2761 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2762 | pinfo->exptime); |
| 2763 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2764 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2765 | pinfo->flags); |
| 2766 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2767 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2768 | pinfo->discovery_timeout); |
| 2769 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2770 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2771 | pinfo->discovery_retries); |
| 2772 | |
| 2773 | nla_nest_end(msg, pinfoattr); |
| 2774 | |
| 2775 | return genlmsg_end(msg, hdr); |
| 2776 | |
| 2777 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2778 | genlmsg_cancel(msg, hdr); |
| 2779 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2783 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2784 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2785 | struct mpath_info pinfo; |
| 2786 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2787 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2788 | u8 dst[ETH_ALEN]; |
| 2789 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2790 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2791 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2792 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2793 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 2794 | if (err) |
| 2795 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2796 | |
| 2797 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2798 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2799 | goto out_err; |
| 2800 | } |
| 2801 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2802 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2803 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2804 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2805 | } |
| 2806 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2807 | while (1) { |
| 2808 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2809 | dst, next_hop, &pinfo); |
| 2810 | if (err == -ENOENT) |
| 2811 | break; |
| 2812 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2813 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2814 | |
| 2815 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2816 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2817 | netdev, dst, next_hop, |
| 2818 | &pinfo) < 0) |
| 2819 | goto out; |
| 2820 | |
| 2821 | path_idx++; |
| 2822 | } |
| 2823 | |
| 2824 | |
| 2825 | out: |
| 2826 | cb->args[1] = path_idx; |
| 2827 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2828 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 2829 | nl80211_finish_netdev_dump(dev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2830 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2834 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2835 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2836 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2837 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2838 | struct mpath_info pinfo; |
| 2839 | struct sk_buff *msg; |
| 2840 | u8 *dst = NULL; |
| 2841 | u8 next_hop[ETH_ALEN]; |
| 2842 | |
| 2843 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2844 | |
| 2845 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2846 | return -EINVAL; |
| 2847 | |
| 2848 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2849 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2850 | if (!rdev->ops->get_mpath) |
| 2851 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2852 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2853 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2854 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2855 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2856 | 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] | 2857 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2858 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2859 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2860 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2861 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2862 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2863 | |
| 2864 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2865 | dev, dst, next_hop, &pinfo) < 0) { |
| 2866 | nlmsg_free(msg); |
| 2867 | return -ENOBUFS; |
| 2868 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2869 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2870 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2874 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2876 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2877 | u8 *dst = NULL; |
| 2878 | u8 *next_hop = NULL; |
| 2879 | |
| 2880 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2881 | return -EINVAL; |
| 2882 | |
| 2883 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2884 | return -EINVAL; |
| 2885 | |
| 2886 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2887 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2888 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2889 | if (!rdev->ops->change_mpath) |
| 2890 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2891 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2892 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2893 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2894 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2895 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2896 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2897 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2898 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2899 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2900 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2901 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2902 | u8 *dst = NULL; |
| 2903 | u8 *next_hop = NULL; |
| 2904 | |
| 2905 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2906 | return -EINVAL; |
| 2907 | |
| 2908 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2909 | return -EINVAL; |
| 2910 | |
| 2911 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2912 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2913 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2914 | if (!rdev->ops->add_mpath) |
| 2915 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 2918 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2919 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2920 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2924 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2926 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2927 | u8 *dst = NULL; |
| 2928 | |
| 2929 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2930 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2931 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2932 | if (!rdev->ops->del_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 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2936 | } |
| 2937 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2938 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2939 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2940 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2941 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2942 | struct bss_parameters params; |
| 2943 | |
| 2944 | memset(¶ms, 0, sizeof(params)); |
| 2945 | /* default to not changing parameters */ |
| 2946 | params.use_cts_prot = -1; |
| 2947 | params.use_short_preamble = -1; |
| 2948 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2949 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2950 | params.ht_opmode = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2951 | |
| 2952 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2953 | params.use_cts_prot = |
| 2954 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2955 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2956 | params.use_short_preamble = |
| 2957 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2958 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2959 | params.use_short_slot_time = |
| 2960 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2961 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2962 | params.basic_rates = |
| 2963 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2964 | params.basic_rates_len = |
| 2965 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2966 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 2967 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 2968 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 2969 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 2970 | params.ht_opmode = |
| 2971 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2972 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2973 | if (!rdev->ops->change_bss) |
| 2974 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2975 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2976 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2977 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2978 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2979 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2980 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2981 | } |
| 2982 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 2983 | 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] | 2984 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2985 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2986 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2987 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2988 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2989 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2990 | }; |
| 2991 | |
| 2992 | static int parse_reg_rule(struct nlattr *tb[], |
| 2993 | struct ieee80211_reg_rule *reg_rule) |
| 2994 | { |
| 2995 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2996 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2997 | |
| 2998 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2999 | return -EINVAL; |
| 3000 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 3001 | return -EINVAL; |
| 3002 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 3003 | return -EINVAL; |
| 3004 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 3005 | return -EINVAL; |
| 3006 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 3007 | return -EINVAL; |
| 3008 | |
| 3009 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 3010 | |
| 3011 | freq_range->start_freq_khz = |
| 3012 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 3013 | freq_range->end_freq_khz = |
| 3014 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 3015 | freq_range->max_bandwidth_khz = |
| 3016 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 3017 | |
| 3018 | power_rule->max_eirp = |
| 3019 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 3020 | |
| 3021 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 3022 | power_rule->max_antenna_gain = |
| 3023 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 3024 | |
| 3025 | return 0; |
| 3026 | } |
| 3027 | |
| 3028 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3029 | { |
| 3030 | int r; |
| 3031 | char *data = NULL; |
| 3032 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3033 | /* |
| 3034 | * You should only get this when cfg80211 hasn't yet initialized |
| 3035 | * completely when built-in to the kernel right between the time |
| 3036 | * window between nl80211_init() and regulatory_init(), if that is |
| 3037 | * even possible. |
| 3038 | */ |
| 3039 | mutex_lock(&cfg80211_mutex); |
| 3040 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3041 | mutex_unlock(&cfg80211_mutex); |
| 3042 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3043 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3044 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 3045 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3046 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3047 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3048 | |
| 3049 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3050 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 3051 | r = regulatory_hint_user(data); |
| 3052 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3053 | return r; |
| 3054 | } |
| 3055 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3056 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3057 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3058 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3060 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3061 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3062 | struct mesh_config cur_params; |
| 3063 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3064 | void *hdr; |
| 3065 | struct nlattr *pinfoattr; |
| 3066 | struct sk_buff *msg; |
| 3067 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3068 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3069 | return -EOPNOTSUPP; |
| 3070 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3071 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3072 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 3073 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3074 | wdev_lock(wdev); |
| 3075 | /* If not connected, get default parameters */ |
| 3076 | if (!wdev->mesh_id_len) |
| 3077 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 3078 | else |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3079 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3080 | &cur_params); |
| 3081 | wdev_unlock(wdev); |
| 3082 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3083 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3084 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3085 | |
| 3086 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3087 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3088 | if (!msg) |
| 3089 | return -ENOMEM; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3090 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3091 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3092 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3093 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3094 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3095 | if (!pinfoattr) |
| 3096 | goto nla_put_failure; |
| 3097 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 3098 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 3099 | cur_params.dot11MeshRetryTimeout); |
| 3100 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 3101 | cur_params.dot11MeshConfirmTimeout); |
| 3102 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 3103 | cur_params.dot11MeshHoldingTimeout); |
| 3104 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 3105 | cur_params.dot11MeshMaxPeerLinks); |
| 3106 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 3107 | cur_params.dot11MeshMaxRetries); |
| 3108 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 3109 | cur_params.dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3110 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 3111 | cur_params.element_ttl); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3112 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 3113 | cur_params.auto_open_plinks); |
| 3114 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3115 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 3116 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 3117 | cur_params.path_refresh_time); |
| 3118 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3119 | cur_params.min_discovery_timeout); |
| 3120 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3121 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 3122 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3123 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 3124 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3125 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3126 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3127 | cur_params.dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3128 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3129 | cur_params.dot11MeshHWMPRannInterval); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3130 | NLA_PUT_U8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3131 | cur_params.dot11MeshGateAnnouncementProtocol); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3132 | nla_nest_end(msg, pinfoattr); |
| 3133 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3134 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3135 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3136 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3137 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3138 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3139 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3140 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3141 | } |
| 3142 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 3143 | 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] | 3144 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 3145 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 3146 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 3147 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 3148 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 3149 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3150 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3151 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 3152 | |
| 3153 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 3154 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 3155 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 3156 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 3157 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 3158 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 3159 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3160 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3161 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3162 | }; |
| 3163 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3164 | static const struct nla_policy |
| 3165 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
| 3166 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 3167 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 3168 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3169 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3170 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3171 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3172 | }; |
| 3173 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3174 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3175 | struct mesh_config *cfg, |
| 3176 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3177 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3178 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3179 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3180 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3181 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 3182 | do {\ |
| 3183 | if (table[attr_num]) {\ |
| 3184 | cfg->param = nla_fn(table[attr_num]); \ |
| 3185 | mask |= (1 << (attr_num - 1)); \ |
| 3186 | } \ |
| 3187 | } while (0);\ |
| 3188 | |
| 3189 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3190 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3191 | return -EINVAL; |
| 3192 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3193 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3194 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3195 | return -EINVAL; |
| 3196 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3197 | /* This makes sure that there aren't more than 32 mesh config |
| 3198 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 3199 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 3200 | |
| 3201 | /* Fill in the params struct */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3202 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 3203 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 3204 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 3205 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 3206 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 3207 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 3208 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 3209 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 3210 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 3211 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 3212 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 3213 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 3214 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
| 3215 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3216 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 3217 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 3218 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 3219 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 3220 | nla_get_u8); |
| 3221 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 3222 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 3223 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 3224 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 3225 | nla_get_u16); |
| 3226 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 3227 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 3228 | nla_get_u32); |
| 3229 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 3230 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 3231 | nla_get_u16); |
| 3232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3233 | dot11MeshHWMPnetDiameterTraversalTime, |
| 3234 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 3235 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 3236 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3237 | dot11MeshHWMPRootMode, mask, |
| 3238 | NL80211_MESHCONF_HWMP_ROOTMODE, |
| 3239 | nla_get_u8); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 3240 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3241 | dot11MeshHWMPRannInterval, mask, |
| 3242 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 3243 | nla_get_u16); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 3244 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 3245 | dot11MeshGateAnnouncementProtocol, mask, |
| 3246 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 3247 | nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3248 | if (mask_out) |
| 3249 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3250 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3251 | return 0; |
| 3252 | |
| 3253 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 3254 | } |
| 3255 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3256 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 3257 | struct mesh_setup *setup) |
| 3258 | { |
| 3259 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 3260 | |
| 3261 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 3262 | return -EINVAL; |
| 3263 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 3264 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 3265 | nl80211_mesh_setup_params_policy)) |
| 3266 | return -EINVAL; |
| 3267 | |
| 3268 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 3269 | setup->path_sel_proto = |
| 3270 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 3271 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 3272 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 3273 | |
| 3274 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 3275 | setup->path_metric = |
| 3276 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 3277 | IEEE80211_PATH_METRIC_VENDOR : |
| 3278 | IEEE80211_PATH_METRIC_AIRTIME; |
| 3279 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3280 | |
| 3281 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3282 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3283 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3284 | if (!is_valid_ie_attr(ieattr)) |
| 3285 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 3286 | setup->ie = nla_data(ieattr); |
| 3287 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3288 | } |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 3289 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 3290 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 3291 | |
| 3292 | return 0; |
| 3293 | } |
| 3294 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3295 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3296 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3297 | { |
| 3298 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3299 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3300 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3301 | struct mesh_config cfg; |
| 3302 | u32 mask; |
| 3303 | int err; |
| 3304 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3305 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 3306 | return -EOPNOTSUPP; |
| 3307 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3308 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3309 | return -EOPNOTSUPP; |
| 3310 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3311 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 3312 | if (err) |
| 3313 | return err; |
| 3314 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3315 | wdev_lock(wdev); |
| 3316 | if (!wdev->mesh_id_len) |
| 3317 | err = -ENOLINK; |
| 3318 | |
| 3319 | if (!err) |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3320 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3321 | mask, &cfg); |
| 3322 | |
| 3323 | wdev_unlock(wdev); |
| 3324 | |
| 3325 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3328 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 3329 | { |
| 3330 | struct sk_buff *msg; |
| 3331 | void *hdr = NULL; |
| 3332 | struct nlattr *nl_reg_rules; |
| 3333 | unsigned int i; |
| 3334 | int err = -EINVAL; |
| 3335 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3336 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3337 | |
| 3338 | if (!cfg80211_regdomain) |
| 3339 | goto out; |
| 3340 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3341 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3342 | if (!msg) { |
| 3343 | err = -ENOBUFS; |
| 3344 | goto out; |
| 3345 | } |
| 3346 | |
| 3347 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 3348 | NL80211_CMD_GET_REG); |
| 3349 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3350 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3351 | |
| 3352 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 3353 | cfg80211_regdomain->alpha2); |
| 3354 | |
| 3355 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 3356 | if (!nl_reg_rules) |
| 3357 | goto nla_put_failure; |
| 3358 | |
| 3359 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 3360 | struct nlattr *nl_reg_rule; |
| 3361 | const struct ieee80211_reg_rule *reg_rule; |
| 3362 | const struct ieee80211_freq_range *freq_range; |
| 3363 | const struct ieee80211_power_rule *power_rule; |
| 3364 | |
| 3365 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 3366 | freq_range = ®_rule->freq_range; |
| 3367 | power_rule = ®_rule->power_rule; |
| 3368 | |
| 3369 | nl_reg_rule = nla_nest_start(msg, i); |
| 3370 | if (!nl_reg_rule) |
| 3371 | goto nla_put_failure; |
| 3372 | |
| 3373 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 3374 | reg_rule->flags); |
| 3375 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 3376 | freq_range->start_freq_khz); |
| 3377 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 3378 | freq_range->end_freq_khz); |
| 3379 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 3380 | freq_range->max_bandwidth_khz); |
| 3381 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 3382 | power_rule->max_antenna_gain); |
| 3383 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 3384 | power_rule->max_eirp); |
| 3385 | |
| 3386 | nla_nest_end(msg, nl_reg_rule); |
| 3387 | } |
| 3388 | |
| 3389 | nla_nest_end(msg, nl_reg_rules); |
| 3390 | |
| 3391 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3392 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3393 | goto out; |
| 3394 | |
| 3395 | nla_put_failure: |
| 3396 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 3397 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 3398 | nlmsg_free(msg); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3399 | err = -EMSGSIZE; |
| 3400 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3401 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3402 | return err; |
| 3403 | } |
| 3404 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3405 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 3406 | { |
| 3407 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 3408 | struct nlattr *nl_reg_rule; |
| 3409 | char *alpha2 = NULL; |
| 3410 | int rem_reg_rules = 0, r = 0; |
| 3411 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 3412 | struct ieee80211_regdomain *rd = NULL; |
| 3413 | |
| 3414 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 3415 | return -EINVAL; |
| 3416 | |
| 3417 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 3418 | return -EINVAL; |
| 3419 | |
| 3420 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 3421 | |
| 3422 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3423 | rem_reg_rules) { |
| 3424 | num_rules++; |
| 3425 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 3426 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3429 | mutex_lock(&cfg80211_mutex); |
| 3430 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3431 | if (!reg_is_valid_request(alpha2)) { |
| 3432 | r = -EINVAL; |
| 3433 | goto bad_reg; |
| 3434 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3435 | |
| 3436 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 3437 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 3438 | |
| 3439 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3440 | if (!rd) { |
| 3441 | r = -ENOMEM; |
| 3442 | goto bad_reg; |
| 3443 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3444 | |
| 3445 | rd->n_reg_rules = num_rules; |
| 3446 | rd->alpha2[0] = alpha2[0]; |
| 3447 | rd->alpha2[1] = alpha2[1]; |
| 3448 | |
| 3449 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 3450 | rem_reg_rules) { |
| 3451 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 3452 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 3453 | reg_rule_policy); |
| 3454 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 3455 | if (r) |
| 3456 | goto bad_reg; |
| 3457 | |
| 3458 | rule_idx++; |
| 3459 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3460 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 3461 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3462 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3463 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | BUG_ON(rule_idx != num_rules); |
| 3467 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3468 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3469 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 3470 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3471 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3472 | return r; |
| 3473 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 3474 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 3475 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3476 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 3477 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3480 | static int validate_scan_freqs(struct nlattr *freqs) |
| 3481 | { |
| 3482 | struct nlattr *attr1, *attr2; |
| 3483 | int n_channels = 0, tmp1, tmp2; |
| 3484 | |
| 3485 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 3486 | n_channels++; |
| 3487 | /* |
| 3488 | * Some hardware has a limited channel list for |
| 3489 | * scanning, and it is pretty much nonsensical |
| 3490 | * to scan for a channel twice, so disallow that |
| 3491 | * and don't require drivers to check that the |
| 3492 | * channel list they get isn't longer than what |
| 3493 | * they can scan, as long as they can scan all |
| 3494 | * the channels they registered at once. |
| 3495 | */ |
| 3496 | nla_for_each_nested(attr2, freqs, tmp2) |
| 3497 | if (attr1 != attr2 && |
| 3498 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 3499 | return 0; |
| 3500 | } |
| 3501 | |
| 3502 | return n_channels; |
| 3503 | } |
| 3504 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3505 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 3506 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3508 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3509 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3510 | struct nlattr *attr; |
| 3511 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3512 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3513 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3514 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3515 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3516 | return -EINVAL; |
| 3517 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3518 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3519 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3520 | if (!rdev->ops->scan) |
| 3521 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3522 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3523 | if (rdev->scan_req) |
| 3524 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3525 | |
| 3526 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3527 | n_channels = validate_scan_freqs( |
| 3528 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3529 | if (!n_channels) |
| 3530 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3531 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3532 | enum ieee80211_band band; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 3533 | n_channels = 0; |
| 3534 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3535 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3536 | if (wiphy->bands[band]) |
| 3537 | n_channels += wiphy->bands[band]->n_channels; |
| 3538 | } |
| 3539 | |
| 3540 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3541 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 3542 | n_ssids++; |
| 3543 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3544 | if (n_ssids > wiphy->max_scan_ssids) |
| 3545 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3546 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3547 | if (info->attrs[NL80211_ATTR_IE]) |
| 3548 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3549 | else |
| 3550 | ie_len = 0; |
| 3551 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3552 | if (ie_len > wiphy->max_scan_ie_len) |
| 3553 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 3554 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3555 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3556 | + sizeof(*request->ssids) * n_ssids |
| 3557 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3558 | + ie_len, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3559 | if (!request) |
| 3560 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3561 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3562 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 3563 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3564 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3565 | if (ie_len) { |
| 3566 | if (request->ssids) |
| 3567 | request->ie = (void *)(request->ssids + n_ssids); |
| 3568 | else |
| 3569 | request->ie = (void *)(request->channels + n_channels); |
| 3570 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3571 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3572 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3573 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3574 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3575 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3576 | struct ieee80211_channel *chan; |
| 3577 | |
| 3578 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3579 | |
| 3580 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3581 | err = -EINVAL; |
| 3582 | goto out_free; |
| 3583 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3584 | |
| 3585 | /* ignore disabled channels */ |
| 3586 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3587 | continue; |
| 3588 | |
| 3589 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3590 | i++; |
| 3591 | } |
| 3592 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3593 | enum ieee80211_band band; |
| 3594 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3595 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3596 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3597 | int j; |
| 3598 | if (!wiphy->bands[band]) |
| 3599 | continue; |
| 3600 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3601 | struct ieee80211_channel *chan; |
| 3602 | |
| 3603 | chan = &wiphy->bands[band]->channels[j]; |
| 3604 | |
| 3605 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3606 | continue; |
| 3607 | |
| 3608 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3609 | i++; |
| 3610 | } |
| 3611 | } |
| 3612 | } |
| 3613 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 3614 | if (!i) { |
| 3615 | err = -EINVAL; |
| 3616 | goto out_free; |
| 3617 | } |
| 3618 | |
| 3619 | request->n_channels = i; |
| 3620 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3621 | i = 0; |
| 3622 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3623 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3624 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3625 | err = -EINVAL; |
| 3626 | goto out_free; |
| 3627 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3628 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3629 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3630 | i++; |
| 3631 | } |
| 3632 | } |
| 3633 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3634 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3635 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3636 | memcpy((void *)request->ie, |
| 3637 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3638 | request->ie_len); |
| 3639 | } |
| 3640 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3641 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 3642 | if (wiphy->bands[i]) |
| 3643 | request->rates[i] = |
| 3644 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3645 | |
| 3646 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 3647 | nla_for_each_nested(attr, |
| 3648 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 3649 | tmp) { |
| 3650 | enum ieee80211_band band = nla_type(attr); |
| 3651 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 3652 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 3653 | err = -EINVAL; |
| 3654 | goto out_free; |
| 3655 | } |
| 3656 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 3657 | nla_data(attr), |
| 3658 | nla_len(attr), |
| 3659 | &request->rates[band]); |
| 3660 | if (err) |
| 3661 | goto out_free; |
| 3662 | } |
| 3663 | } |
| 3664 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 3665 | request->no_cck = |
| 3666 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 3667 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3668 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3669 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3670 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3671 | rdev->scan_req = request; |
| 3672 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3673 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3674 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3675 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3676 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3677 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3678 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3679 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3680 | kfree(request); |
| 3681 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3682 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3683 | return err; |
| 3684 | } |
| 3685 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3686 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 3687 | struct genl_info *info) |
| 3688 | { |
| 3689 | struct cfg80211_sched_scan_request *request; |
| 3690 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3691 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3692 | struct nlattr *attr; |
| 3693 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3694 | 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] | 3695 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3696 | enum ieee80211_band band; |
| 3697 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3698 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3699 | |
| 3700 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3701 | !rdev->ops->sched_scan_start) |
| 3702 | return -EOPNOTSUPP; |
| 3703 | |
| 3704 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3705 | return -EINVAL; |
| 3706 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3707 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 3708 | return -EINVAL; |
| 3709 | |
| 3710 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 3711 | if (interval == 0) |
| 3712 | return -EINVAL; |
| 3713 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3714 | wiphy = &rdev->wiphy; |
| 3715 | |
| 3716 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3717 | n_channels = validate_scan_freqs( |
| 3718 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 3719 | if (!n_channels) |
| 3720 | return -EINVAL; |
| 3721 | } else { |
| 3722 | n_channels = 0; |
| 3723 | |
| 3724 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 3725 | if (wiphy->bands[band]) |
| 3726 | n_channels += wiphy->bands[band]->n_channels; |
| 3727 | } |
| 3728 | |
| 3729 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 3730 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3731 | tmp) |
| 3732 | n_ssids++; |
| 3733 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 3734 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3735 | return -EINVAL; |
| 3736 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3737 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
| 3738 | nla_for_each_nested(attr, |
| 3739 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3740 | tmp) |
| 3741 | n_match_sets++; |
| 3742 | |
| 3743 | if (n_match_sets > wiphy->max_match_sets) |
| 3744 | return -EINVAL; |
| 3745 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3746 | if (info->attrs[NL80211_ATTR_IE]) |
| 3747 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3748 | else |
| 3749 | ie_len = 0; |
| 3750 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 3751 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3752 | return -EINVAL; |
| 3753 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3754 | mutex_lock(&rdev->sched_scan_mtx); |
| 3755 | |
| 3756 | if (rdev->sched_scan_req) { |
| 3757 | err = -EINPROGRESS; |
| 3758 | goto out; |
| 3759 | } |
| 3760 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3761 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3762 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3763 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 3764 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3765 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3766 | if (!request) { |
| 3767 | err = -ENOMEM; |
| 3768 | goto out; |
| 3769 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3770 | |
| 3771 | if (n_ssids) |
| 3772 | request->ssids = (void *)&request->channels[n_channels]; |
| 3773 | request->n_ssids = n_ssids; |
| 3774 | if (ie_len) { |
| 3775 | if (request->ssids) |
| 3776 | request->ie = (void *)(request->ssids + n_ssids); |
| 3777 | else |
| 3778 | request->ie = (void *)(request->channels + n_channels); |
| 3779 | } |
| 3780 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3781 | if (n_match_sets) { |
| 3782 | if (request->ie) |
| 3783 | request->match_sets = (void *)(request->ie + ie_len); |
| 3784 | else if (request->ssids) |
| 3785 | request->match_sets = |
| 3786 | (void *)(request->ssids + n_ssids); |
| 3787 | else |
| 3788 | request->match_sets = |
| 3789 | (void *)(request->channels + n_channels); |
| 3790 | } |
| 3791 | request->n_match_sets = n_match_sets; |
| 3792 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3793 | i = 0; |
| 3794 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3795 | /* user specified, bail out if channel not found */ |
| 3796 | nla_for_each_nested(attr, |
| 3797 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 3798 | tmp) { |
| 3799 | struct ieee80211_channel *chan; |
| 3800 | |
| 3801 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3802 | |
| 3803 | if (!chan) { |
| 3804 | err = -EINVAL; |
| 3805 | goto out_free; |
| 3806 | } |
| 3807 | |
| 3808 | /* ignore disabled channels */ |
| 3809 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3810 | continue; |
| 3811 | |
| 3812 | request->channels[i] = chan; |
| 3813 | i++; |
| 3814 | } |
| 3815 | } else { |
| 3816 | /* all channels */ |
| 3817 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3818 | int j; |
| 3819 | if (!wiphy->bands[band]) |
| 3820 | continue; |
| 3821 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 3822 | struct ieee80211_channel *chan; |
| 3823 | |
| 3824 | chan = &wiphy->bands[band]->channels[j]; |
| 3825 | |
| 3826 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3827 | continue; |
| 3828 | |
| 3829 | request->channels[i] = chan; |
| 3830 | i++; |
| 3831 | } |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | if (!i) { |
| 3836 | err = -EINVAL; |
| 3837 | goto out_free; |
| 3838 | } |
| 3839 | |
| 3840 | request->n_channels = i; |
| 3841 | |
| 3842 | i = 0; |
| 3843 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3844 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 3845 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3846 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3847 | err = -EINVAL; |
| 3848 | goto out_free; |
| 3849 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 3850 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3851 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 3852 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3853 | i++; |
| 3854 | } |
| 3855 | } |
| 3856 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 3857 | i = 0; |
| 3858 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 3859 | nla_for_each_nested(attr, |
| 3860 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 3861 | tmp) { |
| 3862 | struct nlattr *ssid; |
| 3863 | |
| 3864 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 3865 | nla_data(attr), nla_len(attr), |
| 3866 | nl80211_match_policy); |
| 3867 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; |
| 3868 | if (ssid) { |
| 3869 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 3870 | err = -EINVAL; |
| 3871 | goto out_free; |
| 3872 | } |
| 3873 | memcpy(request->match_sets[i].ssid.ssid, |
| 3874 | nla_data(ssid), nla_len(ssid)); |
| 3875 | request->match_sets[i].ssid.ssid_len = |
| 3876 | nla_len(ssid); |
| 3877 | } |
| 3878 | i++; |
| 3879 | } |
| 3880 | } |
| 3881 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3882 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3883 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3884 | memcpy((void *)request->ie, |
| 3885 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 3886 | request->ie_len); |
| 3887 | } |
| 3888 | |
| 3889 | request->dev = dev; |
| 3890 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 3891 | request->interval = interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3892 | |
| 3893 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
| 3894 | if (!err) { |
| 3895 | rdev->sched_scan_req = request; |
| 3896 | nl80211_send_sched_scan(rdev, dev, |
| 3897 | NL80211_CMD_START_SCHED_SCAN); |
| 3898 | goto out; |
| 3899 | } |
| 3900 | |
| 3901 | out_free: |
| 3902 | kfree(request); |
| 3903 | out: |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3904 | mutex_unlock(&rdev->sched_scan_mtx); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3905 | return err; |
| 3906 | } |
| 3907 | |
| 3908 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 3909 | struct genl_info *info) |
| 3910 | { |
| 3911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3912 | int err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3913 | |
| 3914 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 3915 | !rdev->ops->sched_scan_stop) |
| 3916 | return -EOPNOTSUPP; |
| 3917 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 3918 | mutex_lock(&rdev->sched_scan_mtx); |
| 3919 | err = __cfg80211_stop_sched_scan(rdev, false); |
| 3920 | mutex_unlock(&rdev->sched_scan_mtx); |
| 3921 | |
| 3922 | return err; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 3923 | } |
| 3924 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3925 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 3926 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3927 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3928 | struct wireless_dev *wdev, |
| 3929 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3930 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3931 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3932 | void *hdr; |
| 3933 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3934 | int i; |
| 3935 | |
| 3936 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3937 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3938 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3939 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3940 | if (!hdr) |
| 3941 | return -1; |
| 3942 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 3943 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 3944 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3945 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3946 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3947 | |
| 3948 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3949 | if (!bss) |
| 3950 | goto nla_put_failure; |
| 3951 | if (!is_zero_ether_addr(res->bssid)) |
| 3952 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3953 | if (res->information_elements && res->len_information_elements) |
| 3954 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3955 | res->len_information_elements, |
| 3956 | res->information_elements); |
Jouni Malinen | 34a6edd | 2010-01-06 16:19:24 +0200 | [diff] [blame] | 3957 | if (res->beacon_ies && res->len_beacon_ies && |
| 3958 | res->beacon_ies != res->information_elements) |
| 3959 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, |
| 3960 | res->len_beacon_ies, res->beacon_ies); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3961 | if (res->tsf) |
| 3962 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3963 | if (res->beacon_interval) |
| 3964 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3965 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3966 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3967 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3968 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3969 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3970 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3971 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3972 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3973 | break; |
| 3974 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3975 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3976 | break; |
| 3977 | default: |
| 3978 | break; |
| 3979 | } |
| 3980 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3981 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3982 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3983 | case NL80211_IFTYPE_STATION: |
| 3984 | if (intbss == wdev->current_bss) |
| 3985 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3986 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3987 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3988 | if (intbss != wdev->auth_bsses[i]) |
| 3989 | continue; |
| 3990 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3991 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3992 | break; |
| 3993 | } |
| 3994 | break; |
| 3995 | case NL80211_IFTYPE_ADHOC: |
| 3996 | if (intbss == wdev->current_bss) |
| 3997 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3998 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3999 | break; |
| 4000 | default: |
| 4001 | break; |
| 4002 | } |
| 4003 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4004 | nla_nest_end(msg, bss); |
| 4005 | |
| 4006 | return genlmsg_end(msg, hdr); |
| 4007 | |
| 4008 | nla_put_failure: |
| 4009 | genlmsg_cancel(msg, hdr); |
| 4010 | return -EMSGSIZE; |
| 4011 | } |
| 4012 | |
| 4013 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 4014 | struct netlink_callback *cb) |
| 4015 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4016 | struct cfg80211_registered_device *rdev; |
| 4017 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4018 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4019 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4020 | int start = cb->args[1], idx = 0; |
| 4021 | int err; |
| 4022 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4023 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
| 4024 | if (err) |
| 4025 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4026 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4027 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4028 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4029 | wdev_lock(wdev); |
| 4030 | spin_lock_bh(&rdev->bss_lock); |
| 4031 | cfg80211_bss_expire(rdev); |
| 4032 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4033 | cb->seq = rdev->bss_generation; |
| 4034 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4035 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4036 | if (++idx <= start) |
| 4037 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 4038 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4039 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4040 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4041 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4042 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4043 | } |
| 4044 | } |
| 4045 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 4046 | spin_unlock_bh(&rdev->bss_lock); |
| 4047 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4048 | |
| 4049 | cb->args[1] = idx; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4050 | nl80211_finish_netdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4051 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4052 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4053 | } |
| 4054 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4055 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
| 4056 | int flags, struct net_device *dev, |
| 4057 | struct survey_info *survey) |
| 4058 | { |
| 4059 | void *hdr; |
| 4060 | struct nlattr *infoattr; |
| 4061 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4062 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 4063 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 4064 | if (!hdr) |
| 4065 | return -ENOMEM; |
| 4066 | |
| 4067 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 4068 | |
| 4069 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 4070 | if (!infoattr) |
| 4071 | goto nla_put_failure; |
| 4072 | |
| 4073 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 4074 | survey->channel->center_freq); |
| 4075 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
| 4076 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
| 4077 | survey->noise); |
Felix Fietkau | 17e5a80 | 2010-09-29 17:15:30 +0200 | [diff] [blame] | 4078 | if (survey->filled & SURVEY_INFO_IN_USE) |
| 4079 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); |
Felix Fietkau | 8610c29 | 2010-10-09 02:39:29 +0200 | [diff] [blame] | 4080 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) |
| 4081 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 4082 | survey->channel_time); |
| 4083 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) |
| 4084 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 4085 | survey->channel_time_busy); |
| 4086 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) |
| 4087 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 4088 | survey->channel_time_ext_busy); |
| 4089 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) |
| 4090 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 4091 | survey->channel_time_rx); |
| 4092 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) |
| 4093 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 4094 | survey->channel_time_tx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4095 | |
| 4096 | nla_nest_end(msg, infoattr); |
| 4097 | |
| 4098 | return genlmsg_end(msg, hdr); |
| 4099 | |
| 4100 | nla_put_failure: |
| 4101 | genlmsg_cancel(msg, hdr); |
| 4102 | return -EMSGSIZE; |
| 4103 | } |
| 4104 | |
| 4105 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 4106 | struct netlink_callback *cb) |
| 4107 | { |
| 4108 | struct survey_info survey; |
| 4109 | struct cfg80211_registered_device *dev; |
| 4110 | struct net_device *netdev; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4111 | int survey_idx = cb->args[1]; |
| 4112 | int res; |
| 4113 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4114 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
| 4115 | if (res) |
| 4116 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4117 | |
| 4118 | if (!dev->ops->dump_survey) { |
| 4119 | res = -EOPNOTSUPP; |
| 4120 | goto out_err; |
| 4121 | } |
| 4122 | |
| 4123 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4124 | struct ieee80211_channel *chan; |
| 4125 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4126 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
| 4127 | &survey); |
| 4128 | if (res == -ENOENT) |
| 4129 | break; |
| 4130 | if (res) |
| 4131 | goto out_err; |
| 4132 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 4133 | /* Survey without a channel doesn't make sense */ |
| 4134 | if (!survey.channel) { |
| 4135 | res = -EINVAL; |
| 4136 | goto out; |
| 4137 | } |
| 4138 | |
| 4139 | chan = ieee80211_get_channel(&dev->wiphy, |
| 4140 | survey.channel->center_freq); |
| 4141 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 4142 | survey_idx++; |
| 4143 | continue; |
| 4144 | } |
| 4145 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4146 | if (nl80211_send_survey(skb, |
| 4147 | NETLINK_CB(cb->skb).pid, |
| 4148 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4149 | netdev, |
| 4150 | &survey) < 0) |
| 4151 | goto out; |
| 4152 | survey_idx++; |
| 4153 | } |
| 4154 | |
| 4155 | out: |
| 4156 | cb->args[1] = survey_idx; |
| 4157 | res = skb->len; |
| 4158 | out_err: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4159 | nl80211_finish_netdev_dump(dev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 4160 | return res; |
| 4161 | } |
| 4162 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4163 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 4164 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4165 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4166 | } |
| 4167 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4168 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 4169 | { |
| 4170 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 4171 | NL80211_WPA_VERSION_2)); |
| 4172 | } |
| 4173 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4174 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 4175 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4177 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4178 | struct ieee80211_channel *chan; |
| 4179 | const u8 *bssid, *ssid, *ie = NULL; |
| 4180 | int err, ssid_len, ie_len = 0; |
| 4181 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4182 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4183 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4184 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4185 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4186 | return -EINVAL; |
| 4187 | |
| 4188 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4189 | return -EINVAL; |
| 4190 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 4191 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 4192 | return -EINVAL; |
| 4193 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4194 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 4195 | return -EINVAL; |
| 4196 | |
| 4197 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 4198 | return -EINVAL; |
| 4199 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4200 | err = nl80211_parse_key(info, &key); |
| 4201 | if (err) |
| 4202 | return err; |
| 4203 | |
| 4204 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4205 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 4206 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4207 | if (!key.p.key || !key.p.key_len) |
| 4208 | return -EINVAL; |
| 4209 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 4210 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 4211 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 4212 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 4213 | return -EINVAL; |
| 4214 | if (key.idx > 4) |
| 4215 | return -EINVAL; |
| 4216 | } else { |
| 4217 | key.p.key_len = 0; |
| 4218 | key.p.key = NULL; |
| 4219 | } |
| 4220 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4221 | if (key.idx >= 0) { |
| 4222 | int i; |
| 4223 | bool ok = false; |
| 4224 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 4225 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 4226 | ok = true; |
| 4227 | break; |
| 4228 | } |
| 4229 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4230 | if (!ok) |
| 4231 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 4232 | } |
| 4233 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4234 | if (!rdev->ops->auth) |
| 4235 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4236 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4237 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4238 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4239 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4240 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4241 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4242 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4243 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4244 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4245 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4246 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4247 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4248 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4249 | |
| 4250 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4251 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4252 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4253 | } |
| 4254 | |
| 4255 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4256 | if (!nl80211_valid_auth_type(auth_type)) |
| 4257 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4258 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4259 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4260 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4261 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 4262 | ssid, ssid_len, ie, ie_len, |
| 4263 | key.p.key, key.p.key_len, key.idx, |
| 4264 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4265 | } |
| 4266 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4267 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 4268 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4269 | struct cfg80211_crypto_settings *settings, |
| 4270 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4271 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 4272 | memset(settings, 0, sizeof(*settings)); |
| 4273 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4274 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 4275 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4276 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 4277 | u16 proto; |
| 4278 | proto = nla_get_u16( |
| 4279 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 4280 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 4281 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 4282 | proto != ETH_P_PAE) |
| 4283 | return -EINVAL; |
| 4284 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 4285 | settings->control_port_no_encrypt = true; |
| 4286 | } else |
| 4287 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 4288 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4289 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 4290 | void *data; |
| 4291 | int len, i; |
| 4292 | |
| 4293 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4294 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 4295 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 4296 | |
| 4297 | if (len % sizeof(u32)) |
| 4298 | return -EINVAL; |
| 4299 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4300 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4301 | return -EINVAL; |
| 4302 | |
| 4303 | memcpy(settings->ciphers_pairwise, data, len); |
| 4304 | |
| 4305 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4306 | if (!cfg80211_supported_cipher_suite( |
| 4307 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4308 | settings->ciphers_pairwise[i])) |
| 4309 | return -EINVAL; |
| 4310 | } |
| 4311 | |
| 4312 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 4313 | settings->cipher_group = |
| 4314 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 4315 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 4316 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4317 | return -EINVAL; |
| 4318 | } |
| 4319 | |
| 4320 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 4321 | settings->wpa_versions = |
| 4322 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 4323 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 4324 | return -EINVAL; |
| 4325 | } |
| 4326 | |
| 4327 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 4328 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 4329 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4330 | |
| 4331 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4332 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 4333 | settings->n_akm_suites = len / sizeof(u32); |
| 4334 | |
| 4335 | if (len % sizeof(u32)) |
| 4336 | return -EINVAL; |
| 4337 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 4338 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4339 | return -EINVAL; |
| 4340 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4341 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | return 0; |
| 4345 | } |
| 4346 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4347 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 4348 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4349 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4350 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4351 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 4352 | struct ieee80211_channel *chan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4353 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4354 | int err, ssid_len, ie_len = 0; |
| 4355 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4356 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4357 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4358 | return -EINVAL; |
| 4359 | |
| 4360 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4361 | !info->attrs[NL80211_ATTR_SSID] || |
| 4362 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4363 | return -EINVAL; |
| 4364 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4365 | if (!rdev->ops->assoc) |
| 4366 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4367 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4368 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4369 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4370 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4371 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4372 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4373 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4374 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 4375 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4376 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
| 4377 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4378 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4379 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4380 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4381 | |
| 4382 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4383 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4384 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4385 | } |
| 4386 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4387 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4388 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4389 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 4390 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4391 | use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4392 | else if (mfp != NL80211_MFP_NO) |
| 4393 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 4394 | } |
| 4395 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4396 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 4397 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 4398 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4399 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4400 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 4401 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 4402 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4403 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4404 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4405 | return err; |
| 4406 | } |
| 4407 | |
| 4408 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 4409 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4410 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4411 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4412 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4413 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4414 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4415 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4416 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4417 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4418 | return -EINVAL; |
| 4419 | |
| 4420 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4421 | return -EINVAL; |
| 4422 | |
| 4423 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4424 | return -EINVAL; |
| 4425 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4426 | if (!rdev->ops->deauth) |
| 4427 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4428 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4429 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4430 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4431 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4432 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4433 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4434 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4435 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4436 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4437 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4438 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4439 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4440 | |
| 4441 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4442 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4443 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4444 | } |
| 4445 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4446 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4447 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4448 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4449 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 4453 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4455 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4456 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4457 | int ie_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4458 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4459 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4460 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4461 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4462 | return -EINVAL; |
| 4463 | |
| 4464 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4465 | return -EINVAL; |
| 4466 | |
| 4467 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4468 | return -EINVAL; |
| 4469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4470 | if (!rdev->ops->disassoc) |
| 4471 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4472 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4473 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4474 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4475 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4476 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4477 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4478 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4479 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4480 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 4481 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4482 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 4483 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4484 | |
| 4485 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 4486 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4487 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4488 | } |
| 4489 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 4490 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 4491 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4492 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 4493 | local_state_change); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4494 | } |
| 4495 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4496 | static bool |
| 4497 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 4498 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 4499 | int rateval) |
| 4500 | { |
| 4501 | struct wiphy *wiphy = &rdev->wiphy; |
| 4502 | bool found = false; |
| 4503 | int band, i; |
| 4504 | |
| 4505 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 4506 | struct ieee80211_supported_band *sband; |
| 4507 | |
| 4508 | sband = wiphy->bands[band]; |
| 4509 | if (!sband) |
| 4510 | continue; |
| 4511 | |
| 4512 | for (i = 0; i < sband->n_bitrates; i++) { |
| 4513 | if (sband->bitrates[i].bitrate == rateval) { |
| 4514 | mcast_rate[band] = i + 1; |
| 4515 | found = true; |
| 4516 | break; |
| 4517 | } |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | return found; |
| 4522 | } |
| 4523 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4524 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4525 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4526 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4527 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4528 | struct cfg80211_ibss_params ibss; |
| 4529 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4530 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4531 | int err; |
| 4532 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4533 | memset(&ibss, 0, sizeof(ibss)); |
| 4534 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4535 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4536 | return -EINVAL; |
| 4537 | |
| 4538 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 4539 | !info->attrs[NL80211_ATTR_SSID] || |
| 4540 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4541 | return -EINVAL; |
| 4542 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 4543 | ibss.beacon_interval = 100; |
| 4544 | |
| 4545 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 4546 | ibss.beacon_interval = |
| 4547 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4548 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 4549 | return -EINVAL; |
| 4550 | } |
| 4551 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4552 | if (!rdev->ops->join_ibss) |
| 4553 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4554 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4555 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4556 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4557 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4558 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4559 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4560 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4561 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 4562 | |
| 4563 | if (!is_valid_ether_addr(ibss.bssid)) |
| 4564 | return -EINVAL; |
| 4565 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4566 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4567 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4568 | |
| 4569 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4570 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4571 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4572 | } |
| 4573 | |
| 4574 | ibss.channel = ieee80211_get_channel(wiphy, |
| 4575 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4576 | if (!ibss.channel || |
| 4577 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4578 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4579 | return -EINVAL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4580 | |
| 4581 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4582 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4583 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4584 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4585 | u8 *rates = |
| 4586 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4587 | int n_rates = |
| 4588 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4589 | struct ieee80211_supported_band *sband = |
| 4590 | wiphy->bands[ibss.channel->band]; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4591 | int err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4592 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 4593 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 4594 | &ibss.basic_rates); |
| 4595 | if (err) |
| 4596 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4597 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 4598 | |
| 4599 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 4600 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 4601 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 4602 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 4603 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4604 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4605 | connkeys = nl80211_parse_connkeys(rdev, |
| 4606 | info->attrs[NL80211_ATTR_KEYS]); |
| 4607 | if (IS_ERR(connkeys)) |
| 4608 | return PTR_ERR(connkeys); |
| 4609 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4611 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4612 | if (err) |
| 4613 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4614 | return err; |
| 4615 | } |
| 4616 | |
| 4617 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 4618 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4620 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4621 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4622 | if (!rdev->ops->leave_ibss) |
| 4623 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4624 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4625 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 4626 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4627 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4628 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4629 | } |
| 4630 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4631 | #ifdef CONFIG_NL80211_TESTMODE |
| 4632 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 4633 | .name = "testmode", |
| 4634 | }; |
| 4635 | |
| 4636 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 4637 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4638 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4639 | int err; |
| 4640 | |
| 4641 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 4642 | return -EINVAL; |
| 4643 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4644 | err = -EOPNOTSUPP; |
| 4645 | if (rdev->ops->testmode_cmd) { |
| 4646 | rdev->testmode_info = info; |
| 4647 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 4648 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 4649 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 4650 | rdev->testmode_info = NULL; |
| 4651 | } |
| 4652 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4653 | return err; |
| 4654 | } |
| 4655 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 4656 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 4657 | struct netlink_callback *cb) |
| 4658 | { |
| 4659 | struct cfg80211_registered_device *dev; |
| 4660 | int err; |
| 4661 | long phy_idx; |
| 4662 | void *data = NULL; |
| 4663 | int data_len = 0; |
| 4664 | |
| 4665 | if (cb->args[0]) { |
| 4666 | /* |
| 4667 | * 0 is a valid index, but not valid for args[0], |
| 4668 | * so we need to offset by 1. |
| 4669 | */ |
| 4670 | phy_idx = cb->args[0] - 1; |
| 4671 | } else { |
| 4672 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 4673 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 4674 | nl80211_policy); |
| 4675 | if (err) |
| 4676 | return err; |
| 4677 | if (!nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) |
| 4678 | return -EINVAL; |
| 4679 | phy_idx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); |
| 4680 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 4681 | cb->args[1] = |
| 4682 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 4683 | } |
| 4684 | |
| 4685 | if (cb->args[1]) { |
| 4686 | data = nla_data((void *)cb->args[1]); |
| 4687 | data_len = nla_len((void *)cb->args[1]); |
| 4688 | } |
| 4689 | |
| 4690 | mutex_lock(&cfg80211_mutex); |
| 4691 | dev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 4692 | if (!dev) { |
| 4693 | mutex_unlock(&cfg80211_mutex); |
| 4694 | return -ENOENT; |
| 4695 | } |
| 4696 | cfg80211_lock_rdev(dev); |
| 4697 | mutex_unlock(&cfg80211_mutex); |
| 4698 | |
| 4699 | if (!dev->ops->testmode_dump) { |
| 4700 | err = -EOPNOTSUPP; |
| 4701 | goto out_err; |
| 4702 | } |
| 4703 | |
| 4704 | while (1) { |
| 4705 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, |
| 4706 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4707 | NL80211_CMD_TESTMODE); |
| 4708 | struct nlattr *tmdata; |
| 4709 | |
| 4710 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, dev->wiphy_idx) < 0) { |
| 4711 | genlmsg_cancel(skb, hdr); |
| 4712 | break; |
| 4713 | } |
| 4714 | |
| 4715 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4716 | if (!tmdata) { |
| 4717 | genlmsg_cancel(skb, hdr); |
| 4718 | break; |
| 4719 | } |
| 4720 | err = dev->ops->testmode_dump(&dev->wiphy, skb, cb, |
| 4721 | data, data_len); |
| 4722 | nla_nest_end(skb, tmdata); |
| 4723 | |
| 4724 | if (err == -ENOBUFS || err == -ENOENT) { |
| 4725 | genlmsg_cancel(skb, hdr); |
| 4726 | break; |
| 4727 | } else if (err) { |
| 4728 | genlmsg_cancel(skb, hdr); |
| 4729 | goto out_err; |
| 4730 | } |
| 4731 | |
| 4732 | genlmsg_end(skb, hdr); |
| 4733 | } |
| 4734 | |
| 4735 | err = skb->len; |
| 4736 | /* see above */ |
| 4737 | cb->args[0] = phy_idx + 1; |
| 4738 | out_err: |
| 4739 | cfg80211_unlock_rdev(dev); |
| 4740 | return err; |
| 4741 | } |
| 4742 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4743 | static struct sk_buff * |
| 4744 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 4745 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 4746 | { |
| 4747 | struct sk_buff *skb; |
| 4748 | void *hdr; |
| 4749 | struct nlattr *data; |
| 4750 | |
| 4751 | skb = nlmsg_new(approxlen + 100, gfp); |
| 4752 | if (!skb) |
| 4753 | return NULL; |
| 4754 | |
| 4755 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 4756 | if (!hdr) { |
| 4757 | kfree_skb(skb); |
| 4758 | return NULL; |
| 4759 | } |
| 4760 | |
| 4761 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4762 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 4763 | |
| 4764 | ((void **)skb->cb)[0] = rdev; |
| 4765 | ((void **)skb->cb)[1] = hdr; |
| 4766 | ((void **)skb->cb)[2] = data; |
| 4767 | |
| 4768 | return skb; |
| 4769 | |
| 4770 | nla_put_failure: |
| 4771 | kfree_skb(skb); |
| 4772 | return NULL; |
| 4773 | } |
| 4774 | |
| 4775 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 4776 | int approxlen) |
| 4777 | { |
| 4778 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4779 | |
| 4780 | if (WARN_ON(!rdev->testmode_info)) |
| 4781 | return NULL; |
| 4782 | |
| 4783 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 4784 | rdev->testmode_info->snd_pid, |
| 4785 | rdev->testmode_info->snd_seq, |
| 4786 | GFP_KERNEL); |
| 4787 | } |
| 4788 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 4789 | |
| 4790 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 4791 | { |
| 4792 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 4793 | void *hdr = ((void **)skb->cb)[1]; |
| 4794 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4795 | |
| 4796 | if (WARN_ON(!rdev->testmode_info)) { |
| 4797 | kfree_skb(skb); |
| 4798 | return -EINVAL; |
| 4799 | } |
| 4800 | |
| 4801 | nla_nest_end(skb, data); |
| 4802 | genlmsg_end(skb, hdr); |
| 4803 | return genlmsg_reply(skb, rdev->testmode_info); |
| 4804 | } |
| 4805 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 4806 | |
| 4807 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 4808 | int approxlen, gfp_t gfp) |
| 4809 | { |
| 4810 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 4811 | |
| 4812 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 4813 | } |
| 4814 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 4815 | |
| 4816 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 4817 | { |
| 4818 | void *hdr = ((void **)skb->cb)[1]; |
| 4819 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 4820 | |
| 4821 | nla_nest_end(skb, data); |
| 4822 | genlmsg_end(skb, hdr); |
| 4823 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 4824 | } |
| 4825 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 4826 | #endif |
| 4827 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4828 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 4829 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4831 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4832 | struct cfg80211_connect_params connect; |
| 4833 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4834 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4835 | int err; |
| 4836 | |
| 4837 | memset(&connect, 0, sizeof(connect)); |
| 4838 | |
| 4839 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 4840 | return -EINVAL; |
| 4841 | |
| 4842 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 4843 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 4844 | return -EINVAL; |
| 4845 | |
| 4846 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4847 | connect.auth_type = |
| 4848 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 4849 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 4850 | return -EINVAL; |
| 4851 | } else |
| 4852 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4853 | |
| 4854 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 4855 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 4856 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 4857 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4858 | if (err) |
| 4859 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4860 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4861 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4862 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4863 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4864 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4865 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4866 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4867 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4868 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4869 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4870 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 4871 | |
| 4872 | if (info->attrs[NL80211_ATTR_IE]) { |
| 4873 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 4874 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 4875 | } |
| 4876 | |
| 4877 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 4878 | connect.channel = |
| 4879 | ieee80211_get_channel(wiphy, |
| 4880 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 4881 | if (!connect.channel || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4882 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
| 4883 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4884 | } |
| 4885 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4886 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 4887 | connkeys = nl80211_parse_connkeys(rdev, |
| 4888 | info->attrs[NL80211_ATTR_KEYS]); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4889 | if (IS_ERR(connkeys)) |
| 4890 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4891 | } |
| 4892 | |
| 4893 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4894 | if (err) |
| 4895 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4896 | return err; |
| 4897 | } |
| 4898 | |
| 4899 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 4900 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4902 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4903 | u16 reason; |
| 4904 | |
| 4905 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4906 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4907 | else |
| 4908 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4909 | |
| 4910 | if (reason == 0) |
| 4911 | return -EINVAL; |
| 4912 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4913 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4914 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4915 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4916 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4917 | return cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4918 | } |
| 4919 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4920 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4921 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4922 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4923 | struct net *net; |
| 4924 | int err; |
| 4925 | u32 pid; |
| 4926 | |
| 4927 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4928 | return -EINVAL; |
| 4929 | |
| 4930 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4931 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4932 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4933 | if (IS_ERR(net)) |
| 4934 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4935 | |
| 4936 | err = 0; |
| 4937 | |
| 4938 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4939 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4940 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4941 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4942 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4943 | return err; |
| 4944 | } |
| 4945 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4946 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4947 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4948 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4949 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 4950 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4951 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4952 | struct cfg80211_pmksa pmksa; |
| 4953 | |
| 4954 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 4955 | |
| 4956 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4957 | return -EINVAL; |
| 4958 | |
| 4959 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 4960 | return -EINVAL; |
| 4961 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4962 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 4963 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4964 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4965 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4966 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4967 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4968 | |
| 4969 | switch (info->genlhdr->cmd) { |
| 4970 | case NL80211_CMD_SET_PMKSA: |
| 4971 | rdev_ops = rdev->ops->set_pmksa; |
| 4972 | break; |
| 4973 | case NL80211_CMD_DEL_PMKSA: |
| 4974 | rdev_ops = rdev->ops->del_pmksa; |
| 4975 | break; |
| 4976 | default: |
| 4977 | WARN_ON(1); |
| 4978 | break; |
| 4979 | } |
| 4980 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4981 | if (!rdev_ops) |
| 4982 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4983 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4984 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 4988 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4989 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4990 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4991 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4992 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4993 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 4994 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4995 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4996 | if (!rdev->ops->flush_pmksa) |
| 4997 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 4998 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4999 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 5000 | } |
| 5001 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 5002 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 5003 | { |
| 5004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5005 | struct net_device *dev = info->user_ptr[1]; |
| 5006 | u8 action_code, dialog_token; |
| 5007 | u16 status_code; |
| 5008 | u8 *peer; |
| 5009 | |
| 5010 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5011 | !rdev->ops->tdls_mgmt) |
| 5012 | return -EOPNOTSUPP; |
| 5013 | |
| 5014 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 5015 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 5016 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 5017 | !info->attrs[NL80211_ATTR_IE] || |
| 5018 | !info->attrs[NL80211_ATTR_MAC]) |
| 5019 | return -EINVAL; |
| 5020 | |
| 5021 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5022 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 5023 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 5024 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
| 5025 | |
| 5026 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, |
| 5027 | dialog_token, status_code, |
| 5028 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5029 | nla_len(info->attrs[NL80211_ATTR_IE])); |
| 5030 | } |
| 5031 | |
| 5032 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 5033 | { |
| 5034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5035 | struct net_device *dev = info->user_ptr[1]; |
| 5036 | enum nl80211_tdls_operation operation; |
| 5037 | u8 *peer; |
| 5038 | |
| 5039 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 5040 | !rdev->ops->tdls_oper) |
| 5041 | return -EOPNOTSUPP; |
| 5042 | |
| 5043 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 5044 | !info->attrs[NL80211_ATTR_MAC]) |
| 5045 | return -EINVAL; |
| 5046 | |
| 5047 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 5048 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5049 | |
| 5050 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); |
| 5051 | } |
| 5052 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5053 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 5054 | struct genl_info *info) |
| 5055 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5057 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5058 | struct ieee80211_channel *chan; |
| 5059 | struct sk_buff *msg; |
| 5060 | void *hdr; |
| 5061 | u64 cookie; |
| 5062 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 5063 | u32 freq, duration; |
| 5064 | int err; |
| 5065 | |
| 5066 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5067 | !info->attrs[NL80211_ATTR_DURATION]) |
| 5068 | return -EINVAL; |
| 5069 | |
| 5070 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5071 | |
| 5072 | /* |
| 5073 | * We should be on that channel for at least one jiffie, |
| 5074 | * and more than 5 seconds seems excessive. |
| 5075 | */ |
Johannes Berg | a293911 | 2010-12-14 17:54:28 +0100 | [diff] [blame] | 5076 | if (!duration || !msecs_to_jiffies(duration) || |
| 5077 | duration > rdev->wiphy.max_remain_on_channel_duration) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5078 | return -EINVAL; |
| 5079 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5080 | if (!rdev->ops->remain_on_channel) |
| 5081 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5082 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5083 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5084 | channel_type = nla_get_u32( |
| 5085 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5086 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5087 | channel_type != NL80211_CHAN_HT20 && |
| 5088 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5089 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5090 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5094 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5095 | if (chan == NULL) |
| 5096 | return -EINVAL; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5097 | |
| 5098 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5099 | if (!msg) |
| 5100 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5101 | |
| 5102 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5103 | NL80211_CMD_REMAIN_ON_CHANNEL); |
| 5104 | |
| 5105 | if (IS_ERR(hdr)) { |
| 5106 | err = PTR_ERR(hdr); |
| 5107 | goto free_msg; |
| 5108 | } |
| 5109 | |
| 5110 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, |
| 5111 | channel_type, duration, &cookie); |
| 5112 | |
| 5113 | if (err) |
| 5114 | goto free_msg; |
| 5115 | |
| 5116 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5117 | |
| 5118 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5119 | |
| 5120 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5121 | |
| 5122 | nla_put_failure: |
| 5123 | err = -ENOBUFS; |
| 5124 | free_msg: |
| 5125 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5126 | return err; |
| 5127 | } |
| 5128 | |
| 5129 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 5130 | struct genl_info *info) |
| 5131 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5132 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5133 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5134 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5135 | |
| 5136 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5137 | return -EINVAL; |
| 5138 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5139 | if (!rdev->ops->cancel_remain_on_channel) |
| 5140 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5141 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5142 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5143 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5144 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 5145 | } |
| 5146 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5147 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 5148 | u8 *rates, u8 rates_len) |
| 5149 | { |
| 5150 | u8 i; |
| 5151 | u32 mask = 0; |
| 5152 | |
| 5153 | for (i = 0; i < rates_len; i++) { |
| 5154 | int rate = (rates[i] & 0x7f) * 5; |
| 5155 | int ridx; |
| 5156 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 5157 | struct ieee80211_rate *srate = |
| 5158 | &sband->bitrates[ridx]; |
| 5159 | if (rate == srate->bitrate) { |
| 5160 | mask |= 1 << ridx; |
| 5161 | break; |
| 5162 | } |
| 5163 | } |
| 5164 | if (ridx == sband->n_bitrates) |
| 5165 | return 0; /* rate not found */ |
| 5166 | } |
| 5167 | |
| 5168 | return mask; |
| 5169 | } |
| 5170 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5171 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5172 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 5173 | .len = NL80211_MAX_SUPP_RATES }, |
| 5174 | }; |
| 5175 | |
| 5176 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 5177 | struct genl_info *info) |
| 5178 | { |
| 5179 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5181 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5182 | int rem, i; |
| 5183 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5184 | struct nlattr *tx_rates; |
| 5185 | struct ieee80211_supported_band *sband; |
| 5186 | |
| 5187 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
| 5188 | return -EINVAL; |
| 5189 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5190 | if (!rdev->ops->set_bitrate_mask) |
| 5191 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5192 | |
| 5193 | memset(&mask, 0, sizeof(mask)); |
| 5194 | /* Default to all rates enabled */ |
| 5195 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 5196 | sband = rdev->wiphy.bands[i]; |
| 5197 | mask.control[i].legacy = |
| 5198 | sband ? (1 << sband->n_bitrates) - 1 : 0; |
| 5199 | } |
| 5200 | |
| 5201 | /* |
| 5202 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 5203 | * directly to the enum ieee80211_band values used in cfg80211. |
| 5204 | */ |
| 5205 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
| 5206 | { |
| 5207 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5208 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 5209 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5210 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5211 | if (sband == NULL) |
| 5212 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5213 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 5214 | nla_len(tx_rates), nl80211_txattr_policy); |
| 5215 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 5216 | mask.control[band].legacy = rateset_to_mask( |
| 5217 | sband, |
| 5218 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 5219 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5220 | if (mask.control[band].legacy == 0) |
| 5221 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5222 | } |
| 5223 | } |
| 5224 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5225 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 5226 | } |
| 5227 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5228 | 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] | 5229 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5231 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5232 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5233 | |
| 5234 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 5235 | return -EINVAL; |
| 5236 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5237 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 5238 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5239 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5240 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5241 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5242 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5243 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5244 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5245 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5246 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5247 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5248 | |
| 5249 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5250 | if (!rdev->ops->mgmt_tx) |
| 5251 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5252 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5253 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5254 | frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5255 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 5256 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5257 | } |
| 5258 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5259 | 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] | 5260 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5262 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5263 | struct ieee80211_channel *chan; |
| 5264 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5265 | bool channel_type_valid = false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5266 | u32 freq; |
| 5267 | int err; |
| 5268 | void *hdr; |
| 5269 | u64 cookie; |
| 5270 | struct sk_buff *msg; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5271 | unsigned int wait = 0; |
| 5272 | bool offchan; |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5273 | bool no_cck; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5274 | |
| 5275 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 5276 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 5277 | return -EINVAL; |
| 5278 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5279 | if (!rdev->ops->mgmt_tx) |
| 5280 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5281 | |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 5282 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5283 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 5284 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5285 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5286 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Javier Cardona | c7108a7 | 2010-12-16 17:37:50 -0800 | [diff] [blame] | 5287 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5288 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5289 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5290 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5291 | if (info->attrs[NL80211_ATTR_DURATION]) { |
| 5292 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5293 | return -EINVAL; |
| 5294 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 5295 | } |
| 5296 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5297 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 5298 | channel_type = nla_get_u32( |
| 5299 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 5300 | if (channel_type != NL80211_CHAN_NO_HT && |
| 5301 | channel_type != NL80211_CHAN_HT20 && |
| 5302 | channel_type != NL80211_CHAN_HT40PLUS && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5303 | channel_type != NL80211_CHAN_HT40MINUS) |
| 5304 | return -EINVAL; |
Johannes Berg | 252aa63 | 2010-05-19 12:17:12 +0200 | [diff] [blame] | 5305 | channel_type_valid = true; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5306 | } |
| 5307 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5308 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
| 5309 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5310 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5311 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5312 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 5313 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5314 | if (chan == NULL) |
| 5315 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5316 | |
| 5317 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5318 | if (!msg) |
| 5319 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5320 | |
| 5321 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5322 | NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5323 | |
| 5324 | if (IS_ERR(hdr)) { |
| 5325 | err = PTR_ERR(hdr); |
| 5326 | goto free_msg; |
| 5327 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5328 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
| 5329 | channel_type_valid, wait, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 5330 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
| 5331 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5332 | no_cck, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5333 | if (err) |
| 5334 | goto free_msg; |
| 5335 | |
| 5336 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 5337 | |
| 5338 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5339 | return genlmsg_reply(msg, info); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5340 | |
| 5341 | nla_put_failure: |
| 5342 | err = -ENOBUFS; |
| 5343 | free_msg: |
| 5344 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5345 | return err; |
| 5346 | } |
| 5347 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 5348 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 5349 | { |
| 5350 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5351 | struct net_device *dev = info->user_ptr[1]; |
| 5352 | u64 cookie; |
| 5353 | |
| 5354 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 5355 | return -EINVAL; |
| 5356 | |
| 5357 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 5358 | return -EOPNOTSUPP; |
| 5359 | |
| 5360 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
| 5361 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 5362 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 5363 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5364 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5365 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5366 | return -EOPNOTSUPP; |
| 5367 | |
| 5368 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 5369 | |
| 5370 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); |
| 5371 | } |
| 5372 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5373 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5374 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5375 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5376 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5377 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5378 | u8 ps_state; |
| 5379 | bool state; |
| 5380 | int err; |
| 5381 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5382 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 5383 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5384 | |
| 5385 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 5386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5387 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 5388 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5389 | |
| 5390 | wdev = dev->ieee80211_ptr; |
| 5391 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5392 | if (!rdev->ops->set_power_mgmt) |
| 5393 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5394 | |
| 5395 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 5396 | |
| 5397 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5398 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5399 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5400 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
| 5401 | wdev->ps_timeout); |
| 5402 | if (!err) |
| 5403 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5404 | return err; |
| 5405 | } |
| 5406 | |
| 5407 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 5408 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5409 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5410 | enum nl80211_ps_state ps_state; |
| 5411 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5412 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5413 | struct sk_buff *msg; |
| 5414 | void *hdr; |
| 5415 | int err; |
| 5416 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5417 | wdev = dev->ieee80211_ptr; |
| 5418 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5419 | if (!rdev->ops->set_power_mgmt) |
| 5420 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5421 | |
| 5422 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5423 | if (!msg) |
| 5424 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5425 | |
| 5426 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5427 | NL80211_CMD_GET_POWER_SAVE); |
| 5428 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5429 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5430 | goto free_msg; |
| 5431 | } |
| 5432 | |
| 5433 | if (wdev->ps) |
| 5434 | ps_state = NL80211_PS_ENABLED; |
| 5435 | else |
| 5436 | ps_state = NL80211_PS_DISABLED; |
| 5437 | |
| 5438 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
| 5439 | |
| 5440 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5441 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5442 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5443 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5444 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5445 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5446 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 5447 | return err; |
| 5448 | } |
| 5449 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5450 | static struct nla_policy |
| 5451 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { |
| 5452 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 5453 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 5454 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
| 5455 | }; |
| 5456 | |
| 5457 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 5458 | s32 threshold, u32 hysteresis) |
| 5459 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5461 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5462 | struct net_device *dev = info->user_ptr[1]; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5463 | |
| 5464 | if (threshold > 0) |
| 5465 | return -EINVAL; |
| 5466 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5467 | wdev = dev->ieee80211_ptr; |
| 5468 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5469 | if (!rdev->ops->set_cqm_rssi_config) |
| 5470 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5471 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5472 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5473 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 5474 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5475 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5476 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
| 5477 | threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 5478 | } |
| 5479 | |
| 5480 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 5481 | { |
| 5482 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 5483 | struct nlattr *cqm; |
| 5484 | int err; |
| 5485 | |
| 5486 | cqm = info->attrs[NL80211_ATTR_CQM]; |
| 5487 | if (!cqm) { |
| 5488 | err = -EINVAL; |
| 5489 | goto out; |
| 5490 | } |
| 5491 | |
| 5492 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 5493 | nl80211_attr_cqm_policy); |
| 5494 | if (err) |
| 5495 | goto out; |
| 5496 | |
| 5497 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 5498 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
| 5499 | s32 threshold; |
| 5500 | u32 hysteresis; |
| 5501 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 5502 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
| 5503 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 5504 | } else |
| 5505 | err = -EINVAL; |
| 5506 | |
| 5507 | out: |
| 5508 | return err; |
| 5509 | } |
| 5510 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5511 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5512 | { |
| 5513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5514 | struct net_device *dev = info->user_ptr[1]; |
| 5515 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5516 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5517 | int err; |
| 5518 | |
| 5519 | /* start with default */ |
| 5520 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5521 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5522 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5523 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5524 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5525 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5526 | if (err) |
| 5527 | return err; |
| 5528 | } |
| 5529 | |
| 5530 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 5531 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 5532 | return -EINVAL; |
| 5533 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5534 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5535 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 5536 | |
| 5537 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 5538 | /* parse additional setup parameters if given */ |
| 5539 | err = nl80211_parse_mesh_setup(info, &setup); |
| 5540 | if (err) |
| 5541 | return err; |
| 5542 | } |
| 5543 | |
| 5544 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5545 | } |
| 5546 | |
| 5547 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 5548 | { |
| 5549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5550 | struct net_device *dev = info->user_ptr[1]; |
| 5551 | |
| 5552 | return cfg80211_leave_mesh(rdev, dev); |
| 5553 | } |
| 5554 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5555 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5556 | { |
| 5557 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5558 | struct sk_buff *msg; |
| 5559 | void *hdr; |
| 5560 | |
| 5561 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5562 | return -EOPNOTSUPP; |
| 5563 | |
| 5564 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5565 | if (!msg) |
| 5566 | return -ENOMEM; |
| 5567 | |
| 5568 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 5569 | NL80211_CMD_GET_WOWLAN); |
| 5570 | if (!hdr) |
| 5571 | goto nla_put_failure; |
| 5572 | |
| 5573 | if (rdev->wowlan) { |
| 5574 | struct nlattr *nl_wowlan; |
| 5575 | |
| 5576 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 5577 | if (!nl_wowlan) |
| 5578 | goto nla_put_failure; |
| 5579 | |
| 5580 | if (rdev->wowlan->any) |
| 5581 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); |
| 5582 | if (rdev->wowlan->disconnect) |
| 5583 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); |
| 5584 | if (rdev->wowlan->magic_pkt) |
| 5585 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5586 | if (rdev->wowlan->gtk_rekey_failure) |
| 5587 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); |
| 5588 | if (rdev->wowlan->eap_identity_req) |
| 5589 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); |
| 5590 | if (rdev->wowlan->four_way_handshake) |
| 5591 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); |
| 5592 | if (rdev->wowlan->rfkill_release) |
| 5593 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5594 | if (rdev->wowlan->n_patterns) { |
| 5595 | struct nlattr *nl_pats, *nl_pat; |
| 5596 | int i, pat_len; |
| 5597 | |
| 5598 | nl_pats = nla_nest_start(msg, |
| 5599 | NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 5600 | if (!nl_pats) |
| 5601 | goto nla_put_failure; |
| 5602 | |
| 5603 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { |
| 5604 | nl_pat = nla_nest_start(msg, i + 1); |
| 5605 | if (!nl_pat) |
| 5606 | goto nla_put_failure; |
| 5607 | pat_len = rdev->wowlan->patterns[i].pattern_len; |
| 5608 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, |
| 5609 | DIV_ROUND_UP(pat_len, 8), |
| 5610 | rdev->wowlan->patterns[i].mask); |
| 5611 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, |
| 5612 | pat_len, |
| 5613 | rdev->wowlan->patterns[i].pattern); |
| 5614 | nla_nest_end(msg, nl_pat); |
| 5615 | } |
| 5616 | nla_nest_end(msg, nl_pats); |
| 5617 | } |
| 5618 | |
| 5619 | nla_nest_end(msg, nl_wowlan); |
| 5620 | } |
| 5621 | |
| 5622 | genlmsg_end(msg, hdr); |
| 5623 | return genlmsg_reply(msg, info); |
| 5624 | |
| 5625 | nla_put_failure: |
| 5626 | nlmsg_free(msg); |
| 5627 | return -ENOBUFS; |
| 5628 | } |
| 5629 | |
| 5630 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 5631 | { |
| 5632 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5633 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
| 5634 | struct cfg80211_wowlan no_triggers = {}; |
| 5635 | struct cfg80211_wowlan new_triggers = {}; |
| 5636 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; |
| 5637 | int err, i; |
| 5638 | |
| 5639 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) |
| 5640 | return -EOPNOTSUPP; |
| 5641 | |
| 5642 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) |
| 5643 | goto no_triggers; |
| 5644 | |
| 5645 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 5646 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5647 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 5648 | nl80211_wowlan_policy); |
| 5649 | if (err) |
| 5650 | return err; |
| 5651 | |
| 5652 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 5653 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 5654 | return -EINVAL; |
| 5655 | new_triggers.any = true; |
| 5656 | } |
| 5657 | |
| 5658 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 5659 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 5660 | return -EINVAL; |
| 5661 | new_triggers.disconnect = true; |
| 5662 | } |
| 5663 | |
| 5664 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 5665 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 5666 | return -EINVAL; |
| 5667 | new_triggers.magic_pkt = true; |
| 5668 | } |
| 5669 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 5670 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 5671 | return -EINVAL; |
| 5672 | |
| 5673 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 5674 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 5675 | return -EINVAL; |
| 5676 | new_triggers.gtk_rekey_failure = true; |
| 5677 | } |
| 5678 | |
| 5679 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 5680 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 5681 | return -EINVAL; |
| 5682 | new_triggers.eap_identity_req = true; |
| 5683 | } |
| 5684 | |
| 5685 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 5686 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 5687 | return -EINVAL; |
| 5688 | new_triggers.four_way_handshake = true; |
| 5689 | } |
| 5690 | |
| 5691 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 5692 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 5693 | return -EINVAL; |
| 5694 | new_triggers.rfkill_release = true; |
| 5695 | } |
| 5696 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 5697 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 5698 | struct nlattr *pat; |
| 5699 | int n_patterns = 0; |
| 5700 | int rem, pat_len, mask_len; |
| 5701 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; |
| 5702 | |
| 5703 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5704 | rem) |
| 5705 | n_patterns++; |
| 5706 | if (n_patterns > wowlan->n_patterns) |
| 5707 | return -EINVAL; |
| 5708 | |
| 5709 | new_triggers.patterns = kcalloc(n_patterns, |
| 5710 | sizeof(new_triggers.patterns[0]), |
| 5711 | GFP_KERNEL); |
| 5712 | if (!new_triggers.patterns) |
| 5713 | return -ENOMEM; |
| 5714 | |
| 5715 | new_triggers.n_patterns = n_patterns; |
| 5716 | i = 0; |
| 5717 | |
| 5718 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 5719 | rem) { |
| 5720 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, |
| 5721 | nla_data(pat), nla_len(pat), NULL); |
| 5722 | err = -EINVAL; |
| 5723 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || |
| 5724 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) |
| 5725 | goto error; |
| 5726 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); |
| 5727 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 5728 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != |
| 5729 | mask_len) |
| 5730 | goto error; |
| 5731 | if (pat_len > wowlan->pattern_max_len || |
| 5732 | pat_len < wowlan->pattern_min_len) |
| 5733 | goto error; |
| 5734 | |
| 5735 | new_triggers.patterns[i].mask = |
| 5736 | kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 5737 | if (!new_triggers.patterns[i].mask) { |
| 5738 | err = -ENOMEM; |
| 5739 | goto error; |
| 5740 | } |
| 5741 | new_triggers.patterns[i].pattern = |
| 5742 | new_triggers.patterns[i].mask + mask_len; |
| 5743 | memcpy(new_triggers.patterns[i].mask, |
| 5744 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), |
| 5745 | mask_len); |
| 5746 | new_triggers.patterns[i].pattern_len = pat_len; |
| 5747 | memcpy(new_triggers.patterns[i].pattern, |
| 5748 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), |
| 5749 | pat_len); |
| 5750 | i++; |
| 5751 | } |
| 5752 | } |
| 5753 | |
| 5754 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { |
| 5755 | struct cfg80211_wowlan *ntrig; |
| 5756 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), |
| 5757 | GFP_KERNEL); |
| 5758 | if (!ntrig) { |
| 5759 | err = -ENOMEM; |
| 5760 | goto error; |
| 5761 | } |
| 5762 | cfg80211_rdev_free_wowlan(rdev); |
| 5763 | rdev->wowlan = ntrig; |
| 5764 | } else { |
| 5765 | no_triggers: |
| 5766 | cfg80211_rdev_free_wowlan(rdev); |
| 5767 | rdev->wowlan = NULL; |
| 5768 | } |
| 5769 | |
| 5770 | return 0; |
| 5771 | error: |
| 5772 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 5773 | kfree(new_triggers.patterns[i].mask); |
| 5774 | kfree(new_triggers.patterns); |
| 5775 | return err; |
| 5776 | } |
| 5777 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 5778 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 5779 | { |
| 5780 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5781 | struct net_device *dev = info->user_ptr[1]; |
| 5782 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5783 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 5784 | struct cfg80211_gtk_rekey_data rekey_data; |
| 5785 | int err; |
| 5786 | |
| 5787 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 5788 | return -EINVAL; |
| 5789 | |
| 5790 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 5791 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5792 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 5793 | nl80211_rekey_policy); |
| 5794 | if (err) |
| 5795 | return err; |
| 5796 | |
| 5797 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 5798 | return -ERANGE; |
| 5799 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 5800 | return -ERANGE; |
| 5801 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 5802 | return -ERANGE; |
| 5803 | |
| 5804 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), |
| 5805 | NL80211_KEK_LEN); |
| 5806 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), |
| 5807 | NL80211_KCK_LEN); |
| 5808 | memcpy(rekey_data.replay_ctr, |
| 5809 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), |
| 5810 | NL80211_REPLAY_CTR_LEN); |
| 5811 | |
| 5812 | wdev_lock(wdev); |
| 5813 | if (!wdev->current_bss) { |
| 5814 | err = -ENOTCONN; |
| 5815 | goto out; |
| 5816 | } |
| 5817 | |
| 5818 | if (!rdev->ops->set_rekey_data) { |
| 5819 | err = -EOPNOTSUPP; |
| 5820 | goto out; |
| 5821 | } |
| 5822 | |
| 5823 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); |
| 5824 | out: |
| 5825 | wdev_unlock(wdev); |
| 5826 | return err; |
| 5827 | } |
| 5828 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5829 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 5830 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 5831 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5832 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 5833 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 5834 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5835 | |
| 5836 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5837 | struct genl_info *info) |
| 5838 | { |
| 5839 | struct cfg80211_registered_device *rdev; |
| 5840 | struct net_device *dev; |
| 5841 | int err; |
| 5842 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 5843 | |
| 5844 | if (rtnl) |
| 5845 | rtnl_lock(); |
| 5846 | |
| 5847 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
| 5848 | rdev = cfg80211_get_dev_from_info(info); |
| 5849 | if (IS_ERR(rdev)) { |
| 5850 | if (rtnl) |
| 5851 | rtnl_unlock(); |
| 5852 | return PTR_ERR(rdev); |
| 5853 | } |
| 5854 | info->user_ptr[0] = rdev; |
| 5855 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 5856 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
| 5857 | if (err) { |
| 5858 | if (rtnl) |
| 5859 | rtnl_unlock(); |
| 5860 | return err; |
| 5861 | } |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5862 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 5863 | !netif_running(dev)) { |
Johannes Berg | d537f5f | 2010-10-05 21:34:11 +0200 | [diff] [blame] | 5864 | cfg80211_unlock_rdev(rdev); |
| 5865 | dev_put(dev); |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5866 | if (rtnl) |
| 5867 | rtnl_unlock(); |
| 5868 | return -ENETDOWN; |
| 5869 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5870 | info->user_ptr[0] = rdev; |
| 5871 | info->user_ptr[1] = dev; |
| 5872 | } |
| 5873 | |
| 5874 | return 0; |
| 5875 | } |
| 5876 | |
| 5877 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, |
| 5878 | struct genl_info *info) |
| 5879 | { |
| 5880 | if (info->user_ptr[0]) |
| 5881 | cfg80211_unlock_rdev(info->user_ptr[0]); |
| 5882 | if (info->user_ptr[1]) |
| 5883 | dev_put(info->user_ptr[1]); |
| 5884 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 5885 | rtnl_unlock(); |
| 5886 | } |
| 5887 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5888 | static struct genl_ops nl80211_ops[] = { |
| 5889 | { |
| 5890 | .cmd = NL80211_CMD_GET_WIPHY, |
| 5891 | .doit = nl80211_get_wiphy, |
| 5892 | .dumpit = nl80211_dump_wiphy, |
| 5893 | .policy = nl80211_policy, |
| 5894 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5895 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5896 | }, |
| 5897 | { |
| 5898 | .cmd = NL80211_CMD_SET_WIPHY, |
| 5899 | .doit = nl80211_set_wiphy, |
| 5900 | .policy = nl80211_policy, |
| 5901 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5902 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5903 | }, |
| 5904 | { |
| 5905 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 5906 | .doit = nl80211_get_interface, |
| 5907 | .dumpit = nl80211_dump_interface, |
| 5908 | .policy = nl80211_policy, |
| 5909 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5910 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5911 | }, |
| 5912 | { |
| 5913 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 5914 | .doit = nl80211_set_interface, |
| 5915 | .policy = nl80211_policy, |
| 5916 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5917 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5918 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5919 | }, |
| 5920 | { |
| 5921 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 5922 | .doit = nl80211_new_interface, |
| 5923 | .policy = nl80211_policy, |
| 5924 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5925 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 5926 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5927 | }, |
| 5928 | { |
| 5929 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 5930 | .doit = nl80211_del_interface, |
| 5931 | .policy = nl80211_policy, |
| 5932 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5933 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5934 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5935 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5936 | { |
| 5937 | .cmd = NL80211_CMD_GET_KEY, |
| 5938 | .doit = nl80211_get_key, |
| 5939 | .policy = nl80211_policy, |
| 5940 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5941 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5942 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5943 | }, |
| 5944 | { |
| 5945 | .cmd = NL80211_CMD_SET_KEY, |
| 5946 | .doit = nl80211_set_key, |
| 5947 | .policy = nl80211_policy, |
| 5948 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5949 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5950 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5951 | }, |
| 5952 | { |
| 5953 | .cmd = NL80211_CMD_NEW_KEY, |
| 5954 | .doit = nl80211_new_key, |
| 5955 | .policy = nl80211_policy, |
| 5956 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5957 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5958 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5959 | }, |
| 5960 | { |
| 5961 | .cmd = NL80211_CMD_DEL_KEY, |
| 5962 | .doit = nl80211_del_key, |
| 5963 | .policy = nl80211_policy, |
| 5964 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 5965 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5966 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 5967 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5968 | { |
| 5969 | .cmd = NL80211_CMD_SET_BEACON, |
| 5970 | .policy = nl80211_policy, |
| 5971 | .flags = GENL_ADMIN_PERM, |
| 5972 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5973 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5974 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5975 | }, |
| 5976 | { |
| 5977 | .cmd = NL80211_CMD_NEW_BEACON, |
| 5978 | .policy = nl80211_policy, |
| 5979 | .flags = GENL_ADMIN_PERM, |
| 5980 | .doit = nl80211_addset_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5981 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5982 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5983 | }, |
| 5984 | { |
| 5985 | .cmd = NL80211_CMD_DEL_BEACON, |
| 5986 | .policy = nl80211_policy, |
| 5987 | .flags = GENL_ADMIN_PERM, |
| 5988 | .doit = nl80211_del_beacon, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5989 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5990 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5991 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5992 | { |
| 5993 | .cmd = NL80211_CMD_GET_STATION, |
| 5994 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5995 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5996 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5997 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 5998 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5999 | }, |
| 6000 | { |
| 6001 | .cmd = NL80211_CMD_SET_STATION, |
| 6002 | .doit = nl80211_set_station, |
| 6003 | .policy = nl80211_policy, |
| 6004 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6005 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6006 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6007 | }, |
| 6008 | { |
| 6009 | .cmd = NL80211_CMD_NEW_STATION, |
| 6010 | .doit = nl80211_new_station, |
| 6011 | .policy = nl80211_policy, |
| 6012 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6013 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6014 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6015 | }, |
| 6016 | { |
| 6017 | .cmd = NL80211_CMD_DEL_STATION, |
| 6018 | .doit = nl80211_del_station, |
| 6019 | .policy = nl80211_policy, |
| 6020 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6021 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6022 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6023 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6024 | { |
| 6025 | .cmd = NL80211_CMD_GET_MPATH, |
| 6026 | .doit = nl80211_get_mpath, |
| 6027 | .dumpit = nl80211_dump_mpath, |
| 6028 | .policy = nl80211_policy, |
| 6029 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6031 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6032 | }, |
| 6033 | { |
| 6034 | .cmd = NL80211_CMD_SET_MPATH, |
| 6035 | .doit = nl80211_set_mpath, |
| 6036 | .policy = nl80211_policy, |
| 6037 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6038 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6039 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6040 | }, |
| 6041 | { |
| 6042 | .cmd = NL80211_CMD_NEW_MPATH, |
| 6043 | .doit = nl80211_new_mpath, |
| 6044 | .policy = nl80211_policy, |
| 6045 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6046 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6047 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6048 | }, |
| 6049 | { |
| 6050 | .cmd = NL80211_CMD_DEL_MPATH, |
| 6051 | .doit = nl80211_del_mpath, |
| 6052 | .policy = nl80211_policy, |
| 6053 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6054 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6055 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6056 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6057 | { |
| 6058 | .cmd = NL80211_CMD_SET_BSS, |
| 6059 | .doit = nl80211_set_bss, |
| 6060 | .policy = nl80211_policy, |
| 6061 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6062 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6063 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6064 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6065 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6066 | .cmd = NL80211_CMD_GET_REG, |
| 6067 | .doit = nl80211_get_reg, |
| 6068 | .policy = nl80211_policy, |
| 6069 | /* can be retrieved by unprivileged users */ |
| 6070 | }, |
| 6071 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6072 | .cmd = NL80211_CMD_SET_REG, |
| 6073 | .doit = nl80211_set_reg, |
| 6074 | .policy = nl80211_policy, |
| 6075 | .flags = GENL_ADMIN_PERM, |
| 6076 | }, |
| 6077 | { |
| 6078 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 6079 | .doit = nl80211_req_set_reg, |
| 6080 | .policy = nl80211_policy, |
| 6081 | .flags = GENL_ADMIN_PERM, |
| 6082 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6083 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6084 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 6085 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6086 | .policy = nl80211_policy, |
| 6087 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6088 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6089 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6090 | }, |
| 6091 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6092 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 6093 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6094 | .policy = nl80211_policy, |
| 6095 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6096 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6097 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6098 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 6099 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6100 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 6101 | .doit = nl80211_trigger_scan, |
| 6102 | .policy = nl80211_policy, |
| 6103 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6104 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6105 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6106 | }, |
| 6107 | { |
| 6108 | .cmd = NL80211_CMD_GET_SCAN, |
| 6109 | .policy = nl80211_policy, |
| 6110 | .dumpit = nl80211_dump_scan, |
| 6111 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6112 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6113 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 6114 | .doit = nl80211_start_sched_scan, |
| 6115 | .policy = nl80211_policy, |
| 6116 | .flags = GENL_ADMIN_PERM, |
| 6117 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6118 | NL80211_FLAG_NEED_RTNL, |
| 6119 | }, |
| 6120 | { |
| 6121 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 6122 | .doit = nl80211_stop_sched_scan, |
| 6123 | .policy = nl80211_policy, |
| 6124 | .flags = GENL_ADMIN_PERM, |
| 6125 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6126 | NL80211_FLAG_NEED_RTNL, |
| 6127 | }, |
| 6128 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6129 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 6130 | .doit = nl80211_authenticate, |
| 6131 | .policy = nl80211_policy, |
| 6132 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6133 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6134 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6135 | }, |
| 6136 | { |
| 6137 | .cmd = NL80211_CMD_ASSOCIATE, |
| 6138 | .doit = nl80211_associate, |
| 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, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6143 | }, |
| 6144 | { |
| 6145 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 6146 | .doit = nl80211_deauthenticate, |
| 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, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6151 | }, |
| 6152 | { |
| 6153 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 6154 | .doit = nl80211_disassociate, |
| 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, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6159 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6160 | { |
| 6161 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 6162 | .doit = nl80211_join_ibss, |
| 6163 | .policy = nl80211_policy, |
| 6164 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6165 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6166 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6167 | }, |
| 6168 | { |
| 6169 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 6170 | .doit = nl80211_leave_ibss, |
| 6171 | .policy = nl80211_policy, |
| 6172 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6173 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6174 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6175 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6176 | #ifdef CONFIG_NL80211_TESTMODE |
| 6177 | { |
| 6178 | .cmd = NL80211_CMD_TESTMODE, |
| 6179 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 6180 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6181 | .policy = nl80211_policy, |
| 6182 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6183 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6184 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 6185 | }, |
| 6186 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6187 | { |
| 6188 | .cmd = NL80211_CMD_CONNECT, |
| 6189 | .doit = nl80211_connect, |
| 6190 | .policy = nl80211_policy, |
| 6191 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6192 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6193 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6194 | }, |
| 6195 | { |
| 6196 | .cmd = NL80211_CMD_DISCONNECT, |
| 6197 | .doit = nl80211_disconnect, |
| 6198 | .policy = nl80211_policy, |
| 6199 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6200 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6201 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6202 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6203 | { |
| 6204 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 6205 | .doit = nl80211_wiphy_netns, |
| 6206 | .policy = nl80211_policy, |
| 6207 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6208 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6209 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6210 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6211 | { |
| 6212 | .cmd = NL80211_CMD_GET_SURVEY, |
| 6213 | .policy = nl80211_policy, |
| 6214 | .dumpit = nl80211_dump_survey, |
| 6215 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6216 | { |
| 6217 | .cmd = NL80211_CMD_SET_PMKSA, |
| 6218 | .doit = nl80211_setdel_pmksa, |
| 6219 | .policy = nl80211_policy, |
| 6220 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6221 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6222 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6223 | }, |
| 6224 | { |
| 6225 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 6226 | .doit = nl80211_setdel_pmksa, |
| 6227 | .policy = nl80211_policy, |
| 6228 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6229 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6230 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6231 | }, |
| 6232 | { |
| 6233 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 6234 | .doit = nl80211_flush_pmksa, |
| 6235 | .policy = nl80211_policy, |
| 6236 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6237 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6238 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 6239 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6240 | { |
| 6241 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 6242 | .doit = nl80211_remain_on_channel, |
| 6243 | .policy = nl80211_policy, |
| 6244 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6245 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6246 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6247 | }, |
| 6248 | { |
| 6249 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 6250 | .doit = nl80211_cancel_remain_on_channel, |
| 6251 | .policy = nl80211_policy, |
| 6252 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6253 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6254 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6255 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6256 | { |
| 6257 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 6258 | .doit = nl80211_set_tx_bitrate_mask, |
| 6259 | .policy = nl80211_policy, |
| 6260 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6261 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6262 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 6263 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6264 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6265 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 6266 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6267 | .policy = nl80211_policy, |
| 6268 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6269 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6270 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6271 | }, |
| 6272 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 6273 | .cmd = NL80211_CMD_FRAME, |
| 6274 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6275 | .policy = nl80211_policy, |
| 6276 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 6277 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6278 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 6279 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6280 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 6281 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 6282 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 6283 | .policy = nl80211_policy, |
| 6284 | .flags = GENL_ADMIN_PERM, |
| 6285 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6286 | NL80211_FLAG_NEED_RTNL, |
| 6287 | }, |
| 6288 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6289 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 6290 | .doit = nl80211_set_power_save, |
| 6291 | .policy = nl80211_policy, |
| 6292 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6293 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6294 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6295 | }, |
| 6296 | { |
| 6297 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 6298 | .doit = nl80211_get_power_save, |
| 6299 | .policy = nl80211_policy, |
| 6300 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6301 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6302 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 6303 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6304 | { |
| 6305 | .cmd = NL80211_CMD_SET_CQM, |
| 6306 | .doit = nl80211_set_cqm, |
| 6307 | .policy = nl80211_policy, |
| 6308 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6309 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6310 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 6311 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6312 | { |
| 6313 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 6314 | .doit = nl80211_set_channel, |
| 6315 | .policy = nl80211_policy, |
| 6316 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6317 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6318 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6319 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6320 | { |
| 6321 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 6322 | .doit = nl80211_set_wds_peer, |
| 6323 | .policy = nl80211_policy, |
| 6324 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 6325 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 6326 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 6327 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6328 | { |
| 6329 | .cmd = NL80211_CMD_JOIN_MESH, |
| 6330 | .doit = nl80211_join_mesh, |
| 6331 | .policy = nl80211_policy, |
| 6332 | .flags = GENL_ADMIN_PERM, |
| 6333 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6334 | NL80211_FLAG_NEED_RTNL, |
| 6335 | }, |
| 6336 | { |
| 6337 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 6338 | .doit = nl80211_leave_mesh, |
| 6339 | .policy = nl80211_policy, |
| 6340 | .flags = GENL_ADMIN_PERM, |
| 6341 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6342 | NL80211_FLAG_NEED_RTNL, |
| 6343 | }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 6344 | { |
| 6345 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 6346 | .doit = nl80211_get_wowlan, |
| 6347 | .policy = nl80211_policy, |
| 6348 | /* can be retrieved by unprivileged users */ |
| 6349 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6350 | NL80211_FLAG_NEED_RTNL, |
| 6351 | }, |
| 6352 | { |
| 6353 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 6354 | .doit = nl80211_set_wowlan, |
| 6355 | .policy = nl80211_policy, |
| 6356 | .flags = GENL_ADMIN_PERM, |
| 6357 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 6358 | NL80211_FLAG_NEED_RTNL, |
| 6359 | }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 6360 | { |
| 6361 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 6362 | .doit = nl80211_set_rekey_data, |
| 6363 | .policy = nl80211_policy, |
| 6364 | .flags = GENL_ADMIN_PERM, |
| 6365 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6366 | NL80211_FLAG_NEED_RTNL, |
| 6367 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 6368 | { |
| 6369 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 6370 | .doit = nl80211_tdls_mgmt, |
| 6371 | .policy = nl80211_policy, |
| 6372 | .flags = GENL_ADMIN_PERM, |
| 6373 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6374 | NL80211_FLAG_NEED_RTNL, |
| 6375 | }, |
| 6376 | { |
| 6377 | .cmd = NL80211_CMD_TDLS_OPER, |
| 6378 | .doit = nl80211_tdls_oper, |
| 6379 | .policy = nl80211_policy, |
| 6380 | .flags = GENL_ADMIN_PERM, |
| 6381 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 6382 | NL80211_FLAG_NEED_RTNL, |
| 6383 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6384 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 6385 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6386 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 6387 | .name = "mlme", |
| 6388 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6389 | |
| 6390 | /* multicast groups */ |
| 6391 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 6392 | .name = "config", |
| 6393 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6394 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 6395 | .name = "scan", |
| 6396 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6397 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 6398 | .name = "regulatory", |
| 6399 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6400 | |
| 6401 | /* notification functions */ |
| 6402 | |
| 6403 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 6404 | { |
| 6405 | struct sk_buff *msg; |
| 6406 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6407 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6408 | if (!msg) |
| 6409 | return; |
| 6410 | |
| 6411 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 6412 | nlmsg_free(msg); |
| 6413 | return; |
| 6414 | } |
| 6415 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6416 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6417 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6418 | } |
| 6419 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6420 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 6421 | struct cfg80211_registered_device *rdev) |
| 6422 | { |
| 6423 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 6424 | struct nlattr *nest; |
| 6425 | int i; |
| 6426 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6427 | ASSERT_RDEV_LOCK(rdev); |
| 6428 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6429 | if (WARN_ON(!req)) |
| 6430 | return 0; |
| 6431 | |
| 6432 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 6433 | if (!nest) |
| 6434 | goto nla_put_failure; |
| 6435 | for (i = 0; i < req->n_ssids; i++) |
| 6436 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 6437 | nla_nest_end(msg, nest); |
| 6438 | |
| 6439 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 6440 | if (!nest) |
| 6441 | goto nla_put_failure; |
| 6442 | for (i = 0; i < req->n_channels; i++) |
| 6443 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 6444 | nla_nest_end(msg, nest); |
| 6445 | |
| 6446 | if (req->ie) |
| 6447 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 6448 | |
| 6449 | return 0; |
| 6450 | nla_put_failure: |
| 6451 | return -ENOBUFS; |
| 6452 | } |
| 6453 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6454 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 6455 | struct cfg80211_registered_device *rdev, |
| 6456 | struct net_device *netdev, |
| 6457 | u32 pid, u32 seq, int flags, |
| 6458 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6459 | { |
| 6460 | void *hdr; |
| 6461 | |
| 6462 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6463 | if (!hdr) |
| 6464 | return -1; |
| 6465 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 6466 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6467 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6468 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 6469 | /* ignore errors and send incomplete event anyway */ |
| 6470 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6471 | |
| 6472 | return genlmsg_end(msg, hdr); |
| 6473 | |
| 6474 | nla_put_failure: |
| 6475 | genlmsg_cancel(msg, hdr); |
| 6476 | return -EMSGSIZE; |
| 6477 | } |
| 6478 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6479 | static int |
| 6480 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 6481 | struct cfg80211_registered_device *rdev, |
| 6482 | struct net_device *netdev, |
| 6483 | u32 pid, u32 seq, int flags, u32 cmd) |
| 6484 | { |
| 6485 | void *hdr; |
| 6486 | |
| 6487 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 6488 | if (!hdr) |
| 6489 | return -1; |
| 6490 | |
| 6491 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6492 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6493 | |
| 6494 | return genlmsg_end(msg, hdr); |
| 6495 | |
| 6496 | nla_put_failure: |
| 6497 | genlmsg_cancel(msg, hdr); |
| 6498 | return -EMSGSIZE; |
| 6499 | } |
| 6500 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6501 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 6502 | struct net_device *netdev) |
| 6503 | { |
| 6504 | struct sk_buff *msg; |
| 6505 | |
| 6506 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6507 | if (!msg) |
| 6508 | return; |
| 6509 | |
| 6510 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6511 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 6512 | nlmsg_free(msg); |
| 6513 | return; |
| 6514 | } |
| 6515 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6516 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6517 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6518 | } |
| 6519 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6520 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 6521 | struct net_device *netdev) |
| 6522 | { |
| 6523 | struct sk_buff *msg; |
| 6524 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6525 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6526 | if (!msg) |
| 6527 | return; |
| 6528 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6529 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6530 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6531 | nlmsg_free(msg); |
| 6532 | return; |
| 6533 | } |
| 6534 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6535 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6536 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 6540 | struct net_device *netdev) |
| 6541 | { |
| 6542 | struct sk_buff *msg; |
| 6543 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6544 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6545 | if (!msg) |
| 6546 | return; |
| 6547 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 6548 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6549 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6550 | nlmsg_free(msg); |
| 6551 | return; |
| 6552 | } |
| 6553 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6554 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6555 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6556 | } |
| 6557 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6558 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 6559 | struct net_device *netdev) |
| 6560 | { |
| 6561 | struct sk_buff *msg; |
| 6562 | |
| 6563 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6564 | if (!msg) |
| 6565 | return; |
| 6566 | |
| 6567 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 6568 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 6569 | nlmsg_free(msg); |
| 6570 | return; |
| 6571 | } |
| 6572 | |
| 6573 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6574 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6575 | } |
| 6576 | |
| 6577 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 6578 | struct net_device *netdev, u32 cmd) |
| 6579 | { |
| 6580 | struct sk_buff *msg; |
| 6581 | |
| 6582 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 6583 | if (!msg) |
| 6584 | return; |
| 6585 | |
| 6586 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 6587 | nlmsg_free(msg); |
| 6588 | return; |
| 6589 | } |
| 6590 | |
| 6591 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6592 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 6593 | } |
| 6594 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6595 | /* |
| 6596 | * This can happen on global regulatory changes or device specific settings |
| 6597 | * based on custom world regulatory domains. |
| 6598 | */ |
| 6599 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 6600 | { |
| 6601 | struct sk_buff *msg; |
| 6602 | void *hdr; |
| 6603 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6605 | if (!msg) |
| 6606 | return; |
| 6607 | |
| 6608 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 6609 | if (!hdr) { |
| 6610 | nlmsg_free(msg); |
| 6611 | return; |
| 6612 | } |
| 6613 | |
| 6614 | /* Userspace can always count this one always being set */ |
| 6615 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 6616 | |
| 6617 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 6618 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6619 | NL80211_REGDOM_TYPE_WORLD); |
| 6620 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 6621 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6622 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 6623 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 6624 | request->intersect) |
| 6625 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6626 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 6627 | else { |
| 6628 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 6629 | NL80211_REGDOM_TYPE_COUNTRY); |
| 6630 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 6631 | } |
| 6632 | |
| 6633 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 6634 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 6635 | |
| 6636 | if (genlmsg_end(msg, hdr) < 0) { |
| 6637 | nlmsg_free(msg); |
| 6638 | return; |
| 6639 | } |
| 6640 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6641 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6642 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 6643 | GFP_ATOMIC); |
| 6644 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 6645 | |
| 6646 | return; |
| 6647 | |
| 6648 | nla_put_failure: |
| 6649 | genlmsg_cancel(msg, hdr); |
| 6650 | nlmsg_free(msg); |
| 6651 | } |
| 6652 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6653 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 6654 | struct net_device *netdev, |
| 6655 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6656 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6657 | { |
| 6658 | struct sk_buff *msg; |
| 6659 | void *hdr; |
| 6660 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6661 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6662 | if (!msg) |
| 6663 | return; |
| 6664 | |
| 6665 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6666 | if (!hdr) { |
| 6667 | nlmsg_free(msg); |
| 6668 | return; |
| 6669 | } |
| 6670 | |
| 6671 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6672 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6673 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 6674 | |
| 6675 | if (genlmsg_end(msg, hdr) < 0) { |
| 6676 | nlmsg_free(msg); |
| 6677 | return; |
| 6678 | } |
| 6679 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6680 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6681 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6682 | return; |
| 6683 | |
| 6684 | nla_put_failure: |
| 6685 | genlmsg_cancel(msg, hdr); |
| 6686 | nlmsg_free(msg); |
| 6687 | } |
| 6688 | |
| 6689 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6690 | struct net_device *netdev, const u8 *buf, |
| 6691 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6692 | { |
| 6693 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6694 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6695 | } |
| 6696 | |
| 6697 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 6698 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6699 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6700 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6701 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6702 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6703 | } |
| 6704 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6705 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6706 | struct net_device *netdev, const u8 *buf, |
| 6707 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6708 | { |
| 6709 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6710 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6711 | } |
| 6712 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 6713 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 6714 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6715 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6716 | { |
| 6717 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6718 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 6719 | } |
| 6720 | |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 6721 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
| 6722 | struct net_device *netdev, const u8 *buf, |
| 6723 | size_t len, gfp_t gfp) |
| 6724 | { |
| 6725 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6726 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); |
| 6727 | } |
| 6728 | |
| 6729 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, |
| 6730 | struct net_device *netdev, const u8 *buf, |
| 6731 | size_t len, gfp_t gfp) |
| 6732 | { |
| 6733 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 6734 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); |
| 6735 | } |
| 6736 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 6737 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 6738 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6739 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6740 | { |
| 6741 | struct sk_buff *msg; |
| 6742 | void *hdr; |
| 6743 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6744 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6745 | if (!msg) |
| 6746 | return; |
| 6747 | |
| 6748 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 6749 | if (!hdr) { |
| 6750 | nlmsg_free(msg); |
| 6751 | return; |
| 6752 | } |
| 6753 | |
| 6754 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6755 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6756 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 6757 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 6758 | |
| 6759 | if (genlmsg_end(msg, hdr) < 0) { |
| 6760 | nlmsg_free(msg); |
| 6761 | return; |
| 6762 | } |
| 6763 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6764 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6765 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6766 | return; |
| 6767 | |
| 6768 | nla_put_failure: |
| 6769 | genlmsg_cancel(msg, hdr); |
| 6770 | nlmsg_free(msg); |
| 6771 | } |
| 6772 | |
| 6773 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6774 | struct net_device *netdev, const u8 *addr, |
| 6775 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6776 | { |
| 6777 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6778 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6782 | struct net_device *netdev, const u8 *addr, |
| 6783 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6784 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6785 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 6786 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 6787 | } |
| 6788 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6789 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 6790 | struct net_device *netdev, const u8 *bssid, |
| 6791 | const u8 *req_ie, size_t req_ie_len, |
| 6792 | const u8 *resp_ie, size_t resp_ie_len, |
| 6793 | u16 status, gfp_t gfp) |
| 6794 | { |
| 6795 | struct sk_buff *msg; |
| 6796 | void *hdr; |
| 6797 | |
| 6798 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6799 | if (!msg) |
| 6800 | return; |
| 6801 | |
| 6802 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 6803 | if (!hdr) { |
| 6804 | nlmsg_free(msg); |
| 6805 | return; |
| 6806 | } |
| 6807 | |
| 6808 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6809 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6810 | if (bssid) |
| 6811 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6812 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 6813 | if (req_ie) |
| 6814 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6815 | if (resp_ie) |
| 6816 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6817 | |
| 6818 | if (genlmsg_end(msg, hdr) < 0) { |
| 6819 | nlmsg_free(msg); |
| 6820 | return; |
| 6821 | } |
| 6822 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6823 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6824 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6825 | return; |
| 6826 | |
| 6827 | nla_put_failure: |
| 6828 | genlmsg_cancel(msg, hdr); |
| 6829 | nlmsg_free(msg); |
| 6830 | |
| 6831 | } |
| 6832 | |
| 6833 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 6834 | struct net_device *netdev, const u8 *bssid, |
| 6835 | const u8 *req_ie, size_t req_ie_len, |
| 6836 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 6837 | { |
| 6838 | struct sk_buff *msg; |
| 6839 | void *hdr; |
| 6840 | |
| 6841 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 6842 | if (!msg) |
| 6843 | return; |
| 6844 | |
| 6845 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 6846 | if (!hdr) { |
| 6847 | nlmsg_free(msg); |
| 6848 | return; |
| 6849 | } |
| 6850 | |
| 6851 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6852 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6853 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6854 | if (req_ie) |
| 6855 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 6856 | if (resp_ie) |
| 6857 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 6858 | |
| 6859 | if (genlmsg_end(msg, hdr) < 0) { |
| 6860 | nlmsg_free(msg); |
| 6861 | return; |
| 6862 | } |
| 6863 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6864 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6865 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6866 | return; |
| 6867 | |
| 6868 | nla_put_failure: |
| 6869 | genlmsg_cancel(msg, hdr); |
| 6870 | nlmsg_free(msg); |
| 6871 | |
| 6872 | } |
| 6873 | |
| 6874 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 6875 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6876 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6877 | { |
| 6878 | struct sk_buff *msg; |
| 6879 | void *hdr; |
| 6880 | |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 6881 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6882 | if (!msg) |
| 6883 | return; |
| 6884 | |
| 6885 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 6886 | if (!hdr) { |
| 6887 | nlmsg_free(msg); |
| 6888 | return; |
| 6889 | } |
| 6890 | |
| 6891 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6892 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6893 | if (from_ap && reason) |
| 6894 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 6895 | if (from_ap) |
| 6896 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 6897 | if (ie) |
| 6898 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 6899 | |
| 6900 | if (genlmsg_end(msg, hdr) < 0) { |
| 6901 | nlmsg_free(msg); |
| 6902 | return; |
| 6903 | } |
| 6904 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6905 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6906 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6907 | return; |
| 6908 | |
| 6909 | nla_put_failure: |
| 6910 | genlmsg_cancel(msg, hdr); |
| 6911 | nlmsg_free(msg); |
| 6912 | |
| 6913 | } |
| 6914 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6915 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 6916 | struct net_device *netdev, const u8 *bssid, |
| 6917 | gfp_t gfp) |
| 6918 | { |
| 6919 | struct sk_buff *msg; |
| 6920 | void *hdr; |
| 6921 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6923 | if (!msg) |
| 6924 | return; |
| 6925 | |
| 6926 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 6927 | if (!hdr) { |
| 6928 | nlmsg_free(msg); |
| 6929 | return; |
| 6930 | } |
| 6931 | |
| 6932 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6933 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6934 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 6935 | |
| 6936 | if (genlmsg_end(msg, hdr) < 0) { |
| 6937 | nlmsg_free(msg); |
| 6938 | return; |
| 6939 | } |
| 6940 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6941 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6942 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6943 | return; |
| 6944 | |
| 6945 | nla_put_failure: |
| 6946 | genlmsg_cancel(msg, hdr); |
| 6947 | nlmsg_free(msg); |
| 6948 | } |
| 6949 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 6950 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
| 6951 | struct net_device *netdev, |
| 6952 | const u8 *macaddr, const u8* ie, u8 ie_len, |
| 6953 | gfp_t gfp) |
| 6954 | { |
| 6955 | struct sk_buff *msg; |
| 6956 | void *hdr; |
| 6957 | |
| 6958 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 6959 | if (!msg) |
| 6960 | return; |
| 6961 | |
| 6962 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 6963 | if (!hdr) { |
| 6964 | nlmsg_free(msg); |
| 6965 | return; |
| 6966 | } |
| 6967 | |
| 6968 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 6969 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 6970 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); |
| 6971 | if (ie_len && ie) |
| 6972 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); |
| 6973 | |
| 6974 | if (genlmsg_end(msg, hdr) < 0) { |
| 6975 | nlmsg_free(msg); |
| 6976 | return; |
| 6977 | } |
| 6978 | |
| 6979 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 6980 | nl80211_mlme_mcgrp.id, gfp); |
| 6981 | return; |
| 6982 | |
| 6983 | nla_put_failure: |
| 6984 | genlmsg_cancel(msg, hdr); |
| 6985 | nlmsg_free(msg); |
| 6986 | } |
| 6987 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6988 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 6989 | struct net_device *netdev, const u8 *addr, |
| 6990 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6991 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6992 | { |
| 6993 | struct sk_buff *msg; |
| 6994 | void *hdr; |
| 6995 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 6996 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 6997 | if (!msg) |
| 6998 | return; |
| 6999 | |
| 7000 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 7001 | if (!hdr) { |
| 7002 | nlmsg_free(msg); |
| 7003 | return; |
| 7004 | } |
| 7005 | |
| 7006 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7007 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7008 | if (addr) |
| 7009 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 7010 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
Arik Nemtsov | a66b98d | 2011-06-23 00:00:24 +0300 | [diff] [blame] | 7011 | if (key_id != -1) |
| 7012 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7013 | if (tsc) |
| 7014 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 7015 | |
| 7016 | if (genlmsg_end(msg, hdr) < 0) { |
| 7017 | nlmsg_free(msg); |
| 7018 | return; |
| 7019 | } |
| 7020 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7021 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7022 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 7023 | return; |
| 7024 | |
| 7025 | nla_put_failure: |
| 7026 | genlmsg_cancel(msg, hdr); |
| 7027 | nlmsg_free(msg); |
| 7028 | } |
| 7029 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7030 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 7031 | struct ieee80211_channel *channel_before, |
| 7032 | struct ieee80211_channel *channel_after) |
| 7033 | { |
| 7034 | struct sk_buff *msg; |
| 7035 | void *hdr; |
| 7036 | struct nlattr *nl_freq; |
| 7037 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7039 | if (!msg) |
| 7040 | return; |
| 7041 | |
| 7042 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 7043 | if (!hdr) { |
| 7044 | nlmsg_free(msg); |
| 7045 | return; |
| 7046 | } |
| 7047 | |
| 7048 | /* |
| 7049 | * Since we are applying the beacon hint to a wiphy we know its |
| 7050 | * wiphy_idx is valid |
| 7051 | */ |
| 7052 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 7053 | |
| 7054 | /* Before */ |
| 7055 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 7056 | if (!nl_freq) |
| 7057 | goto nla_put_failure; |
| 7058 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 7059 | goto nla_put_failure; |
| 7060 | nla_nest_end(msg, nl_freq); |
| 7061 | |
| 7062 | /* After */ |
| 7063 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 7064 | if (!nl_freq) |
| 7065 | goto nla_put_failure; |
| 7066 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 7067 | goto nla_put_failure; |
| 7068 | nla_nest_end(msg, nl_freq); |
| 7069 | |
| 7070 | if (genlmsg_end(msg, hdr) < 0) { |
| 7071 | nlmsg_free(msg); |
| 7072 | return; |
| 7073 | } |
| 7074 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7075 | rcu_read_lock(); |
| 7076 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 7077 | GFP_ATOMIC); |
| 7078 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 7079 | |
| 7080 | return; |
| 7081 | |
| 7082 | nla_put_failure: |
| 7083 | genlmsg_cancel(msg, hdr); |
| 7084 | nlmsg_free(msg); |
| 7085 | } |
| 7086 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7087 | static void nl80211_send_remain_on_chan_event( |
| 7088 | int cmd, struct cfg80211_registered_device *rdev, |
| 7089 | struct net_device *netdev, u64 cookie, |
| 7090 | struct ieee80211_channel *chan, |
| 7091 | enum nl80211_channel_type channel_type, |
| 7092 | unsigned int duration, gfp_t gfp) |
| 7093 | { |
| 7094 | struct sk_buff *msg; |
| 7095 | void *hdr; |
| 7096 | |
| 7097 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7098 | if (!msg) |
| 7099 | return; |
| 7100 | |
| 7101 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 7102 | if (!hdr) { |
| 7103 | nlmsg_free(msg); |
| 7104 | return; |
| 7105 | } |
| 7106 | |
| 7107 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7108 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7109 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); |
| 7110 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); |
| 7111 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7112 | |
| 7113 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) |
| 7114 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); |
| 7115 | |
| 7116 | if (genlmsg_end(msg, hdr) < 0) { |
| 7117 | nlmsg_free(msg); |
| 7118 | return; |
| 7119 | } |
| 7120 | |
| 7121 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7122 | nl80211_mlme_mcgrp.id, gfp); |
| 7123 | return; |
| 7124 | |
| 7125 | nla_put_failure: |
| 7126 | genlmsg_cancel(msg, hdr); |
| 7127 | nlmsg_free(msg); |
| 7128 | } |
| 7129 | |
| 7130 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, |
| 7131 | struct net_device *netdev, u64 cookie, |
| 7132 | struct ieee80211_channel *chan, |
| 7133 | enum nl80211_channel_type channel_type, |
| 7134 | unsigned int duration, gfp_t gfp) |
| 7135 | { |
| 7136 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
| 7137 | rdev, netdev, cookie, chan, |
| 7138 | channel_type, duration, gfp); |
| 7139 | } |
| 7140 | |
| 7141 | void nl80211_send_remain_on_channel_cancel( |
| 7142 | struct cfg80211_registered_device *rdev, struct net_device *netdev, |
| 7143 | u64 cookie, struct ieee80211_channel *chan, |
| 7144 | enum nl80211_channel_type channel_type, gfp_t gfp) |
| 7145 | { |
| 7146 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 7147 | rdev, netdev, cookie, chan, |
| 7148 | channel_type, 0, gfp); |
| 7149 | } |
| 7150 | |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 7151 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
| 7152 | struct net_device *dev, const u8 *mac_addr, |
| 7153 | struct station_info *sinfo, gfp_t gfp) |
| 7154 | { |
| 7155 | struct sk_buff *msg; |
| 7156 | |
| 7157 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7158 | if (!msg) |
| 7159 | return; |
| 7160 | |
| 7161 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { |
| 7162 | nlmsg_free(msg); |
| 7163 | return; |
| 7164 | } |
| 7165 | |
| 7166 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7167 | nl80211_mlme_mcgrp.id, gfp); |
| 7168 | } |
| 7169 | |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 7170 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
| 7171 | struct net_device *dev, const u8 *mac_addr, |
| 7172 | gfp_t gfp) |
| 7173 | { |
| 7174 | struct sk_buff *msg; |
| 7175 | void *hdr; |
| 7176 | |
| 7177 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7178 | if (!msg) |
| 7179 | return; |
| 7180 | |
| 7181 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 7182 | if (!hdr) { |
| 7183 | nlmsg_free(msg); |
| 7184 | return; |
| 7185 | } |
| 7186 | |
| 7187 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 7188 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 7189 | |
| 7190 | if (genlmsg_end(msg, hdr) < 0) { |
| 7191 | nlmsg_free(msg); |
| 7192 | return; |
| 7193 | } |
| 7194 | |
| 7195 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7196 | nl80211_mlme_mcgrp.id, gfp); |
| 7197 | return; |
| 7198 | |
| 7199 | nla_put_failure: |
| 7200 | genlmsg_cancel(msg, hdr); |
| 7201 | nlmsg_free(msg); |
| 7202 | } |
| 7203 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7204 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
| 7205 | struct net_device *netdev, u32 nlpid, |
| 7206 | int freq, const u8 *buf, size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7207 | { |
| 7208 | struct sk_buff *msg; |
| 7209 | void *hdr; |
| 7210 | int err; |
| 7211 | |
| 7212 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7213 | if (!msg) |
| 7214 | return -ENOMEM; |
| 7215 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7216 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7217 | if (!hdr) { |
| 7218 | nlmsg_free(msg); |
| 7219 | return -ENOMEM; |
| 7220 | } |
| 7221 | |
| 7222 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7223 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7224 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
| 7225 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7226 | |
| 7227 | err = genlmsg_end(msg, hdr); |
| 7228 | if (err < 0) { |
| 7229 | nlmsg_free(msg); |
| 7230 | return err; |
| 7231 | } |
| 7232 | |
| 7233 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
| 7234 | if (err < 0) |
| 7235 | return err; |
| 7236 | return 0; |
| 7237 | |
| 7238 | nla_put_failure: |
| 7239 | genlmsg_cancel(msg, hdr); |
| 7240 | nlmsg_free(msg); |
| 7241 | return -ENOBUFS; |
| 7242 | } |
| 7243 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7244 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
| 7245 | struct net_device *netdev, u64 cookie, |
| 7246 | const u8 *buf, size_t len, bool ack, |
| 7247 | gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7248 | { |
| 7249 | struct sk_buff *msg; |
| 7250 | void *hdr; |
| 7251 | |
| 7252 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 7253 | if (!msg) |
| 7254 | return; |
| 7255 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7256 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7257 | if (!hdr) { |
| 7258 | nlmsg_free(msg); |
| 7259 | return; |
| 7260 | } |
| 7261 | |
| 7262 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7263 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7264 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 7265 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
| 7266 | if (ack) |
| 7267 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); |
| 7268 | |
| 7269 | if (genlmsg_end(msg, hdr) < 0) { |
| 7270 | nlmsg_free(msg); |
| 7271 | return; |
| 7272 | } |
| 7273 | |
| 7274 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 7275 | return; |
| 7276 | |
| 7277 | nla_put_failure: |
| 7278 | genlmsg_cancel(msg, hdr); |
| 7279 | nlmsg_free(msg); |
| 7280 | } |
| 7281 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 7282 | void |
| 7283 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, |
| 7284 | struct net_device *netdev, |
| 7285 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 7286 | gfp_t gfp) |
| 7287 | { |
| 7288 | struct sk_buff *msg; |
| 7289 | struct nlattr *pinfoattr; |
| 7290 | void *hdr; |
| 7291 | |
| 7292 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7293 | if (!msg) |
| 7294 | return; |
| 7295 | |
| 7296 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7297 | if (!hdr) { |
| 7298 | nlmsg_free(msg); |
| 7299 | return; |
| 7300 | } |
| 7301 | |
| 7302 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7303 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7304 | |
| 7305 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7306 | if (!pinfoattr) |
| 7307 | goto nla_put_failure; |
| 7308 | |
| 7309 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 7310 | rssi_event); |
| 7311 | |
| 7312 | nla_nest_end(msg, pinfoattr); |
| 7313 | |
| 7314 | if (genlmsg_end(msg, hdr) < 0) { |
| 7315 | nlmsg_free(msg); |
| 7316 | return; |
| 7317 | } |
| 7318 | |
| 7319 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7320 | nl80211_mlme_mcgrp.id, gfp); |
| 7321 | return; |
| 7322 | |
| 7323 | nla_put_failure: |
| 7324 | genlmsg_cancel(msg, hdr); |
| 7325 | nlmsg_free(msg); |
| 7326 | } |
| 7327 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 7328 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 7329 | struct net_device *netdev, const u8 *bssid, |
| 7330 | const u8 *replay_ctr, gfp_t gfp) |
| 7331 | { |
| 7332 | struct sk_buff *msg; |
| 7333 | struct nlattr *rekey_attr; |
| 7334 | void *hdr; |
| 7335 | |
| 7336 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7337 | if (!msg) |
| 7338 | return; |
| 7339 | |
| 7340 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 7341 | if (!hdr) { |
| 7342 | nlmsg_free(msg); |
| 7343 | return; |
| 7344 | } |
| 7345 | |
| 7346 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7347 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7348 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 7349 | |
| 7350 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 7351 | if (!rekey_attr) |
| 7352 | goto nla_put_failure; |
| 7353 | |
| 7354 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 7355 | NL80211_REPLAY_CTR_LEN, replay_ctr); |
| 7356 | |
| 7357 | nla_nest_end(msg, rekey_attr); |
| 7358 | |
| 7359 | if (genlmsg_end(msg, hdr) < 0) { |
| 7360 | nlmsg_free(msg); |
| 7361 | return; |
| 7362 | } |
| 7363 | |
| 7364 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7365 | nl80211_mlme_mcgrp.id, gfp); |
| 7366 | return; |
| 7367 | |
| 7368 | nla_put_failure: |
| 7369 | genlmsg_cancel(msg, hdr); |
| 7370 | nlmsg_free(msg); |
| 7371 | } |
| 7372 | |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 7373 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 7374 | struct net_device *netdev, int index, |
| 7375 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 7376 | { |
| 7377 | struct sk_buff *msg; |
| 7378 | struct nlattr *attr; |
| 7379 | void *hdr; |
| 7380 | |
| 7381 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7382 | if (!msg) |
| 7383 | return; |
| 7384 | |
| 7385 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 7386 | if (!hdr) { |
| 7387 | nlmsg_free(msg); |
| 7388 | return; |
| 7389 | } |
| 7390 | |
| 7391 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7392 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7393 | |
| 7394 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 7395 | if (!attr) |
| 7396 | goto nla_put_failure; |
| 7397 | |
| 7398 | NLA_PUT_U32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index); |
| 7399 | NLA_PUT(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid); |
| 7400 | if (preauth) |
| 7401 | NLA_PUT_FLAG(msg, NL80211_PMKSA_CANDIDATE_PREAUTH); |
| 7402 | |
| 7403 | nla_nest_end(msg, attr); |
| 7404 | |
| 7405 | if (genlmsg_end(msg, hdr) < 0) { |
| 7406 | nlmsg_free(msg); |
| 7407 | return; |
| 7408 | } |
| 7409 | |
| 7410 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7411 | nl80211_mlme_mcgrp.id, gfp); |
| 7412 | return; |
| 7413 | |
| 7414 | nla_put_failure: |
| 7415 | genlmsg_cancel(msg, hdr); |
| 7416 | nlmsg_free(msg); |
| 7417 | } |
| 7418 | |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 7419 | void |
| 7420 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, |
| 7421 | struct net_device *netdev, const u8 *peer, |
| 7422 | u32 num_packets, gfp_t gfp) |
| 7423 | { |
| 7424 | struct sk_buff *msg; |
| 7425 | struct nlattr *pinfoattr; |
| 7426 | void *hdr; |
| 7427 | |
| 7428 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 7429 | if (!msg) |
| 7430 | return; |
| 7431 | |
| 7432 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 7433 | if (!hdr) { |
| 7434 | nlmsg_free(msg); |
| 7435 | return; |
| 7436 | } |
| 7437 | |
| 7438 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 7439 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 7440 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); |
| 7441 | |
| 7442 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 7443 | if (!pinfoattr) |
| 7444 | goto nla_put_failure; |
| 7445 | |
| 7446 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); |
| 7447 | |
| 7448 | nla_nest_end(msg, pinfoattr); |
| 7449 | |
| 7450 | if (genlmsg_end(msg, hdr) < 0) { |
| 7451 | nlmsg_free(msg); |
| 7452 | return; |
| 7453 | } |
| 7454 | |
| 7455 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 7456 | nl80211_mlme_mcgrp.id, gfp); |
| 7457 | return; |
| 7458 | |
| 7459 | nla_put_failure: |
| 7460 | genlmsg_cancel(msg, hdr); |
| 7461 | nlmsg_free(msg); |
| 7462 | } |
| 7463 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7464 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 7465 | unsigned long state, |
| 7466 | void *_notify) |
| 7467 | { |
| 7468 | struct netlink_notify *notify = _notify; |
| 7469 | struct cfg80211_registered_device *rdev; |
| 7470 | struct wireless_dev *wdev; |
| 7471 | |
| 7472 | if (state != NETLINK_URELEASE) |
| 7473 | return NOTIFY_DONE; |
| 7474 | |
| 7475 | rcu_read_lock(); |
| 7476 | |
| 7477 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
| 7478 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7479 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7480 | |
| 7481 | rcu_read_unlock(); |
| 7482 | |
| 7483 | return NOTIFY_DONE; |
| 7484 | } |
| 7485 | |
| 7486 | static struct notifier_block nl80211_netlink_notifier = { |
| 7487 | .notifier_call = nl80211_netlink_notify, |
| 7488 | }; |
| 7489 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7490 | /* initialisation/exit functions */ |
| 7491 | |
| 7492 | int nl80211_init(void) |
| 7493 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7494 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7495 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 7496 | err = genl_register_family_with_ops(&nl80211_fam, |
| 7497 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7498 | if (err) |
| 7499 | return err; |
| 7500 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7501 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 7502 | if (err) |
| 7503 | goto err_out; |
| 7504 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7505 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 7506 | if (err) |
| 7507 | goto err_out; |
| 7508 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 7509 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 7510 | if (err) |
| 7511 | goto err_out; |
| 7512 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 7513 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 7514 | if (err) |
| 7515 | goto err_out; |
| 7516 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7517 | #ifdef CONFIG_NL80211_TESTMODE |
| 7518 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 7519 | if (err) |
| 7520 | goto err_out; |
| 7521 | #endif |
| 7522 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7523 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 7524 | if (err) |
| 7525 | goto err_out; |
| 7526 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7527 | return 0; |
| 7528 | err_out: |
| 7529 | genl_unregister_family(&nl80211_fam); |
| 7530 | return err; |
| 7531 | } |
| 7532 | |
| 7533 | void nl80211_exit(void) |
| 7534 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7535 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7536 | genl_unregister_family(&nl80211_fam); |
| 7537 | } |